Ejemplo n.º 1
0
void FiltInitDSP(Filt * flt )
{
	int index;
	FiltInit(flt);
	for (index=0;index<DEV_PeriodSamples;index++)
	{
		coefs[index] = flt->filtCoef[index];
	}
	arm_fir_init_f32(&S, NUMTAPS, &(coefs[0]), &(firState[0]), BLOCKSIZE);
}
Ejemplo n.º 2
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); 
    } 
} 
Ejemplo n.º 3
0
int main (void) {                          //Main function

	gpio_set_mode(P2_10,Output);
	arm_fir_init_f32(&S,N,h,state,DMA_BUFFER_SIZE/2);
  audio_init ( hz8000, line_in, dma, DMA_HANDLER);

while(1){
	while (!(rx_buffer_full && tx_buffer_empty)){};
	  gpio_set(P2_10, HIGH);
		proces_buffer();
	  gpio_set(P2_10, LOW);
	}
}
Ejemplo n.º 4
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.º 5
0
void FIRprocessing(uint32_t* input, float32_t* output) {
	arm_fir_instance_f32 S;

	input = &g_ulADCValues[0];
	output = &g_fFIRResult[0];

	arm_fir_init_f32(&S, NUM_TAPS, (float32_t*) &firCoeffs32[0],
			&firStateF32[0], FilterNode[0].blockSize);
	uint32_t i = 0;
	for (i = 0; i < FilterNode[0].blockSize; i++)
		arm_fir_f32(&S, (float32_t*) input + (i * FilterNode[0].blockSize),
				output + (i * FilterNode[0].blockSize),
				FilterNode[0].blockSize);
	setAgainSampling();
}
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); 
  } 
} 
void main (void)
{
  /*开硬件浮点*/
  SCB->CPACR |=((3UL << 10*2)|(3UL << 11*2));     /* set CP10 and CP11 Full Access */
  
  
  
  uint16 flag; 
  uint16 i,j;
  
  DisableInterrupts;
  LCD_init(1);
  Disp_single_colour(Black);
  LCD_PutString(10, 50,"Frequency: ", White, Black);
  LCD_PutString(145, 50,"  KHz", White, Black);
  LCD_PutString(10, 80,"Power: ", White, Black);
  LCD_PutString(145, 80,"   W", White, Black);
  LCD_PutString(10, 110,"Amplify: ", White, Black);
  LCD_PutString(165, 110,"Restrain: ", White, Black);
  init_ADC();
  init_DAC();
  init_DMA();
  init_PDB();
  init_PIT();
  init_gpio_PE24();
  EnableInterrupts;
  LPLD_LPTMR_DelayMs(100);
  
  
  
  flag = Result_flag;
  uint16 ShowAFlag = 0;
  uint16 ShowBFlag = 0;
  uint16 ShowCFlag = 0;
  
  arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize);
  while(1)
  {
    if( flag==Result_flag && Result_flag == 0)
    {
      if(++ShowAFlag<10)
      {
        for(j = 0;j<LENGTH;j++)
          testInput_x[j*2] = Result_A[j];
        for(j = 0;j<LENGTH;j++)
          testInput_x[j*2+1] = 0;
        
        arm_cfft_f32(&arm_cfft_sR_f32_len2048, testInput_x, ifftFlag, doBitReverse);
        
        /* Process the data through the Complex Magnitude Module for
        calculating the magnitude at each bin */
        arm_cmplx_mag_f32(testInput_x, testOutput, fftSize);
        
        testOutput[0] = 0;
        /* Calculates maxValue and returns corresponding BIN value */
        arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
      }
      else
      {
        ShowAFlag = 0;
        if(starfir !=2 )
            LCD_Put_Float(100, 50,"",testIndex*40.0/2048, White, Black);
      }
      if(starfir == 1)
      {
        PTE24_O = 1;
        for(j = 0;j<LENGTH;j++)
          firInput[j] = Result_A[j];
        inputF32 = &firInput[0];
        outputF32 = &firOutput[0];
        for(i=0; i < numBlocks; i++)
          arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
        for(j = 0;j<LENGTH;j++)
          Result_A[j] = firOutput[j];
        PTE24_O = 0;
      }
      flag = 1;
    }
    else  if(flag==Result_flag && Result_flag == 1)
    {
      if(starfir !=2 )
      {
        if(++ShowBFlag<10)
        {
          power = 0;
          for(i=0;i<LENGTH;i++)
            power+=((Result_B[i] - OFFEST)/1241.0)*((Result_B[i] - OFFEST)/1241.0)*90*MyDb/8.0;
          power = power/LENGTH;
        }
        else
        {
          ShowBFlag = 0;
          LCD_Put_Float(100, 80,"",power, White, Black);
        }
      }
      else
      {
        for(i = 0;i<160;i++)
        {
          FFT_RESULT_NEW[i] = testOutput[i*6]/FFT_VALUE;
          if(FFT_RESULT_NEW[i]>239) FFT_RESULT_NEW[i] = 239;
        }
      }
      
      //     {
      //     for(j = 0;j<LENGTH;j++)
      //       testInput_x[j*2] = Result_B[j];
      //     for(j = 0;j<LENGTH;j++)
      //       testInput_x[j*2+1] = 0;
      //     
      //     arm_cfft_f32(&arm_cfft_sR_f32_len2048, testInput_x, ifftFlag, doBitReverse);
      //
      //  /* Process the data through the Complex Magnitude Module for
      //  calculating the magnitude at each bin */
      //    arm_cmplx_mag_f32(testInput_x, testOutput, fftSize);
      //
      //    testOutput[0] = 0;
      //  /* Calculates maxValue and returns corresponding BIN value */
      //    arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
      //     }
      if(starfir == 1)
      {
        PTE24_O = 1;
        for(j = 0;j<LENGTH;j++)
          firInput[j] = Result_B[j];
        inputF32 = &firInput[0];
        outputF32 = &firOutput[0];
        for(i=0; i < numBlocks; i++)
          arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
        for(j = 0;j<LENGTH;j++)
          Result_B[j] = firOutput[j];
        PTE24_O = 0;
      }
      flag = 2;
    }
    else if(flag==Result_flag && Result_flag == 2)
    {
      //   
      //    {
      //     for(j = 0;j<LENGTH;j++)
      //       testInput_x[j*2] = Result_C[j];
      //     for(j = 0;j<LENGTH;j++)
      //       testInput_x[j*2+1] = 0;
      //     
      //     arm_cfft_f32(&arm_cfft_sR_f32_len2048, testInput_x, ifftFlag, doBitReverse);
      //
      //  /* Process the data through the Complex Magnitude Module for
      //  calculating the magnitude at each bin */
      //    arm_cmplx_mag_f32(testInput_x, testOutput, fftSize);
      //
      //    testOutput[0] = 0;
      //  /* Calculates maxValue and returns corresponding BIN value */
      //    arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
      //     }
      if(starfir == 1)
      {
        //    PTE24_O = 1;
        for(j = 0;j<LENGTH;j++)
          firInput[j] = Result_C[j];
        inputF32 = &firInput[0];
        outputF32 = &firOutput[0];
        for(i=0; i < numBlocks; i++)
          arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
        for(j = 0;j<LENGTH;j++)
          Result_C[j] = firOutput[j];
        //   PTE24_O = 0;
      }
      if(starfir != 2)
      {
        if(++ShowCFlag<5)
        {
        }
        else
        {
          if(ShowMenu)
          {
            Disp_single_colour(Black);
            LCD_PutString(10, 50,"Frequency: ", White, Black);
            LCD_PutString(145, 50,"  KHz", White, Black);
            LCD_PutString(10, 80,"Power: ", White, Black);
            LCD_PutString(145, 80,"   W", White, Black);
            LCD_PutString(10, 110,"Amplify: ", White, Black);
            LCD_PutString(165, 110,"Restrain: ", White, Black);
            ShowMenu = 0;
          }
          LCD_Put_Float(100, 110,"",MyDb/0.5, White, Black);
          if(starfir)
            LCD_PutString(260, 110,"On  ", White, Black);
          else
            LCD_PutString(260, 110,"Off", White, Black);
        }
      }
      else
      {
        if(ShowMenu)
        {        
          Disp_single_colour(Black);
          ShowMenu = 0;
        }
        draw_fft();
      }
      flag = 0;
    }
    
  } 
}
Ejemplo n.º 8
0
int main(void)
{
	int nsamp, i;
 	float32_t *input, *output1, *output2;
 	initialize(FS_48K, MONO_IN, STEREO_OUT); 	// Set up the DAC/ADC interface
 	
 	// Allocate Required Memory
 	nsamp = getblocksize();
	
 	input = (float32_t *)malloc(sizeof(float)*nsamp);
 	output1 = (float32_t *)malloc(sizeof(float)*nsamp);
 	output2 = (float32_t *)malloc(sizeof(float)*nsamp);
  
 	if (input==NULL || output1==NULL || output2==NULL) {
 		flagerror(MEMORY_ALLOCATION_ERROR);
 		while(1);
 	}

 	// Impulse response/FIR coefficient array
 	float32_t h[20] = {0.000168, 
                  -0.000883, 
                  -0.004735, 
                  -0.010728, 
                  -0.013639, 
                  -0.004205, 
                  0.025992, 
                  0.077462, 
                  0.138625, 
                  0.188861, 
                  0.208333, 
                  0.188861, 
                  0.138625, 
                  0.077462, 
                  0.025992, 
                  -0.004205, 
                  -0.013639, 
                  -0.010728, 
                  -0.004735, 
                  -0.000883};

    // state buffer used by arm routine of size NUM_TAPS + BLOCKSIZE -1
	float32_t *state = (float32_t *) malloc(sizeof(float)*(20+nsamp-1));
	// arm FIR filter struct initialization
	arm_fir_instance_f32 f1;
	arm_fir_init_f32(&f1,20,&h[0],state,nsamp);

	// Infinite Loop to process the data stream, "nsamp" samples at a time	
	while(1){
    	/*
    	 * Ask for a block of ADC samples to be put into the working buffer
    	 *   getblock() will wait until the input buffer is filled...  On return
    	 *   we work on 	the new data buffer.
    	 */
    	getblock(input);	// Wait here until the input buffer is filled... Then process	
    	
    	// signal processing code to calculate the required output buffers
    	// copy input to output2 for reference
    	for(i=0;i<nsamp;i++) {
    		output2[i] = input[i];
    	}
    	DIGITAL_IO_SET(); 	// Use a scope on PC4 to measure execution time
    	// Call the arm provided FIR filter routine
    	arm_fir_f32(&f1, input, output1, nsamp);
    	
    	DIGITAL_IO_RESET();	// (falling edge....  done processing data )
    	
    	// pass the processed working buffer back for DAC output
    	putblockstereo(output1, output2);
	}
}
Ejemplo n.º 9
0
/**
 * Initialize PPG
 * @param void No arguments
 * @return void No return
 */
