Changeset 3997
- Timestamp:
- 05/29/07 10:26:43 (6 years ago)
- Location:
- experimental/components/Demodulator/src
- Files:
-
- 2 modified
-
DemodulatorDSP.cpp (modified) (6 diffs)
-
DemodulatorDSP.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
experimental/components/Demodulator/src/DemodulatorDSP.cpp
r3996 r3997 29 29 DemodulatorDSP::DemodulatorDSP() 30 30 { 31 bitsPerSymbol = 1; 32 Demodulate = &DemodulateBPSK; 33 state_i = 0; 34 state_q = 0; 31 SetModulationScheme( MOD_BPSK ); 35 32 } 36 33 … … 47 44 Demodulate = &DemodulateBPSK; 48 45 bitsPerSymbol = 1; 46 differentialMode = false; 49 47 break; 50 48 case MOD_QPSK: 51 49 Demodulate = &DemodulateQPSK; 52 50 bitsPerSymbol = 2; 51 differentialMode = false; 53 52 break; 54 53 case MOD_8PSK: 55 54 Demodulate = &Demodulate8PSK; 56 55 bitsPerSymbol = 3; 56 differentialMode = false; 57 57 break; 58 58 case MOD_16QAM: 59 59 Demodulate = &Demodulate16QAM; 60 60 bitsPerSymbol = 4; 61 differentialMode = false; 61 62 break; 62 63 case MOD_4PAM: 63 64 Demodulate = &Demodulate4PAM; 64 65 bitsPerSymbol = 2; 66 differentialMode = false; 65 67 break; 66 68 case MOD_DBPSK: … … 69 71 Demodulate = &DemodulateBPSK; 70 72 bitsPerSymbol = 1; 73 differentialMode = true; 71 74 break; 72 75 case MOD_DQPSK: … … 75 78 Demodulate = &DemodulateQPSK; 76 79 bitsPerSymbol = 2; 80 differentialMode = true; 77 81 break; 78 82 case MOD_D8PSK: … … 81 85 Demodulate = &Demodulate8PSK; 82 86 bitsPerSymbol = 3; 87 differentialMode = true; 83 88 break; 84 89 default: … … 100 105 char * bits_out) 101 106 { 102 unsigned int j(0); 103 for (unsigned int i=0; i<N_in; i++) { 104 Demodulate(I_in[i], Q_in[i], bits_out+j); 105 j += bitsPerSymbol; 107 unsigned int i, j(0); 108 109 // If QAM or PAM correct for amplitude 110 if ( mod_scheme == MOD_16QAM || mod_scheme == MOD_4PAM ) { 111 ScaleSignalAmplitude(I_in, Q_in, N_in, TARGET_SIGNAL_ENERGY); 112 } 113 114 if ( differentialMode ) { 115 ///\todo implement differential PSK demodulation 116 std::cerr << "ERROR: DemodulatorDSP::DemodulateSequence(): " 117 << "differential mode not yet supported!" << std::endl; 118 throw 0; 119 } else { 120 for (i=0; i<N_in; i++) { 121 Demodulate(I_in[i], Q_in[i], bits_out+j); 122 j += bitsPerSymbol; 123 } 124 } 125 } 126 127 128 // 129 void DemodulatorDSP::ScaleSignalAmplitude( 130 short * I_in, 131 short * Q_in, 132 unsigned int N_in, 133 unsigned int targetEnergy) 134 { 135 unsigned int i; 136 float energy(0.0f), scalingFactor(targetEnergy); 137 for (i=0; i<N_in; i++) { 138 energy += float(I_in[i])*float(I_in[i]); 139 energy += float(Q_in[i])*float(Q_in[i]); 140 } 141 energy /= float(N_in); 142 143 scalingFactor = sqrtf(scalingFactor/energy); 144 145 for (i=0; i<N_in; i++) { 146 I_in[i] = short( I_in[i]*scalingFactor ); 147 Q_in[i] = short( Q_in[i]*scalingFactor ); 106 148 } 107 149 } -
experimental/components/Demodulator/src/DemodulatorDSP.h
r3996 r3997 31 31 #define BIT1 1 32 32 33 #define TARGET_SIGNAL_ENERGY 10000 34 33 35 /// Modulation scheme 34 36 enum ModulationScheme { … … 59 61 void SetModulationScheme(ModulationScheme _ms); 60 62 61 /// 63 /// Demodulates sequence of symbols 62 64 void DemodulateSequence( 63 65 short * I_in, … … 67 69 68 70 protected: 69 /// 71 /// Demodulation function pointer 70 72 void (*Demodulate) ( 71 73 short & I_in, … … 74 76 75 77 /// 76 unsigned int bitsPerSymbol; 78 ///\todo check amplitude correction method 79 void ScaleSignalAmplitude( 80 short * I_in, 81 short * Q_in, 82 unsigned int N_in, 83 unsigned int targetEnergy); 77 84 78 /// 79 short state_i; 80 81 /// 82 short state_q; 83 84 ModulationScheme mod_scheme; 85 unsigned int bitsPerSymbol; ///< Number of bits represented by each symbol 86 short state_i; ///< In-phase state for differential mode 87 short state_q; ///< Quadrature state for differential mode 88 ModulationScheme mod_scheme; ///< Current (de)modulation scheme 89 bool differentialMode; ///< Differential PSK mode flag 85 90 86 91 private: