Test of pmic GPA with filter
Dependencies: mbed
Fork of nucf446-cuboid-balance1_strong by
Diff: IIR_filter.cpp
- Revision:
- 10:600d7cf652e7
- Parent:
- 5:d6c7ccbbce78
- Child:
- 17:e9e75de5fe32
diff -r 30ee1d386a1d -r 600d7cf652e7 IIR_filter.cpp --- a/IIR_filter.cpp Thu Mar 22 17:34:18 2018 +0000 +++ b/IIR_filter.cpp Thu Mar 29 19:15:31 2018 +0000 @@ -7,6 +7,7 @@ init for: first order differentiatior: G(s) = s/(T*s + 1) first order lowpass with gain G(s) = K/(T*s + 1) second order lowpass with gain G(s) = K*w0^2/(s^2 + 2*D*w0*s + w0*w0) + nth order, with arbitrary values the billinear transformation is used for s -> z reseting the filter only makes sence for static signals, whatch out if you're using the differnetiator */ @@ -87,6 +88,37 @@ // dc-gain this->K = K; } + +IIR_filter::IIR_filter(float *b,float *a,int nb_, int na_){ + + // filter orders + this->nb = nb_-1; // Filter Order + this->na = na_; // Filter Order + + // filter coefficients + B = (float*)malloc((nb+1)*sizeof(float)); + A = (float*)malloc(na*sizeof(float)); + uk = (float*)malloc((nb+1)*sizeof(float)); + yk = (float*)malloc(na*sizeof(float)); + + for(int k=0;k<=nb;k++){ + B[k]=b[k]; + uk[k]=0.0f; + } + for(int k=0;k<na;k++){ + A[k] = a[k]; + yk[k] = 0.0f; + } + //B[0] = K*k0/k2; + //B[1] = 2.0f*B[0]; + //B[2] = B[0]; + //A[0] = (2.0f*k0 - 8.0f)/k2; + //A[1] = (k0 - k1 + 4.0f)/k2; + + // dc-gain + this->K = 1.0f; +} + IIR_filter::~IIR_filter() {}