Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/complex_vector_int_tests.c @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * complex_vector_int_tests.c | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2006 Steve Underwood | |
9 * | |
10 * All rights reserved. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License version 2, as | |
14 * published by the Free Software Foundation. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * $Id: complex_vector_int_tests.c,v 1.2 2009/04/26 07:00:39 steveu Exp $ | |
26 */ | |
27 | |
28 #if defined(HAVE_CONFIG_H) | |
29 #include "config.h" | |
30 #endif | |
31 | |
32 #include <stdlib.h> | |
33 #include <stdio.h> | |
34 #include <fcntl.h> | |
35 #include <string.h> | |
36 | |
37 #include "spandsp.h" | |
38 | |
39 static complexi32_t cvec_dot_prodi16_dumb(const complexi16_t x[], const complexi16_t y[], int n) | |
40 { | |
41 complexi32_t z; | |
42 int i; | |
43 | |
44 z = complex_seti32(0, 0); | |
45 for (i = 0; i < n; i++) | |
46 { | |
47 z.re += ((int32_t) x[i].re*(int32_t) y[i].re - (int32_t) x[i].im*(int32_t) y[i].im); | |
48 z.im += ((int32_t) x[i].re*(int32_t) y[i].im + (int32_t) x[i].im*(int32_t) y[i].re); | |
49 } | |
50 return z; | |
51 } | |
52 /*- End of function --------------------------------------------------------*/ | |
53 | |
54 static int test_cvec_dot_prodi16(void) | |
55 { | |
56 int i; | |
57 complexi32_t za; | |
58 complexi32_t zb; | |
59 complexi16_t x[99]; | |
60 complexi16_t y[99]; | |
61 | |
62 for (i = 0; i < 99; i++) | |
63 { | |
64 x[i].re = rand(); | |
65 x[i].im = rand(); | |
66 y[i].re = rand(); | |
67 y[i].im = rand(); | |
68 } | |
69 | |
70 for (i = 1; i < 99; i++) | |
71 { | |
72 za = cvec_dot_prodi16(x, y, i); | |
73 zb = cvec_dot_prodi16_dumb(x, y, i); | |
74 if (za.re != zb.re || za.im != zb.im) | |
75 { | |
76 printf("Tests failed\n"); | |
77 exit(2); | |
78 } | |
79 } | |
80 return 0; | |
81 } | |
82 /*- End of function --------------------------------------------------------*/ | |
83 | |
84 static int test_cvec_circular_dot_prodi16(void) | |
85 { | |
86 int i; | |
87 int j; | |
88 int pos; | |
89 int len; | |
90 complexi32_t za; | |
91 complexi32_t zb; | |
92 complexi16_t x[99]; | |
93 complexi16_t y[99]; | |
94 | |
95 /* Verify that we can do circular sample buffer "dot" linear coefficient buffer | |
96 operations properly, by doing two sub-dot products. */ | |
97 for (i = 0; i < 99; i++) | |
98 { | |
99 x[i].re = rand(); | |
100 x[i].im = rand(); | |
101 y[i].re = rand(); | |
102 y[i].im = rand(); | |
103 } | |
104 | |
105 len = 95; | |
106 for (pos = 0; pos < len; pos++) | |
107 { | |
108 za = cvec_circular_dot_prodi16(x, y, len, pos); | |
109 zb = complex_seti32(0, 0); | |
110 for (i = 0; i < len; i++) | |
111 { | |
112 j = (pos + i) % len; | |
113 zb.re += ((int32_t) x[j].re*(int32_t) y[i].re - (int32_t) x[j].im*(int32_t) y[i].im); | |
114 zb.im += ((int32_t) x[j].re*(int32_t) y[i].im + (int32_t) x[j].im*(int32_t) y[i].re); | |
115 } | |
116 | |
117 if (za.re != zb.re || za.im != zb.im) | |
118 { | |
119 printf("Tests failed\n"); | |
120 exit(2); | |
121 } | |
122 } | |
123 return 0; | |
124 } | |
125 /*- End of function --------------------------------------------------------*/ | |
126 | |
127 int main(int argc, char *argv[]) | |
128 { | |
129 test_cvec_dot_prodi16(); | |
130 test_cvec_circular_dot_prodi16(); | |
131 | |
132 printf("Tests passed.\n"); | |
133 return 0; | |
134 } | |
135 /*- End of function --------------------------------------------------------*/ | |
136 /*- End of file ------------------------------------------------------------*/ |