Skip to content

Instantly share code, notes, and snippets.

@Jacajack
Last active July 14, 2019 17:56
Show Gist options
  • Save Jacajack/9b2140549bf32ad5c610cc079df72138 to your computer and use it in GitHub Desktop.
Save Jacajack/9b2140549bf32ad5c610cc079df72138 to your computer and use it in GitHub Desktop.
IIR filter
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