How to find the average peak values and plot?

조회 수: 24 (최근 30일)
Sohel Rana
Sohel Rana 2020년 12월 2일
댓글: Star Strider 2020년 12월 2일
Hi,
I got the attached plot from the code below. I would like to start the graph from 0.3 instead of 0 (y-axis) and then do the average of peaks. Average peaks should be like: average of first and second peak, then average of second and third peak and so on. Then plot them like the attached figure but with the average peak values. I would really apprecite if someone help me with that?
m=1000;
I1=0.5;
I2=0.3;
I3=0.2;
L1=70*m;
L2=140*m;
n1=2;
n2=1.444;
index=n2;
lam=m*(1.5:0.000001:1.6);
Q12=(4*pi*n1*L1)./lam;
Q23=(4*pi*n2*L2)./lam;
Q13=Q12+Q23;
I=I1+I2+I3+2*sqrt(I1*I2).*cos(Q12)+2*sqrt(I2*I3).*cos(Q23)+2*sqrt(I1*I3).*cos(Q13);
plot(lam,I);

채택된 답변

Star Strider
Star Strider 2020년 12월 2일
Try this:
m=1000;
I1=0.5;
I2=0.3;
I3=0.2;
L1=70*m;
L2=140*m;
n1=2;
n2=1.444;
index=n2;
lam=m*(1.5:0.000001:1.6);
Q12=(4*pi*n1*L1)./lam;
Q23=(4*pi*n2*L2)./lam;
Q13=Q12+Q23;
I=I1+I2+I3+2*sqrt(I1*I2).*cos(Q12)+2*sqrt(I2*I3).*cos(Q23)+2*sqrt(I1*I3).*cos(Q13);
I = I + 0.3;
[pks, locs] = findpeaks(I);
pks_avg_2 = movmean(pks,2, 'Endpoints','discard'); % Means Of Consecutive Points With Full Windows (Averaging Two Peaks) Only
figure
plot(lam,I)
hold on
stairs(lam(locs(1:numel(pks_avg_2))), pks_avg_2, '-r')
hold off
grid
legend('Data', 'Mean Of Two Consecuitve Peaks', 'Location','S')
.
  댓글 수: 2
Sohel Rana
Sohel Rana 2020년 12월 2일
Thank you for your quik response. I wanted to say I don't want to consider the values below 0.3 (or 0.5) from my original plot for any further analysis. Think my original plot starts from 0.5 as below (cut the graphs below 0.5). Can I get sine wave like graph (see in thin black line) instead of stair like? Can I get envelope of this graph which will look like sine wave?
Star Strider
Star Strider 2020년 12월 2일
I have absolutely no idea what you want.
Try this:
m=1000;
I1=0.5;
I2=0.3;
I3=0.2;
L1=70*m;
L2=140*m;
n1=2;
n2=1.444;
index=n2;
lam=m*(1.5:0.000001:1.6);
Q12=(4*pi*n1*L1)./lam;
Q23=(4*pi*n2*L2)./lam;
Q13=Q12+Q23;
I=I1+I2+I3+2*sqrt(I1*I2).*cos(Q12)+2*sqrt(I2*I3).*cos(Q23)+2*sqrt(I1*I3).*cos(Q13);
I = I + 0.3;
[pks1, locs1] = findpeaks(I, 'MinPeakHeight',2); % Peaks >= 2.0
[pks2, locs2] = findpeaks(I, 'MinPeakHeight',0.5); % Peaks >= 0.5
pks_avg_2 = movmean(pks2,2, 'Endpoints','discard'); % Means Of Consecutive Points With Full Windows (Averaging Two Peaks) Only
figure
plot(lam,I)
hold on
plot(lam(locs2(1:numel(pks_avg_2))), pks_avg_2, '-r')
plot(lam(locs1), pks1, '-k')
hold off
grid
legend('Data', 'Mean Of Two Consecuitve Peaks', 'Selected Peak Amplitudes (>=2)', 'Location','S')
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by