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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = fsk_2tone_bp.cpp
  3. //
  4. #include <stdlib.h>
  5. //#include <fstream>
  6. #include "parmfile.h"
  7. #include "fsk_2tone_bp.h"
  8. #include "misdefs.h"
  9. #include "model_graph.h"
  10. #include "typedefs.h"
  11. //#include "cmpxsig.h"
  12. extern ParmFile *ParmInput;
  13. //========================================================================
  14. // constructor
  15. FskTwoToneModulator_Bp::FskTwoToneModulator_Bp( char* instance_name,
  16.                               PracSimModel* outer_model,
  17.                               Signal<float>* in_sig,
  18.                               Signal<float>* out_sig)
  19.                 :PracSimModel(instance_name,
  20.                               outer_model)
  21. {
  22.   MODEL_NAME(FskTwoToneModulator_Bp);
  23.   //----------------------------------------
  24.   //  Read model config parms
  25.   OPEN_PARM_BLOCK;
  26.   GET_DOUBLE_PARM(Freq_Lo_Hz);
  27.   GET_DOUBLE_PARM(Freq_Hi_Hz);
  28.   GET_FLOAT_PARM(Lo_Control_Val);
  29.   GET_FLOAT_PARM(Hi_Control_Val);
  30.   GET_DOUBLE_PARM(Full_Scale_Output_Level);
  31.   //-------------------------------------
  32.   //  Connect input and output signals
  33.   In_Sig = in_sig;
  34.   Out_Sig = out_sig;
  35.   MAKE_OUTPUT( Out_Sig );
  36.   MAKE_INPUT( In_Sig );
  37.   //----------------------------------
  38.   //  Compute derived parameters
  39.   Slope_Hi_On = Full_Scale_Output_Level/(Hi_Control_Val - Lo_Control_Val);
  40.   Slope_Lo_On = -Slope_Hi_On;
  41. }
  42. //========================================================
  43. // destructor
  44. FskTwoToneModulator_Bp::~FskTwoToneModulator_Bp( void ){ };
  45. //===========================================
  46. void FskTwoToneModulator_Bp::Initialize(void)
  47. {
  48.   Block_Size = In_Sig->GetBlockSize();
  49.   Samp_Intvl = Out_Sig->GetSampIntvl();
  50.   Time = 0.0;
  51.   Cumul_Phase_Lo = 0.0;
  52.   Cumul_Phase_Hi = 0.0;
  53. }
  54. //============================================
  55. int FskTwoToneModulator_Bp::Execute(void)
  56. {
  57.   float *in_sig_ptr, in_val;
  58.   float *out_sig_ptr;
  59.   double cumul_phase_lo, cumul_phase_hi;
  60.   double freq_hi_hz, freq_lo_hz;
  61.   double lo_control_val, hi_control_val;
  62.   double gain_hi, gain_lo;
  63.   double samp_intvl;
  64.   int is;
  65.   out_sig_ptr = GET_OUTPUT_PTR( Out_Sig );
  66.   in_sig_ptr = GET_INPUT_PTR( In_Sig );
  67.   //omega_hi = Freq_Hi_Rad;
  68.   freq_lo_hz = Freq_Lo_Hz;
  69.   freq_hi_hz = Freq_Hi_Hz;
  70.   samp_intvl = Samp_Intvl;
  71.   cumul_phase_lo = Cumul_Phase_Lo;
  72.   cumul_phase_hi = Cumul_Phase_Hi;
  73.   lo_control_val = Lo_Control_Val;
  74.   hi_control_val = Hi_Control_Val;
  75.   for (is=0; is<Block_Size; is++)
  76.     {
  77.     in_val = *in_sig_ptr++;
  78.     //inst_freq = freq_lo_hz + Hz_Per_Volt * (in_val - Lo_Control_Val);
  79.     gain_hi = Slope_Hi_On * (in_val - Lo_Control_Val);
  80.     gain_lo = Slope_Lo_On * (in_val - Hi_Control_Val);
  81.     cumul_phase_lo = fmod(cumul_phase_lo + samp_intvl * freq_lo_hz, 1.0);
  82.     cumul_phase_hi = fmod(cumul_phase_hi + samp_intvl * freq_hi_hz, 1.0);
  83.     *out_sig_ptr++ = float(gain_lo * sin(TWO_PI * cumul_phase_lo)
  84.                      + gain_hi * sin(TWO_PI * cumul_phase_hi));
  85.     }
  86.   Cumul_Phase_Lo = cumul_phase_lo;
  87.   Cumul_Phase_Hi = cumul_phase_hi;
  88.   return(_MES_AOK);
  89. }