Mercurial > hg > aim92
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5242703e91d3 |
---|---|
1 /* | |
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 | |
3 =========================================================================== | |
4 | |
5 Permission to use, copy, modify, and distribute this software without fee | |
6 is hereby granted for research purposes, provided that this copyright | |
7 notice appears in all copies and in all supporting documentation, and that | |
8 the software is not redistributed for any fee (except for a nominal | |
9 shipping charge). Anyone wanting to incorporate all or part of this | |
10 software in a commercial product must obtain a license from the Medical | |
11 Research Council. | |
12 | |
13 The MRC makes no representations about the suitability of this | |
14 software for any purpose. It is provided "as is" without express or | |
15 implied warranty. | |
16 | |
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES | |
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
23 SOFTWARE. | |
24 */ | |
25 | |
26 /*-------------------------------------------------------------------------*/ | |
27 | |
28 /* removepeaks.c | |
29 * --------------- | |
30 * | |
31 * M.Akeroyd. Summer 1993. Revised Winter 1994. | |
32 */ | |
33 | |
34 | |
35 #include <stdio.h> | |
36 #include <string.h> | |
37 #include <stdlib.h> | |
38 | |
39 #include "tip.h" | |
40 | |
41 | |
42 | |
43 | |
44 extern struct Peak peak[MAX_PEAKS]; /* all channels */ | |
45 extern struct NextEvent nextevent[MAX_PEAKS]; | |
46 | |
47 extern double removevalue; | |
48 extern inputdata[MAX_DATA]; | |
49 | |
50 | |
51 | |
52 | |
53 /*-------------------------------------------------------------------------*/ | |
54 | |
55 | |
56 | |
57 int removepeaks(int total_peaks) | |
58 { | |
59 /* What this code does: | |
60 * | |
61 * Its purpose is to remove, completely, any peak that is very small, | |
62 * and perhaps shouldn't be regarded as being there. This is because they | |
63 * tend to clutter up tents and glaciers. | |
64 * | |
65 * So, go through each peak. If F(n) < (F[n-1]*removevalue) AND | |
66 * F(n) < (F[n+1]*removevalue), then remove it. Exactly what samples are | |
67 * removed depends on the next events. | |
68 * | |
69 * At the end, call findpeaksreverse again, to reset the nextevent counters. | |
70 * RETURN the new value of total_peaks. | |
71 * | |
72 */ | |
73 | |
74 int n; | |
75 int sample; | |
76 | |
77 /*--------------------------------------*/ | |
78 | |
79 for (n=2; n<total_peaks; n++) | |
80 | |
81 if ((peak[n].mag < (int) (peak[n-1].mag * removevalue)) && | |
82 (peak[n].mag < (int) (peak[n+1].mag * removevalue))) { | |
83 /* remove peak */ | |
84 for (sample = peak[n].sample; sample <= nextevent[n-1].sample; sample++) | |
85 inputdata[sample] = 0; | |
86 for (sample = peak[n].sample; sample >= nextevent[n].sample; sample--) | |
87 inputdata[sample] = 0; | |
88 } | |
89 | |
90 /*--------------------------------------*/ | |
91 | |
92 /* repeat for first and last peaks */ | |
93 | |
94 if (peak[1].mag < (int) (peak[2].mag * removevalue)) { | |
95 for (sample = peak[1].sample; sample >= nextevent[1].sample; sample--) | |
96 inputdata[sample] = 0; | |
97 } | |
98 | |
99 n=total_peaks; | |
100 | |
101 if (peak[n].mag < (int) (peak[n-1].mag * removevalue)) { | |
102 for (sample = peak[n].sample; sample <= nextevent[n-1].sample; sample++) | |
103 inputdata[sample] = 0; | |
104 } | |
105 | |
106 /*--------------------------------------*/ | |
107 | |
108 findpeaksreverse(); | |
109 return total_peaks; | |
110 | |
111 } | |
112 | |
113 | |
114 | |
115 | |
116 /* The End */ | |
117 /*-------------------------------------------------------------------------*/ |