![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
スペクトログラム このプログラムの説明は,CQ出版社「トランジスタ技術」の2021年10月号から開始された連載記事「STM32マイコンではじめるPC計測」の中にあります.このプログラムといっしょに使うPC側のプログラムについても同誌を参照してください.
Dependencies: Array_Matrix mbed SerialTxRxIntr DSP_ADDA UIT_FFT_Real Window
IIR_Filter/Biquad.hpp@0:3bf11d2ab6ad, 2021-09-09 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Thu Sep 09 08:55:42 2021 +0000
- Revision:
- 0:3bf11d2ab6ad
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:3bf11d2ab6ad | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:3bf11d2ab6ad | 2 | // 縦続形 IIR フィルタの構成要素として使う 2 次の IIR フィルタ |
MikamiUitOpen | 0:3bf11d2ab6ad | 3 | // b0 は 1 と仮定している |
MikamiUitOpen | 0:3bf11d2ab6ad | 4 | // |
MikamiUitOpen | 0:3bf11d2ab6ad | 5 | // 2020/11/04, Copyright (c) 2020 MIKAMI, Naoki |
MikamiUitOpen | 0:3bf11d2ab6ad | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:3bf11d2ab6ad | 7 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 8 | #include "mbed.h" |
MikamiUitOpen | 0:3bf11d2ab6ad | 9 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 10 | #ifndef IIR_BIQUAD_HPP |
MikamiUitOpen | 0:3bf11d2ab6ad | 11 | #define IIR_BIQUAD_HPP |
MikamiUitOpen | 0:3bf11d2ab6ad | 12 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 13 | class Biquad |
MikamiUitOpen | 0:3bf11d2ab6ad | 14 | { |
MikamiUitOpen | 0:3bf11d2ab6ad | 15 | public: |
MikamiUitOpen | 0:3bf11d2ab6ad | 16 | // フィルタの係数をまとめて扱うための構造体 |
MikamiUitOpen | 0:3bf11d2ab6ad | 17 | struct Coefs { float a1, a2, b1, b2; }; |
MikamiUitOpen | 0:3bf11d2ab6ad | 18 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 19 | // デフォルト・コンストラクタ |
MikamiUitOpen | 0:3bf11d2ab6ad | 20 | // 係数は構造体 Ceofs で与える |
MikamiUitOpen | 0:3bf11d2ab6ad | 21 | Biquad(const Coefs ck = (Coefs){0, 0, 0, 0}) |
MikamiUitOpen | 0:3bf11d2ab6ad | 22 | : a1_(ck.a1), a2_(ck.a2), b1_(ck.b1), b2_(ck.b2), |
MikamiUitOpen | 0:3bf11d2ab6ad | 23 | un1_(0), un2_(0) {} |
MikamiUitOpen | 0:3bf11d2ab6ad | 24 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 25 | // 係数を個別に与えるコンストラクタ |
MikamiUitOpen | 0:3bf11d2ab6ad | 26 | Biquad(float a1, float a2, float b1, float b2) |
MikamiUitOpen | 0:3bf11d2ab6ad | 27 | : a1_(a1), a2_(a2), b1_(b1), b2_(b2), un1_(0), un2_(0) {} |
MikamiUitOpen | 0:3bf11d2ab6ad | 28 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 29 | virtual ~Biquad() {} |
MikamiUitOpen | 0:3bf11d2ab6ad | 30 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 31 | // 2 次のフィルタを実行する |
MikamiUitOpen | 0:3bf11d2ab6ad | 32 | float Execute(float xn) |
MikamiUitOpen | 0:3bf11d2ab6ad | 33 | { |
MikamiUitOpen | 0:3bf11d2ab6ad | 34 | float un = xn + a1_*un1_ + a2_*un2_; |
MikamiUitOpen | 0:3bf11d2ab6ad | 35 | float yn = un + b1_*un1_ + b2_*un2_; |
MikamiUitOpen | 0:3bf11d2ab6ad | 36 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 37 | un2_ = un1_; |
MikamiUitOpen | 0:3bf11d2ab6ad | 38 | un1_ = un; |
MikamiUitOpen | 0:3bf11d2ab6ad | 39 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 40 | return yn; |
MikamiUitOpen | 0:3bf11d2ab6ad | 41 | } |
MikamiUitOpen | 0:3bf11d2ab6ad | 42 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 43 | // 係数を設定する |
MikamiUitOpen | 0:3bf11d2ab6ad | 44 | void SetCoefs(const Coefs ck) |
MikamiUitOpen | 0:3bf11d2ab6ad | 45 | { |
MikamiUitOpen | 0:3bf11d2ab6ad | 46 | a1_ = ck.a1; |
MikamiUitOpen | 0:3bf11d2ab6ad | 47 | a2_ = ck.a2; |
MikamiUitOpen | 0:3bf11d2ab6ad | 48 | b1_ = ck.b1; |
MikamiUitOpen | 0:3bf11d2ab6ad | 49 | b2_ = ck.b2; |
MikamiUitOpen | 0:3bf11d2ab6ad | 50 | } |
MikamiUitOpen | 0:3bf11d2ab6ad | 51 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 52 | // 内部変数(遅延器)のクリア |
MikamiUitOpen | 0:3bf11d2ab6ad | 53 | void Clear() { un1_ = un2_ = 0; } |
MikamiUitOpen | 0:3bf11d2ab6ad | 54 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 55 | private: |
MikamiUitOpen | 0:3bf11d2ab6ad | 56 | float a1_, a2_, b1_, b2_; // フィルタの係数 |
MikamiUitOpen | 0:3bf11d2ab6ad | 57 | float un1_, un2_; // 遅延器 |
MikamiUitOpen | 0:3bf11d2ab6ad | 58 | |
MikamiUitOpen | 0:3bf11d2ab6ad | 59 | // コピー・コンストラクタ禁止 |
MikamiUitOpen | 0:3bf11d2ab6ad | 60 | Biquad(const Biquad&); |
MikamiUitOpen | 0:3bf11d2ab6ad | 61 | }; |
MikamiUitOpen | 0:3bf11d2ab6ad | 62 | #endif // IIR_BIQUAD_HPP |