Frequency shifter using analytic signal for ST Nucleo F401RE.

Dependencies:   UITDSP_ADDA mbed

Committer:
MikamiUitOpen
Date:
Wed Nov 12 10:22:30 2014 +0000
Revision:
2:ba46d7cbb09e
Parent:
0:4269710caf90
Child:
4:04bb0cfea187
3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:4269710caf90 1 //--------------------------------------------------------------
MikamiUitOpen 0:4269710caf90 2 // Frequency shifter using analytic signal
MikamiUitOpen 0:4269710caf90 3 // Frequency is shifted toward 100 Hz higher
MikamiUitOpen 2:ba46d7cbb09e 4 // 2014/11/12, Copyright (c) 2014 MIKAMI, Naoki
MikamiUitOpen 0:4269710caf90 5 //--------------------------------------------------------------
MikamiUitOpen 0:4269710caf90 6
MikamiUitOpen 0:4269710caf90 7 #include "mbed.h"
MikamiUitOpen 0:4269710caf90 8
MikamiUitOpen 0:4269710caf90 9 #include "ADC_Base.hpp" // for ADC not using interrupt
MikamiUitOpen 0:4269710caf90 10 #include "DAC_MCP4922.hpp" // for DAC MCP4922
MikamiUitOpen 0:4269710caf90 11
MikamiUitOpen 0:4269710caf90 12 #include "HilbertTransform.hpp" // Hilbert transform filter
MikamiUitOpen 0:4269710caf90 13 #include "coefsHilbert114.hpp" // Coeffisients of Hilbert transform filter
MikamiUitOpen 0:4269710caf90 14 #include "DC_Cut_Coefficients.hpp" // Coeffisients of DC-cut filter
MikamiUitOpen 0:4269710caf90 15 #include "Biquad.hpp" // For DC-cut filter
MikamiUitOpen 0:4269710caf90 16 #include "TwoPhaseGenerator.hpp" // Two-phase generator
MikamiUitOpen 0:4269710caf90 17
MikamiUitOpen 0:4269710caf90 18 using namespace Mikami;
MikamiUitOpen 0:4269710caf90 19
MikamiUitOpen 0:4269710caf90 20 const int FS_ = 12000; // 12 kHz
MikamiUitOpen 0:4269710caf90 21 ADC_Base adc_(A0, FS_);
MikamiUitOpen 0:4269710caf90 22 DAC_MCP4922 myDac_;
MikamiUitOpen 0:4269710caf90 23
MikamiUitOpen 0:4269710caf90 24 Hilbert<ORDER_> ht_(hm_); // Hilbert transform filter
MikamiUitOpen 0:4269710caf90 25 Biquad DcCut_(c1_); // DC cut filter
MikamiUitOpen 0:4269710caf90 26 TwoPhaseGenerator cosSin_(100, (float)FS_); // 100 Hz
MikamiUitOpen 0:4269710caf90 27
MikamiUitOpen 0:4269710caf90 28 int main()
MikamiUitOpen 0:4269710caf90 29 {
MikamiUitOpen 2:ba46d7cbb09e 30 myDac_.ScfClockTim3(500000); // cutoff frequency: 5 kHz
MikamiUitOpen 0:4269710caf90 31
MikamiUitOpen 0:4269710caf90 32 while (true)
MikamiUitOpen 0:4269710caf90 33 {
MikamiUitOpen 0:4269710caf90 34 float xn = adc_.Read(); // Read from A0
MikamiUitOpen 0:4269710caf90 35 //-----------------------------------------------
MikamiUitOpen 0:4269710caf90 36
MikamiUitOpen 0:4269710caf90 37 xn = DcCut_.Execute(g0_*xn); // DC cut filter
MikamiUitOpen 0:4269710caf90 38 float yIn, yQn;
MikamiUitOpen 0:4269710caf90 39 ht_.Execute(xn, yIn, yQn); // Hilbert transform filter
MikamiUitOpen 0:4269710caf90 40 float cos, sin;
MikamiUitOpen 0:4269710caf90 41 cosSin_.Generate(cos, sin); // cos and sin
MikamiUitOpen 0:4269710caf90 42 float yn = yIn*cos - yQn*sin;
MikamiUitOpen 0:4269710caf90 43
MikamiUitOpen 0:4269710caf90 44 //-----------------------------------------------
MikamiUitOpen 0:4269710caf90 45 myDac_.Write(yn); // Write to DAC
MikamiUitOpen 0:4269710caf90 46 }
MikamiUitOpen 0:4269710caf90 47 }