Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
789 Views

fft code in c

hello everyone, 

 

 

I am working on speech recognition projet using nios 2. 

I need simple fft code in c to run on the nios. 

did anyone know where can i found one?
0 Kudos
4 Replies
Altera_Forum
Honored Contributor I
56 Views

If you haven't found one yet, one way is to use matlab to generate C. 

 

write your fft in matlab (one statement). 

then use mcc tool in Matlab to get C or C++ or exe. 

mcc = Matlab c compiler but may need its own licence
Altera_Forum
Honored Contributor I
56 Views

Here is a radix 2 FFT: http://www.altera.com/literature/tt/c2h_tutorial.zip 

 

Look at the software only version as the hardware (C2H) version has been optimized and may be difficult to understand if you are not familiar with the hardware accelerator. 

 

Note: Most people use dedicated hardware for FFT as it will not run very fast on Nios II. There is a lot of multiplications and additions which makes it much more suitable to offload into hardware.
Altera_Forum
Honored Contributor I
56 Views

I have a question regarding the software fft funtion.  

 

Can someone explain what exactly are they doing here: 

InputData = InData >> FFT_SIZE;  

 

It looks like they are shifting the input to the right by 8 bits, but won't that simply discard the lower 2 digits of the number? Or are they trying to divide each input number by 256? 

 

 

 

Another thing, if I have only the real values as input data, then do I have to add a 0 after each number to account for the missing imaginary data?
Altera_Forum
Honored Contributor I
56 Views

Took me a while to figure out what that scaling of the input data is for. In the hardware accelerator version only 16-bit temp value are stored so by prescaling the input by >> 8 it makes sure the temp results between the FFT stages fit in a 16-bit variable. In reality that's more scaling than is necessary, so if you use the software version of the FFT then you shouldn't have to worry about prescaling the input data since the software FFT uses 32-bit temporary storage of the results of each FFT stage. 

 

>> 8 will discard the lowest 8 bits of the value which is identical to dividing by 256. If you use just the software version it should be safe to use this line of code instead: 

 

InputData[point_counter] = InData[point_counter];
Reply