Voice Lab

vector_distance

double vector_distance(double *vector1, double *vector2, int vector_width, int options)

{

int i, offset;

double distance, diff;

/* Euclidean distance is defined as the square root of the square of the diferences of each element */

/* For this routine to return the Euclidean distance between two vectors, OPTIONS must be set to two */

/* Information taken from Douglas O'Shaughnessy's book */

/* "Speech Communication, Human and Machine" 1990, page 315 equation 7.31 */

/* start with zero distance */

distance = 0.0;

offset = options & 0x01;

for(i = offset; i < (vector_width+offset); i++) {

/* add the square of the distance between each element of the vectors */

diff = (vector1[i] - vector2[i]);

distance += (diff * diff);

number_subs++;

number_muls++;

number_adds++;

}

number_adds--; /* compensate the first add with zero ??? */

if(options & 0x02) distance = sqrt(distance);

if(options & 0x08) distance /= vector_width;

return(distance);

}

## No comments:

## Post a Comment