view saitools/removepeaks.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
line wrap: on
line source
/*
    Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
    ===========================================================================

    Permission to use, copy, modify, and distribute this software without fee 
    is hereby granted for research purposes, provided that this copyright 
    notice appears in all copies and in all supporting documentation, and that 
    the software is not redistributed for any fee (except for a nominal 
    shipping charge). Anyone wanting to incorporate all or part of this 
    software in a commercial product must obtain a license from the Medical 
    Research Council.

    The MRC makes no representations about the suitability of this 
    software for any purpose.  It is provided "as is" without express or 
    implied warranty.
 
    THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 
    THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES 
    OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 
    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 
    SOFTWARE.
*/

/*-------------------------------------------------------------------------*/

/*  removepeaks.c
*  ---------------
*
* M.Akeroyd. Summer 1993. Revised Winter 1994.
*/


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "tip.h"




extern struct Peak peak[MAX_PEAKS];    /* all channels */
extern struct NextEvent nextevent[MAX_PEAKS];

extern double removevalue;
extern inputdata[MAX_DATA];




/*-------------------------------------------------------------------------*/



int removepeaks(int total_peaks)
{
  /* What this code does:
   * 
   * Its purpose is to remove, completely, any peak that is very small, 
   * and perhaps shouldn't be regarded as being there. This is because they 
   * tend to clutter up tents and glaciers.
   *
   * So, go through each peak. If F(n) < (F[n-1]*removevalue)  AND 
   * F(n) < (F[n+1]*removevalue), then remove it. Exactly what samples are 
   * removed depends on the next events.
   *
   * At the end, call findpeaksreverse again, to reset the nextevent counters.
   * RETURN the new value of total_peaks.
   *
   */

  int n;
  int sample;

/*--------------------------------------*/

  for (n=2; n<total_peaks; n++)
    
    if ((peak[n].mag < (int) (peak[n-1].mag * removevalue)) &&
	(peak[n].mag < (int) (peak[n+1].mag * removevalue))) {
      /* remove peak */
      for (sample = peak[n].sample; sample <= nextevent[n-1].sample; sample++)
	inputdata[sample] = 0;
      for (sample = peak[n].sample; sample >= nextevent[n].sample; sample--)
	inputdata[sample] = 0;
    }

/*--------------------------------------*/

  /* repeat for first and last peaks */

  if (peak[1].mag  < (int) (peak[2].mag * removevalue)) {
    for (sample = peak[1].sample; sample >= nextevent[1].sample; sample--)
      inputdata[sample] = 0;
  }

  n=total_peaks;

  if (peak[n].mag < (int) (peak[n-1].mag * removevalue)) {
     for (sample = peak[n].sample; sample <= nextevent[n-1].sample; sample++)
      inputdata[sample] = 0;
  }
    
/*--------------------------------------*/
  
  findpeaksreverse();
  return total_peaks;

}
      



/* The End */
/*-------------------------------------------------------------------------*/