#include #define M 5 float correlate(); main() { int f[100]; int g[100]; int gs,ge, fs, fe, n; int three, four, m; float num; init_corr (f,g); printf ("gs?"); scanf ("%d", &gs); printf ("ge?"); scanf ("%d", &ge); printf ("fs?"); scanf ("%d", &fs); printf ("fe?"); scanf ("%d", &fe); n = ge-gs; four = sum_funct (g, gs, n); three = sum_sqr (g, gs, n); printf ("three: %d", three); printf (" four: %d\n", four); for (m = -M; m <= M; m++) { num = correlate (three, four, f,g, gs,ge, fs+m, n); printf ("=========================================\n"); printf ("m: %d ----> correl_value: %f\n", m, num); printf ("=========================================\n"); } } init_corr(f,g) int f[]; int g[]; { int x; for (x=0;x<=45;x++) { if (x<8) f[x] = 0; else f[x] = x-8; if (x<4) g[x] = 0; else g[x] = x-4; /*printf ("f[%d]: %d", x, f[x]); printf (" --- g[%d]: %d\n", x, g[x]); */ } } sum_funct (array, s,n) int array[]; int s,n; { int x; int sum = 0; for (x=s;x<= s+n;x++) { sum = sum + array[x]; } return (sum); } sum_both (f,g, gs,ge, fs) int f[], g[]; int gs,ge, fs; { int x; int sum = 0; int ind; ind = fs; for (x=gs;x<=ge;x++) { sum = sum + (f[ind] * g[x]); ind++; } return (sum); } sum_sqr (array, s,n) int array[]; int s,n; { int x; int sum = 0; for (x=s;x<=s+n;x++) { sum = sum + (array[x] * array[x]); } return (sum); } float correlate(three, four, f,g, gs,ge, fs, n) int three,four; int f[],g[], gs,ge, fs, n; { int one, two, mt; float numer, denom, first, second; float correl_value; one = sum_funct (f, fs, n); two = sum_sqr (f, fs, n); mt = sum_both (f,g, gs,ge, fs); printf ("one: %d", one); printf (" two: %d", two); printf (" mt: %d\n", mt); numer = (float) (mt - (one * four)/n); first = two - ( (one*one) / n); second = three - ( (four*four) / n ); printf ("first %f second %f times: %f\n", first, second, first*second); denom = sqrt (first * second); correl_value = (float)numer/denom; printf ("numer: %f denom: %f corr: %f\n", numer, denom, correl_value); return ( (float)correl_value); }