second largest peak value

Kaleesh Bala

Kaleesh Bala (view profile)

さんによって質問されました 2019 年 6 月 12 日

Kaleesh Bala (view profile)

さんによって コメントされました 2019 年 8 月 6 日
Alex Mcaulley

Alex Mcaulley (view profile)

さんの 回答が採用されました
I'm getting the amp of second largest peak as correct but the time is wrong ?
How to obtain the second highest value X,Y from this and plot as already Y is correct ,X seems to be in wrong region?
signal(1,1:length(s.ans))=s.ans;
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(1,:))),t);
[highestPeak, indexOfHighestPeak] = max(PkAmp);
[a(1),b2]=max(abs(hilbert(signal(1,:))));
[a2(1),b6]=max(PkAmp(PkAmp<max(PkAmp))); % to get second largest peak value
% error is the time value calcluate and plotted wrong??
Highesttime(1,:) = t(b2);
Highest2time(1,:) = t(b6);
figure;
plot(t,(signal(1,:)),t,abs(hilbert(signal(1,:))),t(b2),a(1),'ro')
hold on
plot(PkTime, PkAmp, '^r', 'MarkerFaceColor','r')
xlim([0 0.0006]);ylim([-inf inf])
grid on
hold on,plot(t(b6),a2(1),'ko')
hold off

0 件のコメント

サインイン to comment.

2 件の回答

Answer by Alex Mcaulley

Alex Mcaulley (view profile)

on 12 Jun 2019

To obtain the coordinates of the second peak you just need:
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(1,:))),t);
[~,idx] = sort(PkAmp,'descend');
PkAmp(idx(2)) %Amplitude of the second peak
PkTime(idx(2)) %Time of the second peak

Alex Mcaulley

Alex Mcaulley (view profile)

on 13 Jun 2019
Using cell array:
[PkAmp{k}, PkTime{k}] = findpeaks(abs(hilbert(signal(k,:))),t);
Kaleesh Bala

Kaleesh Bala (view profile)

on 6 Aug 2019
Dear Alex
I have one more silly doubt in removing the index,I'm trying to find now the the largest time instead of Amp.So,I have used 'ascend' function which helps me to plot the the required time.
clc
clear all
close all
format long;
filenames={"30827"}
S(:,1) = [25 25 21.4 17.92 28.5 32.07 30 35 20 15];
S(:,2)= [10 15 8.5 12.07 8.5 12.07 5 5 5 5 ];
for i=1:numel(filenames)
signal(i,1:length(s(i).ans))=s(i).ans; % loading the signals from the scanning pts
end
for k=1:1:length(S)
[a(k),b2]=max(abs(hilbert(signal(k,:)))); % first peak amp & index
%finding the peaks
set(0,'DefaultFigureWindowStyle','docked')
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(k,:))),t);
[~,idx] = sort (PkTime, 'ascend' );
b6(k) = idx(4); % Index of the fourth largest peak
a6(k) = PkAmp(b6(k)); % Amplitude of the fourth largest peak
time4(k)= PkTime (b6(k)); % Time of the fourth largest peak
figure;
plot(t,(signal(k,:)),t,abs(hilbert(signal(k,:))),t(b2),a(k),'ro')
hold on;grid on
plot(PkTime, PkAmp, '^r', 'MarkerFaceColor','r')
%plotting 4th largest
hold on,plot(time4(k), a6(k),'ko')
hold off
end
As per the script it plots the 4th largest PKTime peak .But how to remove other PkTime based on highest "a" highest PKAmp and then recontinue to plot the graph by taking highest(PKAMP) as PKTIME 1?
Kaleesh Bala

Kaleesh Bala (view profile)

on 6 Aug 2019 サインイン to comment.

Answer by Steven Lord

Steven Lord (view profile)

on 13 Jun 2019

Use the islocalmax function with the 'MaxNumExtrema' option.

0 件のコメント

サインイン to comment.