![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
FIR filter of symmetric coefficiemts for ST Nucleo F401RE.
main.cpp@0:4912234b4155, 2014-10-21 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Oct 21 08:41:14 2014 +0000
- Revision:
- 0:4912234b4155
- Child:
- 1:93d2771b8797
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:4912234b4155 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:4912234b4155 | 2 | // FIR フィルタ,係数の対称性を利用する構造 |
MikamiUitOpen | 0:4912234b4155 | 3 | // Analog Input : A0 |
MikamiUitOpen | 0:4912234b4155 | 4 | // Analog Output: MCP4922 using SPI |
MikamiUitOpen | 0:4912234b4155 | 5 | // 2014/10/21, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:4912234b4155 | 6 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:4912234b4155 | 7 | |
MikamiUitOpen | 0:4912234b4155 | 8 | #include "mbed.h" |
MikamiUitOpen | 0:4912234b4155 | 9 | |
MikamiUitOpen | 0:4912234b4155 | 10 | #include "ADC_Interrupt.hpp" // for ADC using interrupt |
MikamiUitOpen | 0:4912234b4155 | 11 | #include "DAC_MCP4922.hpp" // for DAC MCP4922 |
MikamiUitOpen | 0:4912234b4155 | 12 | #include "ScfClockTim3.hpp" // for clock supplied to SCF |
MikamiUitOpen | 0:4912234b4155 | 13 | #include "Coefficients_200_LPF_Sym.hpp" |
MikamiUitOpen | 0:4912234b4155 | 14 | |
MikamiUitOpen | 0:4912234b4155 | 15 | using namespace Mikami; |
MikamiUitOpen | 0:4912234b4155 | 16 | |
MikamiUitOpen | 0:4912234b4155 | 17 | const int FS_ = 12000; // Sampling frequency: 12 kHz |
MikamiUitOpen | 0:4912234b4155 | 18 | ADC_Base adc_(A0, FS_); // for AD |
MikamiUitOpen | 0:4912234b4155 | 19 | DAC_MCP4922 myDac_(DAC_MCP4922::DAC_A); // for DA |
MikamiUitOpen | 0:4912234b4155 | 20 | |
MikamiUitOpen | 0:4912234b4155 | 21 | int main() |
MikamiUitOpen | 0:4912234b4155 | 22 | { |
MikamiUitOpen | 0:4912234b4155 | 23 | ScfClockTim3(500000); // cutoff frequency: 5 kHz |
MikamiUitOpen | 0:4912234b4155 | 24 | |
MikamiUitOpen | 0:4912234b4155 | 25 | float xn[ORDER_+1]; |
MikamiUitOpen | 0:4912234b4155 | 26 | for (int n=0; n<=ORDER_; n++) |
MikamiUitOpen | 0:4912234b4155 | 27 | xn[n] = 0; |
MikamiUitOpen | 0:4912234b4155 | 28 | |
MikamiUitOpen | 0:4912234b4155 | 29 | while (true) |
MikamiUitOpen | 0:4912234b4155 | 30 | { |
MikamiUitOpen | 0:4912234b4155 | 31 | xn[0] = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:4912234b4155 | 32 | //----------------------------------------------- |
MikamiUitOpen | 0:4912234b4155 | 33 | |
MikamiUitOpen | 0:4912234b4155 | 34 | float yn = hm_[ORDER_/2]*xn[ORDER_/2]; |
MikamiUitOpen | 0:4912234b4155 | 35 | for (int k=0; k<ORDER_/2; k++) |
MikamiUitOpen | 0:4912234b4155 | 36 | yn = yn + hm_[k]*(xn[k] + xn[ORDER_-k]); |
MikamiUitOpen | 0:4912234b4155 | 37 | |
MikamiUitOpen | 0:4912234b4155 | 38 | for (int k=ORDER_; k>0; k--) |
MikamiUitOpen | 0:4912234b4155 | 39 | xn[k] = xn[k-1]; // move input signals |
MikamiUitOpen | 0:4912234b4155 | 40 | |
MikamiUitOpen | 0:4912234b4155 | 41 | //----------------------------------------------- |
MikamiUitOpen | 0:4912234b4155 | 42 | myDac_.Write(yn); // Write to DAC |
MikamiUitOpen | 0:4912234b4155 | 43 | } |
MikamiUitOpen | 0:4912234b4155 | 44 | } |