FIR filter of Direct form for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
main.cpp@0:bbbc6e10e439, 2014-10-21 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Oct 21 08:37:42 2014 +0000
- Revision:
- 0:bbbc6e10e439
- Child:
- 1:124262641129
1
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 | 0:bbbc6e10e439 | 5 | // 2014/10/21, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:bbbc6e10e439 | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:bbbc6e10e439 | 7 | |
MikamiUitOpen | 0:bbbc6e10e439 | 8 | #include "mbed.h" |
MikamiUitOpen | 0:bbbc6e10e439 | 9 | |
MikamiUitOpen | 0:bbbc6e10e439 | 10 | #include "ADC_Interrupt.hpp" // for ADC using interrupt |
MikamiUitOpen | 0:bbbc6e10e439 | 11 | #include "DAC_MCP4922.hpp" // for DAC MCP4922 |
MikamiUitOpen | 0:bbbc6e10e439 | 12 | #include "ScfClockTim3.hpp" // for clock supplied to SCF |
MikamiUitOpen | 0:bbbc6e10e439 | 13 | #include "Coefficients_200_LPF.hpp" |
MikamiUitOpen | 0:bbbc6e10e439 | 14 | |
MikamiUitOpen | 0:bbbc6e10e439 | 15 | using namespace Mikami; |
MikamiUitOpen | 0:bbbc6e10e439 | 16 | |
MikamiUitOpen | 0:bbbc6e10e439 | 17 | const int FS_ = 12000; // Sampling frequency: 12 kHz |
MikamiUitOpen | 0:bbbc6e10e439 | 18 | ADC_Base adc_(A0, FS_); // for AD |
MikamiUitOpen | 0:bbbc6e10e439 | 19 | DAC_MCP4922 myDac_(DAC_MCP4922::DAC_A); // for DA |
MikamiUitOpen | 0:bbbc6e10e439 | 20 | |
MikamiUitOpen | 0:bbbc6e10e439 | 21 | int main() |
MikamiUitOpen | 0:bbbc6e10e439 | 22 | { |
MikamiUitOpen | 0:bbbc6e10e439 | 23 | ScfClockTim3(500000); // cutoff frequency: 5 kHz |
MikamiUitOpen | 0:bbbc6e10e439 | 24 | |
MikamiUitOpen | 0:bbbc6e10e439 | 25 | float xn[ORDER_+1]; |
MikamiUitOpen | 0:bbbc6e10e439 | 26 | for (int n=0; n<=ORDER_; n++) |
MikamiUitOpen | 0:bbbc6e10e439 | 27 | xn[n] = 0; |
MikamiUitOpen | 0:bbbc6e10e439 | 28 | |
MikamiUitOpen | 0:bbbc6e10e439 | 29 | while (true) |
MikamiUitOpen | 0:bbbc6e10e439 | 30 | { |
MikamiUitOpen | 0:bbbc6e10e439 | 31 | xn[0] = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:bbbc6e10e439 | 32 | //----------------------------------------------- |
MikamiUitOpen | 0:bbbc6e10e439 | 33 | |
MikamiUitOpen | 0:bbbc6e10e439 | 34 | float yn = 0; |
MikamiUitOpen | 0:bbbc6e10e439 | 35 | for (int k=0; k<=ORDER_; k++) |
MikamiUitOpen | 0:bbbc6e10e439 | 36 | yn = yn + hm_[k]*xn[k]; |
MikamiUitOpen | 0:bbbc6e10e439 | 37 | |
MikamiUitOpen | 0:bbbc6e10e439 | 38 | for (int k=ORDER_; k>0; k--) |
MikamiUitOpen | 0:bbbc6e10e439 | 39 | xn[k] = xn[k-1]; // move input signals |
MikamiUitOpen | 0:bbbc6e10e439 | 40 | |
MikamiUitOpen | 0:bbbc6e10e439 | 41 | //----------------------------------------------- |
MikamiUitOpen | 0:bbbc6e10e439 | 42 | myDac_.Write(yn); // Write to DAC |
MikamiUitOpen | 0:bbbc6e10e439 | 43 | } |
MikamiUitOpen | 0:bbbc6e10e439 | 44 | } |