![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
The experiment using this program is introduced on "Interface" No.2, CQ publishing Co.,Ltd, 2015. 本プログラムを使った実験は,CQ出版社のインターフェース 2015年2月号で紹介しています.
Dependencies: DSProcessingIO mbed
Biquad.hpp@1:5ece9454ba73, 2014-07-29 (annotated)
- Committer:
- CQpub0Mikami
- Date:
- Tue Jul 29 06:55:48 2014 +0000
- Revision:
- 1:5ece9454ba73
- Parent:
- 0:398107c96b1b
ver.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CQpub0Mikami | 0:398107c96b1b | 1 | //-------------------------------------------------------------- |
CQpub0Mikami | 0:398107c96b1b | 2 | // Biquad filter for IIR filter of cascade structure |
CQpub0Mikami | 0:398107c96b1b | 3 | // Copyright (c) 2014 MIKAMI, Naoki, 2014/07/15 |
CQpub0Mikami | 0:398107c96b1b | 4 | //-------------------------------------------------------------- |
CQpub0Mikami | 0:398107c96b1b | 5 | |
CQpub0Mikami | 0:398107c96b1b | 6 | #ifndef IIR_BIQUAD_HPP |
CQpub0Mikami | 0:398107c96b1b | 7 | #define IIR_BIQUAD_HPP |
CQpub0Mikami | 0:398107c96b1b | 8 | |
CQpub0Mikami | 0:398107c96b1b | 9 | #include "mbed.h" |
CQpub0Mikami | 0:398107c96b1b | 10 | |
CQpub0Mikami | 0:398107c96b1b | 11 | namespace Mikami |
CQpub0Mikami | 0:398107c96b1b | 12 | { |
CQpub0Mikami | 0:398107c96b1b | 13 | // 2nd order IIR filter |
CQpub0Mikami | 0:398107c96b1b | 14 | class Biquad |
CQpub0Mikami | 0:398107c96b1b | 15 | { |
CQpub0Mikami | 0:398107c96b1b | 16 | public: |
CQpub0Mikami | 0:398107c96b1b | 17 | struct Coefs { float a1, a2, b1, b2; }; |
CQpub0Mikami | 0:398107c96b1b | 18 | |
CQpub0Mikami | 0:398107c96b1b | 19 | Biquad() {} // Default constructore |
CQpub0Mikami | 0:398107c96b1b | 20 | |
CQpub0Mikami | 0:398107c96b1b | 21 | Biquad(const Coefs ck) |
CQpub0Mikami | 0:398107c96b1b | 22 | : a1_(ck.a1), a2_(ck.a2), b1_(ck.b1), b2_(ck.b2) |
CQpub0Mikami | 0:398107c96b1b | 23 | { Clear(); } |
CQpub0Mikami | 0:398107c96b1b | 24 | |
CQpub0Mikami | 0:398107c96b1b | 25 | float Execute(float xn) |
CQpub0Mikami | 0:398107c96b1b | 26 | { |
CQpub0Mikami | 0:398107c96b1b | 27 | float un = xn + a1_*un1_ + a2_*un2_; |
CQpub0Mikami | 0:398107c96b1b | 28 | float yn = un + b1_*un1_ + b2_*un2_; |
CQpub0Mikami | 0:398107c96b1b | 29 | |
CQpub0Mikami | 0:398107c96b1b | 30 | un2_ = un1_; |
CQpub0Mikami | 0:398107c96b1b | 31 | un1_ = un; |
CQpub0Mikami | 0:398107c96b1b | 32 | |
CQpub0Mikami | 0:398107c96b1b | 33 | return yn; |
CQpub0Mikami | 0:398107c96b1b | 34 | } |
CQpub0Mikami | 0:398107c96b1b | 35 | |
CQpub0Mikami | 0:398107c96b1b | 36 | void Clear() { un1_ = un2_ = 0; } |
CQpub0Mikami | 0:398107c96b1b | 37 | |
CQpub0Mikami | 0:398107c96b1b | 38 | private: |
CQpub0Mikami | 0:398107c96b1b | 39 | float a1_, a2_, b1_, b2_; |
CQpub0Mikami | 0:398107c96b1b | 40 | float un1_, un2_; |
CQpub0Mikami | 0:398107c96b1b | 41 | |
CQpub0Mikami | 0:398107c96b1b | 42 | Biquad(const Biquad&); |
CQpub0Mikami | 0:398107c96b1b | 43 | }; |
CQpub0Mikami | 0:398107c96b1b | 44 | } |
CQpub0Mikami | 0:398107c96b1b | 45 | #endif // IIR_BIQUAD_HPP |