Last active
July 14, 2019 17:56
-
-
Save Jacajack/9b2140549bf32ad5c610cc079df72138 to your computer and use it in GitHub Desktop.
IIR filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct iir_filter | |
{ | |
float *w; // w coefficients | |
float *a; // a coefficients | |
float *b; // b coefficients | |
int n; // filter size | |
}; | |
float iir_push( struct iir_filter *f, float x ) | |
{ | |
// Calculate value at the beginning of the delay line | |
f->w[0] = x; | |
for ( int i = 1; i < f->n; i++ ) | |
f->w[0] -= f->w[i] * f->a[i]; | |
// Calculate output value | |
float y = 0; | |
for ( int i = 0; i < f->n; i++ ) | |
y += f->w[i] * f->b[i]; | |
// Shift delay line | |
memmove( &f->w[1], &f->w[0], ( f->n - 1 ) * sizeof( f->w[0] ) ); | |
return y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment