![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
FFT によるスペクトル解析器
Dependencies: Array_Matrix mbed SerialTxRxIntr UIT_FFT_Real DSP_ADDA
IIR_Filter/Biquad.hpp@0:91cc5a03f0ca, 2021-01-08 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Jan 08 02:27:46 2021 +0000
- Revision:
- 0:91cc5a03f0ca
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:91cc5a03f0ca | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:91cc5a03f0ca | 2 | // 縦続形 IIR フィルタの構成要素として使う 2 次の IIR フィルタ |
MikamiUitOpen | 0:91cc5a03f0ca | 3 | // b0 は 1 と仮定している |
MikamiUitOpen | 0:91cc5a03f0ca | 4 | // |
MikamiUitOpen | 0:91cc5a03f0ca | 5 | // 2020/11/04, Copyright (c) 2020 MIKAMI, Naoki |
MikamiUitOpen | 0:91cc5a03f0ca | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:91cc5a03f0ca | 7 | |
MikamiUitOpen | 0:91cc5a03f0ca | 8 | #include "mbed.h" |
MikamiUitOpen | 0:91cc5a03f0ca | 9 | |
MikamiUitOpen | 0:91cc5a03f0ca | 10 | #ifndef IIR_BIQUAD_HPP |
MikamiUitOpen | 0:91cc5a03f0ca | 11 | #define IIR_BIQUAD_HPP |
MikamiUitOpen | 0:91cc5a03f0ca | 12 | |
MikamiUitOpen | 0:91cc5a03f0ca | 13 | class Biquad |
MikamiUitOpen | 0:91cc5a03f0ca | 14 | { |
MikamiUitOpen | 0:91cc5a03f0ca | 15 | public: |
MikamiUitOpen | 0:91cc5a03f0ca | 16 | // フィルタの係数をまとめて扱うための構造体 |
MikamiUitOpen | 0:91cc5a03f0ca | 17 | struct Coefs { float a1, a2, b1, b2; }; |
MikamiUitOpen | 0:91cc5a03f0ca | 18 | |
MikamiUitOpen | 0:91cc5a03f0ca | 19 | // デフォルト・コンストラクタ |
MikamiUitOpen | 0:91cc5a03f0ca | 20 | // 係数は構造体 Ceofs で与える |
MikamiUitOpen | 0:91cc5a03f0ca | 21 | Biquad(const Coefs ck = (Coefs){0, 0, 0, 0}) |
MikamiUitOpen | 0:91cc5a03f0ca | 22 | : a1_(ck.a1), a2_(ck.a2), b1_(ck.b1), b2_(ck.b2), |
MikamiUitOpen | 0:91cc5a03f0ca | 23 | un1_(0), un2_(0) {} |
MikamiUitOpen | 0:91cc5a03f0ca | 24 | |
MikamiUitOpen | 0:91cc5a03f0ca | 25 | // 係数を個別に与えるコンストラクタ |
MikamiUitOpen | 0:91cc5a03f0ca | 26 | Biquad(float a1, float a2, float b1, float b2) |
MikamiUitOpen | 0:91cc5a03f0ca | 27 | : a1_(a1), a2_(a2), b1_(b1), b2_(b2), un1_(0), un2_(0) {} |
MikamiUitOpen | 0:91cc5a03f0ca | 28 | |
MikamiUitOpen | 0:91cc5a03f0ca | 29 | virtual ~Biquad() {} |
MikamiUitOpen | 0:91cc5a03f0ca | 30 | |
MikamiUitOpen | 0:91cc5a03f0ca | 31 | // 2 次のフィルタを実行する |
MikamiUitOpen | 0:91cc5a03f0ca | 32 | float Execute(float xn) |
MikamiUitOpen | 0:91cc5a03f0ca | 33 | { |
MikamiUitOpen | 0:91cc5a03f0ca | 34 | float un = xn + a1_*un1_ + a2_*un2_; |
MikamiUitOpen | 0:91cc5a03f0ca | 35 | float yn = un + b1_*un1_ + b2_*un2_; |
MikamiUitOpen | 0:91cc5a03f0ca | 36 | |
MikamiUitOpen | 0:91cc5a03f0ca | 37 | un2_ = un1_; |
MikamiUitOpen | 0:91cc5a03f0ca | 38 | un1_ = un; |
MikamiUitOpen | 0:91cc5a03f0ca | 39 | |
MikamiUitOpen | 0:91cc5a03f0ca | 40 | return yn; |
MikamiUitOpen | 0:91cc5a03f0ca | 41 | } |
MikamiUitOpen | 0:91cc5a03f0ca | 42 | |
MikamiUitOpen | 0:91cc5a03f0ca | 43 | // 係数を設定する |
MikamiUitOpen | 0:91cc5a03f0ca | 44 | void SetCoefs(const Coefs ck) |
MikamiUitOpen | 0:91cc5a03f0ca | 45 | { |
MikamiUitOpen | 0:91cc5a03f0ca | 46 | a1_ = ck.a1; |
MikamiUitOpen | 0:91cc5a03f0ca | 47 | a2_ = ck.a2; |
MikamiUitOpen | 0:91cc5a03f0ca | 48 | b1_ = ck.b1; |
MikamiUitOpen | 0:91cc5a03f0ca | 49 | b2_ = ck.b2; |
MikamiUitOpen | 0:91cc5a03f0ca | 50 | } |
MikamiUitOpen | 0:91cc5a03f0ca | 51 | |
MikamiUitOpen | 0:91cc5a03f0ca | 52 | // 内部変数(遅延器)のクリア |
MikamiUitOpen | 0:91cc5a03f0ca | 53 | void Clear() { un1_ = un2_ = 0; } |
MikamiUitOpen | 0:91cc5a03f0ca | 54 | |
MikamiUitOpen | 0:91cc5a03f0ca | 55 | private: |
MikamiUitOpen | 0:91cc5a03f0ca | 56 | float a1_, a2_, b1_, b2_; // フィルタの係数 |
MikamiUitOpen | 0:91cc5a03f0ca | 57 | float un1_, un2_; // 遅延器 |
MikamiUitOpen | 0:91cc5a03f0ca | 58 | |
MikamiUitOpen | 0:91cc5a03f0ca | 59 | // コピー・コンストラクタ禁止 |
MikamiUitOpen | 0:91cc5a03f0ca | 60 | Biquad(const Biquad&); |
MikamiUitOpen | 0:91cc5a03f0ca | 61 | }; |
MikamiUitOpen | 0:91cc5a03f0ca | 62 | #endif // IIR_BIQUAD_HPP |