tomwalters@0
|
1 /*
|
tomwalters@0
|
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
|
tomwalters@0
|
3 ===========================================================================
|
tomwalters@0
|
4
|
tomwalters@0
|
5 Permission to use, copy, modify, and distribute this software without fee
|
tomwalters@0
|
6 is hereby granted for research purposes, provided that this copyright
|
tomwalters@0
|
7 notice appears in all copies and in all supporting documentation, and that
|
tomwalters@0
|
8 the software is not redistributed for any fee (except for a nominal
|
tomwalters@0
|
9 shipping charge). Anyone wanting to incorporate all or part of this
|
tomwalters@0
|
10 software in a commercial product must obtain a license from the Medical
|
tomwalters@0
|
11 Research Council.
|
tomwalters@0
|
12
|
tomwalters@0
|
13 The MRC makes no representations about the suitability of this
|
tomwalters@0
|
14 software for any purpose. It is provided "as is" without express or
|
tomwalters@0
|
15 implied warranty.
|
tomwalters@0
|
16
|
tomwalters@0
|
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
tomwalters@0
|
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
tomwalters@0
|
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
|
tomwalters@0
|
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
tomwalters@0
|
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
tomwalters@0
|
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
tomwalters@0
|
23 SOFTWARE.
|
tomwalters@0
|
24 */
|
tomwalters@0
|
25
|
tomwalters@0
|
26 /* findintervals_nap.c
|
tomwalters@0
|
27 *
|
tomwalters@0
|
28 * Part of the temporal interval stuff.
|
tomwalters@0
|
29 * M.Akeroyd Summer 1993. Revised Winter 1994. */
|
tomwalters@0
|
30
|
tomwalters@0
|
31
|
tomwalters@0
|
32 #include <stdio.h>
|
tomwalters@0
|
33 #include <string.h>
|
tomwalters@0
|
34 #include <stdlib.h>
|
tomwalters@0
|
35
|
tomwalters@0
|
36 #include "tip.h"
|
tomwalters@0
|
37
|
tomwalters@0
|
38
|
tomwalters@0
|
39
|
tomwalters@0
|
40
|
tomwalters@0
|
41 extern struct Peak peak[MAX_PEAKS]; /* all channels */
|
tomwalters@0
|
42 extern short interval[MAX_CHANNELS][MAX_DATA];
|
tomwalters@0
|
43 extern short clip[MAX_CHANNELS];
|
tomwalters@0
|
44
|
tomwalters@0
|
45 extern struct Peak peak_nap_right[MAX_CHANNELS];
|
tomwalters@0
|
46 extern struct Peak peak_nap_left[MAX_CHANNELS];
|
tomwalters@0
|
47
|
tomwalters@0
|
48 extern short freqdata[MAX_CHANNELS];
|
tomwalters@0
|
49 extern short previousfreqdata[MAX_CHANNELS];
|
tomwalters@0
|
50 extern short previouspreviousfreqdata[MAX_CHANNELS];
|
tomwalters@0
|
51
|
tomwalters@0
|
52
|
tomwalters@0
|
53
|
tomwalters@0
|
54
|
tomwalters@0
|
55 void find_intervals_nap(int channel, int maximum_interval, int sample)
|
tomwalters@0
|
56 {
|
tomwalters@0
|
57 /* What this code does ..
|
tomwalters@0
|
58 *
|
tomwalters@0
|
59 * It looks at the current .nap point. If it's < the previous point,
|
tomwalters@0
|
60 * AND the previous point is >= the one before that, then the PREVIOUS
|
tomwalters@0
|
61 * point is marked as a peak: peak_nap_right[channel].sample = previous
|
tomwalters@0
|
62 * peak_nap_left[channel] = peak_nap_right ..
|
tomwalters@0
|
63 * Then it measures the interval between these two points.
|
tomwalters@0
|
64 * If they are less than the maximum interval, then yippee ...
|
tomwalters@0
|
65 *
|
tomwalters@0
|
66 * The peaks so defined are neither "simple" or "complex", but an
|
tomwalters@0
|
67 * amalgam. A real "complex" peak has its true top interpoltaed. None
|
tomwalters@0
|
68 * of that goes on here. The right-most edge of the plateau
|
tomwalters@0
|
69 * is used ...
|
tomwalters@0
|
70 *
|
tomwalters@0
|
71 * Finally, it moves the columns one notch leftwards.
|
tomwalters@0
|
72 */
|
tomwalters@0
|
73
|
tomwalters@0
|
74 int gap_samples;
|
tomwalters@0
|
75
|
tomwalters@0
|
76
|
tomwalters@0
|
77
|
tomwalters@0
|
78
|
tomwalters@0
|
79 if ((freqdata[channel] < previousfreqdata[channel]) &&
|
tomwalters@0
|
80 (previousfreqdata[channel] >= previouspreviousfreqdata[channel])) {
|
tomwalters@0
|
81
|
tomwalters@0
|
82 /* this is a peak */
|
tomwalters@0
|
83 peak_nap_left[channel].sample = peak_nap_right[channel].sample;
|
tomwalters@0
|
84 peak_nap_right[channel].sample = sample-1;
|
tomwalters@0
|
85 /* -1 beacuse its the prevoius point */
|
tomwalters@0
|
86
|
tomwalters@0
|
87 /* don't want to do any of this if this is the FIRST peak of any
|
tomwalters@0
|
88 * channeL; ie, ...left[].sample == 0
|
tomwalters@0
|
89 */
|
tomwalters@0
|
90 if (peak_nap_left[channel].sample != 0 ) {
|
tomwalters@0
|
91 gap_samples = peak_nap_right[channel].sample - peak_nap_left[channel].sample;
|
tomwalters@0
|
92 if (gap_samples >= maximum_interval)
|
tomwalters@0
|
93 gap_samples = maximum_interval -1;
|
tomwalters@0
|
94 interval[channel][gap_samples]++;
|
tomwalters@0
|
95
|
tomwalters@0
|
96 /* clip check */
|
tomwalters@0
|
97 if (interval[channel][gap_samples] > 32760) {
|
tomwalters@0
|
98 if (clip[channel] == OFF) {
|
tomwalters@0
|
99 fprintf(stderr, " \nclipping (%i %i) ", channel, gap_samples);
|
tomwalters@0
|
100 clip[channel] = ON;}
|
tomwalters@0
|
101 interval[channel][gap_samples] --;
|
tomwalters@0
|
102 }
|
tomwalters@0
|
103 }
|
tomwalters@0
|
104 } /* is this a peak? 'if' */
|
tomwalters@0
|
105
|
tomwalters@0
|
106 /* move everything across anyway */
|
tomwalters@0
|
107 previouspreviousfreqdata[channel] = previousfreqdata[channel];
|
tomwalters@0
|
108 previousfreqdata[channel] = freqdata[channel];
|
tomwalters@0
|
109
|
tomwalters@0
|
110 }
|
tomwalters@0
|
111
|
tomwalters@0
|
112
|
tomwalters@0
|
113
|
tomwalters@0
|
114
|
tomwalters@0
|
115
|
tomwalters@0
|
116
|
tomwalters@0
|
117 /* The End ................................................................*/
|
tomwalters@0
|
118 /*.........................................................................*/
|
tomwalters@0
|
119
|