aboutsummaryrefslogtreecommitdiffstats
path: root/Project/RTDSP/dft.c
diff options
context:
space:
mode:
Diffstat (limited to 'Project/RTDSP/dft.c')
-rw-r--r--Project/RTDSP/dft.c46
1 files changed, 0 insertions, 46 deletions
diff --git a/Project/RTDSP/dft.c b/Project/RTDSP/dft.c
deleted file mode 100644
index 2e47680..0000000
--- a/Project/RTDSP/dft.c
+++ /dev/null
@@ -1,46 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-
-#define E_PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062
-#define N 8
-
-typedef struct {
- float r;
- float i;
-} Complex;
-
-float x[] = {0, 0, 2, 3, 4, 0, 0, 0};
-Complex X[N];
-float x_out[N];
-
-void dft() {
- int n, k;
- for(k = 0; k < N; ++k) {
- X[k].r = 0.f;
- X[k].i = 0.f;
- for(n = 0; n < N; ++n) {
- X[k].r += x[n] * cos(2 * E_PI * k * n / N);
- X[k].i -= x[n] * sin(2 * E_PI * k * n / N);
- }
- }
-}
-
-void idft() {
- int n, k;
- for(n = 0; n < N; ++n) {
- x_out[n] = 0.f;
- for(k = 0; k < N; ++k) {
- x_out[n] += X[k].r * cos(2 * E_PI * k * n / N) - X[k].i * sin(2 * E_PI * k * n / N);
- }
- x_out[n] /= N;
- }
-}
-
-int main() {
- int k;
- dft();
- idft();
- for(k = 0; k < N; ++k) {
- printf("x[%d] = %.2f, X[%d] = %.2f + %.2fi, x_out[%d] = %.2f\n", k, x[k], k, X[k].r, X[k].i, k, x_out[k]);
- }
-}