aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorymherklotz <ymherklotz@gmail.com>2018-03-05 13:10:55 +0000
committerymherklotz <ymherklotz@gmail.com>2018-03-05 13:10:55 +0000
commit722e7e5d2d487ef850a0ddde58de5e34e3e2ac8f (patch)
tree710225624f3f44c3049f69c9cb91adfbfbd33978
parent8c7191df880e9c7c8abec1231e878881f0f698c0 (diff)
parent2e183b1d4429f42d7785a199828f83abe9def68e (diff)
downloadNoiseSilencer-722e7e5d2d487ef850a0ddde58de5e34e3e2ac8f.tar.gz
NoiseSilencer-722e7e5d2d487ef850a0ddde58de5e34e3e2ac8f.zip
Merge branch 'project' of github.com:dan12n/RTDSP into project
-rw-r--r--Project/TestCode/dft.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/Project/TestCode/dft.c b/Project/TestCode/dft.c
new file mode 100644
index 0000000..9ffcfbe
--- /dev/null
+++ b/Project/TestCode/dft.c
@@ -0,0 +1,46 @@
+#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]);
+ }
+} \ No newline at end of file