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

what's wrong with my fft ipcore

Altera_Forum
Honored Contributor II
896 Views

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

I input the signals generated by matlab: 

n=0:2047; 

sink_real=round((2^15-1)*cos(2*pi*n*1/32)); 

sink_imag=round((2^15-1)*sin(2*pi*n*1/32));  

but the output signals was 

source_real=16068; 

source_imag=-3196; 

There must be something wrong,source_imag signals were too big. 

I am a bit confused.can anyone give me some advice?That will be greatly appreciated.
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
216 Views

A 256 points FFT has a potential word size growth of log2(256)= 8 bits, because every butterfly in fft algorithm increases its word size 1 bit. So, the sinusoids amplitude should not be greater than 127, in this case.

0 Kudos
Altera_Forum
Honored Contributor II
216 Views

The internal bit growth should not be an issue for the field engineer.  

Your target is to get unity gain.  

Your input sinusoid is at 2^15-1 amplitude(orthogonal) 

Your fft output says it is sqrt((16068^2 + (-3196)^2)) = 16383 

Hence all you need a scale factor of 2.  

I expect your exponent to be -1, however you got -9. This issue was raised before in another recent thread. I think it is still not clear if altera got the exponent issue right or the designers got it wrong.  

Your post and another post indicate independantly that the altera exponent must be made as exponent + 8 i.e. -9+8 = -1 in order to achieve unity gain. 

 

Edit: 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(by 2048). This leads to unity gain of amplitude across positive and negative frequencies.  

 

Thus in your case: 

y = 1/2048 * fft(complex(sink_real,sink_imag)); 

 

should give you 32767 as amplitude (one sided). 

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
Altera_Forum
Honored Contributor II
216 Views

Thanks for your reply. 

But I still have one question. 

In the case of Matlab fft,I get source_imag from its fft: nearly zeros.This is the right fft output.but in the quartus altera fft ip core,the  

source_real 16068 is right,but the source_imag -3196.even if the exponent is -1,it's still too large.It should be almost zeros.
0 Kudos
Altera_Forum
Honored Contributor II
216 Views

You are right. Matlab imaginary values are close to zero. 

Your hardware results must be close to Matlab. So there is something wrong either in the IP core or the way you input your data.  

 

imbalance of real/imag can easily occur in hardware even one sample lag leads to errors. One test is to use zero imag or zero real and then compare to matlab. A previous post used zero imag and their results were same as matlab apart from the scaling issue.
0 Kudos
Altera_Forum
Honored Contributor II
216 Views

Pass by.:o

0 Kudos
Reply