summaryrefslogtreecommitdiff
path: root/gsl-1.9/doc/examples/fft.c
diff options
context:
space:
mode:
Diffstat (limited to 'gsl-1.9/doc/examples/fft.c')
-rw-r--r--gsl-1.9/doc/examples/fft.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/gsl-1.9/doc/examples/fft.c b/gsl-1.9/doc/examples/fft.c
new file mode 100644
index 0000000..aa00242
--- /dev/null
+++ b/gsl-1.9/doc/examples/fft.c
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <math.h>
+#include <gsl/gsl_errno.h>
+#include <gsl/gsl_fft_complex.h>
+
+#define REAL(z,i) ((z)[2*(i)])
+#define IMAG(z,i) ((z)[2*(i)+1])
+
+int
+main (void)
+{
+ int i; double data[2*128];
+
+ for (i = 0; i < 128; i++)
+ {
+ REAL(data,i) = 0.0; IMAG(data,i) = 0.0;
+ }
+
+ REAL(data,0) = 1.0;
+
+ for (i = 1; i <= 10; i++)
+ {
+ REAL(data,i) = REAL(data,128-i) = 1.0;
+ }
+
+ for (i = 0; i < 128; i++)
+ {
+ printf ("%d %e %e\n", i,
+ REAL(data,i), IMAG(data,i));
+ }
+ printf ("\n");
+
+ gsl_fft_complex_radix2_forward (data, 1, 128);
+
+ for (i = 0; i < 128; i++)
+ {
+ printf ("%d %e %e\n", i,
+ REAL(data,i)/sqrt(128),
+ IMAG(data,i)/sqrt(128));
+ }
+
+ return 0;
+}