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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = qpsk_sim.cpp
  3. //
  4. #define SIM_NAME "QpskSim"
  5. #define SIM_TITLE "Complex Baseband Simulation of QPSK"
  6. #include "global_stuff.h" 
  7. #include "qpsk_theory.h"
  8. #include "bitgen.h"
  9. #include "bitwav.h"
  10. #include "discrete_delay_T.h"
  11. #include "siganchr.h"
  12. #include "quadmod.h"
  13. #include "phase_rotate.h"
  14. #include "add_gaus_noise.h"
  15. #include "spec_analyzer.h"
  16. #include "phase_genie.h"
  17. #include "quaddem.h"
  18. //#include "bitslicer.h"
  19. #include "integ_dump_slice.h"
  20. #include "qpskoptbitdem.h"
  21. #include "ber_ctr.h"
  22. #include "qpsk_err_ctr.h"
  23. main()
  24. {
  25. #include "sim_preamble.cpp"
  26.   //=========================================================================
  27.   //  Misc special processing
  28.   //-----------------------------------------------------
  29.   // create plot file of theoretical PSD for QPSK signal
  30.   QpskPsd(  0.0,  // carrier_freq
  31.             1.0,  // symb_energy,
  32.             1.0,  // symb_intvl,
  33.             -4.0, // beg_freq,
  34.             4.0,  // end_freq,
  35.             801,  // num_pts,
  36.             true, // plot_in_db,
  37.             "qpsk_psd_theor.txt"); //out_filename
  38.   //-----------------------------------------------------
  39.   // create plot file of BER for ideal QPSK
  40.   QpskBer(  -10.0,  // beg_ebno,
  41.             18.0, // end_ebno,
  42.             401,  // num_pts,
  43.             "theor_qpsk_ber.txt");  // out_filename
  44.   //=========================================================================
  45.   //  Allocate signals
  46.   BIT_SIGNAL(i_bits);
  47.   BIT_SIGNAL(q_bits);
  48.   FLOAT_SIGNAL(i_baseband_wave);
  49.   FLOAT_SIGNAL(q_baseband_wave);
  50.   COMPLEX_SIGNAL(modulated_signal);
  51.   COMPLEX_SIGNAL(shifted_signal);
  52.   COMPLEX_SIGNAL(recov_carrier_sig);
  53.   COMPLEX_SIGNAL(noisy_sig);
  54.   BIT_SIGNAL(symb_clock);
  55.   BIT_SIGNAL(delayed_clock);
  56.   BIT_SIGNAL(q_symb_clock);
  57.   FLOAT_SIGNAL(power_meas_sig);
  58.   FLOAT_SIGNAL(i_demod_wave);
  59.   FLOAT_SIGNAL(q_demod_wave);
  60.   FLOAT_SIGNAL(i_samp_wave);
  61.   FLOAT_SIGNAL(q_samp_wave);
  62.   BIT_SIGNAL(i_bit_decis);
  63.   BIT_SIGNAL(q_bit_decis);
  64.   //============================================================
  65.   //  Construct, initialize and connect models
  66.   BitGener* i_bit_gen = new BitGener( "i_bit_gen",
  67.                                       CommSystem,
  68.                                       i_bits );
  69.   BitGener* q_bit_gen = new BitGener( "q_bit_gen",
  70.                                       CommSystem,
  71.                                       q_bits );
  72.   BitsToWave* i_wave_gen = new BitsToWave( "i_wave_gen",
  73.                                            CommSystem,
  74.                                            i_bits,
  75.                                            i_baseband_wave,
  76.                                            symb_clock );
  77.   BitsToWave* q_wave_gen = new BitsToWave( "q_wave_gen",
  78.                                            CommSystem,
  79.                                            q_bits,
  80.                                            q_baseband_wave,
  81.                                            q_symb_clock );
  82.   SignalAnchor* temp_anchor_1 = new SignalAnchor( "temp_anchor_1",
  83.                                                 CommSystem,
  84.                                                 i_baseband_wave,
  85.                                                 q_baseband_wave,
  86.                                                 0.0625, //samp_intvl
  87.                                                 4096 ); //block_size
  88.   QuadratureModulator* qpsk_mod = new QuadratureModulator( "qpsk_mod",
  89.                                                 CommSystem,
  90.                                                 i_baseband_wave,
  91.                                                 q_baseband_wave,
  92.                                                 modulated_signal);
  93.   
  94.   PhaseRotate* phase_shifter = new PhaseRotate( "phase_shifter",
  95.                                                 CommSystem,
  96.                                                 modulated_signal,
  97.                                                 shifted_signal);
  98.   AdditiveGaussianNoise<std::complex<float> >* agn_source = 
  99.                   new AdditiveGaussianNoise<std::complex<float> >( 
  100.                                                 "agn_source",
  101.                                                 CommSystem,
  102.                                                 shifted_signal,
  103.                                                 noisy_sig,
  104.                                                 power_meas_sig);
  105.   SpectrumAnalyzer<std::complex<float> >* spec_analyzer = 
  106.                   new SpectrumAnalyzer<std::complex<float> >( 
  107.                                                   "spec_analyzer",
  108.                                                   CommSystem,
  109.                                                   modulated_signal );
  110.   PhaseRecoveryGenie* carrier_recovery = new PhaseRecoveryGenie( "carrier_recovery",
  111.                                                                    CommSystem,
  112.                                                                    recov_carrier_sig);
  113. //  QpskOptimalBitDemod* qpsk_dem = new QpskOptimalBitDemod( "qpsk_dem",
  114. //                                                    CommSystem,
  115. //                                                    noisy_sig,
  116. //                                                    recov_carrier_sig,
  117. //                                                    symb_clock,
  118. //                                                    i_bit_decis,
  119. //                                                    q_bit_decis);
  120.   
  121.   QuadratureDemod* quad_dem = new QuadratureDemod( "quad_dem",
  122.                                                    CommSystem,
  123.                                                    noisy_sig,
  124.                                                    recov_carrier_sig,
  125.                                                    i_demod_wave,
  126.                                                    q_demod_wave );
  127.   IntegrateDumpAndSlice* i_bit_slicer = new IntegrateDumpAndSlice( "i_bit_slicer",
  128.                                            CommSystem,
  129.                                            i_demod_wave,
  130.                                            symb_clock,
  131.                                            i_samp_wave,
  132.                                            i_bit_decis);
  133.   IntegrateDumpAndSlice* q_bit_slicer = new IntegrateDumpAndSlice( "q_bit_slicer",
  134.                                            CommSystem,
  135.                                            q_demod_wave,
  136.                                            q_symb_clock,
  137.                                            q_samp_wave,
  138.                                            q_bit_decis);
  139.   BerCounter* i_ber_ctr = new BerCounter( "i_ber_ctr",
  140.                                           CommSystem,
  141.                                           i_bits,
  142.                                           i_bit_decis );
  143.   BerCounter* q_ber_ctr = new BerCounter( "q_ber_ctr",
  144.                                           CommSystem,
  145.                                           q_bits,
  146.                                           q_bit_decis );
  147.   QpskErrorCounter* ser_ctr = new QpskErrorCounter( "ser_ctr",
  148.                                                     CommSystem,
  149.                                                     i_bits,
  150.                                                     q_bits,
  151.                                                     i_bit_decis,
  152.                                                     q_bit_decis );
  153.   //=============================================================
  154.   #include "sim_postamble.cpp"
  155.   return 0;
  156. }