Reprinting indicates the source:/postlist
Method 1:
findpeaks Find peak functions
pks = findpeaks(data)
[pks,locs] = findpeaks(data) -------pks corresponds to peak, locs corresponds to peak digits
[...] = findpeaks(data,'minpeakheight',mph)---mph Set the minimum height of the peak
[...] = findpeaks(data,'minpeakdistance',mpd)---mpd Set the minimum number of intervals between two peaks
[...] = findpeaks(data,'threshold',th)
[...] = findpeaks(data,'npeaks',np)
[...] = findpeaks(data,'sortstr',str)
The command findpeaks is used to find the peaks in a vector, that is, an element is larger than the value of two adjacent elements.
For example:
a=[1 3 2 5 6 8 5 3];
findpeaks(a),
Then return 3 8
[v,l]=findpeaks(a),
Then return
v=3 8
l=2 6
If a is a matrix, the values and positions of the peaks are listed in the search order of the columns.
For more details, please refer to help findpeaks
shortcoming:
Can only find wave peak value, but not wave trough value.
Reprinting indicates the source:/postlist
Method 2:
IndMin=find(diff(sign(diff(data)))>0)+1;
IndMax=find(diff(sign(diff(data)))<0)+1;
Among them,
IndMin, data (IndMin) corresponds to the data of the trough point
IndMax, data (IndMax) corresponds to data of the crest point
>> 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
Reprinting indicates the source: /postlist