【问题标题】:finding peak start and end points找到峰值起点和终点
【发布时间】:2017-08-25 13:29:55
【问题描述】:

我有一系列的峰Peaks image,我用matlab findpeaks 找到了峰点。

我需要找到峰宽和峰起点和终点吗?我已经开始了

使用此代码,但它没有给我正确的宽度计算:

% If the peak is at index 150
% Scan to the right.
for k = 151:length(signal)
   if signal(k) < signal(k-1)
    % Signal is starting to fall.
    rightIndex = k-1;
    break;
  end
end
% Scan to the left.
for k = 149: -1 : 1
   if signal(k) < signal(k+1)
     % Signal is starting to fall.
     leftIndex = k+1;
     break;
  end
end
peakWidth = rightIndex - leftIndex;

【问题讨论】:

  • 定义“宽度”。
  • 峰值信号开始和结束的区别
  • 好的,然后定义“开始和结束”;)
  • start 是数据值开始变化(下降)直到达到峰值的位置,从峰值开始信号开始上升直到变化较小的某个点。我已经上传了山峰的图片
  • @doe 定义“开始改变(下降)”和“直到某个点”,但用数学方法定义它们

标签: matlab signal-processing


【解决方案1】:

这里有两种宽度,由findpeaks 计算,一种通过将导数与零进行比较来计算:

% generate sinal
x = 0:0.1:10;
y = x.*sin(x/5).*sin(5*x.^2);
% get derivatives
dy = diff(y);
dx = diff(x);
dy_dx = [0 dy./dx];
% plot default annotated peaks
subplot(211);
findpeaks(y,x,'Annotate','extents');
% get peaks with width computed by 'findpeaks'
[pks,locs,peakWidth1,p] = findpeaks(y,x);
subplot(212);
plot(x,y);
hold on
plot(locs,pks,'*m')
% compute starting and ending points
startpoint = zeros(size(pks));
endpoint = zeros(size(pks));
for ii = 1:length(pks)
    plot(locs(ii) + peakWidth1(ii)*[-.5 .5],pks(ii) - p(ii)/2 + [0 0],'y')
    sp = find((x < locs(ii)) & (dy_dx <= 0),1,'last');
    if isempty(sp)
        sp = 1;
    end
    startpoint(ii) = sp;
    ep = find((x > locs(ii)) & (dy_dx >= 0),1,'first') - 1;
    if isempty(ep)
        ep = length(x);
    end
    endpoint(ii) = ep;
    plot(x(startpoint(ii)),y(startpoint(ii)),'og')
    plot(x(endpoint(ii)),y(endpoint(ii)),'sr')
end
% compute second type of width using ending and starting points
peakWidth2 = x(endpoint) - x(startpoint);

【讨论】:

  • 感谢@user2999345 完美回答。为什么 findpeaks 和导数为零的宽度值不同?哪个更准确?
  • 只是不同的实现,这取决于“宽度”的定义方式。您将宽度定义为“起点”和“终点”之间的 x 差异(使用导数定义),而 findpeaks 将其定义为信号 x 值与峰值一半突出的差异。
  • 半高宽代表峰值持续时间吗?
猜你喜欢
  • 2022-01-03
  • 2021-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多