Asked by Kaleesh Bala
on 26 Sep 2019

I have a graph that takes the values from first maximum peak point and plots it.Now,how shall i introduce a threshold or descend order from that point,so that it find the next highest peak ?

load('signal')

load('t')

S(:,1)=[ 5 15 35 45 5 15 35 45];

S(:,2)=[ 5 15 15 5 45 35 35 45];

for k=1:1:length(S)

[a(k),b2(k)]=max(abs(hilbert(signal(k,:)))); % first peak amp & index

[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(k,:))),t);

peaks(1,1)=a(k);

peaks(2,1)=t(b2(k));

j=2;

for i=1:length(PkTime)

if PkTime(i)>t(b2(k))

peaks(1,j)=PkAmp(i);

peaks(2,j)=PkTime(i);

j=j+1;

end

end

figure;

plot(t,(signal(k,:)),t,abs(hilbert(signal(k,:))),peaks(2,1),peaks(1,1),'ro')

hold on;grid on

plot(PkTime, PkAmp, '^r', 'MarkerFaceColor','r')

xlim([0 0.0006]);ylim([-inf inf])

hold on,plot(peaks(2,3),peaks(1,3),'ko')

end

Answer by Akira Agata
on 26 Sep 2019

Accepted Answer

How about combining envelope and findpeaks functions?

The following is an example.

% Load data

load('signal.mat');

load('t.mat');

% Calculate envelope and detect it's peaks

ul = envelope(signal(1,:));

[pks,locs] = findpeaks(ul,t,'MinPeakProminence',0.5e-3);

% Show the result

figure

plot(t,signal(1,:))

hold on

plot(t,ul)

scatter(locs,pks,'rv')

legend({'Original data','Envelope','Peaks'},'FontSize',12)

Akira Agata
on 30 Sep 2019

Then, how about the followings?

To detect peaks more precisely, I believe you need to tune parameters in findpeaks and envelope function and/or add more options to the findpeaks function.

% Load data

load('signal.mat');

load('t.mat');

% Calculate original peaks

[pks0,locs0] = findpeaks(signal(1,:),t);

% Calculate envelope and detect it's peaks (max: 6 peaks)

ul = envelope(signal(1,:),10,'peaks');

[pks,locs] = findpeaks(ul,t,...

'MinPeakProminence',0.1e-3,...

'NPeaks', 6);

% Find nearest original peak for each envelope peak

D = abs(locs0 - locs');

[~,pt] = min(D,[],2);

% Show the result

figure

plot(t,signal(1,:))

hold on

plot(t,ul,':')

scatter(locs0(pt),pks0(pt),'rv')

legend({'Original data','Envelope','Detected Peaks'},'FontSize',12)

Kaleesh Bala
on 30 Sep 2019

Thank you ! it works well for most signals !

I would like to know how to set that Minpeak prominence ,could you elaborate how to identify it and its significance.

Kaleesh Bala
on 1 Oct 2019

I would like to know how can I further choose different peak values and store them in a separate variable.

Currently pks0(pt) and locs0(pt) is stored as a variable in a linear way according to signal numbers.

But,is there a way using brush option or something to select single peak from a figure and store it as (1,1) and then another peak from another plot and store as (1,2)

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## darova (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/482273-how-can-i-set-a-descend-order-finding-peaks-to-my-graph#comment_750279

## Kaleesh Bala (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/482273-how-can-i-set-a-descend-order-finding-peaks-to-my-graph#comment_750281

## Kaleesh Bala (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/482273-how-can-i-set-a-descend-order-finding-peaks-to-my-graph#comment_750287

## darova (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/482273-how-can-i-set-a-descend-order-finding-peaks-to-my-graph#comment_750290

## Kaleesh Bala (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/482273-how-can-i-set-a-descend-order-finding-peaks-to-my-graph#comment_750461

Sign in to comment.