在Matlab中查找峰值 [英] find peak values in matlab

查看:746
本文介绍了在Matlab中查找峰值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们要确定向量中的峰,如下所示: 我们有一个实值,长度为m的一维向量,或者 x(1),x(2),..... x(m) 如果x(1)> x(2),那么对于第一个峰值(1)= x(1)显然;否则,我们将x(3)与x(2)进行比较,如果x(3)

suppose that we are determine peaks in vector as follow: we have real values one dimensional vector with length m,or x(1),x(2),.....x(m) if x(1)>x(2) then clearly for first point peak(1)=x(1);else we are then comparing x(3) to x(2),if x(3)

[ indexes,peaks]=function(x,m);
c=[];
b=[];
if  x(1)>x(2) 
    peaks(1)=x(1);
else

 for i=2:m-1
     if x(i+1)< x(i) & x(i)>x(i-1)
         peak(i)=x(i);
     end;
 end
end
end

峰值也可以通过下图确定:

peaks are determined also using following picture:

对不起,第二张图片可能不是三角形,只是A和C在一条直线上,但是这里的峰值是B,所以我无法继续编写代码以在矢量中找到峰值的算法.帮我继续

sorry for the second picture,maybe it is not triangle,just A and C are on straight line,but here peak is B,so i can't continue my code for writing algorithm to find peak values in my vector.please help me to continue it

x = [2 1 3 5 4 7 6 8 9] 在这里,因为第一个点比第二个点大,所以这意味着peak(1)= 2,那么我们将1与3进行比较,因为3大于1,我们现在想将5与3进行比较,所以也比较5到4,因为5大于4,则表示peak(2)= 5,因此,如果我们继续下一个峰为7,则最终峰为9 如果第一个元素少于第二个元素,那么我们将第二个元素与第三个元素进行比较,如果第二个元素同时大于第三个元素和第一个元素,则峰值为第二个,依此类推

x=[2 1 3 5 4 7 6 8 9] here because first point is more then second,so it means that peak(1)=2,then we are comparing 1 to 3,because 3 is more then 1,we now want to compare 5 to 3,it is also more,compare 5 to 4,because 5 is more then 4,then it means that peak(2)=5,,so if we continue next peak is 7,and final peak would be 9 in case of first element is less then second,then we are comparing second element to third one,if second is more then third and first elements at the same time,then peak is second,and so on

推荐答案

您可以尝试以下方法:

function [peaks,peak_indices] = find_peaks(row_vector)
    A = [min(row_vector)-1 row_vector min(row_vector)-1];
    j = 1;
    for i=1:length(A)-2
        temp=A(i:i+2);
        if(max(temp)==temp(2))
            peaks(j) = row_vector(i);
            peak_indices(j) = i;
            j = j+1;
        end
    end
end

将其另存为find_peaks.m

Save it as find_peaks.m

现在,您可以将其用作:

Now, you can use it as:

>> A = [2 1 3 5 4 7 6 8 9];
>> [peaks, peak_indices] = find_peaks(A)

peaks =

     2     5     7     9


peak_indices =

     1     4     6     9

但是,这也会给您高原"(相邻且相等的峰值").

This would however give you "plateaus" as well (adjacent and equal "peaks").

这篇关于在Matlab中查找峰值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