![](/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
IIR_LPF.cpp@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 | // IIR filter: Cascade strucrure |
CQpub0Mikami | 0:398107c96b1b | 3 | // |
CQpub0Mikami | 0:398107c96b1b | 4 | // Copyright (c) 2014 MIKAMI, Naoki, 2014/06/22 |
CQpub0Mikami | 0:398107c96b1b | 5 | //-------------------------------------------------------------- |
CQpub0Mikami | 0:398107c96b1b | 6 | |
CQpub0Mikami | 0:398107c96b1b | 7 | #include "mbed.h" |
CQpub0Mikami | 0:398107c96b1b | 8 | #include "AdcInternal.hpp" |
CQpub0Mikami | 0:398107c96b1b | 9 | #include "MCP4922Single.hpp" |
CQpub0Mikami | 0:398107c96b1b | 10 | #include "IIR_Coefficients.hpp" |
CQpub0Mikami | 0:398107c96b1b | 11 | #include "IIR_Cascade.hpp" |
CQpub0Mikami | 0:398107c96b1b | 12 | |
CQpub0Mikami | 0:398107c96b1b | 13 | using namespace Mikami; |
CQpub0Mikami | 0:398107c96b1b | 14 | |
CQpub0Mikami | 0:398107c96b1b | 15 | // sampling frequency |
CQpub0Mikami | 0:398107c96b1b | 16 | const float FS_ = 10.0e3f; |
CQpub0Mikami | 0:398107c96b1b | 17 | |
CQpub0Mikami | 0:398107c96b1b | 18 | Adc adc_(A0); |
CQpub0Mikami | 0:398107c96b1b | 19 | Dac dacA_(Dac::DAC_A); |
CQpub0Mikami | 0:398107c96b1b | 20 | Ticker timer_; // for timer interrupt |
CQpub0Mikami | 0:398107c96b1b | 21 | |
CQpub0Mikami | 0:398107c96b1b | 22 | IirCascade<ORDER_/2> iirLpf(g0_, ck_); |
CQpub0Mikami | 0:398107c96b1b | 23 | |
CQpub0Mikami | 0:398107c96b1b | 24 | // Called every 0.1 ms |
CQpub0Mikami | 0:398107c96b1b | 25 | void TimerIsr() |
CQpub0Mikami | 0:398107c96b1b | 26 | { |
CQpub0Mikami | 0:398107c96b1b | 27 | float xn = adc_.Read(); // input |
CQpub0Mikami | 0:398107c96b1b | 28 | |
CQpub0Mikami | 0:398107c96b1b | 29 | // Execute IIR filter |
CQpub0Mikami | 0:398107c96b1b | 30 | float yn = iirLpf.Execute(xn); |
CQpub0Mikami | 0:398107c96b1b | 31 | |
CQpub0Mikami | 0:398107c96b1b | 32 | dacA_.Write(yn); // output |
CQpub0Mikami | 0:398107c96b1b | 33 | } |
CQpub0Mikami | 0:398107c96b1b | 34 | |
CQpub0Mikami | 0:398107c96b1b | 35 | int main() |
CQpub0Mikami | 0:398107c96b1b | 36 | { |
CQpub0Mikami | 0:398107c96b1b | 37 | timer_.attach_us(&TimerIsr, 1.0e6f/FS_); |
CQpub0Mikami | 0:398107c96b1b | 38 | |
CQpub0Mikami | 0:398107c96b1b | 39 | while (true) {} // infinite loop |
CQpub0Mikami | 0:398107c96b1b | 40 | } |