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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = bscerrorgen.cpp
  3. //
  4. #include <stdlib.h>
  5. #include <fstream>
  6. #include "parmfile.h"
  7. #include "bscerrorgen.h"
  8. #include "uni_rand.h"
  9. #include "model_graph.h"
  10. #include "syst_graph.h"
  11. #include "misdefs.h"
  12. extern ParmFile *ParmInput;
  13. #ifdef _DEBUG
  14.   extern ofstream *DebugFile;
  15. #endif
  16. #define FLOAT_MODULUS 2147483647.0
  17. //======================================================
  18. BscErrorGener::BscErrorGener( char* instance_name,
  19.                               PracSimModel* outer_model,
  20.                               Signal<bit_t>* in_signal,
  21.                               Signal<bit_t>* out_signal)
  22.               :PracSimModel(instance_name,
  23.                             outer_model)
  24. {
  25.    MODEL_NAME(BscErrorGener);
  26.    In_Sig = in_signal;
  27.    Out_Sig = out_signal;
  28.    OPEN_PARM_BLOCK;
  29.    GET_DOUBLE_PARM(Bit_Error_Probability);
  30.    Decis_Thresh = (unsigned long)
  31.                (Bit_Error_Probability * FLOAT_MODULUS);
  32.    BasicResults << "Decis_Thresh = " << Decis_Thresh 
  33.                 << endl;
  34. #ifdef _DEBUG
  35.    *DebugFile << "Decis_Thresh = " << Decis_Thresh 
  36.               << endl;
  37. #endif
  38.    GET_LONG_PARM(Initial_Seed);
  39.    Working_Seed = Initial_Seed;
  40.    MAKE_OUTPUT( Out_Sig );
  41.    MAKE_INPUT( In_Sig );
  42. }
  43. //======================================================
  44. BscErrorGener::~BscErrorGener( void ){ };
  45. //======================================================
  46. void BscErrorGener::Initialize(void)
  47. {
  48.   Block_Size = In_Sig->GetBlockSize();
  49. };
  50. //======================================================
  51. int BscErrorGener::Execute()
  52. {
  53.    bit_t *in_sig_ptr;
  54.    bit_t output_samp, *out_sig_ptr;
  55.    int is, block_size;
  56.    long working_seed;
  57.    long decis_thresh;
  58.    // Get pointers for input and output signal buffers
  59.    out_sig_ptr = GET_OUTPUT_PTR(Out_Sig);
  60.    in_sig_ptr = GET_INPUT_PTR(In_Sig);
  61.    //  copy frequently used items into local storage
  62.    block_size = In_Sig->GetValidBlockSize();
  63.    Out_Sig->SetValidBlockSize(block_size);
  64.    working_seed = Working_Seed;
  65.    decis_thresh = Decis_Thresh;
  66.    for(is=0; is<block_size; is++){
  67.       output_samp = *in_sig_ptr++;
  68.       RandomLong(&working_seed);
  69.       if(working_seed <= decis_thresh) output_samp ^=1;
  70.       *out_sig_ptr++ = output_samp;
  71.    }
  72.    Working_Seed = working_seed;
  73.    return(_MES_AOK);
  74. }