RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dan_pdgm.cpp
Go to the documentation of this file.
1 //
2 // file = dan_pdgm.cpp
3 //
4 #include "dan_pdgm.h"
5 #include "complex.h"
6 #include "fft.h"
7 #include <iostream>
8 #include <stdlib.h>
9 
10 DaniellPeriodogram::DaniellPeriodogram(complex* time_seq, double samp_intvl,
11  int num_samps, int fft_len,
12  GenericWindow* window, int big_p)
13  : PsdEstimate(num_samps, samp_intvl)
14 {
15  int k, m;
16  double sum;
17  double* pdgrm_dan;
18  complex *freq_seq, *windowed_seq;
19  double scale_factor;
20 
21  scale_factor = num_samps * (2 * big_p + 1);
22 
23  freq_seq = new complex[fft_len];
24  windowed_seq = new complex[fft_len];
25  pdgrm_dan = new double[fft_len / 2];
26  fft(time_seq, freq_seq, num_samps, fft_len);
27 
28  //-----------------------------------------------------------------
29  // Compute first P points of periodogram
30 
31  for (m = 0; m < big_p; m++) {
32  sum = 0.0;
33  for (k = m - big_p; k < 0; k++) {
34  sum += mag_sqrd(freq_seq[num_samps + k]);
35  }
36  for (k = 0; k <= (m + big_p); k++) {
37  sum += mag_sqrd(freq_seq[k]);
38  }
39  Psd_Est[m] = samp_intvl * sum / scale_factor;
40  }
41 
42  //-----------------------------------------------------------------
43  // Compute periodogram points P thru (N/2)-1
44 
45  for (m = big_p; m < (fft_len / 2); m++) {
46  sum = 0.0;
47  for (k = m - big_p; k <= (m + big_p); k++) {
48  sum += mag_sqrd(freq_seq[k]);
49  }
50  Psd_Est[m] = samp_intvl * sum / scale_factor;
51  }
52 
53  delete[] freq_seq;
54  delete[] windowed_seq;
55  delete[] pdgrm_dan;
56  return;
57 }
DaniellPeriodogram(complex *big_x, double samp_intvl, int big_n, int fft_len, GenericWindow *data_wind, int big_p)
Definition: dan_pdgm.cpp:10
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