void FloatArray::scale(float factor, FloatArray destination){//supports in-place /// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a> #ifdef ARM_CORTEX arm_scale_f32(data, factor, destination, size); #else for(int n=0; n<size; n++){ destination[n]=factor*data[n]; } #endif }
void ComplexFloatArray::scale(float factor){ #ifdef ARM_CORTEX arm_scale_f32((float*)data, factor, (float*)data, size*2); #else for(int n=0; n<size; n++){ data[n].re *= factor; data[n].im *= factor; } #endif }
int32_t main(void) { uint32_t i; arm_status status; uint32_t index; float32_t minValue; /* Initialize the LMSNorm data structure */ arm_lms_norm_init_f32(&lmsNorm_instance, NUMTAPS, lmsNormCoeff_f32, lmsStateF32, MU, BLOCKSIZE); /* Initialize the FIR data structure */ arm_fir_init_f32(&LPF_instance, NUMTAPS, (float32_t *)FIRCoeff_f32, firStateF32, BLOCKSIZE); /* ---------------------------------------------------------------------- * Loop over the frames of data and execute each of the processing * functions in the system. * ------------------------------------------------------------------- */ for(i=0; i < NUMFRAMES; i++) { /* Read the input data - uniformly distributed random noise - into wire1 */ arm_copy_f32(testInput_f32 + (i * BLOCKSIZE), wire1, BLOCKSIZE); /* Execute the FIR processing function. Input wire1 and output wire2 */ arm_fir_f32(&LPF_instance, wire1, wire2, BLOCKSIZE); /* Execute the LMS Norm processing function*/ arm_lms_norm_f32(&lmsNorm_instance, /* LMSNorm instance */ wire1, /* Input signal */ wire2, /* Reference Signal */ wire3, /* Converged Signal */ err_signal, /* Error Signal, this will become small as the signal converges */ BLOCKSIZE); /* BlockSize */ /* apply overall gain */ arm_scale_f32(wire3, 5, wire3, BLOCKSIZE); /* in-place buffer */ } status = ARM_MATH_SUCCESS; /* ------------------------------------------------------------------------------- * Test whether the error signal has reached towards 0. * ----------------------------------------------------------------------------- */ arm_abs_f32(err_signal, err_signal, BLOCKSIZE); arm_min_f32(err_signal, BLOCKSIZE, &minValue, &index); if (minValue > DELTA_ERROR) { status = ARM_MATH_TEST_FAILURE; } /* ---------------------------------------------------------------------- * Test whether the filter coefficients have converged. * ------------------------------------------------------------------- */ arm_sub_f32((float32_t *)FIRCoeff_f32, lmsNormCoeff_f32, lmsNormCoeff_f32, NUMTAPS); arm_abs_f32(lmsNormCoeff_f32, lmsNormCoeff_f32, NUMTAPS); arm_min_f32(lmsNormCoeff_f32, NUMTAPS, &minValue, &index); if (minValue > DELTA_COEFF) { status = ARM_MATH_TEST_FAILURE; } /* ---------------------------------------------------------------------- * Loop here if the signals did not pass the convergence check. * This denotes a test failure * ------------------------------------------------------------------- */ if( status != ARM_MATH_SUCCESS) { while(1); } }
int32_t main(void) { float32_t *inputF32, *outputF32; arm_biquad_cas_df1_32x64_ins_q31 S1; arm_biquad_cas_df1_32x64_ins_q31 S2; arm_biquad_casd_df1_inst_q31 S3; arm_biquad_casd_df1_inst_q31 S4; arm_biquad_casd_df1_inst_q31 S5; int i; int32_t status; inputF32 = &testInput_f32[0]; outputF32 = &testOutput[0]; /* Initialize the state and coefficient buffers for all Biquad sections */ arm_biquad_cas_df1_32x64_init_q31(&S1, NUMSTAGES, (q31_t *) &coeffTable[190*0 + 10*(gainDB[0] + 9)], &biquadStateBand1Q31[0], 2); arm_biquad_cas_df1_32x64_init_q31(&S2, NUMSTAGES, (q31_t *) &coeffTable[190*1 + 10*(gainDB[1] + 9)], &biquadStateBand2Q31[0], 2); arm_biquad_cascade_df1_init_q31(&S3, NUMSTAGES, (q31_t *) &coeffTable[190*2 + 10*(gainDB[2] + 9)], &biquadStateBand3Q31[0], 2); arm_biquad_cascade_df1_init_q31(&S4, NUMSTAGES, (q31_t *) &coeffTable[190*3 + 10*(gainDB[3] + 9)], &biquadStateBand4Q31[0], 2); arm_biquad_cascade_df1_init_q31(&S5, NUMSTAGES, (q31_t *) &coeffTable[190*4 + 10*(gainDB[4] + 9)], &biquadStateBand5Q31[0], 2); /* Call the process functions and needs to change filter coefficients for varying the gain of each band */ for(i=0; i < NUMBLOCKS; i++) { /* ---------------------------------------------------------------------- ** Convert block of input data from float to Q31 ** ------------------------------------------------------------------- */ arm_float_to_q31(inputF32 + (i*BLOCKSIZE), inputQ31, BLOCKSIZE); /* ---------------------------------------------------------------------- ** Scale down by 1/8. This provides additional headroom so that the ** graphic EQ can apply gain. ** ------------------------------------------------------------------- */ arm_scale_q31(inputQ31, 0x7FFFFFFF, -3, inputQ31, BLOCKSIZE); /* ---------------------------------------------------------------------- ** Call the Q31 Biquad Cascade DF1 32x64 process function for band1, band2 ** ------------------------------------------------------------------- */ arm_biquad_cas_df1_32x64_q31(&S1, inputQ31, outputQ31, BLOCKSIZE); arm_biquad_cas_df1_32x64_q31(&S2, outputQ31, outputQ31, BLOCKSIZE); /* ---------------------------------------------------------------------- ** Call the Q31 Biquad Cascade DF1 process function for band3, band4, band5 ** ------------------------------------------------------------------- */ arm_biquad_cascade_df1_q31(&S3, outputQ31, outputQ31, BLOCKSIZE); arm_biquad_cascade_df1_q31(&S4, outputQ31, outputQ31, BLOCKSIZE); arm_biquad_cascade_df1_q31(&S5, outputQ31, outputQ31, BLOCKSIZE); /* ---------------------------------------------------------------------- ** Convert Q31 result back to float ** ------------------------------------------------------------------- */ arm_q31_to_float(outputQ31, outputF32 + (i * BLOCKSIZE), BLOCKSIZE); /* ---------------------------------------------------------------------- ** Scale back up ** ------------------------------------------------------------------- */ arm_scale_f32(outputF32 + (i * BLOCKSIZE), 8.0f, outputF32 + (i * BLOCKSIZE), BLOCKSIZE); }; snr = arm_snr_f32(testRefOutput_f32, testOutput, TESTLENGTH); if (snr < SNR_THRESHOLD_F32) { status = ARM_MATH_TEST_FAILURE; } else { status = ARM_MATH_SUCCESS; } /* ---------------------------------------------------------------------- ** Loop here if the signal does not match the reference output. ** ------------------------------------------------------------------- */ if( status != ARM_MATH_SUCCESS) { while(1); } while(1); /* main function does not return */ }