energy

Signal Processing Library

Program 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:

  • vector - The double vector of data
  • vector_width - The number of elements in the vector
  • option
    • 0 - sum of squares
    • 2 - square root of sum of squares;
    • 8 - sum of squares/vector_width;

Return value

  • calculated double value

Mathematical Description: e = Sum(values squared)

Comments: Routine is used to calculate the amount of energy in a window (array of data)

User Comments

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