RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bartpdgm.cpp
Go to the documentation of this file.
1 //
2 // File = bartpdgm.cpp
3 //
4 
5 #include "bartpdgm.h"
6 #include "complex.h"
7 #include "fft.h"
8 #include <stdlib.h>
9 
11  double samp_intvl,
12  int num_samps_per_seg, int fft_len,
13  GenericWindow* data_wind,
14  int num_segs_to_avg)
15  : PsdEstimate(num_samps_per_seg, samp_intvl)
16 {
17  int samp_idx, seg_idx;
18  double* window_seq;
19  complex *time_seg, *freq_seg;
20  double scale_factor;
21 
22  time_seg = new complex[num_samps_per_seg];
23  freq_seg = new complex[fft_len];
24 
25  if ((freq_seg == NULL) || (time_seg == NULL)) {
26  std::cout << "Allocation error in BartlettPeriodogram" << std::endl;
27  exit(99);
28  }
29 
30  for (samp_idx = 0; samp_idx < fft_len; samp_idx++) {
31  Psd_Est[samp_idx] = 0.0;
32  }
33  if (data_wind != NULL)
34  window_seq = data_wind->GetDataWindow();
35  for (seg_idx = 0; seg_idx < num_segs_to_avg; seg_idx++) {
36  signal_source->GetNextSegment(time_seg, num_samps_per_seg);
37  if (data_wind != NULL) {
38  for (samp_idx = 0; samp_idx < num_samps_per_seg; samp_idx++)
39  time_seg[samp_idx] *= window_seq[samp_idx];
40  }
41 
42  fft(time_seg, freq_seg, num_samps_per_seg, fft_len);
43 
44  for (samp_idx = 0; samp_idx < fft_len; samp_idx++) {
45  Psd_Est[samp_idx] += mag_sqrd(freq_seg[samp_idx]);
46  }
47  }
48  scale_factor = (float)num_segs_to_avg * num_samps_per_seg / samp_intvl;
49  for (samp_idx = 0; samp_idx < fft_len; samp_idx++) {
50  Psd_Est[samp_idx] /= scale_factor;
51  }
52  delete[] time_seg;
53  delete[] freq_seg;
54  return;
55 }
56 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BartlettPeriodogram(SignalSource *signal_source, double samp_intvl, int num_samps_per_seg, int fft_len, GenericWindow *data_wind, int num_segs_to_avg)
Definition: bartpdgm.cpp:10
double * GetDataWindow(void)
Definition: gen_win.cpp:74
void fft(complex *time_signal, complex *sample_spectrum, int num_samps)
Definition: fft.cpp:24
double mag_sqrd(const complex _z)
Definition: complex.h:128
double * Psd_Est
Definition: psd_est.h:25
virtual void GetNextSegment(complex *, int)
Definition: sig_src.h:19