qam_decoder.cpp
上传用户:jtjnyq9001
上传日期:2014-11-21
资源大小:3974k
文件大小:3k
源码类别:

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = qam_decoder.cpp
  3. //
  4. #include <stdlib.h>
  5. //#include <fstream>
  6. #include "parmfile.h"
  7. #include "qam_decoder.h"
  8. #include "misdefs.h"
  9. #include "model_graph.h"
  10. extern ParmFile *ParmInput;
  11. extern int PassNumber;
  12. #ifdef _DEBUG
  13.   extern ofstream *DebugFile;
  14. #endif
  15. //======================================================
  16. QamSymbolDecoder::QamSymbolDecoder( char* instance_name,
  17.                                   PracSimModel* outer_model,
  18.                                   Signal<float>* i_in_sig,
  19.                                   Signal<float>* q_in_sig,
  20.                                   Signal< byte_t >* out_sig )
  21.                 :PracSimModel(instance_name,
  22.                               outer_model)
  23. {
  24.    MODEL_NAME(QamSymbolDecoder);
  25.    ENABLE_MULTIRATE;
  26.    //-----------------------------------------
  27.    //  Read model config parms
  28.    OPEN_PARM_BLOCK;
  29.    GET_INT_PARM(Bits_Per_Symb);
  30.    //--------------------------------------
  31.    //  Connect input and output signals
  32.    Out_Sig = out_sig;
  33.    I_In_Sig = i_in_sig;
  34.    Q_In_Sig = q_in_sig;
  35.    MAKE_OUTPUT( Out_Sig );
  36.    MAKE_INPUT( I_In_Sig );
  37.    MAKE_INPUT( Q_In_Sig );
  38.    SAME_RATE( I_In_Sig, Out_Sig );
  39.    SAME_RATE( Q_In_Sig, Out_Sig );
  40.    //------------------
  41.    //  compute decision boundaries
  42.    Num_Symb_Rows = 1;
  43.    for(int i=1; i<=Bits_Per_Symb/2; i++)
  44.     Num_Symb_Rows *=2;
  45.    I_Boundary = new double[Num_Symb_Rows-1];
  46.    Q_Boundary = new double[Num_Symb_Rows-1];
  47.    for(int isymb=0; isymb<Num_Symb_Rows-1; isymb++)
  48.       {
  49.       I_Boundary[isymb] = double(2 - Num_Symb_Rows + 2 * isymb)/2.0;
  50.       Q_Boundary[isymb] = double(2 - Num_Symb_Rows + 2 * isymb)/2.0;
  51.       }
  52. }
  53. //==============================================
  54. QamSymbolDecoder::~QamSymbolDecoder( void ){ };
  55. //==============================================
  56. void QamSymbolDecoder::Initialize(void)
  57. {
  58.   Block_Size = I_In_Sig->GetBlockSize();
  59.   Out_Samp_Intvl = Out_Sig->GetSampIntvl();
  60. }
  61. //============================================
  62. int QamSymbolDecoder::Execute()
  63. {
  64.    byte_t *out_sig_ptr;
  65.    byte_t i_decis, q_decis;
  66.    float *i_in_sig_ptr, *q_in_sig_ptr;
  67.    float i_in_val, q_in_val;
  68.    int is;
  69.    byte_t isymb, symb_decis;
  70.    #ifdef _DEBUG
  71.     *DebugFile << "In QamSymbolDecoder::Execute" << endl;
  72.    #endif
  73.    i_in_sig_ptr = GET_INPUT_PTR( I_In_Sig );
  74.    q_in_sig_ptr = GET_INPUT_PTR( Q_In_Sig );
  75.    out_sig_ptr = GET_OUTPUT_PTR( Out_Sig );
  76.    for (is=0; is<Block_Size; is++)
  77.       {
  78.       i_in_val = *i_in_sig_ptr++;
  79.       q_in_val = *q_in_sig_ptr++;
  80.       i_decis = 0;
  81.       for(isymb=0; isymb<Num_Symb_Rows-1; isymb++)
  82.       {
  83.       if(i_in_val < I_Boundary[isymb]) break;
  84.       i_decis++;
  85.       }
  86.       q_decis = 0;
  87.       for(isymb=0; isymb<Num_Symb_Rows-1; isymb++)
  88.       {
  89.       if(q_in_val < Q_Boundary[isymb]) break;
  90.       q_decis++;
  91.       }
  92.       symb_decis = q_decis + Num_Symb_Rows * i_decis;
  93.       *out_sig_ptr = symb_decis;
  94.       out_sig_ptr++;
  95.       }
  96.    return(_MES_AOK);
  97. }