Frequency shifter using analytic signal for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
Diff: main.cpp
- Revision:
- 0:4269710caf90
- Child:
- 2:ba46d7cbb09e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Oct 23 00:48:13 2014 +0000 @@ -0,0 +1,48 @@ +//-------------------------------------------------------------- +// Frequency shifter using analytic signal +// Frequency is shifted toward 100 Hz higher +// 2014/10/23, Copyright (c) 2014 MIKAMI, Naoki +//-------------------------------------------------------------- + +#include "mbed.h" + +#include "ADC_Base.hpp" // for ADC not using interrupt +#include "DAC_MCP4922.hpp" // for DAC MCP4922 +#include "ScfClockTim3.hpp" // for clock supplied to SCF + +#include "HilbertTransform.hpp" // Hilbert transform filter +#include "coefsHilbert114.hpp" // Coeffisients of Hilbert transform filter +#include "DC_Cut_Coefficients.hpp" // Coeffisients of DC-cut filter +#include "Biquad.hpp" // For DC-cut filter +#include "TwoPhaseGenerator.hpp" // Two-phase generator + +using namespace Mikami; + +const int FS_ = 12000; // 12 kHz +ADC_Base adc_(A0, FS_); +DAC_MCP4922 myDac_; + +Hilbert<ORDER_> ht_(hm_); // Hilbert transform filter +Biquad DcCut_(c1_); // DC cut filter +TwoPhaseGenerator cosSin_(100, (float)FS_); // 100 Hz + +int main() +{ + ScfClockTim3(500000); // cutoff frequency: 5 kHz + + while (true) + { + float xn = adc_.Read(); // Read from A0 + //----------------------------------------------- + + xn = DcCut_.Execute(g0_*xn); // DC cut filter + float yIn, yQn; + ht_.Execute(xn, yIn, yQn); // Hilbert transform filter + float cos, sin; + cosSin_.Generate(cos, sin); // cos and sin + float yn = yIn*cos - yQn*sin; + + //----------------------------------------------- + myDac_.Write(yn); // Write to DAC + } +}