![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Cutoff frequency variable LPF by IIR 6th-order Butterworth filter for ST Nucleo F401RE.
Dependencies: UIT_IIR_Filter UIT_ACM1602NI UITDSP_ADDA mbed UIT_AQM1602
Biquad.hpp@6:116f72cda0f4, 2015-07-25 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Jul 25 06:41:36 2015 +0000
- Revision:
- 6:116f72cda0f4
- Parent:
- 0:a9412b9e85b7
7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:a9412b9e85b7 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:a9412b9e85b7 | 2 | // Biquad filter for IIR filter of cascade structure |
MikamiUitOpen | 0:a9412b9e85b7 | 3 | // 2014/10/21, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:a9412b9e85b7 | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:a9412b9e85b7 | 5 | |
MikamiUitOpen | 0:a9412b9e85b7 | 6 | #ifndef IIR_BIQUAD_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 7 | #define IIR_BIQUAD_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 8 | |
MikamiUitOpen | 0:a9412b9e85b7 | 9 | #include "mbed.h" |
MikamiUitOpen | 0:a9412b9e85b7 | 10 | |
MikamiUitOpen | 0:a9412b9e85b7 | 11 | // 2nd order IIR filter |
MikamiUitOpen | 0:a9412b9e85b7 | 12 | class Biquad |
MikamiUitOpen | 0:a9412b9e85b7 | 13 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 14 | public: |
MikamiUitOpen | 0:a9412b9e85b7 | 15 | struct Coefs { float a1, a2, b1, b2; }; |
MikamiUitOpen | 0:a9412b9e85b7 | 16 | |
MikamiUitOpen | 0:a9412b9e85b7 | 17 | Biquad() {} // Default constructore |
MikamiUitOpen | 0:a9412b9e85b7 | 18 | |
MikamiUitOpen | 0:a9412b9e85b7 | 19 | Biquad(const Coefs ck) |
MikamiUitOpen | 0:a9412b9e85b7 | 20 | : a1_(ck.a1), a2_(ck.a2), b1_(ck.b1), b2_(ck.b2) |
MikamiUitOpen | 0:a9412b9e85b7 | 21 | { Clear(); } |
MikamiUitOpen | 0:a9412b9e85b7 | 22 | |
MikamiUitOpen | 0:a9412b9e85b7 | 23 | float Execute(float xn) |
MikamiUitOpen | 0:a9412b9e85b7 | 24 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 25 | float un = xn + a1_*un1_ + a2_*un2_; |
MikamiUitOpen | 0:a9412b9e85b7 | 26 | float yn = un + b1_*un1_ + b2_*un2_; |
MikamiUitOpen | 0:a9412b9e85b7 | 27 | |
MikamiUitOpen | 0:a9412b9e85b7 | 28 | un2_ = un1_; |
MikamiUitOpen | 0:a9412b9e85b7 | 29 | un1_ = un; |
MikamiUitOpen | 0:a9412b9e85b7 | 30 | |
MikamiUitOpen | 0:a9412b9e85b7 | 31 | return yn; |
MikamiUitOpen | 0:a9412b9e85b7 | 32 | } |
MikamiUitOpen | 0:a9412b9e85b7 | 33 | |
MikamiUitOpen | 0:a9412b9e85b7 | 34 | void Clear() { un1_ = un2_ = 0; } |
MikamiUitOpen | 0:a9412b9e85b7 | 35 | |
MikamiUitOpen | 0:a9412b9e85b7 | 36 | private: |
MikamiUitOpen | 0:a9412b9e85b7 | 37 | float a1_, a2_, b1_, b2_; |
MikamiUitOpen | 0:a9412b9e85b7 | 38 | float un1_, un2_; |
MikamiUitOpen | 0:a9412b9e85b7 | 39 | |
MikamiUitOpen | 0:a9412b9e85b7 | 40 | Biquad(const Biquad&); |
MikamiUitOpen | 0:a9412b9e85b7 | 41 | }; |
MikamiUitOpen | 0:a9412b9e85b7 | 42 | |
MikamiUitOpen | 0:a9412b9e85b7 | 43 | #endif // IIR_BIQUAD_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 44 |