Changeset 3997

Show
Ignore:
Timestamp:
05/29/07 10:26:43 (6 years ago)
Author:
jgaeddert
Message:

adding signal amplitude correction method to Demodulator component; needs testing

Location:
experimental/components/Demodulator/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • experimental/components/Demodulator/src/DemodulatorDSP.cpp

    r3996 r3997  
    2929DemodulatorDSP::DemodulatorDSP() 
    3030{ 
    31     bitsPerSymbol = 1; 
    32     Demodulate = &DemodulateBPSK; 
    33     state_i = 0; 
    34     state_q = 0; 
     31    SetModulationScheme( MOD_BPSK ); 
    3532} 
    3633 
     
    4744        Demodulate = &DemodulateBPSK; 
    4845        bitsPerSymbol = 1; 
     46        differentialMode = false; 
    4947        break; 
    5048    case MOD_QPSK: 
    5149        Demodulate = &DemodulateQPSK; 
    5250        bitsPerSymbol = 2; 
     51        differentialMode = false; 
    5352        break; 
    5453    case MOD_8PSK: 
    5554        Demodulate = &Demodulate8PSK; 
    5655        bitsPerSymbol = 3; 
     56        differentialMode = false; 
    5757        break; 
    5858    case MOD_16QAM: 
    5959        Demodulate = &Demodulate16QAM; 
    6060        bitsPerSymbol = 4; 
     61        differentialMode = false; 
    6162        break; 
    6263    case MOD_4PAM: 
    6364        Demodulate = &Demodulate4PAM; 
    6465        bitsPerSymbol = 2; 
     66        differentialMode = false; 
    6567        break; 
    6668    case MOD_DBPSK: 
     
    6971        Demodulate = &DemodulateBPSK; 
    7072        bitsPerSymbol = 1; 
     73        differentialMode = true; 
    7174        break; 
    7275    case MOD_DQPSK: 
     
    7578        Demodulate = &DemodulateQPSK; 
    7679        bitsPerSymbol = 2; 
     80        differentialMode = true; 
    7781        break; 
    7882    case MOD_D8PSK: 
     
    8185        Demodulate = &Demodulate8PSK; 
    8286        bitsPerSymbol = 3; 
     87        differentialMode = true; 
    8388        break; 
    8489    default: 
     
    100105        char * bits_out) 
    101106{ 
    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// 
     129void 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 ); 
    106148    } 
    107149} 
  • experimental/components/Demodulator/src/DemodulatorDSP.h

    r3996 r3997  
    3131#define BIT1 1 
    3232 
     33#define TARGET_SIGNAL_ENERGY 10000 
     34 
    3335/// Modulation scheme 
    3436enum ModulationScheme { 
     
    5961    void SetModulationScheme(ModulationScheme _ms); 
    6062 
    61     /// 
     63    /// Demodulates sequence of symbols 
    6264    void DemodulateSequence( 
    6365        short * I_in, 
     
    6769 
    6870  protected: 
    69     /// 
     71    /// Demodulation function pointer 
    7072    void (*Demodulate) ( 
    7173        short & I_in, 
     
    7476 
    7577    /// 
    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); 
    7784 
    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 
    8590 
    8691  private: