/* Solution to LSU EE 4770 (RTS) 1997 Homework 5, Problem 3 */ #include #include #include long random(void); /* This should be in the include file but isn't. */ #define WINDOW 100 /* Number of samples to compare. */ #define DIST 1.0 /* Distance between sensors, in meters. */ #define SIZE 1000 /* Number of samples to store. */ /* Routine below is core of solution. */ int best_match(int *samp_A, int *samp_B,int size) { int delta = 0; double lowest_err = 0; /* Initialize only to eliminate compiler warnings. */ int best_delta = -1; for( delta=0; delta 700 )printf("Flow velocity %f meters / second.\n",value); if( count == 720 )exit(0); } /* This routine contains the main loop. */ void cross_cor() { int samp_A[SIZE]; /* Hold values read from sensor A. */ int samp_B[SIZE]; /* Hold values read from sensor B. */ double next_sample_time; /* Time at which sensors will be read. */ double sample_interval = 0.1; /* Second, time between reading sensors. */ int i; for(i=0;i0; i--){ samp_A[i] = samp_A[i-1]; samp_B[i] = samp_B[i-1]; } /* Store new samples. */ samp_A[0]=a; samp_B[0]=b; /* Find number of sample times separating flow. */ delta = best_match( &samp_A[0], &samp_B[0], SIZE ); /* Compute flow velocity. */ flow_velocity = DIST / ( sample_interval * delta ); /* Display flow velocity. */ display(flow_velocity); /* Function will return at next_sample_time. */ sleep_until( next_sample_time ); } } int main(int argv, char **argc) { cross_cor(); /* Never returns. */ return 0; }