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