RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fsk_spec.cpp
Go to the documentation of this file.
1 //
2 // file = fsk_spec.cpp
3 //
4 
5 #include "fsk_spec.h"
6 #include "misdefs.h"
7 #include "sinc.h"
8 #include <fstream>
9 #include <iostream>
10 #include <math.h>
11 #include <stdlib.h>
12 
13 CpfskSpectrum::CpfskSpectrum(int big_m, double f_d, double big_t)
14 {
15  double psi, f, phi, alpha_mn;
16  double a_m, a_n, b_mn, x_m, x_n;
17  double sum, sum2;
18  double freq_incr;
19  int n, m, freq_idx;
20 
21  Big_M = big_m;
22  Freq_Dev = f_d;
23  Big_T = big_t;
24 
25  sum = 0.0;
26  for (n = 1; n <= big_m / 2; n++) {
27  sum += (cos(2 * PI * f_d * big_t * (2 * n - 1)));
28  }
29  psi = 2.0 * sum / big_m;
30 
31  freq_incr = 0.125;
32  for (freq_idx = 0; freq_idx < 128; freq_idx++) {
33  f = freq_idx * freq_incr;
34  sum = 0.0;
35  sum2 = 0.0;
36  for (n = 1; n <= big_m; n++) {
37  x_n = PI * big_t * (f - (2 * n - 1 - big_m) * f_d);
38  a_n = sinc(x_n);
39  sum += a_n * a_n;
40 
41  for (m = 1; m <= big_m; m++) {
42  x_m = PI * big_t * (f - (2 * m - 1 - big_m) * f_d);
43  a_m = sinc(x_m);
44 
45  alpha_mn = TWO_PI * f_d * big_t * (m + n - 1 - big_m);
46 
47  b_mn = (cos(TWO_PI * f * big_t - alpha_mn) - psi * cos(alpha_mn)) /
48  (1.0 + psi * psi - 2 * psi * cos(TWO_PI * f * big_t));
49  sum2 += b_mn * a_n * a_m;
50  } // end of loop over m
51  } // end of loop over n
52  phi = big_t * (sum / 2.0 + (sum2 / big_m)) / big_m;
53  if (freq_idx == 0)
54  std::cout << "at f=0, phi = " << phi << std::endl;
55  } // end of loop over freq_idx
56 }
57 double
59 {
60  double psi, phi, alpha_mn;
61  double a_m, a_n, b_mn, x_m, x_n;
62  double sum, sum2;
63  int n, m;
64 
65  sum = 0.0;
66  for (n = 1; n <= Big_M / 2; n++) {
67  sum += (cos(2 * PI * Freq_Dev * Big_T * (2 * n - 1)));
68  }
69  psi = 2.0 * sum / Big_M;
70 
71  sum = 0.0;
72  sum2 = 0.0;
73  for (n = 1; n <= Big_M; n++) {
74  x_n = PI * Big_T * (freq - (2 * n - 1 - Big_M) * Freq_Dev);
75  a_n = sinc(x_n);
76  sum += a_n * a_n;
77 
78  for (m = 1; m <= Big_M; m++) {
79  x_m = PI * Big_T * (freq - (2 * m - 1 - Big_M) * Freq_Dev);
80  a_m = sinc(x_m);
81 
82  alpha_mn = TWO_PI * Freq_Dev * Big_T * (m + n - 1 - Big_M);
83 
84  b_mn = (cos(TWO_PI * freq * Big_T - alpha_mn) - psi * cos(alpha_mn)) /
85  (1.0 + psi * psi - 2 * psi * cos(TWO_PI * freq * Big_T));
86  sum2 += b_mn * a_n * a_m;
87  } // end of loop over m
88  } // end of loop over n
89  phi = Big_T * (sum / 2.0 + (sum2 / Big_M)) / Big_M;
90  return (phi);
91 }
double Big_T
Definition: fsk_spec.h:17
CpfskSpectrum(int big_m, double f_d, double big_t)
Definition: fsk_spec.cpp:13
double sinc(double x)
Definition: sinc.cpp:10
#define PI
Definition: misdefs.h:9
double GetPsdValue(double freq)
Definition: fsk_spec.cpp:58
double Freq_Dev
Definition: fsk_spec.h:18
const double TWO_PI
Definition: misdefs.h:11