Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!know!samsung!uunet!seismo!beno!black From: black@beno.CSS.GOV (Mike Black) Newsgroups: comp.dsp Subject: Re: Peak detection Keywords: peak detect Message-ID: <49136@seismo.CSS.GOV> Date: 7 Oct 90 12:41:12 GMT References: <13060@accuvax.nwu.edu> Sender: usenet@seismo.CSS.GOV Distribution: usa Organization: Center for Seismic Studies, Arlington, VA Lines: 80 In article <13060@accuvax.nwu.edu> sandell@ferret.ils.nwu.edu (Greg Sandell) writes: >Can anybody tell me about the existence of any peak detection >algorithms? Below is an example of what I mean: > >B & E are real peaks, the rest are not. >|--------------------------------------------------| >| B | >| * C | >| * * * | >| * ** * E | >| * * * * | >| * * * ** | >| * * * * | >| * * * * | >| * * D * * | >| * * * * * | >| * * ** * * | >| A * * * * * | >|-------*-----------------*-----*--------------*---| (threshold) >| * * * * * | >| * * * * * * | >|* * * * *| >|* * *| >|--------------------------------------------------| > >A is not a real peak because it falls below my arbitrary >threshold. C is not real because it is subsidiary to >the fall away from real peak B, and D is not real >because it is subsidiary to the climb toward real >peak E. > What you appear to be interested in is a maximum peak detector with a conditional threshold crossing. I would approach it this way: #define N 25 /* # of points in waveform */ #define MIN 10 /* threshold minimum */ int peakloc=-1,crossthreshold=0; int wave[N],threshold=MIN,peakmax=-1; /* these could be floats too */ findpeaks() { int i; for(i=0;ithreshold) { /* cross threshold ? */ crossthreshold=1; } else { /* if on downside show our peak */ if (crossthreshold) { printf("Found peak at %d\n",peakloc); } crossthreshold=0; peakmax=-1; } if (crossthreshold && wave[i]-wave[i+1]>0 && wave[i]>peakmax) { peakmax = wave[i]; peakloc = i; } } if (peakmax > 0) { printf("Found peak? at %d\n",peakloc); } } main() { int i; for(i=0;i