1 #include "BIQUADQ31.h"
2 #include <stdio.h>
3 #include "Error.h"
4
5
6 #define SNR_THRESHOLD 115
7
8 #define ABS_ERROR_Q31 ((q31_t)1000)
9
10 #define SNR_32x64_THRESHOLD 140
11
12 #define ABS_32x64_ERROR_Q31 ((q31_t)25)
13
checkInnerTail(q31_t * b)14 static void checkInnerTail(q31_t *b)
15 {
16 ASSERT_TRUE(b[0] == 0);
17 ASSERT_TRUE(b[1] == 0);
18 ASSERT_TRUE(b[2] == 0);
19 ASSERT_TRUE(b[3] == 0);
20 }
21
test_biquad_cascade_df1()22 void BIQUADQ31::test_biquad_cascade_df1()
23 {
24
25
26 q31_t *statep = state.ptr();
27 const q31_t *coefsp = coefs.ptr();
28
29 const q31_t *inputp = inputs.ptr();
30 q31_t *outp = output.ptr();
31
32 int blockSize;
33
34
35
36 /*
37
38 Python script is generating different tests with
39 different blockSize and numTaps.
40
41 We loop on those configs.
42
43 */
44
45 blockSize = inputs.nbSamples() >> 1;
46
47 /*
48
49 The filter is initialized with the coefs, blockSize and numTaps.
50
51 */
52
53 arm_biquad_cascade_df1_init_q31(&this->S,3,coefsp,statep,2);
54
55
56 /*
57
58 Python script is filtering a 2*blockSize number of samples.
59 We do the same filtering in two pass to check (indirectly that
60 the state management of the fir is working.)
61
62 */
63
64 arm_biquad_cascade_df1_q31(&this->S,inputp,outp,blockSize);
65 outp += blockSize;
66
67 inputp += blockSize;
68 arm_biquad_cascade_df1_q31(&this->S,inputp,outp,blockSize);
69 outp += blockSize;
70
71
72
73
74 ASSERT_EMPTY_TAIL(output);
75
76 ASSERT_SNR(output,ref,(q31_t)SNR_THRESHOLD);
77
78 ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q31);
79
80
81 }
82
test_biquad_cascade_df1_32x64()83 void BIQUADQ31::test_biquad_cascade_df1_32x64()
84 {
85 q63_t *statep = state64.ptr();
86 const q31_t *coefsp = coefs.ptr();
87
88 q31_t *inputp = inputs.ptr();
89 q31_t *outp = output.ptr();
90
91 int blockSize;
92
93
94
95 /*
96
97 Python script is generating different tests with
98 different blockSize and numTaps.
99
100 We loop on those configs.
101
102 */
103
104 blockSize = inputs.nbSamples() >> 1;
105
106 /*
107
108 The filter is initialized with the coefs, blockSize and numTaps.
109
110 */
111
112 arm_biquad_cas_df1_32x64_init_q31(&this->S32x64,3,coefsp,statep,2);
113
114
115 /*
116
117 Python script is filtering a 2*blockSize number of samples.
118 We do the same filtering in two pass to check (indirectly that
119 the state management of the fir is working.)
120
121 */
122 #if 0
123 arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,blockSize);
124 outp += blockSize;
125
126 inputp += blockSize;
127 arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,blockSize);
128 outp += blockSize;
129
130 #else
131 int delta=1;
132 int k;
133 for(k=0;k + delta <2*blockSize ; k+=delta)
134 {
135 arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,delta);
136 outp += delta;
137 checkInnerTail(outp);
138
139 inputp += delta;
140 }
141 if (k < 2*blockSize)
142 {
143 delta = 2*blockSize - k;
144 arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,delta);
145 outp += delta;
146 checkInnerTail(outp);
147
148 inputp += delta;
149 }
150 #endif
151
152
153 ASSERT_EMPTY_TAIL(output);
154
155 ASSERT_SNR(output,ref,(q31_t)SNR_32x64_THRESHOLD);
156
157 ASSERT_NEAR_EQ(output,ref,ABS_32x64_ERROR_Q31);
158
159 }
160
161
setUp(Testing::testID_t id,std::vector<Testing::param_t> & params,Client::PatternMgr * mgr)162 void BIQUADQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
163 {
164
165 (void)params;
166 switch(id)
167 {
168 case BIQUADQ31::TEST_BIQUAD_CASCADE_DF1_1:
169 /* max 4 * nbTaps as generated by Python script */
170 /* Same OUTID is reused. So linked to same output file. If it is dumped
171 it may overwrite the output
172 */
173 state.create(32,BIQUADQ31::OUT_Q31_ID,mgr);
174
175 break;
176
177 case BIQUADQ31::TEST_BIQUAD_CASCADE_DF1_32X64_2:
178 state64.create(32,BIQUADQ31::STATE_Q64_ID,mgr);
179 break;
180
181 }
182
183 inputs.reload(BIQUADQ31::BIQUADINPUTS_Q31_ID,mgr);
184 coefs.reload(BIQUADQ31::BIQUADCOEFS_Q31_ID,mgr);
185 ref.reload(BIQUADQ31::BIQUADREFS_Q31_ID,mgr);
186 output.create(ref.nbSamples(),BIQUADQ31::OUT_Q31_ID,mgr);
187
188
189 }
190
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)191 void BIQUADQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
192 {
193 (void)id;
194 output.dump(mgr);
195 }
196