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

Matlab FFT Vs. DSP Builder FFT

Altera_Forum
Honored Contributor II
1,853 Views

I'v posted a thread in this section, maybe I was wrong, please check it at the following link 

 

http://www.alteraforum.com/forum/showthread.php?t=1654&highlight=dsp+fft (http://www.alteraforum.com/forum/showthread.php?t=1654&highlight=dsp+fft

 

 

THANKS!
0 Kudos
14 Replies
Altera_Forum
Honored Contributor II
1,061 Views

I just commented on your other post. Check it out.

0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

I will continue here the thread. 

 

Thanks wronghorizon, but I've just checked these threads but I really cannot learn too much from them...:(  

 

Also because I found some incompatibility between the System Versions...  

 

I've tried to make my scheme more clear... maybe now somebody can be helpful to me. 

 

I will explain first my scheme and then my problems. 

 

It's fondamentally divided in 3 parts: 

 

1) Matlab FFT power spectrum output using only the proper block "Matlab FFT Spectrum" 

 

2) Matlab FFT power spectrum output using simpler matlab blocks, I made this to understand how to work with the Megacore output.... and to compare the Megacore output to somethin similar 

 

3) Megacore FFT power spectrum 

 

 

 

The first output is obviously perfect!!:D  

 

The second output is not 0 on the frequencies not excaited...this because I haven't implemented the Hanning windowing I think ...but this is not a problem , anyway the plot show the right peak. 

 

The third output has some problem: It's seem to be shifted and it's not really accurate like the matlab one,some times the spectrum is not specular also.....  

 

Can you give me some suggestion???? 

 

THANKS  

 

http://img385.imageshack.us/img385/6451/fftimgqe1.jpg
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

Hi, 

Just a basic question and thought... 

are you doing fft or PSD(power spectrm density). 

I haven't done simulink for years but it seems you are doing (fft) in (1) but possibly a sort of spectrum density on (2,3). 

I have used an old altera fft core(not DSPBuilder-based) and it was producing 

fft. 

compare the matlab functions fft & periodogram. These are two different things.  

fft doesn't use any windowing, periodogram does... 

 

Kaz
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

Hi Kaz, thanks for your reply, 

 

I'm doing an FFT and I choose to display the power spectrum to have an understandable output to compare. 

 

I understood what you are saying. 

 

(1) Calculate the power spectrum using the periodogram with Hann windowing 

 

(2),(3) doesn't 

 

I've used the classic method: 

 

Sign --> FFT --> ( |RE|^2 + |Imm|^2 )/FFT_length --> frequency plot 

 

The problem is in the 3d plot as I've sayed before.
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

Hi, 

 

Let us do things the easy way. 

I assume you want to compare your core fft output with matlab fft. 

This should be very easy, I suggest you consider the following: 

1) ignore plot(2) altogether. 

2) your sine input: 

you need to scale it to 12 bits then round it and input it to Matlab fft. 

and you need to convert these decimal values to 2's complement(12 bits) for the core(unless it uses a different scheme). 

3) all what is left is compare output(should be almost bit-accurate apart from rounding effect) for both real and imaginary components. 

Make sure you read core output when it is ready. Remember core fft is block based and is only ready after some time. Also remember to round up matlab fft output. 

 

you better compare data directly instead of the spectrum at this stage. Your data must be identical and that tells it all. 

 

for step (2) 

to scale the sine wave from(-1 to +1) into 12 bit signed you need this: 

data = round((2^11-1)*sine_data/max(sine_data)); 

this to input to matlab fft 

for core fft you need decimal to 2's complement conversion of data... 

You can use the function dec2bin() but after some trick as the function doesn't accept signed values, you can convert them to equivalent unsigned first then enter them in dec2bin(). 

 

Most importantly, the frequency grid(fft resolution) should be same in both cases. 

 

hope this helps  

 

kaz
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

Be sure to pay attention to the sink_ready signal when you are using Altera's FFT core: the signal indicates when the core is ready to take on input. You are seeing the shift because you are not paying attention to this signal and are sending in data when the core isn't ready.

0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

@Wronghorizon: OK! Thank you!!!! I will check it! 

 

@Kaz: I'm trying also in your way. I'm trying to find the proper simulink blocks to do that.
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

The sink_ready is up after 2 clock steps so I've delayed the input signal of 2 to send the input at the right time but the output is not shifted back... 

 

I've tried also various time delay but the result is only to loose samples on the FFT first window....
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

What version of DSP Builder are you using? I have a FFT/IFFT (Streaming architecture) Unity gain design (built using 8.0SP1) posted somewhere in this forum. That might help you out some...

0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

I have the DSP BUilder 7.2.  

 

Do you know if I can update it easily? Or I need a new license?
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

I found the problem.  

 

I started to think more about the Surce_valid output. 

The problem was that the output start after two cycles of FFT and "some delay": in my case the Souce_ready go up after 536 cycles of clock, 256+256+24.  

This delay creates issues in SIMULINK because the output buffer and so the vector scope start to display datas with a 24 clock delay: this is the cause of the spectrum shift displayed . 

I inserted a 232 delay before the output and so the ouput is syncronyzed with a FFT cycle delay. (But the purpose was to have an understandable right output so the issue is acceptable and my objective is accomplished). 

 

To avoid the one cycle delay I thought about insert a sort of trigger or switch in order to let flow the datas to the buffer only when the Source Valid goes on but I haven't find useful to me till now... 

 

Another thing to do is also to adjust the amplitude. Maybe there is an error inside the second power spectrum, I don't think i had to divide by 256 because the signal is not vectored before the buffer...but..  

 

I post the new scheme and the new file, I hope it can be useful also to other people. 

 

PS: do you know if I need a new license to update my Quartus and my DSP builder from 7.2 to 8.1? 

 

 

http://img399.imageshack.us/img399/5143/schemaprogettorq5.jpg
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

Should be pretty easy to update your license from 7.2 to 8.1. Depends on what type of license you have. But I believe you can easily update your license to a newer version within the original one year window... with that said, I would suggest checking with your FAE or filing a service request with Altera to update your DSP Builder...

0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

Hi again, 

 

in those days I tried to adjust last things and also to recreate the input signal with an IFFT. 

On the file I posted some time ago, I tried to adjust the FFT amplitude that was less then the Matlab one. 

 

I found some trouble with the exponent value again. I will post the text where it speaks about the FFT scaling. 

 

" the exponent records the number of left or right shifts used to perform the scaling. as 

a result, the output magnitude relative to the input level is: 

output*2-exponent 

for example, if exponent = –3, the input samples are shifted right by 

three bits, and hence the magnitude of the output is output*2^3

 

To scale I shifted the real and imaginary output. I found a negative exp so a made a right shift as the example. But... 

 

 

The result is that everything turns really good when I not scale the real and imaginary output. It seem to be futile to scale it! 

 

Also when I try to recreate the input signal with the IFFT everything is good without the scaling.... 

 

..mmm i missed something? 

 

I will post the new scheme that bypass the scaling. 

 

http://img147.imageshack.us/img147/8247/fftsitosc7.jpg
0 Kudos
Altera_Forum
Honored Contributor II
1,061 Views

Hi again, 

 

For signed data of a given width, if you want to scale any signed value by 2^n then you should shift magnitude bits towards MSB (n) bits inserting zeros in new LSBs(leading zeros). The sign bit should stay. Ofcourse the datawidth should accomodate these new bits. 

 

If you want to scale by 2^-n you shift magnitude bits towards LSB (n) bits and insert the sign bit in new MSBs(sign extension). 

 

I hope that's what you mean. 

 

kaz
0 Kudos
Reply