Hi
Im trying to implement the RFFT on the MCU but when processing the data, and checking the results with the one I got from Matlab, there is a big difference... The code for the FFT is here:
bool fft(uint32_t fft_Size, float32_t *input_data, float32_t *output_data)
{
fft_done=0;
arm_status status;
arm_rfft_instance_f32 S;
arm_cfft_radix4_instance_f32 S_CFFT;
status = ARM_MATH_SUCCESS;
/* Initialize the RFFT/RIFFT module
arm_status arm_rfft_init_f32(
arm_rfft_instance_f32 * S,
arm_cfft_radix4_instance_f32 * S_CFFT,
uint32_t fftLenReal,
uint32_t ifftFlagR,
uint32_t bitReverseFlag)*/
status = arm_rfft_init_f32(&S, &S_CFFT, fft_Size, ifftFlagR, doBitReverse);
/* Process the data through the CFFT/CIFFT module */
arm_rfft_f32(&S, input_data, output_data);
/* Process the data through the Complex Magnitude Module for
calculating the magnitude at each bin */
/*void arm_cmplx_mag_f32(
float32_t * pSrc,
float32_t * pDst,
uint32_t numSamples)*/
arm_cmplx_mag_f32(output_data, input_data, fft_Size);
if( status != ARM_MATH_SUCCESS)
{
while(1);
}
if(fft_input==3)
fft_done=1;
return fft_done;
}
I upload the code im using to call the functions
if(fft_input==0)
{
data_count=0;
m_count=0;//;order_filter;
do{
muscle_data1[data_count]=muscle_filtered[m_count];
data_count++;
m_count++;
}while(data_count<fft_Size_1_2);//sizeof(muscle_data1));
fft(fft_Size_1_2, muscle_data1, fft_output1);
fft_input++;
}
if(fft_input==1)
{
data_count=0;
do{
muscle_data2[data_count]=muscle_filtered[m_count];
m_count++;
data_count++;
}while(data_count<fft_Size_1_2);//sizeof(muscle_data2));
fft(fft_Size_1_2, muscle_data2, fft_output2);
fft_input++;
}
if(fft_input==2)
{
data_count=0;
do{
muscle_data3[data_count]=muscle_filtered[m_count];
m_count++;
data_count++;
}while(data_count<fft_Size_3_4);//sizeof(muscle_data2));
fft(fft_Size_3_4, muscle_data3, fft_output3);
fft_input++;
}
if(fft_input==3)
{
data_count=0;
do{
muscle_data4[data_count]=muscle_filtered[m_count];
m_count++;
data_count++;
}while(data_count<fft_Size_3_4);//sizeof(muscle_data4));
m_count=0;
fft(fft_Size_3_4, muscle_data4, fft_output4);
fft_input++;
}
//Obtain maximum
if(fft_input==4 && fft_done==1)
{
fft_input=0;
fft_done=0;
if(fft_input==0)
{
data_count=0;
do{
muscle_FFT_out[fft_data]=muscle_data1[data_count];
data_count++;
fft_data++;
}while(data_count<fft_Size_1_2);//sizeof(muscle_data1));
fft_input++;
}
if(fft_input==1)
{
data_count=0;
do{
muscle_FFT_out[fft_data]=muscle_data2[data_count];
data_count++;
fft_data++;
}while(data_count<fft_Size_1_2);//sizeof(muscle_data2));
fft_input++;
}
if(fft_input==2)
{
data_count=0;
do{
muscle_FFT_out[fft_data]=muscle_data3[data_count];
data_count++;
fft_data++;
}while(data_count<fft_Size_3_4);//sizeof(muscle_data3));
fft_input++;
}
if(fft_input==3)
{
data_count=0;
do{
muscle_FFT_out[fft_data]=muscle_data4[data_count];
data_count++;
fft_data++;
}while(data_count<fft_Size_3_4);//sizeof(muscle_data4));
}
arm_max_f32(muscle_FFT_out, fft_Size_total, &maxValue, &testIndex);
data_count=0;
fft_input=0;
fft_data=0;
}//if(fft_input==4 && fft_done==1)
and the code with the variables:
/* --------------------------------------------------------- * Global variables for FFT *-----------------------------------------------------------*/ static uint32_t fft_Size_1_2 = 2048; static uint32_t fft_Size_3_4 = 512; static uint32_t fft_Size_total = 5120; char fft_input; bool fft_done; static uint32_t ifftFlagR = 0; static uint32_t doBitReverse = 1; uint16_t data_count; //used for the FFT variables uint16_t fft_data; float32_t maxValue; uint32_t testIndex; float32_t muscle_data1[2048]; float32_t muscle_data2[2048]; float32_t muscle_data3[512]; float32_t muscle_data4[512]; float32_t fft_output1[4096]; float32_t fft_output2[4096]; float32_t fft_output3[1024]; float32_t fft_output4[1024]; float32_t muscle_FFT_out[5120];
I don´t know whats happening... Am I calling the rfft init wrong or am I missing something??
Thanks!!



