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

📄 rayl_gen.cpp

📁 无线通信仿真C++使用模型配套代码
💻 CPP
字号:
//
//  File = noise_gen.cpp
//

#include <stdlib.h>
#include <fstream>
#include <math.h>
#include "parmfile.h"
#include "rayl_gen.h"
#include "model_graph.h"
#include "syst_graph.h"
#include "misdefs.h"
#include "raylrand.h"
extern int PassNumber;
extern ParmFile *ParmInput;
extern SystemGraph CommSystemGraph;
#ifdef _DEBUG
  extern ofstream *DebugFile;
#endif

//======================================================
// normal constructor

template <class T>
RayleighNoiseGenerator<T>::RayleighNoiseGenerator( char* instance_name,
                                              PracSimModel* outer_model,
                                              Signal<T>* noise_sig)
                      :PracSimModel(instance_name,
                                    outer_model)
{
  MODEL_NAME(RayleighNoiseGenerator);

  Noise_Sig = noise_sig;

  OPEN_PARM_BLOCK;

  GET_INT_PARM(Seed);
  GET_FLOAT_PARM(Noise_Sigma);

  //----------------------------------------------
  MAKE_OUTPUT(Noise_Sig);

}
//=============================================
template <class T>
RayleighNoiseGenerator<T>::~RayleighNoiseGenerator( void ){ };
//===========================================
template <class T>
void RayleighNoiseGenerator<T>::Initialize(void)
{
  *DebugFile << "Now in RayleighNoiseGenerator::Initialize()" << endl;

  Proc_Block_Size = Noise_Sig->GetBlockSize();
}
//=============================================
template <class T>
int RayleighNoiseGenerator<T>::Execute(void)
{
  int is;
  float *noise_sig_ptr;
  float noise_sigma;
  float rand_var;
  float noise_sig_val;

  //--------------------------------------------
  noise_sigma = Noise_Sigma;
  long seed = Seed;

  //---------------------------------------------

  noise_sig_ptr = GET_OUTPUT_PTR(Noise_Sig);

  //-------------------------------------------------
  //  main loop

  for(is=0; is<Proc_Block_Size; is++)
    {
    // generate gaussian RV
    RayleighRandom(&seed, &rand_var);

    noise_sig_val = noise_sigma * rand_var;

    *noise_sig_ptr++ = noise_sig_val;
    }// end of main loop

  // put back variables that have changed
  Seed = seed;
  Noise_Sig->SetValidBlockSize(Proc_Block_Size);

  //----------------------------------------------

  return(_MES_AOK);
};

template RayleighNoiseGenerator<float>;

⌨️ 快捷键说明

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