annotate saitools/trigger.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
rev   line source
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 /* trigger.c
tomwalters@0 27 *
tomwalters@0 28 * Part of the temporal regularity programs
tomwalters@0 29 *
tomwalters@0 30 * M.Akeroyd. Summer 1993. Revised Winter 1994.
tomwalters@0 31 */
tomwalters@0 32
tomwalters@0 33
tomwalters@0 34
tomwalters@0 35 #include <stdio.h>
tomwalters@0 36 #include <string.h>
tomwalters@0 37 #include <stdlib.h>
tomwalters@0 38
tomwalters@0 39 #include "tip.h"
tomwalters@0 40
tomwalters@0 41
tomwalters@0 42
tomwalters@0 43
tomwalters@0 44 extern struct Peak peak[MAX_PEAKS]; /* all channels */
tomwalters@0 45
tomwalters@0 46 extern int framewidth_samples; /* pwidth + nwidth * samplerate */
tomwalters@0 47 extern int pwidth; /* in msecs */
tomwalters@0 48 extern int nwidth; /* in msecs: NEGATIVE */
tomwalters@0 49 extern int samplerate; /* samples per sec */
tomwalters@0 50
tomwalters@0 51
tomwalters@0 52 extern char progname[MAX_STRING_LENGTH];
tomwalters@0 53
tomwalters@0 54
tomwalters@0 55
tomwalters@0 56
tomwalters@0 57
tomwalters@0 58
tomwalters@0 59 int find_trigger(int frame, int channel, int total_peaks)
tomwalters@0 60 {
tomwalters@0 61
tomwalters@0 62 /* What this code does:
tomwalters@0 63 *
tomwalters@0 64 * it looks for trigger peaks, at or near ImageTime = 0.
tomwalters@0 65 * First, it looks for a peak reasonably
tomwalters@0 66 * close to where the trigger-peak SHOULD be. If there isn't one there, then it reports
tomwalters@0 67 * a failure, and crashes.
tomwalters@0 68 * (No it doesn't: in fact it takes the fisrt peak to the right of the pre-defined trigger point).
tomwalters@0 69 *
tomwalters@0 70 * The peaknumber of the trigger_peak is RETURNed.
tomwalters@0 71 *
tomwalters@0 72 * Version of 1st June 1993.
tomwalters@0 73 */
tomwalters@0 74
tomwalters@0 75
tomwalters@0 76 int n_1;
tomwalters@0 77 int channel_1;
tomwalters@0 78 int trigger_sample; /* where the trigger of channel_1 is */
tomwalters@0 79 double trigger_double;
tomwalters@0 80 int trigger_found = OFF;
tomwalters@0 81 int trigger_peak; /* THIS IS RETURNED */
tomwalters@0 82
tomwalters@0 83
tomwalters@0 84 /* hack ... */
tomwalters@0 85 if (total_peaks == 0)
tomwalters@0 86 return 0;
tomwalters@0 87
tomwalters@0 88 /* First, find out where the trigger-point is :
tomwalters@0 89 * pwidth is in msecs, so divide that by 1000, multiply by sample, and you get pwidth in
tomwalters@0 90 * samples.
tomwalters@0 91 * So, trigger = that - 1 (-1 because the indexing is 0 to (framewidth_samples -1))
tomwalters@0 92 * Hope this integer arithemetic works */
tomwalters@0 93
tomwalters@0 94 trigger_double = (double) ((double) pwidth * (double) samplerate) / 1000.0 - 1;
tomwalters@0 95 trigger_sample = (int) trigger_double;
tomwalters@0 96 n_1 = total_peaks + 1;
tomwalters@0 97
tomwalters@0 98 /* find first peak to RIGHT of trigger (reverse, remember) */
tomwalters@0 99 while ((peak[--n_1].sample < trigger_sample))
tomwalters@0 100 ;
tomwalters@0 101
tomwalters@0 102 /* the next peak will be the trigger, at least on today's definition */
tomwalters@0 103 trigger_found = ON;
tomwalters@0 104 trigger_sample = peak[n_1].sample;
tomwalters@0 105 trigger_peak = n_1;
tomwalters@0 106
tomwalters@0 107 if (trigger_found == OFF ) {
tomwalters@0 108 fprintf(stderr, "%s: unable to find trigger point: frame %i channel %i\n", progname, frame, channel_1);
tomwalters@0 109 exit(-1);}
tomwalters@0 110
tomwalters@0 111 return trigger_peak;
tomwalters@0 112 }
tomwalters@0 113
tomwalters@0 114
tomwalters@0 115
tomwalters@0 116 /* The End .........................................................................*/
tomwalters@0 117 /*..................................................................................*/
tomwalters@0 118
tomwalters@0 119
tomwalters@0 120
tomwalters@0 121
tomwalters@0 122
tomwalters@0 123
tomwalters@0 124
tomwalters@0 125
tomwalters@0 126
tomwalters@0 127
tomwalters@0 128
tomwalters@0 129
tomwalters@0 130
tomwalters@0 131
tomwalters@0 132
tomwalters@0 133
tomwalters@0 134
tomwalters@0 135
tomwalters@0 136