This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problem using RFFT library

Part Number: TMS570LS1224


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!!

  • Miguel,

    So what exactly are you trying to do mathematically and how are the results different than what you get from MATLAB?

    Also what does your Matlab code look like?
  • Another question - have you tried a test input that is a single frequency sinusoid?
  • Hi Anthony

    Hope you're doing great =)

    I explain the code. Since the FFT algorithm accepts a buffer of max. 2048 data. Since I have 5120 data (not sure if im writing it right), I need to break the array into smaller arrays for the FFT. So first I break the arrays, run the FFT and obtain the magnitud of the output array. (So... Im using the militar strategy of divide and conquer... I don't know if that could be causing the problems but... I think it might be more of a mitale from me on the FFT initialization of something...) 

    Then, I concatenate the magnitudes of the 4 arrays I have to obtain the maximum. 

    Here is the image from the output of the MCU:

    And here is the image obtained from the Matlab code using the same data: 

    The data is inside the matlab code. The data is the output from the FIR filter implemented on the MCU, which works exactly as the matlab one. 

    5775.prueba_fourier.m.zip

  • The data is inside the matlab code. The data is the output from the FIR filter implemented on the MCU, which works exactly as the matlab one. 

    (Please visit the site to view this file)This is a bit off-topic, but I downloaded the prueba_fourier.m.zip file on a Windows 7 PC to look at in Matlab.

    After downloading and unziping the file I got the following Windows 7 pop-up, which initially made me think I might have a virus:

    I think this is because the zip file contains something which Windows 7 thinks is an encrypted file (the .__MACOSX/._prueba_fourier.m file is showing as green in Windows explorer).

    Just a warning for anyone else who downloads the zip file.

  • Thats because im using mac. The file is correctly. I have already upload many files here, downloaded them or open the .zip un my windows sesion and always appears the _MACOSX_ file. But you have to open the normal file, not caring about that other. Its just something mac does (i dont know why) I cant add the code here because of the data (is a 5120 buffer...)

  • 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: 

    The code shows FFTs of sizes 2048, 2048, 512 and 512 being run where the resulting output is concatenated into an array of length 5120. The code doesn't calculate the same results as a 5120 point FFT.

    I took your Matlab code and modified to perform the FFTs as per the code, which then produced the following result (which looks to have the same peaks as your plot from the code but twice the amplitude):

     The Matlab file is attached 6786.prueba_fourier_multiple_ffts.zip

    From a quick search if you want to calculate a larger FFT from a number of smaller FFTs you need to perform some calculations to combine the results from the smaller FFTs.

    How to calculate a large size FFT using smaller sized FFTs? and Very large FFT look to contain some useful information.

  • ooooh i see... I will look for it today and let you know. I thought I could concatenate the results directly but appear not... 

    Thanks a lot Chester!! I hope to have something today to update the post

  • Ok. I have been looking at it, and I found that I need to do some modifications on the algorithm... which I don't understand completely.
    Also... Im not sure if I have to use the split_rfft but I think I need to. Just not sure how to... I was taking the example of fft_bin from DSP library but... it looks Im missing something, not only the concatenation part, that implies a modiffication.
  • ok after looking all the weekend, I could not figure out what is the modification I should be doing... I mean... I looked into the code but was not clear to me where the modification should be done... I saw that the N must be modified but.. I got this explanation:
    www.dsprelated.com/.../97880-1.php
    www.astro.gla.ac.uk/.../
    but still not sure where should I do the modification... I would really appreciate any help...

    Thanks!!