Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to differentiate between a double peak and a single peak array in MATLAB?

Tags:

matlab

enter image description here

How to differentiate between a double peak and a single peak array?

Also if the array represents a double peak, how to find the minimum point between two peaks? The minimum points outside of the peaks (left of left peak and right of right peak) should not be considered in finding the minimum point.

like image 851
Sulla Avatar asked Jan 05 '12 20:01

Sulla


People also ask

How do you find peaks in Matlab?

pks = findpeaks( data ) returns a vector with the local maxima (peaks) of the input signal vector, data . A local peak is a data sample that is either larger than its two neighboring samples or is equal to Inf . The peaks are output in order of occurrence.

How does Matlab calculate peak to peak?

y = peak2peak( x ) returns the difference between the maximum and minimum values in x . y = peak2peak( x , dim ) computes the maximum-to-minimum differences of x along dimension dim .

What is the peaks function in Matlab?

The peaks function is useful for demonstrating graphics functions, such as contour , mesh , pcolor , and surf . It is obtained by translating and scaling Gaussian distributions and is defined as. z = 3 ( 1 − x ) 2 e − x 2 − ( y + 1 ) 2 − 10 ( x 5 − x 3 − y 5 ) e − x 2 − y 2 − 1 3 e − ( x + 1 ) 2 − y 2 .

How do you find peaks in a signal?

The 'max' function simply returns the largest single value in a vector. Findpeaks in the Signal Processing Toolbox can be used to find the values and indices of all the peaks in a vector that are higher than a specified peak height and are separated from their neighbors by a specified minimum distance.


1 Answers

I found PEAKDET function to be quite reliable and fast although it's loop based. It does not require pre-smoothing of noisy data, but finds local max and min extrema with difference larger than parameter delta.

Since PEAKDET runs from left to right it sometime misses peaks on the right site. To avoid it I prefer to run it twice:

%# some data
n = 100;
x = linspace(0,3*pi,n);
y = sin(x) + rand(1,n)/5;

%# run peakdet twice left-to-right and right-to-left
delta = 0.5;
[ymaxtab, ymintab] = peakdet(y, delta, x);
[ymaxtab2, ymintab2] = peakdet(y(end:-1:1), delta, x(end:-1:1));
ymaxtab = unique([ymaxtab; ymaxtab2],'rows');
ymintab = unique([ymintab; ymintab2],'rows');

%# plot the curve and show extreme points based on number of peaks
plot(x,y)
hold on
if size(ymaxtab,1) == 2 && size(ymintab,1) == 1 %# if double peak
    plot(ymintab(:,1),ymintab(:,2),'r.','markersize',30)
elseif size(ymaxtab,1) == 1 && size(ymintab,1) == 0 %# if single peak
    plot(ymaxtab(:,1),ymaxtab(:,2),'r.','markersize',30)
else %# if more (or less)
    plot(ymintab(:,1),ymintab(:,2),'r.','markersize',30)
    plot(ymaxtab(:,1),ymaxtab(:,2),'r.','markersize',30)
end
hold off

Two peaks example

like image 138
yuk Avatar answered Sep 21 '22 16:09

yuk