The experiment using this program is introduced on "Interface" No.2, CQ publishing Co.,Ltd, 2015. 本プログラムを使った実験は,CQ出版社のインターフェース 2015年2月号で紹介しています.

Dependencies:   DSProcessingIO mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IIR_LPF.cpp Source File

IIR_LPF.cpp

00001 //--------------------------------------------------------------
00002 // IIR filter: Cascade strucrure
00003 //
00004 // Copyright (c) 2014 MIKAMI, Naoki,  2014/06/22
00005 //--------------------------------------------------------------
00006 
00007 #include "mbed.h"
00008 #include "AdcInternal.hpp"
00009 #include "MCP4922Single.hpp"
00010 #include "IIR_Coefficients.hpp"
00011 #include "IIR_Cascade.hpp"
00012 
00013 using namespace Mikami;
00014 
00015 // sampling frequency
00016 const float FS_ = 10.0e3f;
00017 
00018 Adc adc_(A0);
00019 Dac dacA_(Dac::DAC_A);
00020 Ticker timer_;           // for timer interrupt
00021 
00022 IirCascade<ORDER_/2> iirLpf(g0_, ck_);
00023 
00024 // Called every 0.1 ms
00025 void TimerIsr()
00026 {
00027     float xn = adc_.Read(); // input
00028     
00029     // Execute IIR filter
00030     float yn = iirLpf.Execute(xn);
00031     
00032     dacA_.Write(yn);        // output
00033 }
00034 
00035 int main()
00036 {
00037     timer_.attach_us(&TimerIsr, 1.0e6f/FS_);
00038 
00039     while (true) {}    // infinite loop
00040 }