Defines a second order section of a biquadChain
biquadFilter.cpp@0:5484e3da74be, 2017-10-20 (annotated)
- Committer:
- tvlogman
- Date:
- Fri Oct 20 12:23:40 2017 +0000
- Revision:
- 0:5484e3da74be
- Child:
- 1:8589bd80071d
First version - work in progress
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tvlogman | 0:5484e3da74be | 1 | #include "biquadFilter.h" |
tvlogman | 0:5484e3da74be | 2 | #include "mbed.h" |
tvlogman | 0:5484e3da74be | 3 | |
tvlogman | 0:5484e3da74be | 4 | // Member function definitions |
tvlogman | 0:5484e3da74be | 5 | biquadFilter::biquadFilter(double B0, double B1, double B2, double A0, double A1, double A2):b0(B0),b1(B1),b2(B2),a0(A0),a1(A1),a2(A2){ |
tvlogman | 0:5484e3da74be | 6 | // Initializing filter coefficients |
tvlogman | 0:5484e3da74be | 7 | |
tvlogman | 0:5484e3da74be | 8 | v = 0; |
tvlogman | 0:5484e3da74be | 9 | y = 0; |
tvlogman | 0:5484e3da74be | 10 | v1 = 0; |
tvlogman | 0:5484e3da74be | 11 | v2 = 0; |
tvlogman | 0:5484e3da74be | 12 | } |
tvlogman | 0:5484e3da74be | 13 | |
tvlogman | 0:5484e3da74be | 14 | double biquadFilter :: filterInput(double u){ |
tvlogman | 0:5484e3da74be | 15 | v = u - a1*v1 - a2*v2; |
tvlogman | 0:5484e3da74be | 16 | y = b0*v + b1*v1 + b2*v2; |
tvlogman | 0:5484e3da74be | 17 | |
tvlogman | 0:5484e3da74be | 18 | // Prepare for next sample |
tvlogman | 0:5484e3da74be | 19 | v2 = v1; |
tvlogman | 0:5484e3da74be | 20 | v1 = v; |
tvlogman | 0:5484e3da74be | 21 | |
tvlogman | 0:5484e3da74be | 22 | return y; |
tvlogman | 0:5484e3da74be | 23 | } |