00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <it/io.h>
00026 #include <it/mat.h>
00027 #include <it/transform.h>
00028 #include <it/fourier.h>
00029
00030 int cvec_eq_tol (cvec v1, cvec v2, double tol)
00031 {
00032 idx_t i;
00033 assert (v1);
00034 assert (v2);
00035
00036 if (cvec_length (v1) != cvec_length (v2))
00037 return 0;
00038
00039 for (i = 0; i < cvec_length (v1); i++)
00040 if (cnorm (csub (v1[i], v2[i])) > tol)
00041 return 0;
00042 return 1;
00043 }
00044
00045
00046
00047
00048 int main ()
00049 {
00050 cvec v, r1, r2;
00051 cvec vt;
00052 vec a;
00053 cplx z;
00054
00055 #ifdef FFT_TIMING
00056 cvec t = cvec_new_range (8 * 1024 * 1024);
00057 vt = it_fft (t);
00058 cvec_delete (vt);
00059 return 0;
00060 #endif
00061
00062 #ifdef DFT_TIMING
00063 int i;
00064 cvec t = cvec_new_range (15);
00065 for (i = 0; i < 1000000; i++) {
00066 vt = it_dft (t);
00067 cvec_delete (vt);
00068 }
00069 return 0;
00070 #endif
00071
00072
00073 v = cvec_new_string ("1 2 3");
00074 a = vec_new_string ("1 2 3");
00075 z.r = 0.5;
00076 z.i = 1.0;
00077 it_printf ("z = %z rho = %f theta = %f\n", z, cnorm (z), cang (z));
00078 vt = it_fzt (v, z);
00079 it_printf ("vt[fzt] = $.04z\n", vt);
00080 cvec_delete (vt);
00081
00082 vt = it_dft (v);
00083 it_printf ("vt[dft] = $.04z\n", vt);
00084 cvec_delete (vt);
00085
00086 vt = it_dft_real (a);
00087 it_printf ("vt[dft_real] = $.04z\n", vt);
00088
00089
00090 v = it_idft (vt);
00091 it_printf ("v[idft] = $.04z\n", v);
00092
00093 a = it_idft_real (vt);
00094 it_printf ("a[idft_real] = $.04f\n", a);
00095 cvec_delete (vt);
00096 cvec_delete (v);
00097 vec_delete (a);
00098
00099
00100 v = cvec_new_string ("1+0.5i 2-0.5i 3+0.25i 4-0.25i 5");
00101 it_printf ("v = $z\n", v);
00102
00103
00104 vt = it_dft (v);
00105 cvec_delete (v);
00106 it_printf ("vt = $.04z\n", vt);
00107
00108
00109 v = it_idft (vt);
00110 cvec_delete (vt);
00111 it_printf ("v = $.04z\n", v);
00112
00113 a = vec_new_1N (8);
00114 v = vec_to_cvec (a);
00115 it_printf ("v = $.04z\n", v);
00116
00117
00118 vt = it_dft (v);
00119 cvec_delete (v);
00120 it_printf ("vt = $.04z\n", vt);
00121
00122
00123 v = it_idft (vt);
00124 cvec_delete (vt);
00125 it_printf ("v = $.04z\n", v);
00126
00127
00128
00129
00130
00131 vec_delete (a);
00132
00133
00134
00135 r1 = cvec_new_string ("1 1 1");
00136 r2 = cvec_new_string ("2 2 2");
00137 vt = cvec_fft_conv (r1, r2);
00138
00139 it_printf ("fft_conv($z,$z) = $z\n", r1, r2, vt);
00140 cvec_delete (vt);
00141 vt = cvec_fft_corr (r1, r2);
00142 it_printf ("fft_corr($z,$z) = $z\n", r1, r2, vt);
00143 cvec_delete (vt);
00144 vt = cvec_fft_autocorr (r1);
00145 it_printf ("fft_autocorr($z) = $z\n", r1, vt);
00146 cvec_delete (vt);
00147
00148 return 0;
00149 }