Matlab—寻找峰值函数介绍

来源:互联网 发布:淘宝买射钉枪警察找我 编辑:程序博客网 时间:2024/06/06 01:00

方法一:


findpeaks 寻找峰值函数


pks = findpeaks(data)

[pks,locs] = findpeaks(data) ------pks 对应峰值,locs 对应峰值位数

[...] = findpeaks(data,'minpeakheight',mph)----mph 设定峰值的最小高度

[...] = findpeaks(data,'minpeakdistance',mpd)----mpd 设定两峰值间的最小间隔数

[...] = findpeaks(data,'threshold',th)

[...] = findpeaks(data,'npeaks',np)

[...] = findpeaks(data,'sortstr',str)

命令findpeaks是用于查找向量中的波峰,即某一个元素比相邻两个元素的值都大。
例如:
a=[1 3 2 5 6 8 5 3];
findpeaks(a),
则返回 3 8
[v,l]=findpeaks(a),
则返回
v=3 8
l=2 6
如果a为一个矩阵,则按照列的搜索顺序列出波峰的值和位置。

更详细的可以参考help findpeaks

缺点:

       只能找波峰值,无法找波谷值。


转载注明出处:http://write.blog.csdn.net/postlist


方法二:

IndMin=find(diff(sign(diff(data)))>0)+1;
IndMax=find(diff(sign(diff(data)))<0)+1;


其中的,

IndMin, data(IndMin)对应的是波谷点的数据
IndMax,data(IndMax)对应的是波峰点的数据


[plain] view plain copy
  1. >> a=[1 3 2 5 6 8 5 3]  
  2.   
  3. a =  
  4.   
  5.      1     3     2     5     6     8     5     3  
  6.   
  7. >> IndMax=find(diff(sign(diff(a)))<0)+1  
  8.   
  9. IndMax =  
  10.   
  11.      2     6  
  12.   
  13. >> a(IndMax)  
  14.   
  15. ans =  
  16.   
  17.      3     8  
  18.   
  19. >> IndMin=find(diff(sign(diff(a)))>0)+1  
  20.   
  21. IndMin =  
  22.   
  23.      3  
  24.   
  25. >> a(IndMin)  
  26.   
  27. ans =  
  28.   
  29.      2  

出处:http://write.blog.csdn.net/postlist