Signal Processing LibraryProgram name: autocorrelation Language: C In file: parameter_lib.c Objective: Calculate the autocorrelation of the data in the window Usage: void autocorrelation(double *d_window_i, double ac[], int window_size, int order, int options); Parameters:
Mathematical Description: Comments: Routine to calculate the autocorrelation of the data in the window Code: void autocorrelation(double *d_window_i, double **ac, int window_size, int order, int options) { int i, n; double max, tmp; if(order >= MAX_ALLOC_SIZE) { fprintf(stderr, "Please increase MAX_ALLOC_SIZE in window_lib.h to at least %d\n", order+1); exit(1); } /* Information taken from Douglas O'Shaughnessy's book */ /* "Speech Communication, Human and Machine" 1990, page 37 equation 2.56 */ DEBUG_WRITE(1, "Calculating autocorrelation coefficients\n"); /* Calculation of autocorrelation coefficients */ /* One interesting fact is that there needs to be one more value than the order of the filter */ /* Therefore, the array needs to be dimensioned for order+1 locations */ /* Another interesting fact is that when i = 0 we have the sum of the squares */ max = 0.0; for(i = 0; i <= order; i++) { (*ac)[i] = 0.0; /* Start with a value of zero */ for(n = 0; n < (window_size-i); n++) { /* then sum the rest of the values */ (*ac)[i] += d_window_i[n]*d_window_i[n+i]; } if((*ac)[i] >= 0) { /* value is positive or zero */ if(max < (*ac)[i]) max = (*ac)[i]; } else { /* value is negative -> change sign */ if(max < (-(*ac)[i])) max = (-(*ac)[i]); } DEBUG_WRITE2(1, "max: %f\n", max); DEBUG_WRITE3(1, "(*ac)[%d]: %f\n", i, (*ac)[i]); } tmp = (*ac)[0]; if(options & 0x02) for(i = 0; i <= order; i++) (*ac)[i] /= tmp; if(options & 0x04) for(i = 0; i <= order; i++) (*ac)[i] /= max; if(options & 0x08) for(i = 0; i <= order; i++) (*ac)[i] /= window_size; return; } |
English Version > Documents and tutorials > D.Sc. projects > Routines for DSP > parameter_lib >