FIR filter using DSP instructions for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
Diff: main.cpp
- Revision:
- 4:0b3b70b0af0b
- Parent:
- 3:bfb6d1e6deee
- Child:
- 6:f005cc78b9aa
diff -r bfb6d1e6deee -r 0b3b70b0af0b main.cpp --- a/main.cpp Thu Oct 23 00:19:42 2014 +0000 +++ b/main.cpp Thu Oct 30 02:56:50 2014 +0000 @@ -2,7 +2,7 @@ // FIR フィルタ,基本的な構造, 固定小数点演算用 DSP 命令を使う // Analog Input : A0 // Analog Output: MCP4922 using SPI -// 2014/10/23, Copyright (c) 2014 MIKAMI, Naoki +// 2014/10/29, Copyright (c) 2014 MIKAMI, Naoki //-------------------------------------------------------------- #include "mbed.h" @@ -15,6 +15,7 @@ using namespace Mikami; const int FS_ = 12000; // Sampling frequency: 12 kHz +const uint16_t OFFSET = 2047; // Correspond to "0" ADC_Base adc_(A0, FS_); // for AD DAC_MCP4922 myDac_; // for DA @@ -28,7 +29,7 @@ while (true) { - xn[0] = adc_.Read_u16() - 2047; // Read from A0 + xn[0] = adc_.Read_u16() - OFFSET; // Read from A0 //----------------------------------------------- int32_t yn = hm_[ORDER_]*xn[ORDER_];; @@ -41,8 +42,9 @@ for (int k=ORDER_; k>0; k--) xn[k] = xn[k-1]; // move input signals - yn = (yn + 0x8000) >> 15; // rounding and devide by 32768 + // rounding and devide by 32768 + DC offset + uint16_t yOut = ((yn + 0x8000) >> 15) + OFFSET; //----------------------------------------------- - myDac_.Write((uint16_t)(yn + 2047)); // Write to DAC + myDac_.Write(yOut); // Write to DAC } }