Saturday, June 19, 2010

autocorrelation

Digital Signal Processing Library

Voice Lab

autocorrelation


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 */
/* 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]);
}
}

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;
}


No comments:

Post a Comment