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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = qam_theory.cpp
  3. //
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include "qam_theory.h"
  7. #include "sinc.h"
  8. #include "q_func.h"
  9. #include "log2.h"
  10. #include <fstream>
  11. #ifndef PI
  12.   #define PI 3.1415926535897932
  13. #endif
  14. using namespace std;
  15. void QamPsd( int big_m,
  16.                double carrier_freq,
  17.               double symb_energy,
  18.               double bit_rate,
  19.               double beg_freq,
  20.               double end_freq,
  21.               int num_pts,
  22.               bool plot_in_db,
  23.               char* out_filename)
  24. {
  25.   double freq, val;
  26.   ofstream *out_file;
  27.   out_file = new ofstream(out_filename, ios::out);
  28.   double delta_freq = (end_freq - beg_freq)/double(num_pts-1);
  29.   double m_factor = double(ilog2(big_m));
  30.   double energy = symb_energy / 2.0;
  31.   for(int n=0; n<num_pts; n++)
  32.     {
  33.     freq = beg_freq + n * delta_freq;
  34.     val = energy * (  sinc_sqrd((freq-carrier_freq)*m_factor/bit_rate)
  35.                         + sinc_sqrd((freq+carrier_freq)*m_factor/bit_rate) );
  36.     if( plot_in_db )
  37.       {
  38.       if(val>0.0)
  39.         {
  40.         val = 10.0 * log10(val);
  41.         }
  42.       else
  43.         {
  44.         val = -200.0;
  45.         }
  46.       }
  47.     (*out_file) << freq << ", " << val << endl;
  48.     }
  49.   delete out_file;
  50. }
  51. //==========================================================
  52. void QamBer( int big_m,
  53.                double beg_ebno,
  54.                double end_ebno,
  55.                int num_pts,
  56.                char* out_filename)
  57. {
  58.   double ebno_numeric, ebno_db, bit_err, symb_err, q_arg;
  59.   double m_factor, sin_arg;
  60.   ofstream *out_file;
  61.   out_file = new ofstream(out_filename, ios::out);
  62.   double delta_ebno = (end_ebno - beg_ebno)/double(num_pts-1);
  63.   m_factor = double(ilog2(big_m));
  64.   sin_arg = PI/double(big_m);
  65.   for(int n=0; n<num_pts; n++)
  66.     {
  67.     ebno_db = beg_ebno + n * delta_ebno;
  68.     ebno_numeric = pow(10.0, ebno_db/10.0);
  69.     q_arg = sqrt(2.0 * m_factor * ebno_numeric) * sin(sin_arg);
  70.     symb_err = 2.0 * q_func(q_arg);
  71.     bit_err = symb_err/m_factor;
  72.     //bit_err = 0.5 * erfc(sqrt(ebno_numeric));
  73.     //symb_err = bit_err * (2.0 - bit_err);
  74.     (*out_file) << ebno_db << ", " << bit_err << ", " << symb_err << endl;
  75.     }
  76.   delete out_file;
  77. }
  78. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++