Last active
August 29, 2015 14:04
-
-
Save TimSC/e50875922e8fda7d0991 to your computer and use it in GitHub Desktop.
IIR Filtering
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
void NaiveIir(const vector<float> &b, const vector<float> &a, const vector<float> &in, vector<float> &out) | |
{ | |
//IIR filtering, unoptimised | |
//Call like scipy's lfilter | |
//http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lfilter.html | |
out.resize(0); | |
out.resize(in.size()); | |
for(int i=0; i < in.size(); i++) | |
{ | |
float tmp = 0.; | |
int j=0; | |
out[i] = 0.f; | |
for(j=0; j < b.size(); j++) | |
{ | |
if(i - j < 0) continue; | |
tmp += b[j] * in[i-j]; | |
} | |
for(j=1; j < a.size(); j++) | |
{ | |
if(i - j < 0) continue; | |
tmp -= a[j]*out[i-j]; | |
} | |
tmp /= a[0]; | |
out[i] = tmp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment