Frequency shifter using analytic signal for ST Nucleo F401RE.

Dependencies:   UITDSP_ADDA mbed

Committer:
MikamiUitOpen
Date:
Thu Oct 23 00:48:13 2014 +0000
Revision:
0:4269710caf90
Child:
2:ba46d7cbb09e
1

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 0:4269710caf90 4 // 2014/10/23, 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 #include "ScfClockTim3.hpp" // for clock supplied to SCF
MikamiUitOpen 0:4269710caf90 12
MikamiUitOpen 0:4269710caf90 13 #include "HilbertTransform.hpp" // Hilbert transform filter
MikamiUitOpen 0:4269710caf90 14 #include "coefsHilbert114.hpp" // Coeffisients of Hilbert transform filter
MikamiUitOpen 0:4269710caf90 15 #include "DC_Cut_Coefficients.hpp" // Coeffisients of DC-cut filter
MikamiUitOpen 0:4269710caf90 16 #include "Biquad.hpp" // For DC-cut filter
MikamiUitOpen 0:4269710caf90 17 #include "TwoPhaseGenerator.hpp" // Two-phase generator
MikamiUitOpen 0:4269710caf90 18
MikamiUitOpen 0:4269710caf90 19 using namespace Mikami;
MikamiUitOpen 0:4269710caf90 20
MikamiUitOpen 0:4269710caf90 21 const int FS_ = 12000; // 12 kHz
MikamiUitOpen 0:4269710caf90 22 ADC_Base adc_(A0, FS_);
MikamiUitOpen 0:4269710caf90 23 DAC_MCP4922 myDac_;
MikamiUitOpen 0:4269710caf90 24
MikamiUitOpen 0:4269710caf90 25 Hilbert<ORDER_> ht_(hm_); // Hilbert transform filter
MikamiUitOpen 0:4269710caf90 26 Biquad DcCut_(c1_); // DC cut filter
MikamiUitOpen 0:4269710caf90 27 TwoPhaseGenerator cosSin_(100, (float)FS_); // 100 Hz
MikamiUitOpen 0:4269710caf90 28
MikamiUitOpen 0:4269710caf90 29 int main()
MikamiUitOpen 0:4269710caf90 30 {
MikamiUitOpen 0:4269710caf90 31 ScfClockTim3(500000); // cutoff frequency: 5 kHz
MikamiUitOpen 0:4269710caf90 32
MikamiUitOpen 0:4269710caf90 33 while (true)
MikamiUitOpen 0:4269710caf90 34 {
MikamiUitOpen 0:4269710caf90 35 float xn = adc_.Read(); // Read from A0
MikamiUitOpen 0:4269710caf90 36 //-----------------------------------------------
MikamiUitOpen 0:4269710caf90 37
MikamiUitOpen 0:4269710caf90 38 xn = DcCut_.Execute(g0_*xn); // DC cut filter
MikamiUitOpen 0:4269710caf90 39 float yIn, yQn;
MikamiUitOpen 0:4269710caf90 40 ht_.Execute(xn, yIn, yQn); // Hilbert transform filter
MikamiUitOpen 0:4269710caf90 41 float cos, sin;
MikamiUitOpen 0:4269710caf90 42 cosSin_.Generate(cos, sin); // cos and sin
MikamiUitOpen 0:4269710caf90 43 float yn = yIn*cos - yQn*sin;
MikamiUitOpen 0:4269710caf90 44
MikamiUitOpen 0:4269710caf90 45 //-----------------------------------------------
MikamiUitOpen 0:4269710caf90 46 myDac_.Write(yn); // Write to DAC
MikamiUitOpen 0:4269710caf90 47 }
MikamiUitOpen 0:4269710caf90 48 }