|
|
|
@ -6,7 +6,6 @@ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
|
#include "fourierTransformation.h" |
|
|
|
|
#include "globals.h" |
|
|
|
|
|
|
|
|
@ -19,12 +18,13 @@ void DFT(double x[SIG_LEN], double Xre[SIG_LEN], double Xim[SIG_LEN], |
|
|
|
|
* X_real, X_imag DFT of x (real and imaginary parts) |
|
|
|
|
* P power spectrum of x |
|
|
|
|
*/ |
|
|
|
|
const float two_pi = 2 * M_PI / SIG_LEN; |
|
|
|
|
|
|
|
|
|
for (int k = 0; k < SIG_LEN; ++k) { |
|
|
|
|
for (int k = 0; k < SIG_LEN; k++) { |
|
|
|
|
Xre[k] = Xim[k] = 0; |
|
|
|
|
for (int n = 0; n < SIG_LEN; ++n) { |
|
|
|
|
Xre[k] += x[n] * cos(n * k * PI2 / SIG_LEN); |
|
|
|
|
Xim[k] -= x[n] * sin(n * k * PI2 / SIG_LEN); |
|
|
|
|
for (int n = 0; n < SIG_LEN; n++) { |
|
|
|
|
Xre[k] += x[n] * cos(n * k * two_pi); |
|
|
|
|
Xim[k] -= x[n] * sin(n * k * two_pi); |
|
|
|
|
} |
|
|
|
|
// Power at kth frequency bin
|
|
|
|
|
P[k] = Xre[k] * Xre[k] + Xim[k] * Xim[k]; |
|
|
|
|