![](/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
IIR_Cascade.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 | // IIR filter ---- Cascade structure |
MikamiUitOpen | 0:a9412b9e85b7 | 3 | // 2014/10/23, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:a9412b9e85b7 | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:a9412b9e85b7 | 5 | |
MikamiUitOpen | 0:a9412b9e85b7 | 6 | #ifndef IIR_CASCADE_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 7 | #define IIR_CASCADE_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 8 | |
MikamiUitOpen | 0:a9412b9e85b7 | 9 | #include "mbed.h" |
MikamiUitOpen | 0:a9412b9e85b7 | 10 | #include "Biquad.hpp" |
MikamiUitOpen | 0:a9412b9e85b7 | 11 | |
MikamiUitOpen | 0:a9412b9e85b7 | 12 | namespace Mikami |
MikamiUitOpen | 0:a9412b9e85b7 | 13 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 14 | // IIR filter -- Cascade structure |
MikamiUitOpen | 0:a9412b9e85b7 | 15 | template<int order> class IirCascade |
MikamiUitOpen | 0:a9412b9e85b7 | 16 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 17 | private: |
MikamiUitOpen | 0:a9412b9e85b7 | 18 | Biquad hk_[order]; // Elements of cascade structure |
MikamiUitOpen | 0:a9412b9e85b7 | 19 | float g0_; // gain factor |
MikamiUitOpen | 0:a9412b9e85b7 | 20 | |
MikamiUitOpen | 0:a9412b9e85b7 | 21 | IirCascade(const IirCascade&); |
MikamiUitOpen | 0:a9412b9e85b7 | 22 | IirCascade& operator=(const IirCascade&); |
MikamiUitOpen | 0:a9412b9e85b7 | 23 | |
MikamiUitOpen | 0:a9412b9e85b7 | 24 | public: |
MikamiUitOpen | 0:a9412b9e85b7 | 25 | IirCascade() {} |
MikamiUitOpen | 0:a9412b9e85b7 | 26 | IirCascade(float g0, const Biquad::Coefs ck[]) |
MikamiUitOpen | 0:a9412b9e85b7 | 27 | { SetCoefs(g0, ck); } |
MikamiUitOpen | 0:a9412b9e85b7 | 28 | |
MikamiUitOpen | 0:a9412b9e85b7 | 29 | void SetCoefs(float g0, const Biquad::Coefs ck[]) |
MikamiUitOpen | 0:a9412b9e85b7 | 30 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 31 | g0_ = g0; |
MikamiUitOpen | 0:a9412b9e85b7 | 32 | for (int k=0; k<order; k++) |
MikamiUitOpen | 0:a9412b9e85b7 | 33 | hk_[k] = Biquad(ck[k]); |
MikamiUitOpen | 0:a9412b9e85b7 | 34 | } |
MikamiUitOpen | 0:a9412b9e85b7 | 35 | |
MikamiUitOpen | 0:a9412b9e85b7 | 36 | float Execute(float xn) |
MikamiUitOpen | 0:a9412b9e85b7 | 37 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 38 | float yn = g0_*xn; |
MikamiUitOpen | 0:a9412b9e85b7 | 39 | for (int k=0; k<order; k++) |
MikamiUitOpen | 0:a9412b9e85b7 | 40 | yn = hk_[k].Execute(yn); |
MikamiUitOpen | 0:a9412b9e85b7 | 41 | |
MikamiUitOpen | 0:a9412b9e85b7 | 42 | return yn; |
MikamiUitOpen | 0:a9412b9e85b7 | 43 | } |
MikamiUitOpen | 0:a9412b9e85b7 | 44 | |
MikamiUitOpen | 0:a9412b9e85b7 | 45 | void Clear() |
MikamiUitOpen | 0:a9412b9e85b7 | 46 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 47 | for (int k=0; k<order; k++) |
MikamiUitOpen | 0:a9412b9e85b7 | 48 | hk_[k].Clear(); |
MikamiUitOpen | 0:a9412b9e85b7 | 49 | } |
MikamiUitOpen | 0:a9412b9e85b7 | 50 | }; |
MikamiUitOpen | 0:a9412b9e85b7 | 51 | } |
MikamiUitOpen | 0:a9412b9e85b7 | 52 | #endif // IIR_CASCADE_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 53 | |
MikamiUitOpen | 0:a9412b9e85b7 | 54 | |
MikamiUitOpen | 0:a9412b9e85b7 | 55 |