| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE MultirateSynchronizer. |
|---|
| 6 | |
|---|
| 7 | OSSIE MultirateSynchronizer is free software; you can redistribute it and/or |
|---|
| 8 | modify it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE MultirateSynchronizer is distributed in the hope that it will be |
|---|
| 13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with OSSIE MultirateSynchronizer; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | ****************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #ifndef MULTIRATESYNCHRONIZERDSP_IMPL_H |
|---|
| 25 | #define MULTIRATESYNCHRONIZERDSP_IMPL_H |
|---|
| 26 | |
|---|
| 27 | #include <stdlib.h> |
|---|
| 28 | #include "SymbolSyncPolyDSP.h" |
|---|
| 29 | |
|---|
| 30 | #define ALPHA_C_LO 0.0066667 |
|---|
| 31 | #define ALPHA_C_HI 0.066667 |
|---|
| 32 | #define BETA_C_LO 7.8567e-06 |
|---|
| 33 | #define BETA_C_HI 0.0023570 |
|---|
| 34 | |
|---|
| 35 | #define QAM16_PHASE_ERROR_THRESHOLD_1 7236 |
|---|
| 36 | #define QAM16_PHASE_ERROR_THRESHOLD_2 11708 |
|---|
| 37 | |
|---|
| 38 | /// Modulation scheme for phase error generator |
|---|
| 39 | enum ModulationScheme { |
|---|
| 40 | MOD_BPSK = 0, |
|---|
| 41 | MOD_QPSK = 1, |
|---|
| 42 | MOD_8PSK = 2, |
|---|
| 43 | MOD_16QAM = 3, |
|---|
| 44 | MOD_4PAM = 4 |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | /** \brief Digital signal processing for the synchronizer component |
|---|
| 49 | * implemented with the polyphase filter bank |
|---|
| 50 | * |
|---|
| 51 | * |
|---|
| 52 | */ |
|---|
| 53 | class MultirateSynchronizerDSP : public SymbolSyncPolyDSP |
|---|
| 54 | { |
|---|
| 55 | public: |
|---|
| 56 | /// Initializing constructor |
|---|
| 57 | MultirateSynchronizerDSP(); |
|---|
| 58 | |
|---|
| 59 | /// Destructor |
|---|
| 60 | ~MultirateSynchronizerDSP(); |
|---|
| 61 | |
|---|
| 62 | /// Set modulation scheme for phase error generator |
|---|
| 63 | void SetModulationScheme(ModulationScheme _ms); |
|---|
| 64 | |
|---|
| 65 | /// |
|---|
| 66 | ///\todo change to : void UpdatePhaseLoopFilterCoefficients(float _BT); |
|---|
| 67 | void UpdatePhaseLoopFilterCoefficients(float _alpha_c, float _beta_c) { |
|---|
| 68 | alpha_c = _alpha_c; |
|---|
| 69 | beta_c = _beta_c; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | /// Overriding method... |
|---|
| 73 | void SynchronizeAndDecimate(short * I_in, |
|---|
| 74 | short * Q_in, |
|---|
| 75 | unsigned int N_in, |
|---|
| 76 | short * I_out, |
|---|
| 77 | short * Q_out, |
|---|
| 78 | unsigned int & N_out); |
|---|
| 79 | |
|---|
| 80 | protected: |
|---|
| 81 | /// |
|---|
| 82 | ModulationScheme mod_scheme; |
|---|
| 83 | |
|---|
| 84 | /// |
|---|
| 85 | float (*GeneratePhaseError) (short &I, short &Q); |
|---|
| 86 | |
|---|
| 87 | /// Pushes inputs determined by flow control as necessary (overloaded function) |
|---|
| 88 | void PushInputs( short * I_in, short * Q_in, unsigned int &i, unsigned int N_in ); |
|---|
| 89 | |
|---|
| 90 | /// |
|---|
| 91 | void AdvancePhaseLoopFilter() { |
|---|
| 92 | q_prime_c = q_c*beta_c + buff2_c; |
|---|
| 93 | q_hat_c = alpha_c*q_c + q_prime_c; |
|---|
| 94 | buff2_c = q_prime_c; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | /// Apply numerically controlled oscillator |
|---|
| 98 | void ApplyNCO( short I_in, short Q_in, short &I_out, short &Q_out ) { |
|---|
| 99 | I_out = short( float(I_in) * nco_i + float(Q_in) * nco_q ); |
|---|
| 100 | Q_out = short( float(Q_in) * nco_i - float(I_in) * nco_q ); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | /// Update numerically controlled oscillator |
|---|
| 104 | void UpdateNCO(); |
|---|
| 105 | |
|---|
| 106 | // Carrier phase loop filter |
|---|
| 107 | float alpha_c; ///< Phase loop filter coefficient, \f$\alpha_c\f$ |
|---|
| 108 | float beta_c; ///< Phase loop filter coefficient, \f$\beta_c\f$ |
|---|
| 109 | float q_c; ///< Phase error signal |
|---|
| 110 | float q_hat_c; ///< Filtered phase error signal |
|---|
| 111 | float q_prime_c; ///< Phase loop filter buffer 1 |
|---|
| 112 | float buff2_c; ///< Phase loop filter buffer 2 |
|---|
| 113 | |
|---|
| 114 | // Numerically-controlled oscillator |
|---|
| 115 | float nco_control; ///< NCO control phase, \f$\int{cv}\f$ |
|---|
| 116 | float cv; ///< NCO control voltage |
|---|
| 117 | float wcTs; ///< Initial frequency offset estimate |
|---|
| 118 | float nco_i; ///< NCO in-phase output |
|---|
| 119 | float nco_q; ///< NCO quadrature output |
|---|
| 120 | |
|---|
| 121 | private: |
|---|
| 122 | /// Disallow copy constructor |
|---|
| 123 | MultirateSynchronizerDSP(MultirateSynchronizerDSP&); |
|---|
| 124 | |
|---|
| 125 | }; |
|---|
| 126 | |
|---|
| 127 | /// Phase error generator for BPSK modulation |
|---|
| 128 | float GeneratePhaseErrorBPSK(short &I, short &Q); |
|---|
| 129 | |
|---|
| 130 | /// Phase error generator for QPSK modulation |
|---|
| 131 | float GeneratePhaseErrorQPSK(short &I, short &Q); |
|---|
| 132 | |
|---|
| 133 | /// Phase error generator for 8PSK modulation |
|---|
| 134 | float GeneratePhaseError8PSK(short &I, short &Q); |
|---|
| 135 | |
|---|
| 136 | /// Phase error generator for 16QAM modulation |
|---|
| 137 | float GeneratePhaseError16QAM(short &I, short &Q); |
|---|
| 138 | |
|---|
| 139 | /// Phase error generator for 4-PAM modulation |
|---|
| 140 | float GeneratePhaseError4PAM(short &I, short &Q); |
|---|
| 141 | |
|---|
| 142 | #endif |
|---|
| 143 | |
|---|