資源簡介
自動尋峰谷算法matlab實現(xiàn),非常不錯,大師實現(xiàn)
代碼片段和文件信息
function?V=findvalleys(xySlopeThresholdAmpThresholdsmoothwidthpeakgroupsmoothtype)
%?function?P=findvalleys(xySlopeThresholdAmpThresholdsmoothwidthpeakgroupsmoothtype)
%?Function?to?locate?the?valleys?(mimnima)?in?a?noisy?x-y?time?series?data
%?set.??Detects?valleys?by?looking?for?upward?zero-crossings
%?in?the?first?derivative?that?exceed?SlopeThreshold.
%?Returns?list?(V)?containing?valley?number?and?position?
%?depth?and?width?of?each?valley.?Arguments?“slopeThreshold“
%?“ampThreshold“?and?“smoothwidth“?control?sensitivity.
%?Higher?values?will?neglect?smaller?features.?“Smoothwidth“?is
%?the?width?of?the?smooth?applied?before?valley?detection;?larger
%?values?ignore?narrow?features.?“Peakgroup“?is?the?number?points?
%?around?the?bottom?part?of?the?valley?that?are?fit?to?a?parabola?to
%?determine?the?valley?vertex?(x?and?y?at?lowest?point)?and?width.
%?The?argument?“smoothtype“?determines?the?smooth?algorithm:
%???If?smoothtype=1?rectangular?(sliding-average?or?boxcar)?
%???If?smoothtype=2?triangular?(2?passes?of?sliding-average)
%???If?smoothtype=3?pseudo-Gaussian?(3?passes?of?sliding-average)
%?See?http://terpconnect.umd.edu/~toh/spectrum/Smoothing.html?and?
%?http://terpconnect.umd.edu/~toh/spectrum/PeakFindingandMeasurement.htm
%?T.?C.?O‘Haver?Version?3.1?June?2013
if?nargin~=7;smoothtype=1;end??%?smoothtype=1?if?not?specified?in?argument
if?smoothtype>3;smoothtype=3;end
if?smoothtype<1;smoothtype=1;end?
smoothwidth=round(smoothwidth);
peakgroup=round(peakgroup);
d=fastsmooth(deriv(y)smoothwidthsmoothtype);
n=round(peakgroup/2+1);
V=[0?0?0?0?0];
vectorlength=length(y);
peak=1;
AmpTest=AmpThreshold;
for?j=smoothwidth:length(y)-smoothwidth
????if?sign(d(j))?????????if?d(j+1)-d(j)?>?SlopeThreshold*y(j)?%?if?slope?of?derivative?is?larger?than?SlopeThreshold
????????????if?y(j)?>?AmpTest??%?if?height?of?valley?is?larger?than?AmpThreshold
????????????????xx=zeros(size(peakgroup));yy=zeros(size(peakgroup));
????????????????for?k=1:peakgroup?%?Create?sub-group?of?points?near?valley
????????????????????groupindex=j+k-n+1;
????????????????????if?groupindex<1?groupindex=1;end
????????????????????if?groupindex>vectorlength?groupindex=vectorlength;end
????????????????????xx(k)=x(groupindex);yy(k)=y(groupindex);
????????????????end
????????????????[coefSMU]=polyfit(xxyy2);??%?Fit?parabola?to?sub-group?with?centering?and?scaling
????????????????c1=coef(3);c2=coef(2);c3=coef(1);
????????????????valleyX=-((MU(2).*c2/(2*c3))-MU(1));????%?Compute?valley?position?and?height?of?fitted?parabola
????????????????valleyY=(c1-(c2*c2/(4*c3)));
????????????????MeasuredWidth=norm(MU(2).*2.35482/(sqrt(2)*sqrt(-1*c3)));
????????????????%?if?the?valley?is?too?narrow?for?least-squares?technique?to?work
????????????????%?well?just?use?the?min?value?of?y?in?the?sub-group?of?points?near?valley.
????????????????if?peakgroup<5
????????????????????valley
評論
共有 條評論