FIR filter of Direct form for ST Nucleo F401RE.

Dependencies:   UITDSP_ADDA mbed

Committer:
MikamiUitOpen
Date:
Wed Nov 12 09:48:06 2014 +0000
Revision:
6:5a7e4d3d786a
Parent:
4:32b07aecbc14
Child:
8:927d97f834b0
7

Who changed what in which revision?

UserRevisionLine numberNew 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 6:5a7e4d3d786a 5 // 2014/11/12, 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 1:124262641129 10 #include "ADC_Base.hpp" // for ADC not using interrupt
MikamiUitOpen 0:bbbc6e10e439 11 #include "DAC_MCP4922.hpp" // for DAC MCP4922
MikamiUitOpen 0:bbbc6e10e439 12 #include "Coefficients_200_LPF.hpp"
MikamiUitOpen 0:bbbc6e10e439 13
MikamiUitOpen 0:bbbc6e10e439 14 using namespace Mikami;
MikamiUitOpen 0:bbbc6e10e439 15
MikamiUitOpen 3:09f0a4b0a8f1 16 const int FS_ = 12000; // Sampling frequency: 12 kHz
MikamiUitOpen 3:09f0a4b0a8f1 17 ADC_Base adc_(A0, FS_); // for AD
MikamiUitOpen 3:09f0a4b0a8f1 18 DAC_MCP4922 myDac_; // for DA
MikamiUitOpen 0:bbbc6e10e439 19
MikamiUitOpen 0:bbbc6e10e439 20 int main()
MikamiUitOpen 0:bbbc6e10e439 21 {
MikamiUitOpen 6:5a7e4d3d786a 22 myDac_.ScfClockTim3(500000); // cutoff frequency: 5 kHz
MikamiUitOpen 0:bbbc6e10e439 23
MikamiUitOpen 0:bbbc6e10e439 24 float xn[ORDER_+1];
MikamiUitOpen 0:bbbc6e10e439 25 for (int n=0; n<=ORDER_; n++)
MikamiUitOpen 0:bbbc6e10e439 26 xn[n] = 0;
MikamiUitOpen 0:bbbc6e10e439 27
MikamiUitOpen 0:bbbc6e10e439 28 while (true)
MikamiUitOpen 0:bbbc6e10e439 29 {
MikamiUitOpen 6:5a7e4d3d786a 30 xn[0] = adc_.Read(); // Read from A0
MikamiUitOpen 0:bbbc6e10e439 31 //-----------------------------------------------
MikamiUitOpen 0:bbbc6e10e439 32
MikamiUitOpen 0:bbbc6e10e439 33 float yn = 0;
MikamiUitOpen 0:bbbc6e10e439 34 for (int k=0; k<=ORDER_; k++)
MikamiUitOpen 0:bbbc6e10e439 35 yn = yn + hm_[k]*xn[k];
MikamiUitOpen 0:bbbc6e10e439 36
MikamiUitOpen 0:bbbc6e10e439 37 for (int k=ORDER_; k>0; k--)
MikamiUitOpen 6:5a7e4d3d786a 38 xn[k] = xn[k-1]; // move input signals
MikamiUitOpen 0:bbbc6e10e439 39
MikamiUitOpen 0:bbbc6e10e439 40 //-----------------------------------------------
MikamiUitOpen 6:5a7e4d3d786a 41 myDac_.Write(yn); // Write to DAC
MikamiUitOpen 0:bbbc6e10e439 42 }
MikamiUitOpen 0:bbbc6e10e439 43 }