zero_crossings

Signal Processing Library

Program name: zero_crossings

Language: C

In file: parameter_lib.c

Objective: Calculate number of zero crossings in window of data

Usage: void zero_crossings(double *d_window_i, int window_size, FILE *outfile);

Parameters:

  • d_window_i - The double window of data
  • window_size - The length of the window
  • outfile - The open output file pointer

Mathematical Description:

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

User Comments

Code:

void zero_crossings(double *d_window_i, int window_size, FILE *outfile)
{
        int l, sgn[MAX_WINDOW_SIZE+1];
        int count=0;

        if(window_size >= MAX_WINDOW_SIZE) {
                fprintf(stderr, "Please increase MAX_WINDOW_SIZE in window_lib.h to at least %d\n", window_size+1);
                exit(1);
        }
        for(l = 0; l < window_size; l++) {
                if(d_window_i[l] >=0.0) {
                        sgn[l] = 1;
                } else {
                        sgn[l] = -1;
                }
        }
        for(l = 1; l < window_size; l++) {
                count += abs(sgn[l] - sgn[l-1]);
        }

        fprintf(outfile,"%d\n", count/2);
}