![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Frequency shifter using analytic signal for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
TwoPhaseGenerator.hpp@4:04bb0cfea187, 2015-07-25 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Jul 25 07:32:50 2015 +0000
- Revision:
- 4:04bb0cfea187
- Parent:
- 0:4269710caf90
5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:4269710caf90 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:4269710caf90 | 2 | // Two phase sin generator class |
MikamiUitOpen | 0:4269710caf90 | 3 | // 2014/10/22, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:4269710caf90 | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:4269710caf90 | 5 | |
MikamiUitOpen | 0:4269710caf90 | 6 | #ifndef TWO_PHASE_GENERATOR_HPP |
MikamiUitOpen | 0:4269710caf90 | 7 | #define TWO_PHASE_GENERATOR_HPP |
MikamiUitOpen | 0:4269710caf90 | 8 | |
MikamiUitOpen | 0:4269710caf90 | 9 | #include "mbed.h" |
MikamiUitOpen | 0:4269710caf90 | 10 | |
MikamiUitOpen | 0:4269710caf90 | 11 | namespace Mikami |
MikamiUitOpen | 0:4269710caf90 | 12 | { |
MikamiUitOpen | 0:4269710caf90 | 13 | class TwoPhaseGenerator |
MikamiUitOpen | 0:4269710caf90 | 14 | { |
MikamiUitOpen | 0:4269710caf90 | 15 | public: |
MikamiUitOpen | 0:4269710caf90 | 16 | // Constructor |
MikamiUitOpen | 0:4269710caf90 | 17 | TwoPhaseGenerator(float f0, float fs) |
MikamiUitOpen | 0:4269710caf90 | 18 | : a1_(cosf(6.283185f*f0/fs)), |
MikamiUitOpen | 0:4269710caf90 | 19 | b1_(sinf(6.283185f*f0/fs)), |
MikamiUitOpen | 0:4269710caf90 | 20 | xn1_(1.0f), yn1_(0.0f) {} |
MikamiUitOpen | 0:4269710caf90 | 21 | |
MikamiUitOpen | 0:4269710caf90 | 22 | // -1.0f <= x1, x2 <= 1.0f |
MikamiUitOpen | 0:4269710caf90 | 23 | void Generate(float& xn, float& yn) |
MikamiUitOpen | 0:4269710caf90 | 24 | { |
MikamiUitOpen | 0:4269710caf90 | 25 | yn = a1_*yn1_ + b1_*xn1_; // sin |
MikamiUitOpen | 0:4269710caf90 | 26 | xn = -b1_*yn1_ + a1_*xn1_; // cos |
MikamiUitOpen | 0:4269710caf90 | 27 | |
MikamiUitOpen | 0:4269710caf90 | 28 | float c1 = 1.5f - 0.5f*(xn*xn + yn*yn); |
MikamiUitOpen | 0:4269710caf90 | 29 | |
MikamiUitOpen | 0:4269710caf90 | 30 | xn1_ = c1*xn; |
MikamiUitOpen | 0:4269710caf90 | 31 | yn1_ = c1*yn; |
MikamiUitOpen | 0:4269710caf90 | 32 | } |
MikamiUitOpen | 0:4269710caf90 | 33 | |
MikamiUitOpen | 0:4269710caf90 | 34 | private: |
MikamiUitOpen | 0:4269710caf90 | 35 | const float a1_, b1_; |
MikamiUitOpen | 0:4269710caf90 | 36 | float xn1_, yn1_; |
MikamiUitOpen | 0:4269710caf90 | 37 | |
MikamiUitOpen | 0:4269710caf90 | 38 | TwoPhaseGenerator(const TwoPhaseGenerator&); |
MikamiUitOpen | 0:4269710caf90 | 39 | TwoPhaseGenerator& operator=(const TwoPhaseGenerator&); |
MikamiUitOpen | 0:4269710caf90 | 40 | }; |
MikamiUitOpen | 0:4269710caf90 | 41 | } |
MikamiUitOpen | 0:4269710caf90 | 42 | #endif // TWO_PHASE_GENERATOR_HPP |