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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = fsk_demod_bp.cpp
  3. //
  4. #include <stdlib.h>
  5. //#include <fstream>
  6. #include "parmfile.h"
  7. #include "fsk_demod_bp.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. FskBandpassDemod::FskBandpassDemod( char* instance_name,
  17.                                   PracSimModel* outer_model,
  18.                                   Signal< float >* in_sig,
  19.                                   Signal< bit_t >* symb_clock_in,
  20.                                   Signal< bit_t >* decis_out,
  21.                                   Signal< float >* lo_filt_output,
  22.                                   Signal< float >* hi_filt_output,
  23.                                   Signal< float >* lo_integ_sig,
  24.                                   Signal< float >* hi_integ_sig )
  25.                 :PracSimModel(instance_name,
  26.                               outer_model)
  27. {
  28.   MODEL_NAME(FskBandpassDemod);
  29.   ENABLE_MULTIRATE;
  30.   //-----------------------------------------
  31.   //  Read model config parms
  32.   OPEN_PARM_BLOCK;
  33.   GET_INT_PARM(Samps_Per_Symb);
  34.   GET_DOUBLE_PARM(Dly_To_Start);
  35.   //--------------------------------------
  36.   //  Connect input and output signals
  37.   Decis_Out = decis_out;
  38.   Symb_Clock_In = symb_clock_in;
  39.   In_Sig = in_sig;
  40.   Lo_Filt_Output = lo_filt_output;
  41.   Hi_Filt_Output = hi_filt_output;
  42.   Lo_Integ_Sig = lo_integ_sig;
  43.   Hi_Integ_Sig = hi_integ_sig;
  44.   MAKE_OUTPUT( Decis_Out );
  45.   MAKE_OUTPUT( Lo_Filt_Output );
  46.   MAKE_OUTPUT( Hi_Filt_Output );
  47.   MAKE_OUTPUT( Lo_Integ_Sig );
  48.   MAKE_OUTPUT( Hi_Integ_Sig );
  49.   MAKE_INPUT( Symb_Clock_In );
  50.   MAKE_INPUT( In_Sig );
  51.   double resamp_rate = 1.0/double(Samps_Per_Symb);
  52.   CHANGE_RATE( In_Sig, Decis_Out, resamp_rate );
  53.   SAME_RATE( In_Sig, Lo_Filt_Output );
  54.   SAME_RATE( In_Sig, Hi_Filt_Output );
  55.   SAME_RATE( In_Sig, Lo_Integ_Sig );
  56.   SAME_RATE( In_Sig, Hi_Integ_Sig );
  57.   CHANGE_RATE( Symb_Clock_In, Decis_Out, resamp_rate );
  58.   //-----------------------------------------
  59.   //  subordinate models
  60.   char sub_name[50];
  61.   strcpy(sub_name, GetInstanceName());
  62.   strcat(sub_name, ":Lo_Freq_Filter");
  63.   Lo_Freq_Filter = 
  64.         new ButterworthFilterByIir<float>(  sub_name,
  65.                                             this,
  66.                                             In_Sig,
  67.                                             Lo_Filt_Output );
  68.   strcpy(sub_name, GetInstanceName());
  69.   strcat(sub_name, ":Hi_Freq_Filter");
  70.   Hi_Freq_Filter = 
  71.         new ButterworthFilterByIir<float>(  sub_name,
  72.                                             this,
  73.                                             In_Sig,
  74.                                             Hi_Filt_Output );
  75.   strcpy(sub_name, GetInstanceName());
  76.   strcat(sub_name, ":Lo_Envel_Filter");
  77.   Lo_Envel_Filter = 
  78.         new ButterworthFilterByIir<float>(  sub_name,
  79.                                             this,
  80.                                             Lo_Filt_Output,
  81.                                             Lo_Integ_Sig );
  82.   strcpy(sub_name, GetInstanceName());
  83.   strcat(sub_name, ":Hi_Envel_Filter");
  84.   Hi_Envel_Filter = 
  85.         new ButterworthFilterByIir<float>(  sub_name,
  86.                                             this,
  87.                                             Hi_Filt_Output,
  88.                                             Hi_Integ_Sig );
  89. }
  90. //==============================================
  91. FskBandpassDemod::~FskBandpassDemod( void ){ };
  92. //==============================================
  93. void FskBandpassDemod::Initialize(void)
  94. {
  95.   Block_Size = In_Sig->GetBlockSize();
  96.   Out_Samp_Intvl = Decis_Out->GetSampIntvl();
  97.   In_Samp_Intvl = In_Sig->GetSampIntvl();
  98.   Lo_Integ_Val = 0.0;
  99.   Hi_Integ_Val = 0.0;
  100.   Lo_Freq_Filter->Initialize(Block_Size, In_Samp_Intvl);
  101.   Hi_Freq_Filter->Initialize(Block_Size, In_Samp_Intvl);
  102.   Lo_Envel_Filter->Initialize(Block_Size, In_Samp_Intvl);
  103.   Hi_Envel_Filter->Initialize(Block_Size, In_Samp_Intvl);
  104. }
  105. //============================================
  106. int FskBandpassDemod::Execute()
  107. {
  108.   bit_t *decis_out_ptr;
  109.   float *in_sig_ptr;
  110.   float *lo_filt_output_ptr;
  111.   float *hi_filt_output_ptr;
  112.   float *lo_integ_sig_ptr;
  113.   float *hi_integ_sig_ptr;
  114.   bit_t *symb_clock_in_ptr;
  115.   float in_val;
  116.   double lo_integ_val, hi_integ_val;
  117.   double max_val=0.0;
  118.   int is;
  119.   #ifdef _DEBUG
  120.     *DebugFile << "In FskBandpassDemod::Execute" << endl;
  121.   #endif
  122.   /*  Run block of input samples thru low freq BP filter */
  123.   in_sig_ptr = GET_INPUT_PTR( In_Sig );
  124.   lo_filt_output_ptr = GET_OUTPUT_PTR( Lo_Filt_Output );
  125.   Lo_Freq_Filter->Execute();
  126.   /*  Run block of input samples thru high freq BP filter */
  127.   in_sig_ptr = GET_INPUT_PTR( In_Sig );
  128.   hi_filt_output_ptr = GET_OUTPUT_PTR( Hi_Filt_Output );
  129.   Hi_Freq_Filter->Execute();
  130.   symb_clock_in_ptr = GET_INPUT_PTR( Symb_Clock_In );
  131.   decis_out_ptr = GET_OUTPUT_PTR( Decis_Out );
  132.   lo_integ_sig_ptr = GET_OUTPUT_PTR( Lo_Integ_Sig );
  133.   hi_integ_sig_ptr = GET_OUTPUT_PTR( Hi_Integ_Sig );
  134.   lo_integ_val = Lo_Integ_Val;
  135.   hi_integ_val = Hi_Integ_Val;
  136.   for (is=0; is<Block_Size; is++)
  137.     {
  138.     *lo_filt_output_ptr = fabs(*lo_filt_output_ptr);
  139.     lo_filt_output_ptr++;
  140.     *hi_filt_output_ptr = fabs(*hi_filt_output_ptr);
  141.     hi_filt_output_ptr++;
  142.     }
  143.   lo_filt_output_ptr = GET_OUTPUT_PTR( Lo_Filt_Output );
  144.   hi_filt_output_ptr = GET_OUTPUT_PTR( Hi_Filt_Output );
  145.   /*  Run block of input samples thru low freq envelope filter */
  146.   ///in_sig_ptr = GET_INPUT_PTR( In_Sig );
  147.   //lo_filt_output_ptr = GET_OUTPUT_PTR( Lo_Filt_Output );
  148.   Lo_Envel_Filter->Execute();
  149.   Hi_Envel_Filter->Execute();
  150.   for (is=0; is<Block_Size; is++)
  151.     {
  152.     in_val = *in_sig_ptr++;
  153.     // correlate input signal against recovered carrier
  154.     lo_integ_val += fabs(*lo_filt_output_ptr++);
  155.     hi_integ_val += fabs(*hi_filt_output_ptr++);
  156.     lo_integ_sig_ptr++;
  157.     hi_integ_sig_ptr++;
  158.     if(*symb_clock_in_ptr != 0)
  159.       {
  160.       // time to make a decision
  161.       if(*hi_integ_sig_ptr > *lo_integ_sig_ptr )
  162.         {
  163.         *decis_out_ptr++ = 1;
  164.         }
  165.       else
  166.         {
  167.         *decis_out_ptr++ = 0;
  168.         }
  169.       lo_integ_val = 0.0;
  170.       hi_integ_val = 0.0;
  171.       }
  172.     symb_clock_in_ptr++;
  173.     }
  174.   Lo_Integ_Val = lo_integ_val;
  175.   Hi_Integ_Val = hi_integ_val;
  176.   return(_MES_AOK);
  177. }