![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Frequency shifter using analytic signal for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
HilbertTransform.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 | // Hilbert transform filter |
MikamiUitOpen | 0:4269710caf90 | 3 | // Copyright (c) 2014 MIKAMI, Naoki, 2014/06/23 |
MikamiUitOpen | 0:4269710caf90 | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:4269710caf90 | 5 | |
MikamiUitOpen | 0:4269710caf90 | 6 | #ifndef HILBERT_TRANSFORM_HPP |
MikamiUitOpen | 0:4269710caf90 | 7 | #define HILBERT_TRANSFORM_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 | // order must be 4K+2, K: integer |
MikamiUitOpen | 0:4269710caf90 | 14 | template<int order> class Hilbert |
MikamiUitOpen | 0:4269710caf90 | 15 | { |
MikamiUitOpen | 0:4269710caf90 | 16 | private: |
MikamiUitOpen | 0:4269710caf90 | 17 | const float *const hm_; // pointer for filter coefficients |
MikamiUitOpen | 0:4269710caf90 | 18 | float xn_[order+1]; // buffer for inputs |
MikamiUitOpen | 0:4269710caf90 | 19 | |
MikamiUitOpen | 0:4269710caf90 | 20 | Hilbert(const Hilbert&); |
MikamiUitOpen | 0:4269710caf90 | 21 | Hilbert& operator=(const Hilbert&); |
MikamiUitOpen | 0:4269710caf90 | 22 | public: |
MikamiUitOpen | 0:4269710caf90 | 23 | Hilbert(const float hk[]) : hm_(hk) |
MikamiUitOpen | 0:4269710caf90 | 24 | { |
MikamiUitOpen | 0:4269710caf90 | 25 | if ( ((order-2) % 4) != 0) |
MikamiUitOpen | 0:4269710caf90 | 26 | fprintf(stderr, "order must be 4*K+2, K: integer\r\n"); |
MikamiUitOpen | 0:4269710caf90 | 27 | Clear(); |
MikamiUitOpen | 0:4269710caf90 | 28 | } |
MikamiUitOpen | 0:4269710caf90 | 29 | |
MikamiUitOpen | 0:4269710caf90 | 30 | // yI: in-phase signal |
MikamiUitOpen | 0:4269710caf90 | 31 | // yQ: quadrature signal |
MikamiUitOpen | 0:4269710caf90 | 32 | void Execute(float xin, float& yI, float& yQ) |
MikamiUitOpen | 0:4269710caf90 | 33 | { |
MikamiUitOpen | 0:4269710caf90 | 34 | yQ = 0.0; |
MikamiUitOpen | 0:4269710caf90 | 35 | xn_[0] = xin; |
MikamiUitOpen | 0:4269710caf90 | 36 | |
MikamiUitOpen | 0:4269710caf90 | 37 | for (int k=0; k<=order/4; k++) |
MikamiUitOpen | 0:4269710caf90 | 38 | yQ = yQ + hm_[k]*(xn_[2*k] - xn_[order-2*k]); |
MikamiUitOpen | 0:4269710caf90 | 39 | yI = xn_[order/2]; // in-phase signal |
MikamiUitOpen | 0:4269710caf90 | 40 | |
MikamiUitOpen | 0:4269710caf90 | 41 | for (int k=order; k>0; k--) |
MikamiUitOpen | 0:4269710caf90 | 42 | xn_[k] = xn_[k-1]; // move input signals |
MikamiUitOpen | 0:4269710caf90 | 43 | } |
MikamiUitOpen | 0:4269710caf90 | 44 | |
MikamiUitOpen | 0:4269710caf90 | 45 | void Clear() |
MikamiUitOpen | 0:4269710caf90 | 46 | { for (int k=0; k<=order; k++) xn_[k] = 0.0f; } |
MikamiUitOpen | 0:4269710caf90 | 47 | }; |
MikamiUitOpen | 0:4269710caf90 | 48 | } |
MikamiUitOpen | 0:4269710caf90 | 49 | #endif // HILBERT_TRANSFORM_HPP |
MikamiUitOpen | 0:4269710caf90 | 50 | |
MikamiUitOpen | 0:4269710caf90 | 51 |