Signal Processing LibraryProgram name: energy Language: C In file: parameter_lib.c Objective: Calculate amount of energy present in a vector of data Usage: double energy(double *vector, int vector_width, int option); Parameters:
Return value
Mathematical Description: e = Sum(values squared) Comments: Routine is used to calculate the amount of energy in a window (array of data) Code: double energy(double *vector, int vector_width, int option) { int i; double d_energy; /* start with zero energy */ d_energy = 0.0; for(i = 0; i < vector_width; i++){ /* add the square of each element of the vector */ d_energy += (vector[i] * vector[i]); } if(option & 0x02) return(sqrt(d_energy)); if(option & 0x08) return(d_energy/vector_width); return(d_energy); } |
English Version > Documents and tutorials > D.Sc. projects > Routines for DSP > parameter_lib >