FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
6355 Discussions

FFT v8 - not getting the desired output

Altera_Forum
Honored Contributor II
950 Views

Hello all, 

 

I'm experimenting with the FFT block in Quartus and trying to build a system that will eventually record audio from a microphone and send it to the FFT block to get the frequency spectrum. 

 

At the moment, I've built a system involving the Nios II and the FFT block. The Nios II generates some test data (a sine wave with 2 frequency components at 500Hz and 127Hz), sends that to the FFT block, reads the result then sends that to the PC via the serial port. 

 

I think that I've got the interface with the FFT block sussed - I can send data to the FFT block and receive data back with no errors occurring (or so I think - I added checks in the code). 

 

However, when I open up the data in MATLAB, I find that the output spectrum (after combining real, imaginary and exp parts then using the fftshift command) only shows one peak at 0Hz and nothing else. 

 

I'm not really very well versed in FFT and I'm learning it as I go along. I'm wondering whether maybe the DC component is so large that the other components are being scaled down so much they become 0? If so, how can I remedy this? 

 

I've attached a couple of things to this post to outline what I've tried. The image shows the schematic of my system in Quartus - the FFT block has a transform length of 1024 (I'm giving it 1000 samples), 16 bit data, 16 bit twiddle, single output, 1 parallel FFT engine burst mode. 

 

The main Nios code is in the file hello_world.c in the zip archive. In it, I generate the sample data, pass it through to the FFT block and write the results out to the serial port (115200 baud). 

 

I've also included the output of my program so you can see the data that is being generated and the data received. 

 

Thanks, 

 

--Amr
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
260 Views

*Bump* Any thoughts?

0 Kudos
Altera_Forum
Honored Contributor II
260 Views

Hi, 

 

 

I see your set-up is complicated and I suggest you break it up. 

 

I had a quick look at your data scaling below: 

 

for (t=0.0;t<0.1;t+=0.0001) 

temp=sin(2*pi*500*t)+sin(2*pi*127*t); //Max/Min = 2/-2 

data[i++]=(temp+2)*16383; //Scale the result so that it's between 0-65535 

 

You are generating dc since your fft , I assume, uses 2's complement  

you must scale to + 32767 for 16 bits e.g. 

 

data[i++]= round(temp*32767/max(abs(temp))) 

 

note also that your frequency is a function of your sampling rate and I am not sure you are generating it at the stated frequency. 

 

you might better remove nios from the scene. Pass one sinusoid from a LUT into fft then use signaltap to capture a frame. convert data to text and read in matlab. 

 

Kaz
0 Kudos
Altera_Forum
Honored Contributor II
260 Views

hey amrbekhit, 

 

kaz's advice is right on about the FFT accepting 2's compliment inputs. you need to either bias your data to 0 DC or scale it so it resides in +/-2^15. 

 

i did some simulations with your FFT setup and data using Simulink and DSPBuilder (and the Altera FFT MegaCore v8.1). 

 

in this result the input data is scaled by 1/2 

https://www.alteraforum.com/forum/attachment.php?attachmentid=799  

 

in this result the input data is biased by -2^15 

https://www.alteraforum.com/forum/attachment.php?attachmentid=800  

 

you can see the DC in the first result but not the second because it was biased out. so it is possible to get useful power spectrum from your data (with a small fix) and FFT setup. 

 

what data are you sending to the FFT after your 1000 points are over? i am using zeros. 

 

i suspect your problem might be in NIOS or interfacing to the FFT core. will you be using an FFT window? it will give you much better results. 

 

i have attached a .zip of my plots in full resolution. 

https://www.alteraforum.com/forum/attachment.php?attachmentid=801
0 Kudos
Altera_Forum
Honored Contributor II
260 Views

I hope you can help me like what you did here. 

I will be more than thankful.
0 Kudos
Reply