void arm_rfft_fast_f32(
arm_rfft_fast_instance_f32 * S,
float32_t * p, float32_t * pOut,
uint8_t ifftFlag)
{
   arm_cfft_instance_f32 * Sint = &(S->Sint);
   Sint->fftLen = S->fftLenRFFT / 2;

   /* Calculation of Real FFT */
   if(ifftFlag)
   {
      /*  Real FFT compression */
      merge_rfft_f32(S, p, pOut);

      /* Complex radix-4 IFFT process */
      arm_cfft_f32( Sint, pOut, ifftFlag, 1);
   }
   else
   {
      /* Calculation of RFFT of input */
      arm_cfft_f32( Sint, p, ifftFlag, 1);
   
      /*  Real FFT extraction */
      stage_rfft_f32(S, p, pOut);
   }
}
int32_t main(void)
{

  arm_status status;
  float32_t maxValue;

  status = ARM_MATH_SUCCESS;

  /* Process the data through the CFFT/CIFFT module */
  arm_cfft_f32(&arm_cfft_sR_f32_len1024, testInput_f32_10khz, ifftFlag, doBitReverse);

  /* Process the data through the Complex Magnitude Module for
  calculating the magnitude at each bin */
  arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, fftSize);

  /* Calculates maxValue and returns corresponding BIN value */
  arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);

  if(testIndex !=  refIndex)
  {
    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 */
}
void FFTprocessing1(uint32_t *inFFT, float32_t* outFFT, FFT_LENGTH_ FFTlength) {
	if (g_ucDMAMethod == DMA_METHOD_SLOW) {
		adcNode[0].g_ucDataReady = 0;
	}
	float32_t complexBuffer[NUM_SAMPLES ];
	ComplexBufFFT(inFFT, complexBuffer, FFTlength);
	arm_cfft_f32(&arm_cfft_sR_f32_len256, complexBuffer, ifftFlag,
			doBitReverse); //da test voi 512 nhung chay mot luc thi gia tri khong cap nhat nua
	arm_cmplx_mag_f32(complexBuffer, outFFT, FFTlength);

	// ignore the DC value
	outFFT[0] = 0.0f;
	uint16_t n = 0;
	///(50*SAMPLE_RATE)/fftLength;
	// squash everything under 100Hz
	for (n = 0; n < fix_minFFTIndex; n++) {
		outFFT[n] = 0.0f;
	}

	arm_max_f32(outFFT, FFTlength / 2, &fftNode[0].maxValue,
			&fftNode[0].maxIndex);
	arm_mean_f32(outFFT, FFTlength, &fftNode[0].averageValue);
	// calculate frequency value of peak bin
	fftNode[0].hertz = fftNode[0].HerztPerBin * (float32_t) fftNode[0].maxIndex
			* 2;

	setAgainSampling();
}
Esempio n. 4
0
void DSPCalculateFFT(tDSPInstance* instance) {
	if (instance->signalSize != 1024*8) {
	  UART_PRINT("signalsize different than expected!\n\r");
	  while(1) {}//signal size different than our assumption
	}

	uint32_t ifftFlag = 0;
	uint32_t doBitReverse = 1;
	uint32_t i;

//	UART_PRINT("\n\r\n\r");
//	for (i=0; i<instance->signalSize; i++) {
//		UART_PRINT("%d ", instance->ucpSignal[i]);
//	}
//	UART_PRINT("\n\r\n\r");

//	UART_PRINT("\n\r\n\r");
//	for (i=0; i<instance->signalSize/2; i++) {
//		UART_PRINT("%f ", instance->fpSignal[i]);
//	}
//	UART_PRINT("\n\r\n\r");

	/* Hanning window the time signal */
	for (i=0; i<instance->signalSize/2; i++) {
		instance->fpSignal[i] *= HanningWindow_4096[i];
	}
//	UART_PRINT("\n\r\n\r");
//	for (i=0; i<instance->signalSize/2; i++) {
//		UART_PRINT("%f ", instance->fpSignal[i]);
//	}
//	UART_PRINT("\n\r\n\r");

    /* Process the data through the CFFT/CIFFT module */
    arm_cfft_f32(&arm_cfft_sR_f32_len2048, instance->fpSignal, ifftFlag, doBitReverse);
//    UART_PRINT("\n\r\n\r");
//    for (i=0; i<instance->signalSize/2; i++) {
//    	UART_PRINT("%f ", instance->fpSignal[i]);
//    }
//    UART_PRINT("\n\r\n\r");

    /* Process the data through the Complex Magnitude Module for
    calculating the magnitude at each bin */
    arm_cmplx_mag_f32(instance->fpSignal, instance->FFTResults, instance->fftSize);
    //ignore dc bias
    instance->FFTResults[0] = 0;
    //also ignore 2nd bin when using hanning window (got this from experimentation)
    instance->FFTResults[1] = 0;
//    UART_PRINT("\n\r\n\r");
//    for (i=0; i<instance->fftSize; i++) {
//    	UART_PRINT("%f ", instance->FFTResults[i]);
//    }
//    UART_PRINT("\n\r\n\r");

    /* Calculates maxValue and returns corresponding BIN value */
    arm_max_f32(instance->FFTResults, instance->fftSize/2/*only half of fft is unique*/, &instance->maxEnergyBinValue, &instance->maxEnergyBinIndex);
//    UART_PRINT("max energy at (%d:%f)\n\r", instance->maxEnergyBinIndex, instance->maxEnergyBinValue);

//    UART_PRINT("\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r");
}
Esempio n. 5
0
void TM_FFT_Process_F32(TM_FFT_F32_t* FFT) {
	/* Process FFT */
	arm_cfft_f32(FFT->S, FFT->Input, 0, 1);
	
	/* Process the data through the Complex Magniture Module for calculating the magnitude at each bin */
	arm_cmplx_mag_f32(FFT->Input, FFT->Output, FFT->FFT_Size);
	
	/* Calculates maxValue and returns corresponding value */
	arm_max_f32(FFT->Output, FFT->FFT_Size, &FFT->MaxValue, &FFT->MaxIndex);
	
	/* Reset count */
	FFT->Count = 0;
}
Esempio n. 6
0
int main()
{    
  int n;
	gpio_set_mode(P2_10, Output);
	
  for(n=0 ; n<N ; n++)
  {
    samples[2*n] = arm_cos_f32(2*PI*TESTFREQ*n/SAMPLING_FREQ);
    samples[2*n+1] = 0.0;
  }
	gpio_set(P2_10, HIGH);
  arm_cfft_f32(&arm_cfft_sR_f32_len128, samples, 0, 1);
	gpio_set(P2_10, LOW);
  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;
    }
    
  } 
}