![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Frequency shifter using analytic signal for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
main.cpp@4:04bb0cfea187, 2015-07-25 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Jul 25 07:32:50 2015 +0000
- Revision:
- 4:04bb0cfea187
- Parent:
- 2:ba46d7cbb09e
5
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:04bb0cfea187 | 4 | // sw number = even : No frequency shift |
MikamiUitOpen | 4:04bb0cfea187 | 5 | // sw number = odd : Frequency shift |
MikamiUitOpen | 4:04bb0cfea187 | 6 | |
MikamiUitOpen | 4:04bb0cfea187 | 7 | // 2015/07/25, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:4269710caf90 | 8 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:4269710caf90 | 9 | |
MikamiUitOpen | 4:04bb0cfea187 | 10 | #include "ADC_BuiltIn.hpp" // for ADC not using interrupt |
MikamiUitOpen | 4:04bb0cfea187 | 11 | #include "DAC_MCP4921.hpp" // for DAC MCP4921, MCP4922 |
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 | 4:04bb0cfea187 | 22 | ADC_BuiltIn adc_(A0, FS_); |
MikamiUitOpen | 4:04bb0cfea187 | 23 | DAC_MCP4921 myDac_; |
MikamiUitOpen | 4:04bb0cfea187 | 24 | DigitalIn sw_(D2, PullDown); |
MikamiUitOpen | 0:4269710caf90 | 25 | |
MikamiUitOpen | 0:4269710caf90 | 26 | Hilbert<ORDER_> ht_(hm_); // Hilbert transform filter |
MikamiUitOpen | 0:4269710caf90 | 27 | Biquad DcCut_(c1_); // DC cut filter |
MikamiUitOpen | 0:4269710caf90 | 28 | TwoPhaseGenerator cosSin_(100, (float)FS_); // 100 Hz |
MikamiUitOpen | 0:4269710caf90 | 29 | |
MikamiUitOpen | 0:4269710caf90 | 30 | int main() |
MikamiUitOpen | 0:4269710caf90 | 31 | { |
MikamiUitOpen | 2:ba46d7cbb09e | 32 | myDac_.ScfClockTim3(500000); // cutoff frequency: 5 kHz |
MikamiUitOpen | 0:4269710caf90 | 33 | |
MikamiUitOpen | 0:4269710caf90 | 34 | while (true) |
MikamiUitOpen | 0:4269710caf90 | 35 | { |
MikamiUitOpen | 0:4269710caf90 | 36 | float xn = adc_.Read(); // Read from A0 |
MikamiUitOpen | 0:4269710caf90 | 37 | //----------------------------------------------- |
MikamiUitOpen | 0:4269710caf90 | 38 | |
MikamiUitOpen | 0:4269710caf90 | 39 | xn = DcCut_.Execute(g0_*xn); // DC cut filter |
MikamiUitOpen | 0:4269710caf90 | 40 | float yIn, yQn; |
MikamiUitOpen | 0:4269710caf90 | 41 | ht_.Execute(xn, yIn, yQn); // Hilbert transform filter |
MikamiUitOpen | 0:4269710caf90 | 42 | float cos, sin; |
MikamiUitOpen | 0:4269710caf90 | 43 | cosSin_.Generate(cos, sin); // cos and sin |
MikamiUitOpen | 0:4269710caf90 | 44 | float yn = yIn*cos - yQn*sin; |
MikamiUitOpen | 0:4269710caf90 | 45 | |
MikamiUitOpen | 4:04bb0cfea187 | 46 | if (sw_.read() == 0) yn = xn; // no frequency shift |
MikamiUitOpen | 0:4269710caf90 | 47 | //----------------------------------------------- |
MikamiUitOpen | 0:4269710caf90 | 48 | myDac_.Write(yn); // Write to DAC |
MikamiUitOpen | 0:4269710caf90 | 49 | } |
MikamiUitOpen | 0:4269710caf90 | 50 | } |