![](/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
Diff: BilinearDesignLpfHpf/BilinearDesignLH.hpp
- Revision:
- 0:a9412b9e85b7
- Child:
- 5:b291c4653eb9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BilinearDesignLpfHpf/BilinearDesignLH.hpp Thu Oct 23 06:44:40 2014 +0000 @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// Design of Butterworth LPF and HPF using bilinear transform -- Header +// +// 2014/06/29, Copyright (c) 2014 MIKAMI, Naoki +//------------------------------------------------------------------------------ + +#ifndef BILINEAR_BUTTERWORTH_HPP +#define BILINEAR_BUTTERWORTH_HPP + +#include "mbed.h" +#include <complex> // requisite + +namespace Mikami +{ + typedef complex<float> Complex; // define "Complex" + + class BiliearDesign + { + public: + struct Coefs { float a1, a2, b1; }; + enum Type { LPF, HPF }; + + // Constructor + BiliearDesign(int order, float fs, Type pb) + : PI_FS_(PI_/fs), ORDER_(order), PB_(pb) + { + sP_ = new Complex[order/2]; + zP_ = new Complex[order/2]; + ck_ = new Coefs[order/2]; + } + + // Destractor + ~BiliearDesign() + { + delete[] sP_; + delete[] zP_; + delete[] ck_; + } + + // Execution of design + void Execute(float fc, Coefs c[], float& g); + + private: + static const float PI_ = 3.1415926536f; + const float PI_FS_; + const int ORDER_; + const Type PB_; + + Complex* sP_; // Poles on s-plane + Complex* zP_; // Poles on z-plane + Coefs* ck_; // Coefficients of transfer function for cascade form + float gain_; // Gain factor for cascade form + + void Butterworth(); + void Bilinear(float fc); + void ToCascade(); + void GetGain(); + void GetCoefs(Coefs c[], float& gain); + }; +} +#endif // BILINEAR_BUTTERWORTH_HPP +