comparison peck_test.c @ 0:723f588b82ac

import
author Peter Meerwald <p.meerwald@bct-electronic.com>
date Fri, 16 Sep 2011 12:53:08 +0200
parents
children 2d6c49fcafcb
comparison
equal deleted inserted replaced
-1:000000000000 0:723f588b82ac
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <float.h>
4
5 #include <peck_fft.h>
6 #include <peck_fftr.h>
7
8 void enable_runfast() {
9 #ifdef __arm__
10 static const unsigned int x = 0x04086060;
11 static const unsigned int y = 0x03000000;
12 int r;
13 asm volatile (
14 "fmrx %0, fpscr \n\t" //r0 = FPSCR
15 "and %0, %0, %1 \n\t" //r0 = r0 & 0x04086060
16 "orr %0, %0, %2 \n\t" //r0 = r0 | 0x03000000
17 "fmxr fpscr, %0 \n\t" //FPSCR = r0
18 : "=r"(r)
19 : "r"(x), "r"(y)
20 );
21 #endif
22 }
23
24 int main(int argc, char *argv[]) {
25 unsigned int i, j;
26 peck_fftr_cfg p, pi;
27
28 enable_runfast();
29
30 const unsigned int N = 256;
31
32 peck_fft_scalar in[N];
33 peck_fft_cpx out[N/2 + 1];
34 peck_fft_scalar res[N];
35
36 for (i = 0; i < N; i++) {
37 in[i] = (i % 13) / 3;
38 }
39
40 p = peck_fftr_alloc(N, 0, NULL, NULL);
41 pi = peck_fftr_alloc(N, 1, NULL, NULL);
42
43 for (j = 0; j < 10000; j++) {
44 if (j == 0) {
45 for (i = 0; i < 8; i++)
46 printf("%d: %f\n", i, in[i]);
47 printf("----\n");
48 }
49
50 peck_fftr(p, in, out);
51
52 if (j == 0) {
53 for (i = 0; i < 8; i++)
54 printf("%d: %f %f\n", i, out[i].r, out[i].i);
55 printf("----\n");
56 }
57
58 peck_fftri(pi, out, res);
59
60 if (j == 0) {
61 for (i = 0; i < 8; i++)
62 printf("%d: %f\n", i, res[i] / N);
63 }
64 }
65 peck_fftr_free(p);
66 peck_fftr_free(pi);
67 peck_fft_cleanup();
68
69 for (i = 0; i < N; i++) {
70 if (fabs(in[i] - res[i]/N) > 0.00001) {
71 fprintf(stderr, "!!!! ERROR !!!! at %d\n", i);
72 exit(EXIT_FAILURE);
73 }
74 }
75
76 return EXIT_SUCCESS;
77 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.