![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
revised version of F746_SD_GraphicEqualizer
Dependencies: BSP_DISCO_F746NG F746_GUI F746_SAI_IO FrequencyResponseDrawer LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed
Fork of F746_SD_GraphicEqualizer by
MyClasses_Functions/BiquadGrEq.hpp@0:e953eb392151, 2016-04-27 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Wed Apr 27 13:56:39 2016 +0000
- Revision:
- 0:e953eb392151
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:e953eb392151 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 2 | // グラフィックイコライザで使う 1D タイプの 2 次のフィルタ |
MikamiUitOpen | 0:e953eb392151 | 3 | // Biquad filter of 1D type for graphic equalizer |
MikamiUitOpen | 0:e953eb392151 | 4 | // このクラスでは,係数は実行中に書き換えられることを想定している |
MikamiUitOpen | 0:e953eb392151 | 5 | // |
MikamiUitOpen | 0:e953eb392151 | 6 | // u[n] = x[n] + a1*u[n-1] + a2*u[n-2] |
MikamiUitOpen | 0:e953eb392151 | 7 | // y[n] = b0*u[n] + b1*u[n-1] + b2*u[n-2] |
MikamiUitOpen | 0:e953eb392151 | 8 | // x[n] : input signal |
MikamiUitOpen | 0:e953eb392151 | 9 | // y[n] : output signal |
MikamiUitOpen | 0:e953eb392151 | 10 | // |
MikamiUitOpen | 0:e953eb392151 | 11 | // 2016/03/25, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:e953eb392151 | 12 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 13 | |
MikamiUitOpen | 0:e953eb392151 | 14 | #ifndef IIR_BIQUAD_HPP |
MikamiUitOpen | 0:e953eb392151 | 15 | #define IIR_BIQUAD_HPP |
MikamiUitOpen | 0:e953eb392151 | 16 | |
MikamiUitOpen | 0:e953eb392151 | 17 | #include "mbed.h" |
MikamiUitOpen | 0:e953eb392151 | 18 | |
MikamiUitOpen | 0:e953eb392151 | 19 | // 2nd order IIR filter |
MikamiUitOpen | 0:e953eb392151 | 20 | namespace Mikami |
MikamiUitOpen | 0:e953eb392151 | 21 | { |
MikamiUitOpen | 0:e953eb392151 | 22 | class BiquadGrEq |
MikamiUitOpen | 0:e953eb392151 | 23 | { |
MikamiUitOpen | 0:e953eb392151 | 24 | public: |
MikamiUitOpen | 0:e953eb392151 | 25 | struct Coefs { float a1, a2, b0, b1, b2; }; |
MikamiUitOpen | 0:e953eb392151 | 26 | |
MikamiUitOpen | 0:e953eb392151 | 27 | BiquadGrEq() {} // Default constructore |
MikamiUitOpen | 0:e953eb392151 | 28 | |
MikamiUitOpen | 0:e953eb392151 | 29 | BiquadGrEq(const Coefs ck) |
MikamiUitOpen | 0:e953eb392151 | 30 | { |
MikamiUitOpen | 0:e953eb392151 | 31 | SetCoefficients(ck); |
MikamiUitOpen | 0:e953eb392151 | 32 | Clear(); |
MikamiUitOpen | 0:e953eb392151 | 33 | } |
MikamiUitOpen | 0:e953eb392151 | 34 | |
MikamiUitOpen | 0:e953eb392151 | 35 | void SetCoefficients(const Coefs ck) |
MikamiUitOpen | 0:e953eb392151 | 36 | { |
MikamiUitOpen | 0:e953eb392151 | 37 | a1_ = ck.a1; |
MikamiUitOpen | 0:e953eb392151 | 38 | a2_ = ck.a2; |
MikamiUitOpen | 0:e953eb392151 | 39 | b0_ = ck.b0; |
MikamiUitOpen | 0:e953eb392151 | 40 | b1_ = ck.b1; |
MikamiUitOpen | 0:e953eb392151 | 41 | b2_ = ck.b2; |
MikamiUitOpen | 0:e953eb392151 | 42 | } |
MikamiUitOpen | 0:e953eb392151 | 43 | |
MikamiUitOpen | 0:e953eb392151 | 44 | float Execute(float xn) |
MikamiUitOpen | 0:e953eb392151 | 45 | { |
MikamiUitOpen | 0:e953eb392151 | 46 | float un = xn + a1_*un1_ + a2_*un2_; |
MikamiUitOpen | 0:e953eb392151 | 47 | float yn = b0_*un + b1_*un1_ + b2_*un2_; |
MikamiUitOpen | 0:e953eb392151 | 48 | |
MikamiUitOpen | 0:e953eb392151 | 49 | un2_ = un1_; |
MikamiUitOpen | 0:e953eb392151 | 50 | un1_ = un; |
MikamiUitOpen | 0:e953eb392151 | 51 | |
MikamiUitOpen | 0:e953eb392151 | 52 | return yn; |
MikamiUitOpen | 0:e953eb392151 | 53 | } |
MikamiUitOpen | 0:e953eb392151 | 54 | |
MikamiUitOpen | 0:e953eb392151 | 55 | void Clear() { un1_ = un2_ = 0; } |
MikamiUitOpen | 0:e953eb392151 | 56 | |
MikamiUitOpen | 0:e953eb392151 | 57 | private: |
MikamiUitOpen | 0:e953eb392151 | 58 | float a1_, a2_, b0_, b1_, b2_; |
MikamiUitOpen | 0:e953eb392151 | 59 | float un1_, un2_; |
MikamiUitOpen | 0:e953eb392151 | 60 | |
MikamiUitOpen | 0:e953eb392151 | 61 | // disallow copy constructor |
MikamiUitOpen | 0:e953eb392151 | 62 | BiquadGrEq(const BiquadGrEq&); |
MikamiUitOpen | 0:e953eb392151 | 63 | }; |
MikamiUitOpen | 0:e953eb392151 | 64 | } |
MikamiUitOpen | 0:e953eb392151 | 65 | #endif // IIR_BIQUAD_HPP |
MikamiUitOpen | 0:e953eb392151 | 66 |