![](/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
BilinearDesignLpfHpf/BilinearDesignLH.hpp@0:a9412b9e85b7, 2014-10-23 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Thu Oct 23 06:44:40 2014 +0000
- Revision:
- 0:a9412b9e85b7
- Child:
- 5:b291c4653eb9
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:a9412b9e85b7 | 1 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:a9412b9e85b7 | 2 | // Design of Butterworth LPF and HPF using bilinear transform -- Header |
MikamiUitOpen | 0:a9412b9e85b7 | 3 | // |
MikamiUitOpen | 0:a9412b9e85b7 | 4 | // 2014/06/29, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:a9412b9e85b7 | 5 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:a9412b9e85b7 | 6 | |
MikamiUitOpen | 0:a9412b9e85b7 | 7 | #ifndef BILINEAR_BUTTERWORTH_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 8 | #define BILINEAR_BUTTERWORTH_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 9 | |
MikamiUitOpen | 0:a9412b9e85b7 | 10 | #include "mbed.h" |
MikamiUitOpen | 0:a9412b9e85b7 | 11 | #include <complex> // requisite |
MikamiUitOpen | 0:a9412b9e85b7 | 12 | |
MikamiUitOpen | 0:a9412b9e85b7 | 13 | namespace Mikami |
MikamiUitOpen | 0:a9412b9e85b7 | 14 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 15 | typedef complex<float> Complex; // define "Complex" |
MikamiUitOpen | 0:a9412b9e85b7 | 16 | |
MikamiUitOpen | 0:a9412b9e85b7 | 17 | class BiliearDesign |
MikamiUitOpen | 0:a9412b9e85b7 | 18 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 19 | public: |
MikamiUitOpen | 0:a9412b9e85b7 | 20 | struct Coefs { float a1, a2, b1; }; |
MikamiUitOpen | 0:a9412b9e85b7 | 21 | enum Type { LPF, HPF }; |
MikamiUitOpen | 0:a9412b9e85b7 | 22 | |
MikamiUitOpen | 0:a9412b9e85b7 | 23 | // Constructor |
MikamiUitOpen | 0:a9412b9e85b7 | 24 | BiliearDesign(int order, float fs, Type pb) |
MikamiUitOpen | 0:a9412b9e85b7 | 25 | : PI_FS_(PI_/fs), ORDER_(order), PB_(pb) |
MikamiUitOpen | 0:a9412b9e85b7 | 26 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 27 | sP_ = new Complex[order/2]; |
MikamiUitOpen | 0:a9412b9e85b7 | 28 | zP_ = new Complex[order/2]; |
MikamiUitOpen | 0:a9412b9e85b7 | 29 | ck_ = new Coefs[order/2]; |
MikamiUitOpen | 0:a9412b9e85b7 | 30 | } |
MikamiUitOpen | 0:a9412b9e85b7 | 31 | |
MikamiUitOpen | 0:a9412b9e85b7 | 32 | // Destractor |
MikamiUitOpen | 0:a9412b9e85b7 | 33 | ~BiliearDesign() |
MikamiUitOpen | 0:a9412b9e85b7 | 34 | { |
MikamiUitOpen | 0:a9412b9e85b7 | 35 | delete[] sP_; |
MikamiUitOpen | 0:a9412b9e85b7 | 36 | delete[] zP_; |
MikamiUitOpen | 0:a9412b9e85b7 | 37 | delete[] ck_; |
MikamiUitOpen | 0:a9412b9e85b7 | 38 | } |
MikamiUitOpen | 0:a9412b9e85b7 | 39 | |
MikamiUitOpen | 0:a9412b9e85b7 | 40 | // Execution of design |
MikamiUitOpen | 0:a9412b9e85b7 | 41 | void Execute(float fc, Coefs c[], float& g); |
MikamiUitOpen | 0:a9412b9e85b7 | 42 | |
MikamiUitOpen | 0:a9412b9e85b7 | 43 | private: |
MikamiUitOpen | 0:a9412b9e85b7 | 44 | static const float PI_ = 3.1415926536f; |
MikamiUitOpen | 0:a9412b9e85b7 | 45 | const float PI_FS_; |
MikamiUitOpen | 0:a9412b9e85b7 | 46 | const int ORDER_; |
MikamiUitOpen | 0:a9412b9e85b7 | 47 | const Type PB_; |
MikamiUitOpen | 0:a9412b9e85b7 | 48 | |
MikamiUitOpen | 0:a9412b9e85b7 | 49 | Complex* sP_; // Poles on s-plane |
MikamiUitOpen | 0:a9412b9e85b7 | 50 | Complex* zP_; // Poles on z-plane |
MikamiUitOpen | 0:a9412b9e85b7 | 51 | Coefs* ck_; // Coefficients of transfer function for cascade form |
MikamiUitOpen | 0:a9412b9e85b7 | 52 | float gain_; // Gain factor for cascade form |
MikamiUitOpen | 0:a9412b9e85b7 | 53 | |
MikamiUitOpen | 0:a9412b9e85b7 | 54 | void Butterworth(); |
MikamiUitOpen | 0:a9412b9e85b7 | 55 | void Bilinear(float fc); |
MikamiUitOpen | 0:a9412b9e85b7 | 56 | void ToCascade(); |
MikamiUitOpen | 0:a9412b9e85b7 | 57 | void GetGain(); |
MikamiUitOpen | 0:a9412b9e85b7 | 58 | void GetCoefs(Coefs c[], float& gain); |
MikamiUitOpen | 0:a9412b9e85b7 | 59 | }; |
MikamiUitOpen | 0:a9412b9e85b7 | 60 | } |
MikamiUitOpen | 0:a9412b9e85b7 | 61 | #endif // BILINEAR_BUTTERWORTH_HPP |
MikamiUitOpen | 0:a9412b9e85b7 | 62 |