Method one:
findpeaks function
PKS = findpeaks(data)
[PKS,locs] = findpeaks(data) — the number of peaks corresponding to PKS and locs
[…] = findpeaks(data,’minpeakheight’, MPH)– MPH sets the minimum peakheight
[…] = findpeaks(data,’minpeakdistance’, MPD)– MPD sets the minimum interval between two peaks
[…] = findpeaks(data,’threshold’,th)
[…] = findpeaks(data,’npeaks’,np)
[…] = findpeaks(data,’sortstr’, STR)
the command findpeaks is used to findpeaks of a vector that is greater than the value of two adjacent elements.
for example:
a=[1 3 2 5 6 8 5 3];
findpeaks(a),
returns 3 8
[v,l]= findbb2 (a),
returns
v=3 8
l=2 6
if a is a matrix, the values and locations of the peaks are listed in column search order.
For more information, see Help FindPeaks
Disadvantages:
You can only find the peak, you can’t find the trough.
Reproduced indicate the source: http://write.blog.csdn.net/postlist
Method 2:
IndMin=find(diff(sign(diff(data)))> 0) + 1;
IndMax=find(diff(sign(diff(data)))< 0) + 1;
where,
IndMin, data(IndMin) corresponds to the trough data
IndMax,data(IndMax) corresponds to the crest data
>> a=[1 3 2 5 6 8 5 3]
a =
1 3 2 5 6 8 5 3
>> IndMax=find(diff(sign(diff(a)))<0)+1
IndMax =
2 6
>> a(IndMax)
ans =
3 8
>> IndMin=find(diff(sign(diff(a)))>0)+1
IndMin =
3
>> a(IndMin)
ans =
2
Reprint with reference to:
http://write.blog.csdn.net/postlist