* Let the libmontiumc version output it's input and output in a matlab
authorMatthijs Kooijman <matthijs@stdin.nl>
Tue, 8 Apr 2008 13:27:31 +0000 (15:27 +0200)
committerunknown <s0042331@.dynamic.ewi.utwente.nl>
Tue, 8 Apr 2008 13:27:31 +0000 (15:27 +0200)
   compatible format.
 * Use a longer period worth of sinus function.

FFT_support.cpp

index 7fc2484be97043c091505e99354a165015e2e2a1..2ddf150b6f1bb8e3e215dac89d9256cbb4fe31cd 100644 (file)
@@ -6,7 +6,7 @@
 #define FIXED_POINT 15\r
 #define WORD_SIZE   16\r
 \r
-#define WORDS_PER_LINE 8\r
+#define WORDS_PER_LINE 4\r
 #define WORDS_PER_GROUP 1\r
 \r
 mem input_a_re, input_a_im, input_b_re, input_b_im, output_a_re, output_a_im, output_b_re, output_b_im, twiddle_re, twiddle_im; \r
@@ -27,7 +27,7 @@ float from_fixed(int n)
        return n / (float)(1<<FIXED_POINT);\r
 }\r
 \r
-void print_mem(mem m, int offset, int size, bool fixed)\r
+void print_mem(mem m, int offset, int size, bool fixed, bool newline)\r
 {\r
        int i;\r
        for(i = offset;i<offset+size;i++)\r
@@ -36,12 +36,12 @@ void print_mem(mem m, int offset, int size, bool fixed)
                        printf("%0.4f", from_fixed(get_mem(m->id, i)));\r
                else\r
                        printf("%04hx", (short)get_mem(m->id, i));\r
-               if ((i + 1) % WORDS_PER_LINE == 0)\r
+               if (newline && (i + 1) % WORDS_PER_LINE == 0)\r
                        printf("\n");\r
                else if ((i + 1) % WORDS_PER_GROUP == 0)\r
                        printf(" ");\r
        }\r
-       if (i % WORDS_PER_LINE != 0)\r
+       if (newline && i % WORDS_PER_LINE != 0)\r
                printf("\n");\r
 }\r
 \r
@@ -67,9 +67,9 @@ void pre_run()
        \r
        for (i=0;i<PARAM_N_t;i++)\r
        {\r
-               /* We take the sine from 0 to 2*2*Pi, ie two periods. We divide \r
+               /* We take the sine from 0 to 20*2*Pi, ie twenty periods. We divide \r
                 * the value by PARAM_N_t to prevent overflow. */\r
-               int value = to_fixed(sin((float)i*2*2*M_PI/PARAM_N_t)/PARAM_N_t);\r
+               int value = to_fixed(sin((float)i*20*2*M_PI/PARAM_N_t)/PARAM_N_t);\r
 \r
                if (i<PARAM_N_t/2)\r
                {\r
@@ -94,14 +94,19 @@ void pre_run()
        }\r
        \r
        printf("re(W)\n");\r
-       print_mem(twiddle_re, 0, PARAM_N_t/2, true);\r
+       print_mem(twiddle_re, 0, PARAM_N_t/2, true, true);\r
        printf("im(W)\n");\r
-       print_mem(twiddle_im, 0, PARAM_N_t/2, true);\r
+       print_mem(twiddle_im, 0, PARAM_N_t/2, true, true);\r
        printf("re(in_a)\n");\r
-       print_mem(input_a_re, 0, PARAM_N_t/2, true);\r
+       print_mem(input_a_re, 0, PARAM_N_t/2, true, true);\r
        printf("re(in_b)\n");\r
-       print_mem(input_b_re, 0, PARAM_N_t/2, true);\r
-       \r
+       print_mem(input_b_re, 0, PARAM_N_t/2, true, true);\r
+\r
+       printf("re_in = [");\r
+       print_mem(input_a_re, 0, PARAM_N_t/2, true, false);\r
+       print_mem(input_b_re, 0, PARAM_N_t/2, true, false);\r
+       printf("];\n");\r
+\r
 /* Write out memory contents for use by the python simulator */\r
        save_mem_range_to_file(input_a_re->id, 0, PARAM_N_t/2, "Memory/sin_a_re.mm");\r
        save_mem_range_to_file(input_a_im->id, 0, PARAM_N_t/2, "Memory/sin_a_im.mm");\r
@@ -126,18 +131,21 @@ void post_run()
                output_b_re  = alloc_mem(P2M1);\r
                output_b_im  = alloc_mem(P3M1);\r
        }\r
+       printf("re_out = [");\r
+       print_mem(output_a_re, 0, PARAM_N_t/2, true, false);\r
+       print_mem(output_b_re, 0, PARAM_N_t/2, true, false);\r
+       printf("];\n");\r
+       printf("im_out = [");\r
+       print_mem(output_a_im, 0, PARAM_N_t/2, true, false);\r
+       print_mem(output_b_im, 0, PARAM_N_t/2, true, false);\r
+       printf("];\n");\r
+       /*\r
        printf("re(out)\n");\r
-       print_mem(output_a_re, 0, PARAM_N_t/2, true);\r
-       print_mem(output_b_re, 0, PARAM_N_t/2, true);\r
-       printf("im(out)\n");\r
-       print_mem(output_a_im, 0, PARAM_N_t/2, true);\r
-       print_mem(output_b_im, 0, PARAM_N_t/2, true);\r
-       \r
-       printf("re(out)\n");\r
-       print_mem(output_a_re, 0, PARAM_N_t/2, false);\r
-       print_mem(output_b_re, 0, PARAM_N_t/2, false);\r
+       print_mem(output_a_re, 0, PARAM_N_t/2, false, true);\r
+       print_mem(output_b_re, 0, PARAM_N_t/2, false, true);\r
        printf("im(out)\n");\r
-       print_mem(output_a_im, 0, PARAM_N_t/2, false);\r
-       print_mem(output_b_im, 0, PARAM_N_t/2, false);\r
+       print_mem(output_a_im, 0, PARAM_N_t/2, false, true);\r
+       print_mem(output_b_im, 0, PARAM_N_t/2, false, true);\r
+       */\r
 \r
 }\r