1 #include "BIQUADF64.h"
2 #include <stdio.h>
3 #include "Error.h"
4 
5 #define SNR_THRESHOLD 98
6 
7 /*
8 
9 Reference patterns are generated with
10 a double precision computation.
11 
12 */
13 #define REL_ERROR (1.2e-3)
14 
test_biquad_cascade_df2T_ref()15     void BIQUADF64::test_biquad_cascade_df2T_ref()
16     {
17 
18 
19         float64_t *statep = state.ptr();
20 
21 
22         float64_t *coefsp = coefs.ptr();
23 
24 
25         float64_t *inputp = inputs.ptr();
26         float64_t *outp = output.ptr();
27 
28         int blockSize;
29 
30 
31 
32         /*
33 
34         Python script is generating different tests with
35         different blockSize and numTaps.
36 
37         We loop on those configs.
38 
39         */
40 
41            blockSize = inputs.nbSamples() >> 1;
42 
43            /*
44 
45            The filter is initialized with the coefs, blockSize and numTaps.
46 
47            */
48            arm_biquad_cascade_df2T_init_f64(&this->Sdf2T,3,coefsp,statep);
49 
50 
51            /*
52 
53            Python script is filtering a 2*blockSize number of samples.
54            We do the same filtering in two pass to check (indirectly that
55            the state management of the fir is working.)
56 
57            */
58 
59            arm_biquad_cascade_df2T_f64(&this->Sdf2T,inputp,outp,blockSize);
60            outp += blockSize;
61 
62 
63            inputp += blockSize;
64            arm_biquad_cascade_df2T_f64(&this->Sdf2T,inputp,outp,blockSize);
65            outp += blockSize;
66 
67 
68            ASSERT_EMPTY_TAIL(output);
69 
70            ASSERT_SNR(output,ref,(float64_t)SNR_THRESHOLD);
71 
72            ASSERT_REL_ERROR(output,ref,REL_ERROR);
73 
74 
75     }
76 
77 
78 
test_biquad_cascade_df2T_rand()79     void BIQUADF64::test_biquad_cascade_df2T_rand()
80     {
81 
82 
83         float64_t *statep = state.ptr();
84         const int16_t *configsp = configs.ptr();
85 
86         float64_t *coefsp = coefs.ptr();
87 
88 
89         float64_t *inputp = inputs.ptr();
90         float64_t *outp = output.ptr();
91 
92         int blockSize;
93         int numStages;
94 
95         unsigned long i;
96 
97 
98 
99         for(i=0;i < configs.nbSamples(); i+=2)
100         {
101 
102         /*
103 
104         Python script is generating different tests with
105         different blockSize and numTaps.
106 
107         We loop on those configs.
108 
109         */
110 
111            numStages = configsp[0];
112            blockSize = configsp[1];
113 
114            configsp += 2;
115 
116 
117 
118            /*
119 
120            The filter is initialized with the coefs, blockSize and numTaps.
121 
122            */
123            arm_biquad_cascade_df2T_init_f64(&this->Sdf2T,numStages,coefsp,statep);
124 
125            coefsp += numStages * 5;
126 
127            /*
128 
129            Python script is filtering a 2*blockSize number of samples.
130            We do the same filtering in two pass to check (indirectly that
131            the state management of the fir is working.)
132 
133            */
134 
135            arm_biquad_cascade_df2T_f64(&this->Sdf2T,inputp,outp,blockSize);
136            outp += blockSize;
137            inputp += blockSize;
138 
139         }
140 
141            ASSERT_EMPTY_TAIL(output);
142 
143            ASSERT_SNR(output,ref,(float64_t)SNR_THRESHOLD);
144 
145            ASSERT_REL_ERROR(output,ref,REL_ERROR);
146 
147 
148     }
149 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & params,Client::PatternMgr * mgr)150     void BIQUADF64::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
151     {
152 
153        (void)params;
154        switch(id)
155        {
156         case BIQUADF64::TEST_BIQUAD_CASCADE_DF2T_REF_1:
157 
158            inputs.reload(BIQUADF64::BIQUADINPUTS_F64_ID,mgr);
159            coefs.reload(BIQUADF64::BIQUADCOEFS_F64_ID,mgr);
160            ref.reload(BIQUADF64::BIQUADREFS_F64_ID,mgr);
161         break;
162 
163         case BIQUADF64::TEST_BIQUAD_CASCADE_DF2T_RAND_2:
164 
165            inputs.reload(BIQUADF64::ALLBIQUADINPUTS_F64_ID,mgr);
166            coefs.reload(BIQUADF64::ALLBIQUADCOEFS_F64_ID,mgr);
167            ref.reload(BIQUADF64::ALLBIQUADREFS_F64_ID,mgr);
168            configs.reload(BIQUADF64::ALLBIQUADCONFIGS_S16_ID,mgr);
169         break;
170 
171        }
172 
173 
174 
175 
176        output.create(ref.nbSamples(),BIQUADF64::OUT_F64_ID,mgr);
177 
178        state.create(128,BIQUADF64::STATE_F64_ID,mgr);
179 
180 
181     }
182 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)183     void BIQUADF64::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
184     {
185         (void)id;
186         output.dump(mgr);
187 
188     }
189