Forum Discussion
Help with altera FFT
hello;
what i want to do is to get spectrum of an sinusoidal signal using the altera fft core i have generated a v8 fft with the following setting: fft point : 64 (to start with) architecture : brust data width : 16 twidle width : 16 i am including the matlab files in the attachment .. the input is a 64 point 2`compliment form. in the compare.m file i am doing three fft,,2 matlab fft and 1 altera core fft what i cant figure out is why the magnitude of the second and the the third power spectrum has bigger amplitude than the first fft at the signal fundmental frequency ? and why are those two are not so clean like the first one ? please have a look .. thanks to anyone who replies.56 Replies
- Altera_Forum
Honored Contributor
Continuing with my question on interpreting the FFT output...
May be the observation that I described in my previous post has something to do with my initial question several posts ago, i.e., the amplitudes fluctuate constantly with a constant input. Because I am only looking at the source_exp and source_real FFT outputs, and ignoring the source_imag output, therefore, in every 64th cycle, source_real goes to 0. And for the other cycles, source_real decreases between the max and 0? Do you thing this is the reason? - Altera_Forum
Honored Contributor
Hi,
To avoid guess work you better compare results with matlab. in matlab: test = round(fftshift(fft(ROM_data)); test must equal your hardware fft(allowing for rounding variations) You may use cos instead of sin since sin will give zero real. you may also want to visulaise the spectrum of your output or matlab output by typing: f = linspace(-.5,.5,64); plot(f,abs(test)) or plot(f,abs(your fft output)); - Altera_Forum
Honored Contributor
Thanks, however, I do not have Matlab. Attached is the mif file for my ROM data if it is possible for you to check it out in Matlab for me.
Can you tell me how do I easily combine the real and the imag together to form one meaningful number? - Altera_Forum
Honored Contributor
I glanced at your mif and it looks ok to me, tomorrow I will do fft in Matlab and send you my results(hopefully).
complex signals in hardware are represented on two (real) channels. One is treated as real and the other as representing the imaginary value(units of sqrt(-1). Don't worry about details now. All you need is that to see amplitude response you look at absolute value i.e. Amplitude of complex vector = sqrt(I^2 + Q^2). plot amplitude and you should see two symmetrical lines unless your input is sine/cosine which leads to one line only(non-symmetrical spectrum). Complex math is same as vector math... - Altera_Forum
Honored Contributor
What are the I and Q in your equation sqrt(I^2 + Q^2)? Are they the real and imaginary values from the FFT source_real and source_imag?
Do I do the scaling with source_exp on both the source_real AND source_imag? Also do I do the scaling before or after doing the sqrt(I^2 + Q^2)? - Altera_Forum
Honored Contributor
--- Quote Start --- What are the I and Q in your equation sqrt(I^2 + Q^2)? Are they the real and imaginary values from the FFT source_real and source_imag? --- Quote End --- yes, I & Q are the special names in communications given to the two channels representing in effect a complex signal, I = inphase, Q=Qudrature. --- Quote Start --- Do I do the scaling with source_exp on both the source_real AND source_imag? --- Quote End --- you need to scale according to the way altera have done their IP. I believe it is the output of fft that must be scaled...ofcourse, check the IP data sheet. --- Quote Start --- Also do I do the scaling before or after doing the sqrt(I^2 + Q^2)? --- Quote End --- In normal computation such as matlab you don't need any scaling. Altera simply left that for you. So for your hardware results yes do scaling first. I checked the matlab output and it looks like your results: your result .....................matlab fft real = zeros .....................same imag(0) = 0 .....................same imag(1) = -8192 ..............-1048576 imag(63) = +8192 ............+1048576 imag(others) = 0 ..............same If you now multiply 8192 by 2^7 you get matlab result. Your problem now is this: your final output value needs far more bits than just 16 signed so you need to divide down by truncation to a max of 32767 or less. Your other case of having one sample just above zero ...etc. No don't do that. By doing that you are no longer having a proper sine in the sense of orthogonality in a complex vector. - Altera_Forum
Honored Contributor
Thanks a lot Kaz. You have been so helpful.
I am now going to change the input to analog audio data passing through an ADC. When I get that to work, I think I will post my entire results here so that people like me don't have to keep asking the same questions about implementating the FFT. Enoch - Altera_Forum
Honored Contributor
However, my suspicion now is that the fluctuating amp is due to one or both of the following:
1) wrong fft scaling 2) fft and its scaling ok but your test is misleading as you may be injecting the analog sinusoid with different phase each fft block. Your fft resolution is too low, it is better to have many sinusoid cycles per fft block rather than just one cycle as phase changes become exagerated. So either increase the fft resolution to say 2048 and/or increase the speed of your sinusoid. - Altera_Forum
Honored Contributor
How can I increase the speed of my sinusoid if my input is a sound wave with a certain frequency?
- Altera_Forum
Honored Contributor
The easiest fix for you is to first make sure your fft scaling is ok. Not just the use of exponent but your truncation afterwards. If this is ok then your fft is ok and I wouldn't worry about the test.
If you want your test to do better then increase fft resolution. If your audio is received upsampled then you may decimate it down to minimum (for test purposes only). Thats what I labelled speed by mistake. Remember fft resolution doesn't have to be equal to number of points per sinusoid cycle, that ruins the test unless you get the phase exactly same per each block. In short make your fft 2048 and repeat the test. Try also pass the audio to both real and imaginary so that the phase change is on both channels(again for test purpose only).