Digital Signal Processing Library
Voice Lab
Program name: distortion
Language: C
In file: vector_lib.c
Objective: Find distortion of group of vectors in relation to a codebook
Usage: double distortion(double **cb_vector, int cb_length, int vector_width, double **vector, int number_vectors, int *vector_index, int options);
Parameters:
- cb_vector - The pointer to the codebook vector
- cb_length - The number of vectors in the codebook
- vector_width - Number of data points in each vactor
- vector - array of vectors to classify
- number_vectors - number of vectors in array
- vector_index - index of closest codebook vector for each vector in array
- options - normalization options
Return value
Mathematical Description:
Comments:
User Comments
Code:
double distortion(double **cb_vector, int cb_length, int vector_width, double **vector, int number_vectors, int *vector_index, int options) { int i, opt; double total_distortion;
// vector_classify(cb_vector, cb_length, vector_width, vector, number_vectors, vector_index);
total_distortion = 0.0;
//if(opt == 0) distance = distance; //if(opt == 2) distance = sqrt(distance); //if(opt == 8) distance /= vector_width; opt = 2;
for(i = 0; i < number_vectors; i++) { total_distortion += vector_distance(vector[i], cb_vector[vector_index[i]],\ vector_width, opt); number_adds++; }
number_adds--;
/* ** Compensate the number of additions, subtractions, and multiplications ** that are not necessary for the total distortion calculation */
for(i = 0; i < (number_vectors*vector_width); i++) { number_subs--; number_muls--; }
for(i = 0; i < (number_vectors*(vector_width-1)); i++) { number_adds--; }
if(options == 1) total_distortion /= number_vectors;
return(total_distortion); }
|