📄 fir_algos.c
字号:
/****************************************************************************** Name: FirAlgs.c** Synopsis: FIR filter algorithms for use in C** Description:** This module provides functions to implement Finite Impulse Response (FIR)* filters using a variety of algorithms. ** These functions use most or all of the following input parameters:** input - the input sample data* ntaps - the number of taps in the filter * h[] - the FIR coefficient array* z[] - the FIR delay line array * *p_state - the "state" of the filter; initialize this to 0 before* the first call** The functions fir_basic, fir_shuffle, and fir_circular are not very* efficient in C, and are provided here mainly to illustrate FIR * algorithmic concepts. However, the functions fir_split, fir_double_z* and fir_double_h are all fairly efficient ways to implement FIR filters* in C.******************************************************************************/#include <stdio.h>#include <stdlib.h>#include "fir.h"/****************************************************************************//* clear: zeroize a FIR delay line *//****************************************************************************/void clear(int ntaps, SAMPLE z[]) { int ii; for (ii = 0; ii < ntaps; ii++) { z[ii] = 0; }}/***************************************************************************** fir_double_z: double the delay line so the FIR calculation always* operates on a flat buffer *****************************************************************************/SAMPLE fir_double_z(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[], int *p_state){ SAMPLE accum; int ii, state = *p_state; SAMPLE const *p_h, *p_z; /* store input at the beginning of the delay line as well as ntaps more */ z[state] = z[state + ntaps] = input; /* calculate the filter */ p_h = h; p_z = z + state; accum = 0; for (ii = 0; ii < ntaps; ii++) { accum += *p_h++ * *p_z++; } /* decrement state, wrapping if below zero */ if (--state < 0) { state += ntaps; } *p_state = state; /* return new state to caller */ return accum;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -