# Analysing PWM duty cycle of a signal

조회 수: 13 (최근 30일)
편집: Sherzaad Dinah 2023년 3월 24일
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 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이전 댓글 1개 표시이전 댓글 1개 숨기기
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 2023년 3월 24일
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?
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에서 MATLAB에 대해 자세히 알아보기

R2016b

### Community Treasure Hunt

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

Start Hunting!

Translated by