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