不韋 呂
/
UIT2_IIR_Direct_float
IIR filter of direct form using float type operations and coefficients for ST Nucleo F401RE.
Diff: main.cpp
- Revision:
- 0:3797037e0936
- Child:
- 1:bb0320fb8ad1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 20 23:22:42 2014 +0000 @@ -0,0 +1,60 @@ +//-------------------------------------------------------------- +// IIR フィルタ,直接形,float で演算 +// Analog Input : A0 +// Analog Output: MCP4922 using SPI +// 2014/10/20, Copyright (c) 2014 MIKAMI, Naoki +//-------------------------------------------------------------- + +#include "mbed.h" + +#include "ADC_Interrupt.hpp" // for ADC using interrupt +#include "DAC_MCP4922.hpp" // for DAC MCP4922 +#include "ScfClockTim3.hpp" // for clock supplied to SCF + +using namespace Mikami; + +const int ORDER_ = 8; // order +// 低域通過フィルタ +// 連立チェビシェフ特性 +// 次数 :6 次 +// 標本化周波数: 12.00 kHz +// 遮断周波数 : 0.40 kHz +// 通過域のリップル: 0.50 dB +// 阻止域の減衰量 :40.00 dB +const float am_[ORDER_] = { + 5.684787115202E+00, -1.354501388127E+01, 1.731054054746E+01, + -1.251297336508E+01, 4.850124049778E+00, -7.874837248679E-01}; +const float bm_[ORDER_+1] = { + 1.000028097647E-02, -5.466081078904E-02, 1.292315717890E-01, + -1.691239024945E-01, 1.292315717890E-01, -5.466081078904E-02, + 1.000028097647E-02}; + +const int FS_ = 12000; // Sampling frequency: 12 kHz +ADC_Base adc_(A0, FS_); // for AD +DAC_MCP4922 myDac_(DAC_MCP4922::DAC_A); // for DA + +int main() +{ + ScfClockTim3(500000); // cutoff frequency: 5 kHz + + float un[ORDER_]; // 過去の計算結果を格納する配列 + for (int k=0; k<ORDER_; k++) un[k] = 0; + + while (true) + { + float xn = adc_.Read(); // Read from A0 + //----------------------------------------------- + + float u0 = xn; + for (int k=0; k<ORDER_; k++) u0 = u0 + am_[k]*un[k]; + float yn = bm_[0]*u0; + for (int k=0; k<ORDER_; k++) yn = yn + bm_[k+1]*un[k]; + + // 計算結果の移動 + for (int k=ORDER_-1; k>0; k--) un[k] = un[k-1]; + un[0] = u0; + + //----------------------------------------------- + myDac_.Write(yn); // Write to DAC + } +}