Analysing PWM duty cycle of a signal

7 次查看(过去 30 天)
I have recorded a PWM signal from a given device.
I require to determine the duty cycle(s) of the signal as the transitions from one state to another.
How may I output the duty cycle of the PWM thoughout the signal?
I am using Matlab 2016b

回答(1 个)

David Hill
David Hill 2023-3-20
s=pwm>threshold;%pwm is your signal, threshold is when it is considered on or off
d=diff(s);
idx1=find(s,1);
idx2=find(d==-1);
idx3=find(d==1);
num=idx2-[idx1-1,idx3(1:end-1)];
denom=diff([idx1-1,idx3]);
dutyCycle=num./denom;
  3 个评论
David Hill
David Hill 2023-3-21
编辑:David Hill 2023-3-21
I assumed your data was a horizontal array. For a better response, attach your data.
s=CH01_01(:)';%convert to horizontal array
s=s>.75;
Sherzaad Dinah
Sherzaad Dinah 2023-3-22
编辑:Sherzaad Dinah 2023-3-24
Thank you for your help,
After making the change, I no longer have any error.
However all the calculated duty cycles are greater than 1?!
Is there something else that needs to be done with the data please?
I have attached the data as requested. Kindly please advise.
s = CH01_01(:)';
s=s>0.75;%pwm is your signal, threshold is when it is considered on or off
d=diff(s);
idx1=find(s,1);
idx2=find(d==-1);
idx3=find(d==1);
num=idx2-[idx1-1,idx3(1:end-1)];
denom=diff([idx1-1,idx3]);
dutyCycle=num./denom

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by