pull/4/head
Daniel 2 years ago
parent 7e08405a44
commit 6bf6f6c2da
  1. 10
      src/fourierTransformation.c
  2. 4
      src/globals.h

@ -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];

@ -8,6 +8,10 @@
#ifndef GLOBALS_H_
#define GLOBALS_H_
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define PI2 6.2832 //2*pi
#define SIG_LEN 128 //signal length

Loading…
Cancel
Save