![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
IirCascade クラスの使用例(低域通過フィルタ). Example for IirCascade class (lowpass filter).
Dependencies: UITDSP_ADDA UIT_IIR_Filter mbed
main.cpp@1:19144f5db82a, 2015-09-11 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Sep 11 07:34:46 2015 +0000
- Revision:
- 1:19144f5db82a
- Parent:
- 0:6de881bdce72
2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:6de881bdce72 | 1 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:6de881bdce72 | 2 | // IirCascade クラスの使用例(低域通過フィルタ) |
MikamiUitOpen | 0:6de881bdce72 | 3 | // Example for IirCascade class (lowpass filter) |
MikamiUitOpen | 1:19144f5db82a | 4 | // 2015/09/11, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:6de881bdce72 | 5 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:6de881bdce72 | 6 | |
MikamiUitOpen | 0:6de881bdce72 | 7 | #include "ADC_BuiltIn.hpp" |
MikamiUitOpen | 0:6de881bdce72 | 8 | #include "DAC_MCP4922.hpp" |
MikamiUitOpen | 0:6de881bdce72 | 9 | |
MikamiUitOpen | 0:6de881bdce72 | 10 | #include "IIR_Cascade.hpp" |
MikamiUitOpen | 0:6de881bdce72 | 11 | #include "Coefficients.hpp" // Coeffisients for the IIR filter |
MikamiUitOpen | 0:6de881bdce72 | 12 | |
MikamiUitOpen | 0:6de881bdce72 | 13 | using namespace Mikami; // must be declared |
MikamiUitOpen | 0:6de881bdce72 | 14 | |
MikamiUitOpen | 0:6de881bdce72 | 15 | const int FS_ = 16000; // sampling frequency: 10 kHz |
MikamiUitOpen | 0:6de881bdce72 | 16 | ADC_BuiltIn adc_(A0, FS_); // for A0 of built-in ADC |
MikamiUitOpen | 0:6de881bdce72 | 17 | DAC_MCP4922 myDac_; // for external DAC |
MikamiUitOpen | 0:6de881bdce72 | 18 | DigitalIn sw_(D2, PullDown); // for rotary dip switch |
MikamiUitOpen | 0:6de881bdce72 | 19 | |
MikamiUitOpen | 0:6de881bdce72 | 20 | // Object for lowpass filter |
MikamiUitOpen | 1:19144f5db82a | 21 | IirCascade<ORDER_> lpf_(g0_, ck_); |
MikamiUitOpen | 0:6de881bdce72 | 22 | |
MikamiUitOpen | 0:6de881bdce72 | 23 | int main() |
MikamiUitOpen | 0:6de881bdce72 | 24 | { |
MikamiUitOpen | 0:6de881bdce72 | 25 | myDac_.ScfClockTim3(700000); // cutoff frequency of smoothing LPF: 7 kHz |
MikamiUitOpen | 0:6de881bdce72 | 26 | |
MikamiUitOpen | 0:6de881bdce72 | 27 | lpf_.Clear(); // clear internal buffer in lowpass filter |
MikamiUitOpen | 0:6de881bdce72 | 28 | |
MikamiUitOpen | 0:6de881bdce72 | 29 | while (true) |
MikamiUitOpen | 0:6de881bdce72 | 30 | { |
MikamiUitOpen | 0:6de881bdce72 | 31 | float xn = adc_.Read(); // read input signal |
MikamiUitOpen | 0:6de881bdce72 | 32 | //----------------------------------------------- |
MikamiUitOpen | 0:6de881bdce72 | 33 | |
MikamiUitOpen | 0:6de881bdce72 | 34 | float yn = lpf_.Execute(xn); // execute LPF |
MikamiUitOpen | 0:6de881bdce72 | 35 | |
MikamiUitOpen | 0:6de881bdce72 | 36 | //----------------------------------------------- |
MikamiUitOpen | 0:6de881bdce72 | 37 | if (sw_ == 0) myDac_.Write(xn); // through |
MikamiUitOpen | 0:6de881bdce72 | 38 | else myDac_.Write(yn); // filtered output |
MikamiUitOpen | 0:6de881bdce72 | 39 | } |
MikamiUitOpen | 0:6de881bdce72 | 40 | } |
MikamiUitOpen | 1:19144f5db82a | 41 |