void PPG_Init(void)
{
	// Init FIR
	arm_fir_init_f32(&g_Ppg_FirInst, s_PPG__FIR_NUM_TAPS, (float32_t *)&s_PPPG_FIR_COEFFS[0], &g_Ppg_FirState[0], s_PPG__FIR_BLOCK_SIZE);
}
Ejemplo n.º 10
0
/**
 * @brief [initialize eq struct for equalizer routines]
 * 
 * @param low_gain [bass gain in dB]
 * @param mid_gain [mid gain in dB]
 * @param high_gain [treble gain in dB]
 * @param block_size [number of samples to work on]
 * @param FS [sampling frequency used in the delay routine]
 * @return [pointer to the eq struct]
 */
EQ_T * init_eq(float low_gain, float mid_gain, float high_gain, int block_size, int FS) {

	int i, j;

	// set up struct for eq -------------------------------------------------------------------------------------
	EQ_T * Q = (EQ_T *)malloc(sizeof(EQ_T));	// allocate struct
	if(Q == NULL) return NULL;					// errcheck malloc call
	
	Q->block_size = block_size;

	// pow(dB / 20) = gain
	Q->low_scale = pow(10, (low_gain / 20.0));
	Q->mid_scale = pow(10, (mid_gain / 20.0));
	Q->high_scale = pow(10, (high_gain / 20.0));


	// initialize delays for keeping the outputs in phase with each other ---------------------------------------
	// delay the same amount as the delay caused by the fir routine
	// both filters have the same number of coefs, so the delays will be the same
	int sample_delay = ((eq_low_num - 1) / 2);	// delay for fir is (M-1)/2
	Q->D1 = init_delay(0, FS, sample_delay, 1, block_size); // 0 is delay in samples instead of in seconds
	Q->D2 = init_delay(0, FS, sample_delay, 1, block_size);
	Q->D3 = init_delay(0, FS, sample_delay, 1, block_size);
	if(Q->D1 == NULL || Q->D2 == NULL || Q->D3 == NULL) return NULL; 


	// declare and initialize variables necessary for arm fir routines ------------------------------------------
	float * low_state = (float *)malloc(sizeof(float) * (eq_low_num + block_size - 1));
	float * mid_state = (float *)malloc(sizeof(float) * (eq_mid_num + block_size - 1));
	if(low_state == NULL || mid_state == NULL) return NULL; 

	// declare arm struct
	arm_fir_instance_f32 S_low;
	arm_fir_instance_f32 S_mid;

	// initialize arm struct
	arm_fir_init_f32(&S_low, eq_low_num, &(eq_low_coefs[0]), low_state, block_size);
	arm_fir_init_f32(&S_mid, eq_mid_num, &(eq_mid_coefs[0]), mid_state, block_size);

	Q->S_low = S_low;
	Q->S_mid = S_mid;


	// initialize band output buffers --------------------------------------------------------------------------
	Q->low_band_out = (float *)malloc(sizeof(float) * block_size);
	Q->mid_band_out = (float *)malloc(sizeof(float) * block_size);
	Q->high_band_out = (float *)malloc(sizeof(float) * block_size);
	if(Q->low_band_out == NULL || Q->mid_band_out == NULL || Q->high_band_out == NULL) return NULL; 
	for(i = 0; i < block_size; i++) {
		Q->low_band_out[i] = 0.0;
		Q->mid_band_out[i] = 0.0;
		Q->high_band_out[i] = 0.0;
	}


	// initialize eq output buffer -----------------------------------------------------------------------------
	Q->output = (float *)malloc(sizeof(float) * block_size);
	if(Q->output == NULL) return NULL;
	for(j = 0; j < block_size; j++) {
		Q->output[j] = 0.0;
	}


	// return pointer to struct---------------------------------------------------------------------------------
	return Q;

}