Filter window subroutine. Uses hanning. More...
#include <filter.h>
Go to the source code of this file.
Functions | |
void | filter_window (double **filter_window, char *type, int width) |
Filter window subroutine. |
Filter window subroutine. Uses hanning.
Definition in file filter_window.c.
void filter_window | ( | double ** | filter_window, | |
char * | type, | |||
int | width | |||
) |
Filter window subroutine.
Uses hanning.
[out] | filter_window | Output filter window vector. |
[in] | type | Type of filter. Possible values: hanning. |
[in] | width | Width of filter. |
We are using a hanning filter.
Definition at line 58 of file filter_window.c.
References alloc_error().
Referenced by filter().
00058 { 00065 double scale_factor; /* Hanning filter scale factor. */ 00066 double alpha = 0.5; /* alpha value for hanning filter. */ 00067 double sum; /* Sum for normalizing filter window. */ 00068 int i; /* Loop counter. */ 00069 00070 /* Check if number is odd. If it is, make it even by adding one. */ 00071 if (width % 2 != 0) width++; 00072 00073 /* Allocate memory */ 00074 (*filter_window) = (double *) calloc(width, sizeof(double)); 00075 if ((*filter_window) == NULL) alloc_error(__FILE__, __LINE__); 00076 00077 if ( !strcmp(type, "hanning") ) { 00080 /* Scale factor */ 00081 scale_factor = 2.0 * M_PI / (double) width; 00082 00083 /* Compute filter window. */ 00084 sum = 0.0; 00085 for (i=0; i<width; i++) { 00086 /* Hanning definition */ 00087 (*filter_window)[i] = (alpha - 1.0) * cos( ((double) i) * scale_factor) + alpha; 00088 sum += (*filter_window)[i]; 00089 } 00090 00091 /* Normalizing to 1.0 */ 00092 for (i=0; i<width; i++) 00093 (*filter_window)[i] /= sum; 00094 } 00095 else { 00096 /* Unknown filter type */ 00097 (void) fprintf(stderr, "%s: ABORT: Unknown filtering type: %s\n", __FILE__, type); 00098 (void) abort(); 00099 } 00100 }