⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findpeaks.m

📁 A fast customizable function for locating and measuring the peaks in noisy time-series signals. Adju
💻 M
字号:
function P=findpeaks(x,y,SlopeThreshold,AmpThreshold,smoothwidth,peakgroup)
% Function to locate the positive peaks in a noisy x-y data
% set.  Detects peaks by looking for downward zero-crossings
% in the third derivative that exceed SlopeThreshold.
% Determines the position, height, and width of
% each peak by fitting the log of top part of the peak with
% a parabola.  Returns list (P) containing peak number and
% position, height, and width of each peak. SlopeThreshold,
% AmpThreshold, and smoothwidth control sensitivity
% Higher values will neglect smaller features. Peakgroup
% is the number of points around the "top part" of the peak.
% T. C. O'Haver, 1995.  Version 1.2  Last revised August 24, 2006
smoothwidth=round(smoothwidth);
peakgroup=round(peakgroup);
d1=fastsmooth(deriv(y),smoothwidth);
d2=-fastsmooth(deriv(d1),smoothwidth);
d3=fastsmooth(deriv(d2),smoothwidth);
d=d3;
n=round(peakgroup/2+1);
P=[0 0 0 0];
peak=1;
AmpTest=AmpThreshold.*max(y);
for j=smoothwidth:length(y)-smoothwidth,
   if sign(d(j)) > sign (d(j+1)), % Detects zero-crossing
     if d(j)-d(j+1) > SlopeThreshold, % if slope of derivative is larger than SlopeThreshold
        if y(j) > AmpTest,  % if height of peak is larger than AmpThreshold
          for k=1:peakgroup, % Create sub-group of points near peak
            xx(k)=x(j+k-n+1);yy(k)=y(j+k-n+1);
          end
          [coef,S,MU]=polyfit(xx,log(abs(yy)),2);  % Fit parabola to log10 of sub-group with centering and scaling
          c1=coef(3);c2=coef(2);c3=coef(1);
          PeakX=-((MU(2).*c2/(2*c3))-MU(1));   % Compute peak position and height of fitted parabola
          PeakY=exp(c1-c3*(c2/(2*c3))^2);
          MeasuredWidth=MU(2).*2.35703/(sqrt(2)*sqrt(-1*c3));
          % Construct matrix P. One row for each peak 
          % detected, containing the peak number, peak 
          % position (x-value) and peak height (y-value).
          P(peak,:) = [round(peak) PeakX PeakY MeasuredWidth];
          peak=peak+1;
        end
      end
   end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -