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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = costas_loop_sim.cpp
  3. //
  4. #define SIM_NAME "CostasLoop"
  5. #define SIM_TITLE "Simulation of Costas Loop"
  6. #include "global_stuff.h" 
  7. #include "qpsk_theory.h"
  8. #include "bitgen.h"
  9. #include "bitwav.h"
  10. #include "siganchr.h"
  11. #include "bpsk_mod_bp.h"
  12. #include "phase_rotate.h"
  13. #include "add_gaus_noise.h"
  14. #include "butt_filt_iir.h"
  15. #include "spec_analyzer.h"
  16. #include "quad_carr_genie.h"
  17. #include "costas_loop.h"
  18. #include "contin_delay_T.h"
  19. #include "mixer_bp.h"
  20. #include "quad_mixer_bp.h"
  21. #include "integ_dump_slice.h"
  22. #include "qpskoptbitdem.h"
  23. #include "ber_ctr.h"
  24. #include "qpsk_err_ctr.h"
  25. main()
  26. {
  27. #include "sim_preamble.cpp"
  28.   //=========================================================================
  29.   //  Misc special processing
  30.   //-----------------------------------------------------
  31.   // create plot file of theoretical PSD for QPSK signal
  32.   QpskPsd(  0.0,  // carrier_freq
  33.             1.0,  // symb_energy,
  34.             1.0,  // symb_intvl,
  35.             -4.0, // beg_freq,
  36.             4.0,  // end_freq,
  37.             801,  // num_pts,
  38.             true, // plot_in_db,
  39.             "qpsk_psd_theor.txt"); //out_filename
  40.   //-----------------------------------------------------
  41.   // create plot file of BER for ideal QPSK
  42.   QpskBer(  -10.0,  // beg_ebno,
  43.             18.0, // end_ebno,
  44.             401,  // num_pts,
  45.             "theor_qpsk_ber.txt");  // out_filename
  46.   //=========================================================================
  47.   //  Allocate signals
  48.   BIT_SIGNAL(bit_vals);
  49.   FLOAT_SIGNAL(baseband_wave);
  50.   FLOAT_SIGNAL(modulated_signal);
  51.   FLOAT_SIGNAL(pll_err_sig);
  52.   FLOAT_SIGNAL(pll_filt_err_sig);
  53.   FLOAT_SIGNAL(pll_ref_sig);
  54.   FLOAT_SIGNAL(pll_vco_phase_sig);
  55.   FLOAT_SIGNAL(pll_vco_freq_sig);
  56.   FLOAT_SIGNAL(squared_signal);
  57.   FLOAT_SIGNAL(error_signal);
  58.   FLOAT_SIGNAL(filt_squared_signal);
  59.   FLOAT_SIGNAL(recov_carrier_sig);
  60.   FLOAT_SIGNAL(i_recov_carrier_sig);
  61.   FLOAT_SIGNAL(q_recov_carrier_sig);
  62.   FLOAT_SIGNAL(noisy_sig);
  63.   //FLOAT_SIGNAL(sqrd_noisy_sig);
  64.   BIT_SIGNAL(symb_clock);
  65.   FLOAT_SIGNAL(power_meas_sig);
  66.   //============================================================
  67.   //  Construct, initialize and connect models
  68.   BitGener* bit_gen = new BitGener( "bit_gen",
  69.                                       CommSystem,
  70.                                       bit_vals );
  71.   BitsToWave* wave_gen = new BitsToWave( "wave_gen",
  72.                                            CommSystem,
  73.                                            bit_vals,
  74.                                            baseband_wave,
  75.                                            symb_clock );
  76.   SignalAnchor* temp_anchor_1 = new SignalAnchor( "temp_anchor_1",
  77.                                                 CommSystem,
  78.                                                 baseband_wave,
  79.                                                 //q_baseband_wave,
  80.                                                 0.0078125, //samp_intvl
  81.                                                 4096 ); //block_size
  82.   BpskBandpassModulator* bpsk_mod = new BpskBandpassModulator( "bpsk_mod",
  83.                                                 CommSystem,
  84.                                                 baseband_wave,
  85.                                                 modulated_signal);
  86.   
  87.   AdditiveGaussianNoise<float>* agn_source = 
  88.                   new AdditiveGaussianNoise<float>( 
  89.                                                 "agn_source",
  90.                                                 CommSystem,
  91.                                                 modulated_signal,
  92.                                                 noisy_sig,
  93.                                                 power_meas_sig);
  94.   SpectrumAnalyzer<float>* spec_analyzer = 
  95.                   new SpectrumAnalyzer<float>( 
  96.                                                   "spec_analyzer",
  97.                                                   CommSystem,
  98.                                                   modulated_signal );
  99. //   BandpassSquaringPLL* carr_recov_loop = new BandpassSquaringPLL( "carr_recov_loop",
  100. //                                                                     CommSystem,
  101. //                                                                     noisy_sig,
  102. //                                                                     sqrd_noisy_sig,
  103. //                                                                     pll_err_sig,
  104. //                                                                     pll_filt_err_sig,
  105. //                                                                     pll_ref_sig,
  106. //                                                                     pll_vco_freq_sig,
  107. //                                                                     pll_phase_sig,
  108. //                                                                     recov_carrier_sig);
  109. //   ContinuousDelay< float >* loop_delay_elem = new ContinuousDelay<float>( "loop_delay_elem",
  110. //                                   CommSystem,
  111. //                                   squared_signal,
  112. //                                   delay_squared_signal);
  113.    CostasLoop* carr_recov_loop = new CostasLoop( "carr_recov_loop",
  114.                                                 CommSystem,
  115.                                                 modulated_signal,
  116.                                                 pll_err_sig,
  117.                                                 pll_filt_err_sig,
  118.                                                 pll_ref_sig,
  119.                                                 pll_vco_freq_sig,
  120.                                                 pll_vco_phase_sig,
  121.                                                 recov_carrier_sig);
  122. //  ButterworthFilterByIir<float>* double_freq_filter = 
  123. //            new ButterworthFilterByIir<float>( "double_freq_filter",
  124. //                                        CommSystem,
  125. //                                        squared_signal,
  126. //                                        filt_squared_signal );
  127. //  SpectrumAnalyzer<float>* spec_anal_2 = 
  128. //                  new SpectrumAnalyzer<float>( 
  129. //                                                  "spec_anal_2",
  130. //                                                  CommSystem,
  131. //                                                  sqrd_noisy_sig );
  132.   SpectrumAnalyzer<float>* spec_anal_3 = 
  133.                   new SpectrumAnalyzer<float>( 
  134.                                                   "spec_anal_3",
  135.                                                   CommSystem,
  136.                                                   pll_err_sig );
  137.   SpectrumAnalyzer<float>* spec_anal_4 = 
  138.                   new SpectrumAnalyzer<float>( 
  139.                                                   "spec_anal_4",
  140.                                                   CommSystem,
  141.                                                   pll_filt_err_sig );
  142. //  QuadCarrierRecovGenie* carrier_recovery = new QuadCarrierRecovGenie( "carrier_recovery",
  143. //                                                                   CommSystem,
  144. //                                                                   i_recov_carrier_sig,
  145. //                                                                   q_recov_carrier_sig);
  146.   
  147. //  QuadBandpassMixer* quad_dem = new QuadBandpassMixer( "quad_dem",
  148. //                                                   CommSystem,
  149. //                                                   noisy_sig,
  150. //                                                   i_recov_carrier_sig,
  151. //                                                   q_recov_carrier_sig,
  152. //                                                   i_demod_wave,
  153. //                                                   q_demod_wave );
  154. //  IntegrateDumpAndSlice* i_bit_slicer = new IntegrateDumpAndSlice( "i_bit_slicer",
  155. //                                           CommSystem,
  156. //                                           i_demod_wave,
  157. //                                           symb_clock,
  158. //                                           i_samp_wave,
  159. //                                           i_bit_decis);
  160. //  IntegrateDumpAndSlice* q_bit_slicer = new IntegrateDumpAndSlice( "q_bit_slicer",
  161. //                                           CommSystem,
  162. //                                           q_demod_wave,
  163. //                                           q_symb_clock,
  164. //                                           q_samp_wave,
  165. //                                           q_bit_decis);
  166. //  BerCounter* i_ber_ctr = new BerCounter( "i_ber_ctr",
  167. //                                          CommSystem,
  168. //                                          i_bits,
  169. //                                          i_bit_decis );
  170. //  BerCounter* q_ber_ctr = new BerCounter( "q_ber_ctr",
  171. //                                          CommSystem,
  172. //                                          q_bits,
  173. //                                          q_bit_decis );
  174. //  QpskErrorCounter* ser_ctr = new QpskErrorCounter( "ser_ctr",
  175. //                                                    CommSystem,
  176. //                                                    i_bits,
  177. //                                                    q_bits,
  178. //                                                    i_bit_decis,
  179. //                                                    q_bit_decis );
  180.   //=============================================================
  181.   #include "sim_postamble.cpp"
  182.   return 0;
  183. }