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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = bpsk_correl_demod.cpp
  3. //
  4. #include <stdlib.h>
  5. #include <fstream>
  6. #include "parmfile.h"
  7. #include "bpsk_correl_demod.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. BpskCorrelationDemod::BpskCorrelationDemod( char* instance_name,
  17.                                   PracSimModel* outer_model,
  18.                                   Signal< std::complex< float > >* in_sig,
  19.                                   Signal< std::complex<float> >* phase_ref_sig,
  20.                                   Signal< bit_t >* symb_clock_in,
  21.                                   Signal< bit_t >* decis_out )
  22.                 :PracSimModel(instance_name,
  23.                               outer_model)
  24. {
  25.   MODEL_NAME(BpskCorrelationDemod);
  26.   ENABLE_MULTIRATE;
  27.   //-----------------------------------------
  28.   //  Read model config parms
  29.   OPEN_PARM_BLOCK;
  30.   GET_INT_PARM(Samps_Per_Symb);
  31.   GET_DOUBLE_PARM(Dly_To_Start);
  32.   //--------------------------------------
  33.   //  Connect input and output signals
  34.   Decis_Out = decis_out;
  35.   Symb_Clock_In = symb_clock_in;
  36.   In_Sig = in_sig;
  37.   Phase_Ref_Sig = phase_ref_sig;
  38.   MAKE_OUTPUT( Decis_Out );
  39.   MAKE_INPUT( Symb_Clock_In );
  40.   MAKE_INPUT( Phase_Ref_Sig );
  41.   MAKE_INPUT( In_Sig );
  42.   double resamp_rate = 1.0/double(Samps_Per_Symb);
  43.   CHANGE_RATE( In_Sig, Decis_Out, resamp_rate );
  44.   CHANGE_RATE( Phase_Ref_Sig, Decis_Out, resamp_rate );
  45.   CHANGE_RATE( Symb_Clock_In, Decis_Out, resamp_rate );
  46. }
  47. //==============================================
  48. BpskCorrelationDemod::~BpskCorrelationDemod( void ){ };
  49. //==============================================
  50. void BpskCorrelationDemod::Initialize(void)
  51. {
  52.   Block_Size = In_Sig->GetBlockSize();
  53.   Out_Samp_Intvl = Decis_Out->GetSampIntvl();
  54.   Integ_Val = 0.0;
  55. }
  56. //============================================
  57. int BpskCorrelationDemod::Execute()
  58. {
  59.   bit_t *decis_out_ptr;
  60.   std::complex<float> *in_sig_ptr;
  61.   bit_t *symb_clock_in_ptr;
  62.   std::complex<float> in_val;
  63.   std::complex<float> *phase_ref_sig_ptr;
  64.   std::complex<float> phase_ref_val;
  65.   double integ_val;
  66.   double max_val=0.0;
  67.   int is;
  68.   #ifdef _DEBUG
  69.     *DebugFile << "In BpskCorrelationDemod::Execute" << endl;
  70.   #endif
  71.   int valid_block_size = In_Sig->GetValidBlockSize();
  72.   int out_block_size = valid_block_size/Samps_Per_Symb;
  73.   if(valid_block_size != Samps_Per_Symb*out_block_size) {
  74.       //error
  75.       }
  76.       else {
  77.          Decis_Out->SetValidBlockSize(out_block_size);
  78.       }
  79.   in_sig_ptr = GET_INPUT_PTR( In_Sig );
  80.   symb_clock_in_ptr = GET_INPUT_PTR( Symb_Clock_In );
  81.   phase_ref_sig_ptr = GET_INPUT_PTR( Phase_Ref_Sig );
  82.   decis_out_ptr = GET_OUTPUT_PTR( Decis_Out );
  83.   integ_val = Integ_Val;
  84.   for (is=0; is<valid_block_size; is++)
  85.     {
  86.     in_val = *in_sig_ptr++;
  87.     // correlate input signal against recovered carrier
  88.     phase_ref_val = *phase_ref_sig_ptr++;
  89. //    Integ_Val += std::real(in_val * 
  90. //                  std::complex<float>( cos(phase_ref_val), -sin(phase_ref_val) ));
  91.     Integ_Val += std::real(in_val * phase_ref_val);
  92.     if(*symb_clock_in_ptr != 0)
  93.       {
  94.       // time to make a decision
  95.       if(Integ_Val > 0.0 )
  96.         {
  97.         *decis_out_ptr++ = 1;
  98.         }
  99.       else
  100.         {
  101.         *decis_out_ptr++ = 0;
  102.         }
  103.       Integ_Val = 0.0;
  104.       }
  105.     symb_clock_in_ptr++;
  106.     }
  107.   //Integ_Val = integ_val;
  108.   return(_MES_AOK);
  109. }