![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
FIR filter of Direct form for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
main.cpp@8:927d97f834b0, 2015-09-04 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Sep 04 09:09:05 2015 +0000
- Revision:
- 8:927d97f834b0
- Parent:
- 6:5a7e4d3d786a
9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:bbbc6e10e439 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:bbbc6e10e439 | 2 | // FIR フィルタ,基本的な構造 |
MikamiUitOpen | 0:bbbc6e10e439 | 3 | // Analog Input : A0 |
MikamiUitOpen | 0:bbbc6e10e439 | 4 | // Analog Output: MCP4922 using SPI |
MikamiUitOpen | 8:927d97f834b0 | 5 | // 2015/07/03, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:bbbc6e10e439 | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:bbbc6e10e439 | 7 | |
MikamiUitOpen | 8:927d97f834b0 | 8 | #include "ADC_BuiltIn.hpp" // for ADC not using interrupt |
MikamiUitOpen | 8:927d97f834b0 | 9 | #include "DAC_MCP4921.hpp" // for DAC MCP4921, MCP4922 |
MikamiUitOpen | 0:bbbc6e10e439 | 10 | #include "Coefficients_200_LPF.hpp" |
MikamiUitOpen | 0:bbbc6e10e439 | 11 | |
MikamiUitOpen | 0:bbbc6e10e439 | 12 | using namespace Mikami; |
MikamiUitOpen | 0:bbbc6e10e439 | 13 | |
MikamiUitOpen | 8:927d97f834b0 | 14 | const int FS_ = 12000; // Sampling frequency: 12 kHz |
MikamiUitOpen | 8:927d97f834b0 | 15 | ADC_BuiltIn adc_(A0, FS_); // for AD |
MikamiUitOpen | 8:927d97f834b0 | 16 | DAC_MCP4921 myDac_; // for DA |
MikamiUitOpen | 0:bbbc6e10e439 | 17 | |
MikamiUitOpen | 0:bbbc6e10e439 | 18 | int main() |
MikamiUitOpen | 0:bbbc6e10e439 | 19 | { |
MikamiUitOpen | 6:5a7e4d3d786a | 20 | myDac_.ScfClockTim3(500000); // cutoff frequency: 5 kHz |
MikamiUitOpen | 0:bbbc6e10e439 | 21 | |
MikamiUitOpen | 0:bbbc6e10e439 | 22 | float xn[ORDER_+1]; |
MikamiUitOpen | 0:bbbc6e10e439 | 23 | for (int n=0; n<=ORDER_; n++) |
MikamiUitOpen | 0:bbbc6e10e439 | 24 | xn[n] = 0; |
MikamiUitOpen | 0:bbbc6e10e439 | 25 | |
MikamiUitOpen | 0:bbbc6e10e439 | 26 | while (true) |
MikamiUitOpen | 0:bbbc6e10e439 | 27 | { |
MikamiUitOpen | 6:5a7e4d3d786a | 28 | xn[0] = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:bbbc6e10e439 | 29 | //----------------------------------------------- |
MikamiUitOpen | 0:bbbc6e10e439 | 30 | |
MikamiUitOpen | 0:bbbc6e10e439 | 31 | float yn = 0; |
MikamiUitOpen | 0:bbbc6e10e439 | 32 | for (int k=0; k<=ORDER_; k++) |
MikamiUitOpen | 0:bbbc6e10e439 | 33 | yn = yn + hm_[k]*xn[k]; |
MikamiUitOpen | 0:bbbc6e10e439 | 34 | |
MikamiUitOpen | 0:bbbc6e10e439 | 35 | for (int k=ORDER_; k>0; k--) |
MikamiUitOpen | 6:5a7e4d3d786a | 36 | xn[k] = xn[k-1]; // move input signals |
MikamiUitOpen | 0:bbbc6e10e439 | 37 | |
MikamiUitOpen | 0:bbbc6e10e439 | 38 | //----------------------------------------------- |
MikamiUitOpen | 6:5a7e4d3d786a | 39 | myDac_.Write(yn); // Write to DAC |
MikamiUitOpen | 0:bbbc6e10e439 | 40 | } |
MikamiUitOpen | 0:bbbc6e10e439 | 41 | } |