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

Altera FFT - output scaling. How to do this correctly?

Altera_Forum
Honored Contributor II
5,926 Views

Hi, 

 

I do not get correct scaled results if I do everything the FFT user guide recommends. 

 

I have instantiated a 1024 points FFT, with single output and burst architecture. The data width and twiddle factor precision is 16bits. 

 

I input 1024 times 16bit signed integers from the ADC to the 16bit real-input of the FFT module. (The ADC has a +/-2.5V input) To the imaginary input of the FFT module I apply 16bit zeros. This should be correct, shouldn’t it? The FFT module outputs 1024 pairs of 16bit real and 16bit imaginary part. 

 

First question: Are the real and imaginary 16bit values the mantissa in the sense of a floating point mantissa (first bit = sign, second bit = 1.digit in front of the radix point, remaining 14bits = decimal places) OR do I have to interpret these values as fixed point values. 

 

I have a sample frequency of 3kHz and used a very low frequency of 1Hz and 9Hz to verify the scaling to not have additional falsifications, caused by the rectangular window I used for the first shot. I input samples of an ideal sine waveform with different amplitudes and the same frequency, BUT whether I scale the output back with the given exponent value or not, the calculated magnitude is not the expected one. For example: 

For a 9Hz sine with an amplitude of +/-2,3V which is equal to +30146/-30147 decimal (+/-2.5V ADC input) I got the following real and imaginary parts for the corresponding frequency. 

 

Real: 3384 (0x0D38) 

Imaginary: -14391 (0xC7C9) 

 

I would expect a magnitude in the range of 30146 decimal, but using these values the magnitude is 14783. Using the exponent makes the results too big and I see no relation to input signal with such big numbers. How can such a large output (31bits in my case, max exponent = 15bits) provide unity gain, if the input is much smaller (16bits). Just choosing the lower 16bits of the shifted/scaled values can not be correct, because of the sign. I am a bit confused.  

 

 

Can somebody give me a hint? An example calcualtion would also be a great help.
0 Kudos
22 Replies
Altera_Forum
Honored Contributor II
376 Views

It seems you are saying that altera acknowledged the wrong exponent and passed the issue to you. This is unrealistic. With the suggested method you may find out scaling in real time if you use sine input only but can't use it when input is random or an application signal since amplitudes are unknown.

0 Kudos
Altera_Forum
Honored Contributor II
376 Views

Just a minor correction on my Matlab scaling: 

 

I divided the 1024 Matlab fft by 512 to get correct output amplitude. 

In fact it should have been divided by 1024(fft resolution).  

This was due to the fact that your output was symmetrical two bands. Hence each side should be at 1/2 amplitude. 

 

This is an excerpt from one of my recent posts: 

 

Matlab scaling Vs altera scaling 

In the case of Matlab scaling, if you want to get unity gain from its fft then you should divide by the fft resolution. This leads to unity gain of amplitude across positive and negative frequencies.  

 

However if the frequency is two sided then Matlab scaling implies that the sum of two sides = input amplitude. In this case the comparison with hardware may not be useful if you want to use full resolution of both the real and imag bitwidth. It follows that we must be clear about our target scaling. We may target unity amplitude gain or target full use of bit resolution of each of real and imaginary widths
0 Kudos
Reply