diff saitools/findintervals_nap.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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/saitools/findintervals_nap.c	Fri May 20 15:19:45 2011 +0100
@@ -0,0 +1,119 @@
+/*
+    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.
+*/
+
+/* findintervals_nap.c
+* 
+* Part of the temporal interval stuff.
+* 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 short interval[MAX_CHANNELS][MAX_DATA];
+extern short clip[MAX_CHANNELS];
+
+extern struct Peak peak_nap_right[MAX_CHANNELS];
+extern struct Peak peak_nap_left[MAX_CHANNELS];
+
+extern short freqdata[MAX_CHANNELS];                
+extern short previousfreqdata[MAX_CHANNELS];
+extern short previouspreviousfreqdata[MAX_CHANNELS];
+
+
+
+
+void find_intervals_nap(int channel, int maximum_interval, int sample)
+{
+  /* What this code does ..
+   *
+   * It looks at the current .nap point. If it's < the previous point, 
+   * AND the previous point is >= the one before that, then the PREVIOUS
+   * point is marked as a peak: peak_nap_right[channel].sample = previous
+   *                            peak_nap_left[channel] = peak_nap_right ..
+   * Then it measures the interval between these two points.
+   * If they are less than the maximum interval, then yippee ...
+   *
+   * The peaks so defined are neither "simple" or "complex", but an
+   * amalgam. A real "complex" peak has its true top interpoltaed. None
+   * of that goes on here. The right-most edge of the plateau
+   * is used ...
+   *
+   * Finally, it moves the columns one notch leftwards.
+   */
+
+  int gap_samples;
+
+
+
+
+  if ((freqdata[channel] < previousfreqdata[channel]) &&
+      (previousfreqdata[channel] >= previouspreviousfreqdata[channel])) {
+    
+    /* this is a peak */
+    peak_nap_left[channel].sample = peak_nap_right[channel].sample;
+    peak_nap_right[channel].sample = sample-1; 
+        /* -1 beacuse its the prevoius point */
+
+    /* don't want to do any of this if this is the FIRST peak of any 
+     * channeL; ie, ...left[].sample == 0 
+     */
+    if (peak_nap_left[channel].sample != 0 ) {
+      gap_samples = peak_nap_right[channel].sample - peak_nap_left[channel].sample;
+      if (gap_samples >= maximum_interval)
+	gap_samples = maximum_interval -1;
+      interval[channel][gap_samples]++; 
+      
+      /* clip check */
+      if (interval[channel][gap_samples] > 32760) {
+	if (clip[channel] == OFF) {
+	  fprintf(stderr, " \nclipping (%i %i) ", channel, gap_samples);
+	  clip[channel] = ON;}
+	interval[channel][gap_samples] --;
+      }
+    }
+  } /* is this a peak? 'if' */
+
+  /* move everything across anyway */
+  previouspreviousfreqdata[channel] = previousfreqdata[channel];
+  previousfreqdata[channel] = freqdata[channel];
+
+}
+
+
+
+
+
+
+/* The End ................................................................*/
+/*.........................................................................*/
+