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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = m_pskharddem.cpp
  3. //
  4. #include <stdlib.h>
  5. //#include <fstream>
  6. #include "parmfile.h"
  7. #include "m_pskharddem.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. M_PskHardDemod::M_PskHardDemod( char* instance_name,
  17.                                   PracSimModel* outer_model,
  18.                                   Signal< std::complex< float > >* in_sig,
  19.                                   Signal< std::complex< float > >* integ_sig,
  20.                                   Signal< byte_t >* out_sig )
  21.                 :PracSimModel(instance_name,
  22.                               outer_model)
  23. {
  24.   MODEL_NAME(M_PskHardDemod);
  25.   ENABLE_MULTIRATE;
  26.   //-----------------------------------------
  27.   //  Read model config parms
  28.   OPEN_PARM_BLOCK;
  29.   GET_DOUBLE_PARM(Phase_Unbal);
  30.   GET_INT_PARM(Bits_Per_Symb);
  31.   GET_INT_PARM(Samps_Per_Symb);
  32.   GET_DOUBLE_PARM(Dly_To_Start);
  33.   //int block_size = ParmInput.GetIntParm("block_size");
  34.   //double samp_intvl = ParmInput.GetDoubleParm("samp_intvl");
  35.   //--------------------------------------
  36.   //  Connect input and output signals
  37.   Out_Sig = out_sig;
  38.   Integ_Sig = integ_sig;
  39.   In_Sig = in_sig;
  40.   MAKE_OUTPUT( Integ_Sig );
  41.   MAKE_OUTPUT( Out_Sig );
  42.   MAKE_INPUT( In_Sig );
  43.   double resamp_rate = 1.0/double(Samps_Per_Symb);
  44.   CHANGE_RATE( In_Sig, Out_Sig, resamp_rate );
  45.   SAME_RATE( In_Sig, Integ_Sig );
  46.   //------------------
  47.   //  compute decision boundaries
  48.   Num_Diff_Symbs = 1;
  49.   for(int i=1; i<=Bits_Per_Symb; i++)
  50.     Num_Diff_Symbs *=2;
  51.   double offset = TWO_PI/(2.0*Num_Diff_Symbs);
  52.   Decis_Bound = new float[Num_Diff_Symbs];
  53.   for(int isymb=0; isymb<Num_Diff_Symbs; isymb++)
  54.     {
  55.     Decis_Bound[isymb] = float(offset + isymb*TWO_PI/double(Num_Diff_Symbs));
  56.     }
  57. }
  58. //==============================================
  59. M_PskHardDemod::~M_PskHardDemod( void ){ };
  60. //==============================================
  61. void M_PskHardDemod::Initialize(void)
  62. {
  63.   Block_Size = In_Sig->GetBlockSize();
  64.   Integ_Val = std::complex<float>(0.0,0.0);
  65.   Out_Samp_Intvl = Out_Sig->GetSampIntvl();
  66. }
  67. //============================================
  68. int M_PskHardDemod::Execute()
  69. {
  70.   byte_t *out_sig_ptr;
  71.   //double ref_phase, phase_unbal;
  72.   std::complex<float> *in_sig_ptr, *integ_sig_ptr;
  73.   std::complex<float> in_val, integ_val;
  74.   float angle;
  75.   int is;
  76.   int isymb;
  77.   byte_t symb_decis;
  78.   #ifdef _DEBUG
  79.     *DebugFile << "In M_PskHardDemod::Execute" << endl;
  80.   #endif
  81.   in_sig_ptr = GET_INPUT_PTR( In_Sig );
  82.   integ_sig_ptr = GET_INPUT_PTR( Integ_Sig );
  83.   out_sig_ptr = GET_OUTPUT_PTR( Out_Sig );
  84.   integ_val = Integ_Val;
  85.   if(PassNumber == 1)
  86.     {
  87.     int num_filler_samps = int(ceil(Dly_To_Start/Out_Samp_Intvl));
  88.     for(int n=0; n<num_filler_samps; n++)
  89.       {
  90.       *out_sig_ptr++ = 0;
  91.       }
  92.     }
  93.   //phase_unbal = Phase_Unbal;
  94.   int samps_in_curr_symb = -Samps_Per_Symb;
  95.   for (is=0; is<Block_Size; is++)
  96.     {
  97.     in_val = *in_sig_ptr++;
  98.     integ_val += in_val;
  99.     *integ_sig_ptr++ = integ_val;
  100.     samps_in_curr_symb++;
  101.     if(samps_in_curr_symb >= 0)
  102.       {
  103.       // time to make a decision
  104.       angle = std::arg<float>(integ_val);
  105.       integ_val = std::complex<float>(0.0,0.0);
  106.       if(angle < 0.0) angle += TWO_PI;
  107.       for(isymb=0; isymb<Num_Diff_Symbs; isymb++)
  108.         {
  109.         symb_decis = isymb;
  110.         if(angle < Decis_Bound[isymb]) break;
  111.         symb_decis = 0;
  112.         }
  113.       *out_sig_ptr = symb_decis;
  114.       out_sig_ptr++;
  115.       samps_in_curr_symb -= Samps_Per_Symb;
  116.       }
  117.     }
  118.   Integ_Val = integ_val;
  119.   return(_MES_AOK);
  120. }