【问题标题】:Matlab : Find Peaks of Multiple curves in a single imageMatlab:在单个图像中查找多条曲线的峰值
【发布时间】:2015-10-16 13:14:10
【问题描述】:

绘图中有三条曲线,我无法找到这三条曲线的峰值。

如何去寻找山峰?

以下是(x,y) 的值。

>> [x,y]
ans =
 1    86
 5    91
 8    94
12    98
15   101
19   103
21   104
23   105
28   106
28   184
31   191
34   105
39   103
41   101
41   210
42   212
43   214
44    99
45   215
47    96
48   216
49    93
51   215
54    87
54   213
56    84
56   210
60    78
65   191
66    43
68   184
69    47
71    49
73    52
73    54
77    56
82    60
85    62
87    63
89    64
92    65
98    66
104    65
107    64
109    63
112    62
114    60
119    56
125    49
127    47
130    43

绘制时将给出 3 条不同的曲线。但是,虽然找到最大值只返回最高曲线的峰值。

【问题讨论】:

  • 您是否总是为每条曲线获得一个峰值?也许在每条曲线上单独使用 max() 会更容易。另外,如果您提供一些代码会很好......
  • 这实际上是一组 (x,y) 值。 max() 函数只给出一条曲线。但我需要所有三个曲线。
  • 你能以某种方式分割曲线,得到三个单独的曲线吗?不幸的是,Matlab 不“知道”这里有三条曲线......
  • 如何分割曲线? (x,y) 值是由传感器获得的,不是用户定义的。
  • @lhcgeneva 我认为这就是重点。可以尝试拟合 3 个简单多项式的总和,但我猜这已经失败了。编辑:我意识到数据重叠,我看到了问题... Edit2 看看cumsum(y),并将3 个移位多项式的总和拟合到那个怎么样?这有意义吗?不,我想不会……我想在这种情况下,一组样本数据会很有帮助:)

标签: matlab max matlab-figure


【解决方案1】:

这是一个快速而肮脏的解决方案,绝对不通用,绝对慢,并且可能只节省一点手动工作。它沿着您的x 向量前进,并尝试根据连续点的距离将您的点分类为等价类。这可能比solution of anon0909 更通用一些,但对于分离度较差的数据仍然可能失败,并且需要手动调整以正确选择半径。 代码:

%sort to be on the safe side
[x inds]=sort(x);
y=y(inds);

eqradius=15; %the key parameter

equivs=[];
equivs(1).ind=1;
equivs(1).x=x(1); %redundant but useful
equivs(1).y=y(1); %redundant but useful

for i=2:length(x) % go over remaining points
    foundone=0;
    for eqclass=1:length(equivs) %go over found equivalence classes
        if norm([x(i) y(i)] - [equivs(eqclass).x(end) equivs(eqclass).y(end)])<eqradius
            foundone=1;
            equivs(eqclass).ind = [equivs(eqclass).ind; i];
            equivs(eqclass).x = [equivs(eqclass).x; x(i)];
            equivs(eqclass).y = [equivs(eqclass).y; y(i)];
        end
        if foundone==1
            break %break eqclass if
        end
    end

    if ~foundone
        equivs(length(equivs)+1).ind = i;
        equivs(length(equivs)).x = x(i);
        equivs(length(equivs)).y = y(i);
    %else
    %    continue % but the loop is already over
    end
end

%plot classes
figure;
eqclass=1;
hold all;
legendcell={};
for eqclass=1:length(equivs)
    plot(equivs(eqclass).x,equivs(eqclass).y,'o');
    legendcell{end+1}=num2str(eqclass);
end
legend(legendcell);

如您所见,在您的 eqradius=15 案例中,我们无意中将 2 号曲线分成 3 个单独的等价类,因此您仍然需要一些体力劳动。或者你可以尝试增加eqradius,但这最终会导致你的曲线相互拖尾。

这可能是比所引用的更好的解决方案的唯一情况是,当您在同一 y 波段中有两条曲线但在 x 中分离良好...

【讨论】:

    【解决方案2】:

    这些问题在很大程度上取决于您可以/不能假设的数据集中的特征,以及您希望在代码中自动化的程度。但是,从您提供的数据来看,您似乎可以简单地将每个凹凸按它们的 y 值分开,并取子集的每个最大值。即,像这样:

    y1 = y(y<=75);
    y2 = y(75<y<=150);
    y3 = y(y>150);
    max1 = max(y1);
    max2 = max(y2);
    max3 = max(y3);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-20
      • 2011-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多