tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal tomwalters@0: shipping charge). Anyone wanting to incorporate all or part of this tomwalters@0: software in a commercial product must obtain a license from the Medical tomwalters@0: Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or tomwalters@0: implied warranty. tomwalters@0: tomwalters@0: THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING tomwalters@0: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL tomwalters@0: THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES tomwalters@0: OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, tomwalters@0: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, tomwalters@0: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS tomwalters@0: SOFTWARE. tomwalters@0: */ tomwalters@0: tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: /* removepeaks.c tomwalters@0: * --------------- tomwalters@0: * tomwalters@0: * M.Akeroyd. Summer 1993. Revised Winter 1994. tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: tomwalters@0: #include "tip.h" tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: extern struct Peak peak[MAX_PEAKS]; /* all channels */ tomwalters@0: extern struct NextEvent nextevent[MAX_PEAKS]; tomwalters@0: tomwalters@0: extern double removevalue; tomwalters@0: extern inputdata[MAX_DATA]; tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: int removepeaks(int total_peaks) tomwalters@0: { tomwalters@0: /* What this code does: tomwalters@0: * tomwalters@0: * Its purpose is to remove, completely, any peak that is very small, tomwalters@0: * and perhaps shouldn't be regarded as being there. This is because they tomwalters@0: * tend to clutter up tents and glaciers. tomwalters@0: * tomwalters@0: * So, go through each peak. If F(n) < (F[n-1]*removevalue) AND tomwalters@0: * F(n) < (F[n+1]*removevalue), then remove it. Exactly what samples are tomwalters@0: * removed depends on the next events. tomwalters@0: * tomwalters@0: * At the end, call findpeaksreverse again, to reset the nextevent counters. tomwalters@0: * RETURN the new value of total_peaks. tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: int n; tomwalters@0: int sample; tomwalters@0: tomwalters@0: /*--------------------------------------*/ tomwalters@0: tomwalters@0: for (n=2; n= nextevent[n].sample; sample--) tomwalters@0: inputdata[sample] = 0; tomwalters@0: } tomwalters@0: tomwalters@0: /*--------------------------------------*/ tomwalters@0: tomwalters@0: /* repeat for first and last peaks */ tomwalters@0: tomwalters@0: if (peak[1].mag < (int) (peak[2].mag * removevalue)) { tomwalters@0: for (sample = peak[1].sample; sample >= nextevent[1].sample; sample--) tomwalters@0: inputdata[sample] = 0; tomwalters@0: } tomwalters@0: tomwalters@0: n=total_peaks; tomwalters@0: tomwalters@0: if (peak[n].mag < (int) (peak[n-1].mag * removevalue)) { tomwalters@0: for (sample = peak[n].sample; sample <= nextevent[n-1].sample; sample++) tomwalters@0: inputdata[sample] = 0; tomwalters@0: } tomwalters@0: tomwalters@0: /*--------------------------------------*/ tomwalters@0: tomwalters@0: findpeaksreverse(); tomwalters@0: return total_peaks; tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* The End */ tomwalters@0: /*-------------------------------------------------------------------------*/