/* ----------------------------------------------------------------------------
* Calculation of Sine values from Cubic Interpolation and Linear interpolation
* ---------------------------------------------------------------------------- */
int32_t main(void)
{
	uint32_t i;
	arm_status status;

	arm_linear_interp_instance_f32 S = {188495, -3.141592653589793238, XSPACING, &arm_linear_interep_table[0]};

	/*------------------------------------------------------------------------------
	*  Method 1: Test out Calculated from Cubic Interpolation
	*------------------------------------------------------------------------------*/
	for(i=0; i< TEST_LENGTH_SAMPLES; i++)
	{
		testOutput[i] = arm_sin_f32(testInputSin_f32[i]);
	}

	/*------------------------------------------------------------------------------
	*  Method 2: Test out Calculated from Cubic Interpolation and Linear interpolation
	*------------------------------------------------------------------------------*/

	for(i=0; i< TEST_LENGTH_SAMPLES; i++)
	{
	  	testLinIntOutput[i] = arm_linear_interp_f32(&S, testInputSin_f32[i]);
	}

	/*------------------------------------------------------------------------------
	*  					SNR calculation for method 1
	*------------------------------------------------------------------------------*/
	snr1 = arm_snr_f32(testRefSinOutput32_f32, testOutput, 2);

	/*------------------------------------------------------------------------------
	*  					SNR calculation for method 2
	*------------------------------------------------------------------------------*/
	snr2 = arm_snr_f32(testRefSinOutput32_f32, testLinIntOutput, 2);

	/*------------------------------------------------------------------------------
	*  					Initialise status depending on SNR calculations
	*------------------------------------------------------------------------------*/
	if( snr2 > snr1)
	{
		status = ARM_MATH_SUCCESS;
	}
	else
	{
		status = ARM_MATH_TEST_FAILURE;
	}

	/* ----------------------------------------------------------------------
	** Loop here if the signals fail the PASS check.
	** This denotes a test failure
	** ------------------------------------------------------------------- */
	if( status != ARM_MATH_SUCCESS)
	{
		while(1);
	}

    while(1);                             /* main function does not return */
}
Ejemplo n.º 2
0
int main() {
    Sine_f32 sine_1KHz(  1000, SAMPLE_RATE, 1.0);
    Sine_f32 sine_15KHz(15000, SAMPLE_RATE, 0.5);
    FIR_f32<NUM_TAPS> fir(firCoeffs32);
    
    float32_t buffer_a[BLOCK_SIZE];
    float32_t buffer_b[BLOCK_SIZE];
    for (float32_t *sgn=output; sgn<(output+TEST_LENGTH_SAMPLES); sgn += BLOCK_SIZE) {
        sine_1KHz.generate(buffer_a);           // Generate a 1KHz sine wave
        sine_15KHz.process(buffer_a, buffer_b); // Add a 15KHz sine wave
        fir.process(buffer_b, sgn);             // FIR low pass filter: 6KHz cutoff
    }
    
    sine_1KHz.reset();
    for (float32_t *sgn=expected_output; sgn<(expected_output+TEST_LENGTH_SAMPLES); sgn += BLOCK_SIZE) {
        sine_1KHz.generate(sgn);        // Generate a 1KHz sine wave
    }
    
    float snr = arm_snr_f32(&expected_output[DELAY-1], &output[WARMUP-1], TEST_LENGTH_SAMPLES-WARMUP);
    printf("snr: %f\n\r", snr);
    if (snr < SNR_THRESHOLD_F32) {
        printf("Failed\n\r");
    } else {
        printf("Success\n\r");
    }
}
Ejemplo n.º 3
0
int32_t main(void)
{
  arm_status status;                           /* Status of the example */
  arm_cfft_radix4_instance_f32 cfft_instance;  /* CFFT Structure instance */

  /* CFFT Structure instance pointer */
  arm_cfft_radix4_instance_f32 *cfft_instance_ptr =
      (arm_cfft_radix4_instance_f32*) &cfft_instance;

  /* output length of convolution */
  outLen = srcALen + srcBLen - 1;

  /* Initialise the fft input buffers with all zeros */
  arm_fill_f32(0.0,  Ak, MAX_BLOCKSIZE);
  arm_fill_f32(0.0,  Bk, MAX_BLOCKSIZE);

  /* Copy the input values to the fft input buffers */
  arm_copy_f32(testInputA_f32,  Ak, MAX_BLOCKSIZE/2);
  arm_copy_f32(testInputB_f32,  Bk, MAX_BLOCKSIZE/2);

  /* Initialize the CFFT function to compute 64 point fft */
  status = arm_cfft_radix4_init_f32(cfft_instance_ptr, 64, 0, 1);

  /* Transform input a[n] from time domain to frequency domain A[k] */
  arm_cfft_radix4_f32(cfft_instance_ptr, Ak);
  /* Transform input b[n] from time domain to frequency domain B[k] */
  arm_cfft_radix4_f32(cfft_instance_ptr, Bk);

  /* Complex Multiplication of the two input buffers in frequency domain */
  arm_cmplx_mult_cmplx_f32(Ak, Bk, AxB, MAX_BLOCKSIZE/2);

  /* Initialize the CIFFT function to compute 64 point ifft */
  status = arm_cfft_radix4_init_f32(cfft_instance_ptr, 64, 1, 1);

  /* Transform the multiplication output from frequency domain to time domain,
     that gives the convolved output  */
  arm_cfft_radix4_f32(cfft_instance_ptr, AxB);

  /* SNR Calculation */
  snr = arm_snr_f32((float32_t *)testRefOutput_f32, AxB, srcALen + srcBLen - 1);

  /* Compare the SNR with threshold to test whether the
     computed output is matched with the reference output values. */
  if( snr > SNR_THRESHOLD)
  {
    status = ARM_MATH_SUCCESS;
  }

  if( status != ARM_MATH_SUCCESS)
  {
    while(1);
  }

  while(1);                             /* main function does not return */
}
Ejemplo n.º 4
0
int32_t main(void) 
{ 
  uint32_t i; 
  arm_fir_instance_f32 S; 
  arm_status status; 
  float32_t  *inputF32, *outputF32; 
 
  /* Initialize input and output buffer pointers */ 
  inputF32 = &testInput_f32_1kHz_15kHz[0];	 
  outputF32 = &testOutput[0]; 

  /* Call FIR init function to initialize the instance structure. */
  arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize); 
 
  /* ---------------------------------------------------------------------- 
  ** Call the FIR process function for every blockSize samples  
  ** ------------------------------------------------------------------- */ 

  for(i=0; i < numBlocks; i++)  
    {	 
      Enable_Performance_Monitor(0);  								// Init PMU
      Performance_Monitor_Start(0);								// start PMU counters
      arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);  
      Performance_Monitor_Stop(0);     								// stop PMU counters
      PMU_counter0_result[i] = Performance_Monitor_Read_Counter0(0);
      PMU_counter1_result[i] = Performance_Monitor_Read_Counter1(0);
      PMU_counter2_result[i] = Performance_Monitor_Read_Counter2(0);
      PMU_cycle_count[i]     = Performance_Monitor_Read_CycleCount(0);
    } 
 
  /* ---------------------------------------------------------------------- 
  ** Compare the generated output against the reference output computed
  ** in MATLAB.
  ** ------------------------------------------------------------------- */ 

  snr = arm_snr_f32(&refOutput[0], &testOutput[0], TEST_LENGTH_SAMPLES); 
 
  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); 
    } 
} 
arm_status test_arm_cmplx_dot_prod_f32( void )   
{   
  uint32_t i;	       /* loop counter */  
  test_config *config; /* configuration structure pointer variable */  
   
  /* Loop over number of test cases */  
  for(i = 0; i < NUM_TESTS; i++)   
  {   
	  /* points to each configuration */  
      config = &CONFIG[i];   
         
      /* Process the data through the Complex Dot Product */   
      arm_cmplx_dot_prod_f32_test_render(config->inputAF32, config->inputBF32,   
	  		config->blockSize, testOutput_real, testOutput_imag);   
   
      /* compare the Real parts of final result with the reference output */   
      snr_real = arm_snr_f32(&config->outputF32_real, &testOutput_real[0], 1);   
   
	  /* compare the calculated snr withe the threshold value */  
      if (snr_real < SNR_THRESHOLD)   
	  {   
	    /* If the output is not matched with the refereence output values,   
		   return the status as ARM_MATH_TEST_FAILURE */  
	  	return(ARM_MATH_TEST_FAILURE); 			   
	  }   
  
	  /* compare the Imaginary parts of final result with the reference output */  
	  snr_imag = arm_snr_f32(&config->outputF32_imag, &testOutput_imag[0], 1);   
   
	  /* compare the calculated snr withe the threshold value */  
      if (snr_imag < SNR_THRESHOLD)   
	  { 		      
	    /* If the output is not matched with the refereence output values,   
		   return the status as ARM_MATH_TEST_FAILURE */  
	  	return(ARM_MATH_TEST_FAILURE); 			   
	  }  
   }   
   
   /* All tests passed! */   
   return(ARM_MATH_SUCCESS);   
}   
Ejemplo n.º 6
0
int main(void)
{
  uint32_t i;
  arm_fir_instance_f32 S;
  arm_status status;
  float32_t  *inputF32, *outputF32;

  /* Initialize input and output buffer pointers */
  inputF32 = &testInput_f32_1kHz_15kHz[0];
  outputF32 = &testOutput[0];

  /* Call FIR init function to initialize the instance structure. */
  arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize);

  /* ----------------------------------------------------------------------
  ** Call the FIR process function for every blockSize samples
  ** ------------------------------------------------------------------- */

  for(i=0; i < numBlocks; i++)
  {
    arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
  }

  /* ----------------------------------------------------------------------
  ** Compare the generated output against the reference output computed
  ** in MATLAB.
  ** ------------------------------------------------------------------- */

  snr = arm_snr_f32(&refOutput[0], &testOutput[0], TEST_LENGTH_SAMPLES);

  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 */
}
Ejemplo n.º 7
0
int32_t main(void)
{

  arm_matrix_instance_f32 A;      /* Matrix A Instance */
  arm_matrix_instance_f32 AT;     /* Matrix AT(A transpose) instance */
  arm_matrix_instance_f32 ATMA;   /* Matrix ATMA( AT multiply with A) instance */
  arm_matrix_instance_f32 ATMAI;  /* Matrix ATMAI(Inverse of ATMA) instance */
  arm_matrix_instance_f32 B;      /* Matrix B instance */
  arm_matrix_instance_f32 X;      /* Matrix X(Unknown Matrix) instance */

  uint32_t srcRows, srcColumns;  /* Temporary variables */
  arm_status status;

  /* Initialise A Matrix Instance with numRows, numCols and data array(A_f32) */
  srcRows = 4;
  srcColumns = 4;
  arm_mat_init_f32(&A, srcRows, srcColumns, (float32_t *)A_f32);

  /* Initialise Matrix Instance AT with numRows, numCols and data array(AT_f32) */
  srcRows = 4;
  srcColumns = 4;
  arm_mat_init_f32(&AT, srcRows, srcColumns, AT_f32);

  /* calculation of A transpose */
  status = arm_mat_trans_f32(&A, &AT);


  /* Initialise ATMA Matrix Instance with numRows, numCols and data array(ATMA_f32) */
  srcRows = 4;
  srcColumns = 4;
  arm_mat_init_f32(&ATMA, srcRows, srcColumns, ATMA_f32);

  /* calculation of AT Multiply with A */
  status = arm_mat_mult_f32(&AT, &A, &ATMA);

  /* Initialise ATMAI Matrix Instance with numRows, numCols and data array(ATMAI_f32) */
  srcRows = 4;
  srcColumns = 4;
  arm_mat_init_f32(&ATMAI, srcRows, srcColumns, ATMAI_f32);

  /* calculation of Inverse((Transpose(A) * A) */
  status = arm_mat_inverse_f32(&ATMA, &ATMAI);

  /* calculation of (Inverse((Transpose(A) * A)) *  Transpose(A)) */
  status = arm_mat_mult_f32(&ATMAI, &AT, &ATMA);

  /* Initialise B Matrix Instance with numRows, numCols and data array(B_f32) */
  srcRows = 4;
  srcColumns = 1;
  arm_mat_init_f32(&B, srcRows, srcColumns, (float32_t *)B_f32);

  /* Initialise X Matrix Instance with numRows, numCols and data array(X_f32) */
  srcRows = 4;
  srcColumns = 1;
  arm_mat_init_f32(&X, srcRows, srcColumns, X_f32);

  /* calculation ((Inverse((Transpose(A) * A)) *  Transpose(A)) * B) */
  status = arm_mat_mult_f32(&ATMA, &B, &X);

  /* Comparison of reference with test output */
  snr = arm_snr_f32((float32_t *)xRef_f32, X_f32, 4);

  /*------------------------------------------------------------------------------
  *            Initialise status depending on SNR calculations
  *------------------------------------------------------------------------------*/
  if( snr > SNR_THRESHOLD)
  {
    status = ARM_MATH_SUCCESS;
  }
  else
  {
    status = ARM_MATH_TEST_FAILURE;
  }


  /* ----------------------------------------------------------------------
  ** Loop here if the signals fail the PASS check.
  ** This denotes a test failure
  ** ------------------------------------------------------------------- */
  if( status != ARM_MATH_SUCCESS)
  {
    while(1);
  }

  while(1);                             /* main function does not return */
}
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 */
}