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: /* findintervals_sai.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: extern struct Peak peak[MAX_PEAKS]; /* all channels */ tomwalters@0: extern short interval[MAX_CHANNELS][MAX_DATA]; tomwalters@0: extern short clip[MAX_CHANNELS]; tomwalters@0: tomwalters@0: extern int weightflag; tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: void find_intervals(int total_peaks, int channel, int maximum_interval) tomwalters@0: { tomwalters@0: /* WARNING! Reverse */ tomwalters@0: tomwalters@0: int gap_samples; tomwalters@0: int n; tomwalters@0: tomwalters@0: tomwalters@0: for(n=2; n <= total_peaks; n++){ tomwalters@0: tomwalters@0: gap_samples = peak[n-1].sample - peak[n].sample; tomwalters@0: if (gap_samples >= maximum_interval) tomwalters@0: gap_samples = maximum_interval -1; tomwalters@0: interval[channel][gap_samples]++; tomwalters@0: tomwalters@0: /*---------------------------------*/ tomwalters@0: /* weighting options */ tomwalters@0: tomwalters@0: if (weightflag == OFF) tomwalters@0: interval[channel][gap_samples]++; tomwalters@0: else if (weightflag == NORMAL_WEIGHTING) tomwalters@0: interval[channel][gap_samples] += (short) (peak[n-1].mag + peak[n].mag) / 2 ; tomwalters@0: else if (weightflag == LOG_WEIGHTING) tomwalters@0: interval[channel][gap_samples] += (short) log((peak[n-1].mag + peak[n].mag)/2)/log(10.0); tomwalters@0: tomwalters@0: /*---------------------------------*/ tomwalters@0: /* clip check */ tomwalters@0: if ((interval[channel][gap_samples] > 32765) || tomwalters@0: (interval[channel][gap_samples] < 0)){ tomwalters@0: if (clip[channel] == OFF) { tomwalters@0: fprintf(stderr, " \nclipping: channel %i, interval %i samples.\n ", channel, gap_samples); tomwalters@0: clip[channel] = ON;} tomwalters@0: interval[channel][gap_samples] = 32765; tomwalters@0: } tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* The End */ tomwalters@0: /*------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: