⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contin_delay_t.cpp

📁 无线通信仿真C++使用模型配套代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
//  File = contin_delay_T.cpp
//

#include <stdlib.h>
#include <fstream>
#include <strstream>
#include "parmfile.h"
#include "sigplot.h"
#include "model_error.h"
#include "contin_delay_T.h"
#include "model_graph.h"
#include "complex_io.h"
#include "sinc.h"
extern SignalPlotter SigPlot;
extern int PassNumber;
extern int EnclaveNumber;
extern int EnclaveOffset[10];
extern ParmFile *ParmInput;
extern ofstream *DebugFile;
extern PracSimModel *ActiveModel;

//==================================================================
// general constructor that supports any of the possible delay modes

template< class T >
ContinuousDelay< T >::ContinuousDelay( char* instance_name,
                                PracSimModel* outer_model,
                                Signal<T>* in_signal,
                                Signal<T>* out_signal,
                                Control<float> *new_delay,
                                Control<bool> *delay_change_enabled )
              :PracSimModel(instance_name,
                            outer_model)
{  
  this->Constructor_Common_Tasks( instance_name, in_signal, out_signal);
  //------------------------------------------
  //  Controls

  New_Delay = new_delay;
  Delay_Change_Enabled = delay_change_enabled;

  return;
  }
//==================================================================
//  Constructor 2
//  This constructor supports any delay mode except DELAY_MODE_GATED
//  (The calling sequence does not pass the gating control.)

template< class T >
ContinuousDelay< T >::ContinuousDelay( char* instance_name,
                                PracSimModel* outer_model,
                                Signal<T>* in_signal,
                                Signal<T>* out_signal,
                                Control<float> *new_delay )
              :PracSimModel(instance_name,
                            outer_model)
{  
  this->Constructor_Common_Tasks( instance_name, in_signal, out_signal);
  //------------------------------------------
  //  Controls

  New_Delay = new_delay;

  switch (Delay_Mode)
    {
    case DELAY_MODE_NONE:
    case DELAY_MODE_FIXED:
    case DELAY_MODE_DYNAMIC:
      break;
    case DELAY_MODE_GATED:
      {
      ostrstream temp_stream;
      temp_stream << "DELAY_MODE_GATED is not supported by called constructor (2)"
                   << ends;
      char *message = temp_stream.str();
      PsModelError(FATAL, message);
      delete []message;
      }
      break;
    }
  return;
  }
//======================================================================
//  Constructor 3
//  This constructor supports only DELAY_MODE_NONE and DELAY_MODE_FIXED
//  (The calling sequence does not pass the delay control or 
//   the gating control.)

template< class T >
ContinuousDelay< T >::ContinuousDelay( char* instance_name,
                                PracSimModel* outer_model,
                                Signal<T>* in_signal,
                                Signal<T>* out_signal )
              :PracSimModel(instance_name,
                            outer_model)
{  
  this->Constructor_Common_Tasks( instance_name, in_signal, out_signal);

  switch (Delay_Mode)
    {
    case DELAY_MODE_NONE:
    case DELAY_MODE_FIXED:
      break;
    case DELAY_MODE_DYNAMIC:
      {
      ostrstream temp_stream;
      temp_stream << "DELAY_MODE_DYNAMIC is not supported by called contructor (3)"
                   << ends;
      char *message = temp_stream.str();
      PsModelError(FATAL, message);
      delete []message;
      }
      break;
    case DELAY_MODE_GATED:
      {
      ostrstream temp_stream;
      temp_stream << "DELAY_MODE_GATED is not supported by called constructor (3)"
                   << ends;
      char *message = temp_stream.str();
      PsModelError(FATAL, message);
      delete []message;
      }
      break;
    }
  return;
  }
//===================================================================
template< class T >
void ContinuousDelay< T >::Constructor_Common_Tasks( char* instance_name,
                                              Signal<T>* in_signal,
                                              Signal<T>* out_signal)
{
  MODEL_NAME(ContinuousDelay);
  ActiveModel = this;

  //-----------------------------------
  // Read configuration parameters
  OPEN_PARM_BLOCK;

  Delay_Mode = GetDelayModeParm("Delay_Mode\0");
  BasicResults << "   " << "Delay_Mode = " << Delay_Mode << endl;

  Interp_Mode = GetInterpModeParm("Interp_Mode\0");
  BasicResults << "   " << "Interp_Mode = " << Interp_Mode << endl;

  if( Interp_Mode == INTERP_MODE_SINC )
    {
    GET_INT_PARM(Num_Sidelobes);
    }
  else
    {
    Num_Sidelobes = 0;
    }

  GET_DOUBLE_PARM(Max_Delay);

  GET_DOUBLE_PARM(Initial_Delay);

  //-----------------------------------
  //  Signals

  In_Sig = in_signal;
  Out_Sig = out_signal;

  MAKE_INPUT( In_Sig );
  EnclaveNumber++; // must come after MAKE_INPUT and before MAKE_OUTPUT
  MAKE_OUTPUT( Out_Sig );
};
//================================================
template< class T >
ContinuousDelay<T>::~ContinuousDelay( void ){ };

//=======================================================

template< class T >
void ContinuousDelay<T>::Initialize()
{
  double active_delay_in_samps;
  double sinc_offset;
  int idx;

  EnclaveNumber++;
  Return_Status = _MES_RESTART;
  New_Pass_Number = 0;
  //---------------------------------------
  //  Initialize derived parameters

  Samp_Intvl = In_Sig->GetSampIntvl();
  Block_Size = In_Sig->GetBlockSize();
  //---------------------------------------
  //  Initialize physical buffer

  Blocks_Of_Offset = 1;
  EnclaveOffset[EnclaveNumber]=Blocks_Of_Offset;
  //Max_Buffer_Len = 1 + Num_Sidelobes + int(Max_Delay / Samp_Intvl);
  //Max_Buffer_Len = 4500;
  //---------------------------------------
  //  Initialize active portion of buffer

  Active_Delay = Initial_Delay;
  sinc_offset = ceil(Active_Delay/Samp_Intvl) - (Active_Delay/Samp_Intvl);
  Offset_Sum_Start_To_Out_Samp = Num_Sidelobes + int(ceil(Active_Delay/Samp_Intvl))-1;
  Max_Buffer_Len = Block_Size * Blocks_Of_Offset + Offset_Sum_Start_To_Out_Samp+1;

  Start_Of_Buffer = new T[Max_Buffer_Len];
  for(int i=0; i<Max_Buffer_Len; i++)
    {
    *(Start_Of_Buffer+i) = 0;
    }

  active_delay_in_samps = Active_Delay/Samp_Intvl;
  Active_Buffer_Len = 1 + int(floor(active_delay_in_samps));

  Interp_Weight = active_delay_in_samps - floor(active_delay_in_samps); //correct one
  if(Interp_Weight > 0.999999) Interp_Weight = 1.0;
  if(Interp_Weight < 0.000001) Interp_Weight = 0.0;
  One_Minus_Weight = 1.0 - Interp_Weight;

  End_Of_Buffer = Start_Of_Buffer + Max_Buffer_Len - 1;
  Write_Ptr = Start_Of_Buffer;
  Read_Ptr_Start = Start_Of_Buffer + Max_Buffer_Len - Offset_Sum_Start_To_Out_Samp;
  Num_Blocks_Skipped = 0;

  Sinc_Val = new float[2*Num_Sidelobes];
  double sum = 0.0;
  double sum_sqrs = 0.0;
  for(idx=0; idx < 2*Num_Sidelobes; idx++)
    {
    Sinc_Val[idx] = float(sinc(Num_Sidelobes - 1 - idx + sinc_offset));
    sum += Sinc_Val[idx];
    sum_sqrs += Sinc_Val[idx] * Sinc_Val[idx];
    //Sinc_Val[idx] = 1.0/float(2*Num_Sidelobes);
    }
  Sinc_Val[0] *= 0.5;
  Sinc_Val[2*Num_Sidelobes-1] *= 0.5;
  //double sum2 = 0.0;
  //sum = sqrt(sum_sqrs);
  for(idx=0; idx < 2*Num_Sidelobes; idx++)
    {
    //Sinc_Val[idx] /= sum_sqrs;
    //sum2 += Sinc_Val[idx];
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -