RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cpfsk.cpp
Go to the documentation of this file.
1 //
2 // File = cpfsk.cpp
3 //
4 
5 #include "cpfsk.h"
6 #include "complex.h"
7 #include "misdefs.h"
8 #include "uni_rand.h"
9 #include <fstream>
10 #include <iostream>
11 #include <math.h>
12 #include <stdlib.h>
13 
14 //==========================================
15 // constructor
16 //------------------------------------------
17 
18 CpfskSource::CpfskSource(double samp_intvl, double freq_dev, int samps_per_symb,
19  long prn_seed, int num_samps_per_seg,
20  int samps_initial_delay)
21  : SignalSource()
22 {
23  Samp_Intvl = samp_intvl;
24  Freq_Dev = freq_dev;
25  Prn_Seed = prn_seed;
26  Num_Samps_Per_Seg = num_samps_per_seg;
27  Seg_Num = 0;
28  Samps_Per_Symb = samps_per_symb;
29  Samps_Initial_Delay = samps_initial_delay;
30 
31  if (samps_initial_delay == 0)
33  else
35 
36  Old_Phi = 0.0;
37  Saved_Samp_Idx = 0;
38  Saved_Rad_Freq = 0.0;
39 }
40 
41 //++++++++++++++++++++++++++++++++++++++++++
42 
43 //==========================================
44 // destructor
45 //------------------------------------------
46 
48 {
49 }
50 //++++++++++++++++++++++++++++++++++++++++++
51 
52 //====================================================
53 // method to generate the next segment of signal data
54 //----------------------------------------------------
55 
56 void
57 CpfskSource::GetNextSegment(double* time_seq, int num_samps)
58 {
59  int samp_idx, cumul_samp_idx;
60  double phi, rand_val, rad_freq;
61  double td_energy;
62 
63  cumul_samp_idx = 0;
64  td_energy = 0.0;
65 
66  if (In_Delay_Intvl == TRUE) {
67  for (samp_idx = 0; samp_idx < Samps_Initial_Delay; samp_idx++) {
68  time_seq[cumul_samp_idx] = 0.0;
69  cumul_samp_idx++;
70  }
72  }
73 
74  while (cumul_samp_idx < num_samps) {
75  if (Saved_Samp_Idx != 0) {
76  for (samp_idx = Saved_Samp_Idx; samp_idx < Samps_Per_Symb; samp_idx++) {
78  Old_Phi = fmod(phi, TWO_PI);
79  time_seq[cumul_samp_idx] = sin(Old_Phi);
80  td_energy += (sin(Old_Phi) * sin(Old_Phi));
81  cumul_samp_idx++;
82  }
83  Saved_Samp_Idx = 0;
84  }
85  // flip a fair coin to get next symbol value
86  rand_val = UniformRandom(&Prn_Seed);
87  if (rand_val < 0.5)
88  rad_freq = -TWO_PI * Freq_Dev;
89  else
90  rad_freq = TWO_PI * Freq_Dev;
91 
92  // generate samples for next symbol
93  for (samp_idx = 0; samp_idx < Samps_Per_Symb; samp_idx++) {
94  phi = Old_Phi + rad_freq * Samp_Intvl;
95  Old_Phi = fmod(phi, TWO_PI);
96  time_seq[cumul_samp_idx] = sin(Old_Phi);
97  td_energy += (sin(Old_Phi) * sin(Old_Phi));
98  cumul_samp_idx++;
99  if (cumul_samp_idx >= num_samps) {
100  Saved_Rad_Freq = rad_freq;
101  Saved_Samp_Idx = samp_idx + 1;
102  break;
103  }
104  } // end of loop over samp_idx
105  }
106  Seg_Num++;
107 
108  return;
109 }
110 //====================================================
111 // method to generate the next segment of signal data
112 //----------------------------------------------------
113 
114 void
115 CpfskSource::GetNextSegment(complex* time_seq, int num_samps)
116 {
117  int samp_idx, cumul_samp_idx;
118  double phi, rand_val, rad_freq;
119  double td_energy;
120 
121  cumul_samp_idx = 0;
122  td_energy = 0.0;
123 
124  if (In_Delay_Intvl == TRUE) {
125  for (samp_idx = 0; samp_idx < Samps_Initial_Delay; samp_idx++) {
126  time_seq[cumul_samp_idx] = 0.0;
127  cumul_samp_idx++;
128  }
130  }
131 
132  while (cumul_samp_idx < num_samps) {
133  // Finish off any partial symbol started in previous segment
134  if (Saved_Samp_Idx != 0) {
135  for (samp_idx = Saved_Samp_Idx; samp_idx < Samps_Per_Symb; samp_idx++) {
137  Old_Phi = fmod(phi, TWO_PI);
138  time_seq[cumul_samp_idx] = complex(sin(Old_Phi), 0.0);
139  td_energy += (sin(Old_Phi) * sin(Old_Phi));
140  cumul_samp_idx++;
141  }
142  Saved_Samp_Idx = 0;
143  }
144  // flip a fair coin to get next symbol value
145  rand_val = UniformRandom(&Prn_Seed);
146  if (rand_val < 0.5)
147  rad_freq = -TWO_PI * Freq_Dev;
148  else
149  rad_freq = TWO_PI * Freq_Dev;
150 
151  // generate samples for next symbol
152  for (samp_idx = 0; samp_idx < Samps_Per_Symb; samp_idx++) {
153  phi = Old_Phi + rad_freq * Samp_Intvl;
154  Old_Phi = fmod(phi, TWO_PI);
155  time_seq[cumul_samp_idx] = complex(sin(Old_Phi), 0.0);
156  td_energy += (sin(Old_Phi) * sin(Old_Phi));
157  cumul_samp_idx++;
158  if (cumul_samp_idx >= num_samps) {
159  Saved_Rad_Freq = rad_freq;
160  Saved_Samp_Idx = samp_idx + 1;
161  break;
162  }
163  } // end of loop over samp_idx
164  }
165  if (Seg_Num == 0)
166  std::cout << "td_energy = " << td_energy << std::endl;
167  Seg_Num++;
168 
169  return;
170 }
int Samps_Per_Symb
Definition: cpfsk.h:28
long Prn_Seed
Definition: cpfsk.h:30
double Freq_Dev
Definition: cpfsk.h:31
CpfskSource(double sampling_interval, double freq_dev, int samps_per_symb, long prn_seed, int num_samps_per_seg, int samps_initial_delay)
Definition: cpfsk.cpp:18
double Samp_Intvl
Definition: cpfsk.h:25
double Saved_Rad_Freq
Definition: cpfsk.h:33
void GetNextSegment(double *output_vector, int num_samps)
Definition: cpfsk.cpp:57
logical In_Delay_Intvl
Definition: cpfsk.h:36
int Seg_Num
Definition: cpfsk.h:27
#define FALSE
Definition: misdefs.h:14
int Saved_Samp_Idx
Definition: cpfsk.h:29
#define TRUE
Definition: misdefs.h:13
int Num_Samps_Per_Seg
Definition: cpfsk.h:26
float UniformRandom(long *seed)
Definition: uni_rand.cpp:19
~CpfskSource()
Definition: cpfsk.cpp:47
const double TWO_PI
Definition: misdefs.h:11
int Samps_Initial_Delay
Definition: cpfsk.h:35
double Old_Phi
Definition: cpfsk.h:32