1 #include "InterpolationTestsF32.h" 2 #include <stdio.h> 3 #include "Error.h" 4 5 #define SNR_THRESHOLD 119 6 7 /* 8 9 Reference patterns are generated with 10 a double precision computation. 11 12 */ 13 #define REL_ERROR (8.0e-5) 14 15 16 test_linear_interp_f32()17 void InterpolationTestsF32::test_linear_interp_f32() 18 { 19 const float32_t *inp = input.ptr(); 20 float32_t *outp = output.ptr(); 21 22 unsigned long nb; 23 for(nb = 0; nb < input.nbSamples(); nb++) 24 { 25 outp[nb] = arm_linear_interp_f32(&S,inp[nb]); 26 } 27 28 ASSERT_EMPTY_TAIL(output); 29 30 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 31 32 ASSERT_REL_ERROR(output,ref,REL_ERROR); 33 34 } 35 36 test_bilinear_interp_f32()37 void InterpolationTestsF32::test_bilinear_interp_f32() 38 { 39 const float32_t *inp = input.ptr(); 40 float32_t *outp = output.ptr(); 41 float32_t x,y; 42 unsigned long nb; 43 for(nb = 0; nb < input.nbSamples(); nb += 2) 44 { 45 x = inp[nb]; 46 y = inp[nb+1]; 47 *outp++=arm_bilinear_interp_f32(&SBI,x,y); 48 } 49 50 ASSERT_EMPTY_TAIL(output); 51 52 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 53 54 ASSERT_REL_ERROR(output,ref,REL_ERROR); 55 56 } 57 58 test_spline_square_f32()59 void InterpolationTestsF32::test_spline_square_f32() 60 { 61 const float32_t *inpX = inputX.ptr(); 62 const float32_t *inpY = inputY.ptr(); 63 const float32_t *outX = outputX.ptr(); 64 float32_t *outp = output.ptr(); 65 float32_t *buf = buffer.ptr(); // ((2*4-1)*sizeof(float32_t)) 66 float32_t *coef = splineCoefs.ptr(); // ((3*(4-1))*sizeof(float32_t)) 67 68 arm_spline_instance_f32 S; 69 arm_spline_init_f32(&S, ARM_SPLINE_PARABOLIC_RUNOUT, inpX, inpY, 4, coef, buf); 70 arm_spline_f32(&S, outX, outp, 20); 71 72 ASSERT_EMPTY_TAIL(buffer); 73 ASSERT_EMPTY_TAIL(splineCoefs); 74 ASSERT_EMPTY_TAIL(output); 75 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 76 } 77 test_spline_sine_f32()78 void InterpolationTestsF32::test_spline_sine_f32() 79 { 80 const float32_t *inpX = inputX.ptr(); 81 const float32_t *inpY = inputY.ptr(); 82 const float32_t *outX = outputX.ptr(); 83 float32_t *outp = output.ptr(); 84 float32_t *buf = buffer.ptr(); // ((2*9-1)*sizeof(float32_t)) 85 float32_t *coef = splineCoefs.ptr(); // ((3*(9-1))*sizeof(float32_t)) 86 87 arm_spline_instance_f32 S; 88 arm_spline_init_f32(&S, ARM_SPLINE_NATURAL, inpX, inpY, 9, coef, buf); 89 arm_spline_f32(&S, outX, outp, 33); 90 91 ASSERT_EMPTY_TAIL(buffer); 92 ASSERT_EMPTY_TAIL(splineCoefs); 93 ASSERT_EMPTY_TAIL(output); 94 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 95 } 96 test_spline_ramp_f32()97 void InterpolationTestsF32::test_spline_ramp_f32() 98 { 99 const float32_t *inpX = inputX.ptr(); 100 const float32_t *inpY = inputY.ptr(); 101 const float32_t *outX = outputX.ptr(); 102 float32_t *outp = output.ptr(); 103 float32_t *buf = buffer.ptr(); // ((2*3-1)*sizeof(float32_t)) 104 float32_t *coef = splineCoefs.ptr(); // ((3*(3-1))*sizeof(float32_t)) 105 106 arm_spline_instance_f32 S; 107 arm_spline_init_f32(&S, ARM_SPLINE_PARABOLIC_RUNOUT, inpX, inpY, 3, coef, buf); 108 arm_spline_f32(&S, outX, outp, 30); 109 110 ASSERT_EMPTY_TAIL(buffer); 111 ASSERT_EMPTY_TAIL(splineCoefs); 112 ASSERT_EMPTY_TAIL(output); 113 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); 114 } 115 116 setUp(Testing::testID_t id,std::vector<Testing::param_t> & params,Client::PatternMgr * mgr)117 void InterpolationTestsF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr) 118 { 119 120 const int16_t *pConfig; 121 Testing::nbSamples_t nb=MAX_NB_SAMPLES; 122 (void)params; 123 124 125 switch(id) 126 { 127 case InterpolationTestsF32::TEST_LINEAR_INTERP_F32_1: 128 input.reload(InterpolationTestsF32::INPUT_F32_ID,mgr,nb); 129 y.reload(InterpolationTestsF32::YVAL_F32_ID,mgr,nb); 130 ref.reload(InterpolationTestsF32::REF_LINEAR_F32_ID,mgr,nb); 131 132 133 S.nValues=y.nbSamples(); /**< nValues */ 134 /* Those values must be coherent with the ones in the 135 Python script generating the patterns */ 136 S.x1=0.0; /**< x1 */ 137 S.xSpacing=1.0; /**< xSpacing */ 138 S.pYData=y.ptr(); /**< pointer to the table of Y values */ 139 break; 140 141 case InterpolationTestsF32::TEST_BILINEAR_INTERP_F32_2: 142 input.reload(InterpolationTestsF32::INPUTBI_F32_ID,mgr,nb); 143 config.reload(InterpolationTestsF32::CONFIGBI_S16_ID,mgr,nb); 144 y.reload(InterpolationTestsF32::YVALBI_F32_ID,mgr,nb); 145 ref.reload(InterpolationTestsF32::REF_BILINEAR_F32_ID,mgr,nb); 146 147 pConfig = config.ptr(); 148 149 SBI.numRows = pConfig[1]; 150 SBI.numCols = pConfig[0]; 151 152 SBI.pData = y.ptr(); 153 154 break; 155 156 case TEST_SPLINE_SQUARE_F32_3: 157 inputX.reload(InterpolationTestsF32::INPUT_SPLINE_SQU_X_F32_ID,mgr,4); 158 inputY.reload(InterpolationTestsF32::INPUT_SPLINE_SQU_Y_F32_ID,mgr,4); 159 outputX.reload(InterpolationTestsF32::OUTPUT_SPLINE_SQU_X_F32_ID,mgr,20); 160 ref.reload(InterpolationTestsF32::REF_SPLINE_SQU_F32_ID,mgr,20); 161 splineCoefs.create(3*(4-1),InterpolationTestsF32::COEFS_SPLINE_F32_ID,mgr); 162 163 buffer.create(2*4-1,InterpolationTestsF32::TEMP_SPLINE_F32_ID,mgr); 164 output.create(20,InterpolationTestsF32::OUT_SAMPLES_F32_ID,mgr); 165 break; 166 167 case TEST_SPLINE_SINE_F32_4: 168 inputX.reload(InterpolationTestsF32::INPUT_SPLINE_SIN_X_F32_ID,mgr,9); 169 inputY.reload(InterpolationTestsF32::INPUT_SPLINE_SIN_Y_F32_ID,mgr,9); 170 outputX.reload(InterpolationTestsF32::OUTPUT_SPLINE_SIN_X_F32_ID,mgr,33); 171 ref.reload(InterpolationTestsF32::REF_SPLINE_SIN_F32_ID,mgr,33); 172 splineCoefs.create(3*(9-1),InterpolationTestsF32::COEFS_SPLINE_F32_ID,mgr); 173 174 buffer.create(2*9-1,InterpolationTestsF32::TEMP_SPLINE_F32_ID,mgr); 175 output.create(33,InterpolationTestsF32::OUT_SAMPLES_F32_ID,mgr); 176 break; 177 178 case TEST_SPLINE_RAMP_F32_5: 179 inputX.reload(InterpolationTestsF32::INPUT_SPLINE_RAM_X_F32_ID,mgr,3); 180 inputY.reload(InterpolationTestsF32::INPUT_SPLINE_RAM_Y_F32_ID,mgr,3); 181 outputX.reload(InterpolationTestsF32::OUTPUT_SPLINE_RAM_X_F32_ID,mgr,30); 182 ref.reload(InterpolationTestsF32::REF_SPLINE_RAM_F32_ID,mgr,30); 183 splineCoefs.create(3*(3-1),InterpolationTestsF32::COEFS_SPLINE_F32_ID,mgr); 184 185 buffer.create(2*3-1,InterpolationTestsF32::TEMP_SPLINE_F32_ID,mgr); 186 output.create(30,InterpolationTestsF32::OUT_SAMPLES_F32_ID,mgr); 187 break; 188 } 189 190 191 192 output.create(ref.nbSamples(),InterpolationTestsF32::OUT_SAMPLES_F32_ID,mgr); 193 } 194 tearDown(Testing::testID_t id,Client::PatternMgr * mgr)195 void InterpolationTestsF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) 196 { 197 (void)id; 198 output.dump(mgr); 199 } 200