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

3G开发

开发平台:

Visual C++

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