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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = nrz_theory.cpp
  3. //
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include "nrz_theory.h"
  7. #include "sinc.h"
  8. #include <fstream>
  9. #ifndef PI
  10.   #define PI 3.1415926535897932
  11. #endif
  12. using namespace std;
  13. void NrzPsd(  double bit_energy,
  14.               double bit_rate,
  15.               double beg_freq,
  16.               double end_freq,
  17.               int num_pts,
  18.               bool plot_in_db,
  19.               char* out_filename)
  20. {
  21.   double freq, val;
  22.   ofstream *out_file;
  23.   out_file = new ofstream(out_filename, ios::out);
  24.   double delta_freq = (end_freq - beg_freq)/double(num_pts-1);
  25.   for(int n=0; n<num_pts; n++)
  26.     {
  27.     freq = beg_freq + n * delta_freq;
  28.     val = bit_energy * sinc_sqrd(freq/bit_rate);
  29.     if( plot_in_db )
  30.       {
  31.       if(val>0.0)
  32.         {
  33.         val = 10.0 * log10(val);
  34.         }
  35.       else
  36.         {
  37.         val = -200.0;
  38.         }
  39.       }
  40.     (*out_file) << freq << ", " << val << endl;
  41.     }
  42.   delete out_file;
  43. }
  44. //================================================================
  45. void BiphasePsd(  double bit_energy,
  46.               double bit_rate,
  47.               double beg_freq,
  48.               double end_freq,
  49.               int num_pts,
  50.               bool plot_in_db,
  51.               char* out_filename)
  52. {
  53.   double freq, val, argument;
  54.   ofstream *out_file;
  55.   out_file = new ofstream(out_filename, ios::out);
  56.   double delta_freq = (end_freq - beg_freq)/double(num_pts-1);
  57.   for(int n=0; n<num_pts; n++)
  58.     {
  59.     freq = beg_freq + n * delta_freq;
  60.     argument = freq/bit_rate/2.0;
  61.     val = sin(PI*argument);
  62.     val *= val;
  63.     val *= bit_energy * sinc_sqrd(argument);
  64.     if( plot_in_db )
  65.       {
  66.       if(val>0.0)
  67.         {
  68.         val = 10.0 * log10(val);
  69.         }
  70.       else
  71.         {
  72.         val = -200.0;
  73.         }
  74.       }
  75.     (*out_file) << freq << ", " << val << endl;
  76.     }
  77.   delete out_file;
  78. }
  79. //================================================================
  80. void MillerPsd(  double bit_energy,
  81.               double bit_rate,
  82.               double beg_freq,
  83.               double end_freq,
  84.               int num_pts,
  85.               bool plot_in_db,
  86.               char* out_filename)
  87. {
  88.   double freq, val, phi;
  89.   ofstream *out_file;
  90.   out_file = new ofstream(out_filename, ios::out);
  91.   double delta_freq = (end_freq - beg_freq)/double(num_pts-1);
  92.   for(int n=0; n<num_pts; n++)
  93.     {
  94.     freq = beg_freq + n * delta_freq;
  95.     phi = PI*freq/bit_rate;
  96.     val = 23 - 2.0*cos(phi) - 22.0*cos(2.0*phi) - 12.0*cos(3.0*phi) + 5.0*cos(4.0*phi);
  97.     val += 12.0*cos(5.0*phi) + 2.0*cos(6.0*phi) - 8.0*cos(7.0*phi) + 2.0*cos(8.0*phi);
  98.     val /= phi * phi * (34.0 + 16.0*cos(8.0*phi));
  99.     val *= bit_energy;
  100.     if( plot_in_db )
  101.       {
  102.       if(val>0.0)
  103.         {
  104.         val = 10.0 * log10(val);
  105.         }
  106.       else
  107.         {
  108.         val = -200.0;
  109.         }
  110.       }
  111.     (*out_file) << freq << ", " << val << endl;
  112.     }
  113.   delete out_file;
  114. }
  115. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++