// file: /data/courses/ece_1111/lectures/current/lecture_11/functs_00.cc // // local include files // #include "example.h" // function: myinit // // arguments: // float* v: data to be initialized // long N: number of points // // return: returns a boolean value indicating status // // This method initializes a matrix. // bool myinit(float* v, long N, FILE* fp) { // loop over the data // float sum = 0.0; for (long i = 0; i < N; i++) { float val = RANGE * (drand48() - OFFSET); sum += val * val; *v++ = val; } // output the variance // fprintf(fp, "variance = %f\n", sum / (float)N); // exit gracefully // return true; } // function: myprint // // arguments: // float* v: data // long N: number of data points // char* lbl: a label to tag each line // // return: returns a boolean value indicating status // // This method prints a signal. // bool myprint(float* v, long N, char* lbl, FILE* fp) { // loop over the data // for (long i = 0; i < N; i++) { // print the value // fprintf(stdout, "%s[%.5d] = %10.4f\n", lbl, i, v[i]); } // exit gracefully // return true; } // function: mycor // // arguments: // float* r: output autocorrelation function // float* sig: input signal // long N: number of signal points // long K: number of autocorrelation lags // // return: returns a boolean value indicating status // // This method computes an autocorrelation function. // bool mycor(float* r, float* sig, long N, long K) { // loop over the number of lags // for (long k = 0; k < K; k++) { // loop over the data // float sum = 0.0; for (long n = 0; n < N; n++) { sum += sig[n] * sig[n + k]; // sum += *s++ * y++; } // scale the output // r[k] = sum / (float)N; } // exit gracefully // return true; }