🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.dsp
Article #978

Re: Peak detection

#978
From: Mike Black
Date: Sun, 07 Oct 1990 12:41
80 lines
3297 bytes
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;i<N-1;i++) {
		if (wave[i]>threshold) { /* 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<N;i++) scanf("%d",&wave[i]);
	findpeaks();
}

I think this should run fairly fast for you but could use some optimization.
Mike...

--
-------------------------------------------------------------------------------
: usenet: black@beno.CSS.GOV   :  land line: 407-494-5853  : I want a computer:
: real home: Melbourne, FL     :  home line: 407-242-8619  : that does it all!:
-------------------------------------------------------------------------------
Technical Details
Message-ID: <49136@seismo.CSS.GOV>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!know!samsung!uunet!seismo!beno!black
References: <13060@accuvax.nwu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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