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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = qam_symbtowave.cpp
  3. //
  4. #include <stdlib.h>
  5. //#include <fstream>
  6. #include "parmfile.h"
  7. #include "qam_symbtowave.h"
  8. #include "model_error.h"
  9. #include "misdefs.h"
  10. #include "model_graph.h"
  11. #include "typedefs.h"
  12. //#include "cmpxsig.h"
  13. extern ParmFile *ParmInput;
  14. #ifdef _DEBUG
  15.   extern ofstream *DebugFile;
  16. #endif
  17. //======================================================
  18. QamSymbsToQuadWaves::QamSymbsToQuadWaves( char* instance_name,
  19.                               PracSimModel* outer_model,
  20.                               Signal<byte_t>* in_symb_seq,
  21.                               Signal<float>* i_out_sig,
  22.                               Signal<float>* q_out_sig,
  23.                               Signal<bit_t>* symb_clock_out )
  24.                 :PracSimModel(instance_name,
  25.                               outer_model)
  26. {
  27.   MODEL_NAME(QamSymbsToQuadWaves);
  28.   ENABLE_MULTIRATE;
  29.   //----------------------------------------
  30.   //  Read model config parms
  31.   OPEN_PARM_BLOCK;
  32.   GET_INT_PARM(Bits_Per_Symb);
  33.   GET_INT_PARM(Samps_Per_Symb);
  34.   GET_DOUBLE_PARM(Symb_Duration);
  35.   //-------------------------------------
  36.   //  Connect input and output signals
  37.   In_Symb_Seq = in_symb_seq;
  38.   I_Out_Sig = i_out_sig;
  39.   Q_Out_Sig = q_out_sig;
  40.   Symb_Clock_Out = symb_clock_out;
  41.   MAKE_OUTPUT( I_Out_Sig );
  42.   MAKE_OUTPUT( Q_Out_Sig );
  43.   MAKE_OUTPUT( Symb_Clock_Out );
  44.   MAKE_INPUT( In_Symb_Seq );
  45.   // one sample per symbol from input
  46.   double resamp_rate = double(Samps_Per_Symb);
  47.   SET_SAMP_INTVL( In_Symb_Seq, Symb_Duration);
  48.   CHANGE_RATE( In_Symb_Seq, Symb_Clock_Out, resamp_rate );
  49.   CHANGE_RATE( In_Symb_Seq, I_Out_Sig, resamp_rate );
  50.   CHANGE_RATE( In_Symb_Seq, Q_Out_Sig, resamp_rate );
  51.   //-----------------------------------------
  52.   // Set up derived parms
  53.   Num_Symb_Rows = 1;
  54.   for(int i=1; i<=Bits_Per_Symb/2; i++)
  55.     Num_Symb_Rows *=2;
  56.   //------------------------------------------------------------
  57.   //  generate tables of I & Q values for desired constellation
  58.   I_Compon = new float[Num_Symb_Rows];
  59.   Q_Compon = new float[Num_Symb_Rows];
  60.   for(int isymb=0; isymb<Num_Symb_Rows; isymb++)
  61.     {
  62.     I_Compon[isymb] = float(1 - Num_Symb_Rows + 2 * isymb);
  63.     Q_Compon[isymb] = float(1 - Num_Symb_Rows + 2 * isymb);
  64.     }
  65. }
  66. //===========================================
  67. QamSymbsToQuadWaves::~QamSymbsToQuadWaves( void ){ };
  68. //===========================================
  69. void QamSymbsToQuadWaves::Initialize(void)
  70. {
  71.   In_Block_Size = In_Symb_Seq->GetBlockSize();
  72.   Out_Block_Size = I_Out_Sig->GetBlockSize();
  73. }
  74. //============================================
  75. int QamSymbsToQuadWaves::Execute(void)
  76. {
  77.   byte_t *in_symb_seq_ptr;
  78.   byte_t i_part, q_part;
  79.   float i_comp, q_comp;
  80.   float *i_out_sig_ptr, *q_out_sig_ptr;
  81.   int in_block_size;
  82.   int out_block_size;
  83.   bit_t *symb_clock_out_ptr;
  84.   int is;
  85.   #ifdef _DEBUG
  86.     *DebugFile << "In QamSymbsToQuadWaves::Execute" << endl;
  87.   #endif
  88.   i_out_sig_ptr = GET_OUTPUT_PTR( I_Out_Sig );
  89.   q_out_sig_ptr = GET_OUTPUT_PTR( Q_Out_Sig );
  90.   symb_clock_out_ptr = GET_OUTPUT_PTR( Symb_Clock_Out );
  91.   in_symb_seq_ptr = GET_INPUT_PTR( In_Symb_Seq );
  92.   in_block_size = In_Symb_Seq->GetValidBlockSize();
  93.   out_block_size = Samps_Per_Symb * in_block_size;
  94.   I_Out_Sig->SetValidBlockSize(out_block_size);
  95.   Q_Out_Sig->SetValidBlockSize(out_block_size);
  96.   Symb_Clock_Out->SetValidBlockSize(out_block_size);
  97.   for (is=0; is<in_block_size; is++)
  98.     {
  99.     //  get input symbol and split into ideal I & Q components
  100.     i_part = (*in_symb_seq_ptr)/Num_Symb_Rows; // 2 MSBs
  101.     q_part = (*in_symb_seq_ptr)%Num_Symb_Rows; // 2 LSBs
  102.     i_comp = I_Compon[i_part];
  103.     q_comp = Q_Compon[q_part];
  104.     in_symb_seq_ptr++;
  105.     for(int isamp=0; isamp<Samps_Per_Symb; isamp++)
  106.       {
  107.       *i_out_sig_ptr++ = i_comp;
  108.       *q_out_sig_ptr++ = q_comp;
  109.       if(isamp == (Samps_Per_Symb-1))
  110.         *symb_clock_out_ptr++ = 1;
  111.       else
  112.         *symb_clock_out_ptr++ = 0;
  113.       }
  114.     }
  115.   return(_MES_AOK);
  116. }