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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = quadmod.cpp
  3. //
  4. #include <stdlib.h>
  5. #include "parmfile.h"
  6. #include "quadmod.h"
  7. #include "misdefs.h"
  8. #include "model_graph.h"
  9. #include "typedefs.h"
  10. extern ParmFile *ParmInput;
  11. //========================================================================
  12. // general constructor that supports both complex and polar-form outputs
  13. QuadratureModulator::QuadratureModulator( char* instance_name,
  14.                               PracSimModel* outer_model,
  15.                               Signal<float>* i_in_sig,
  16.                               Signal<float>* q_in_sig,
  17.                               Signal< std::complex<float> >* cmpx_out_sig,
  18.                               Signal<float>* mag_out_sig,
  19.                               Signal<float>* phase_out_sig )
  20.                 :PracSimModel(instance_name,
  21.                               outer_model)
  22. {
  23.   MODEL_NAME(QuadratureModulator);
  24.   Mag_Out_Sig = mag_out_sig;
  25.   Phase_Out_Sig = phase_out_sig;
  26.   this->Constructor_Common_Tasks( instance_name, i_in_sig, q_in_sig, cmpx_out_sig);
  27.   Polar_Outputs_Enabled = true;
  28.   MAKE_OUTPUT( Mag_Out_Sig );
  29.   MAKE_OUTPUT( Phase_Out_Sig );
  30. }
  31. //========================================================================
  32. // limited constructor that supports only complex outputs
  33. QuadratureModulator::QuadratureModulator( char* instance_name,
  34.                               PracSimModel* outer_model,
  35.                               Signal<float>* i_in_sig,
  36.                               Signal<float>* q_in_sig,
  37.                               Signal< std::complex<float> >* cmpx_out_sig)
  38.                 :PracSimModel(instance_name,
  39.                               outer_model)
  40. {
  41.   MODEL_NAME(QuadratureModulator);
  42.   this->Constructor_Common_Tasks( instance_name, i_in_sig, q_in_sig, cmpx_out_sig);
  43.   Polar_Outputs_Enabled = false;
  44. }
  45. //==========================================================================================
  46. void QuadratureModulator::Constructor_Common_Tasks( char* instance_name,
  47.                                                 Signal<float>* i_in_sig,
  48.                                                 Signal<float>* q_in_sig,
  49.                                                 Signal< std::complex<float> >* cmpx_out_sig)
  50. {
  51.   //----------------------------------------
  52.   //  Read model config parms
  53.   OPEN_PARM_BLOCK;
  54.   GET_DOUBLE_PARM(Phase_Unbal);
  55.   GET_DOUBLE_PARM(Amp_Unbal);
  56.   //-------------------------------------
  57.   //  Connect input and output signals
  58.   I_In_Sig = i_in_sig;
  59.   Q_In_Sig = q_in_sig;
  60.   Cmpx_Out_Sig = cmpx_out_sig;
  61.   MAKE_OUTPUT( Cmpx_Out_Sig );
  62.   MAKE_INPUT( I_In_Sig );
  63.   MAKE_INPUT( Q_In_Sig );
  64.   //-----------------------------------------
  65.   // Set up derived parms
  66.   double phase_unbal_rad = PI * Phase_Unbal / 180.0;
  67.   Real_Unbal = float(cos(phase_unbal_rad) * Amp_Unbal);
  68.   Imag_Unbal = float(sin(phase_unbal_rad) * Amp_Unbal);
  69. }
  70. //===========================================
  71. QuadratureModulator::~QuadratureModulator( void ){ };
  72. //===========================================
  73. void QuadratureModulator::Initialize(void)
  74. {
  75.   Block_Size = I_In_Sig->GetBlockSize();
  76. }
  77. //============================================
  78. int QuadratureModulator::Execute(void)
  79. {
  80.   float *i_in_sig_ptr, *q_in_sig_ptr;
  81.   float i_out, q_out;
  82.   float *phase_out_sig_ptr, *mag_out_sig_ptr;
  83.   double real_unbal, imag_unbal;
  84.   std::complex<float> *cmpx_out_sig_ptr;
  85.   int is;
  86.   int block_size;
  87.   //Cmpx_Out_Sig->SetValidBlockSize(Block_Size);
  88.   cmpx_out_sig_ptr = GET_OUTPUT_PTR( Cmpx_Out_Sig );
  89.    block_size = I_In_Sig->GetValidBlockSize();
  90.    Cmpx_Out_Sig->SetValidBlockSize(block_size);
  91.   if(Polar_Outputs_Enabled)
  92.     {
  93.       Phase_Out_Sig->SetValidBlockSize(block_size);
  94.       Mag_Out_Sig->SetValidBlockSize(block_size);
  95.     phase_out_sig_ptr = GET_OUTPUT_PTR( Phase_Out_Sig );
  96.     mag_out_sig_ptr = GET_OUTPUT_PTR( Mag_Out_Sig );
  97.     }
  98.   i_in_sig_ptr = GET_INPUT_PTR( I_In_Sig );
  99.   q_in_sig_ptr = GET_INPUT_PTR( Q_In_Sig );
  100.   real_unbal = Real_Unbal;
  101.   imag_unbal = Imag_Unbal;
  102.   //cout << "real_unbal = " << real_unbal << endl;
  103.   //cout << "imag_unbal = " << imag_unbal << endl;
  104.   for (is=0; is<block_size; is++)
  105.     {
  106.     i_out = (*i_in_sig_ptr) - (imag_unbal * (*q_in_sig_ptr));
  107.     q_out = real_unbal * (*q_in_sig_ptr);
  108.     //i_out *= 1.4;
  109.     //q_out *= 1.4;
  110.     *cmpx_out_sig_ptr++ = std::complex<float>( i_out, q_out);
  111.     if(Polar_Outputs_Enabled)
  112.       {
  113.       *phase_out_sig_ptr++ = 180.0*atan2(q_out, i_out)/PI;
  114.       *mag_out_sig_ptr++ = sqrt(i_out*i_out + q_out*q_out);
  115.       }
  116.     i_in_sig_ptr++;
  117.     q_in_sig_ptr++;
  118.     //cmpx_out_sig_ptr++;
  119.     //phase_out_sig_ptr++;
  120.     //mag_out_sig_ptr++;
  121.     }
  122.   return(_MES_AOK);
  123. }