Merge pull request 'optimize_real_DFT' (#4) from optimize_real_DFT into master

Reviewed-on: #4
master optimize_real_DFT
daniel.koersten 2 years ago
commit e6d6256d96
  1. 19
      src/fourierTransformation.c
  2. 4
      src/globals.h

@ -6,8 +6,6 @@
*/
#include <math.h>
#include <complex.h>
#include "fourierTransformation.h"
#include "globals.h"
@ -20,18 +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;
int n, k;
for (k = 0; k < SIG_LEN; ++k) {
// Real part of X[k]
Xre[k] = 0;
for (n = 0; n < SIG_LEN; ++n) {
Xre[k] += x[n] * cos(n * k * PI2 / SIG_LEN);
}
// Imaginary part of X[k]
Xim[k] = 0;
for (n = 0; n < SIG_LEN; ++n) {
Xim[k] -= x[n] * sin(n * k * PI2 / SIG_LEN);
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 * 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