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
--- Quote Start --- I was expecting two symmetrical lines (well apart) and more towards the edges than the centre. --- Quote End --- I did not take the pictures with the lines on the right side, but actually I do have the two lines toward the edges. --- Quote Start --- your truncation of 29 bits by taking bit 19:12 is not clear to me. You should be taking the value from MSBs. unless they are "dead" bits i.e. never used by result(indicating low input swing or bad design) --- Quote End --- I noticed that the results never get up pass bit 19. That's why I'm truncating them. --- Quote Start --- another issue that popped up now is the way you display on the monitor. You must latch your fft output while refrshing the monitor otherwise a free running fft will not give identical block data unless you work hard to do that --- Quote End --- Isn't it good enough to have the dual-port RAM where the FFT is writing its output to it, and the monitor is reading from it? I just thought of something else that might cause the lines to fluctuate... It has to do with my ADC setup. The ADC is outputting the digitized data for the left and right channels alternatively on the same bus, i.e. multiplexing the data. I am de-multiplexing the ADC output to Left and Right channels, but only passing the Left channel data to the FFT. Is it right to say that half of the time the FFT is getting zeros? Hmm, may be the FFT is just using the same left channel data twice because it is latched? What should be the correct way of doing this? Should I pass one channel to the FFT real input and the other channel to the imaginary input? - Altera_Forum
Honored Contributor
If you are convinced about location of lines, fair enough.
if your fft output doesn't use all those bits then who to blame, input swing or altera design? I guess you have taken care of sign bit(bit index 28) and checked against overflow of your used bits e.g by clipping. Your left/rt muxing shouldn't be a problem if you have one channel correctly muxed and sampled, muxing must be correct and don't try patching up with Re/Im trick. Rd/Wr of data is better frozen under your control so that the monitor displays same block, better only you update it manually, this way you get same lines - Altera_Forum
Honored Contributor
I am convinced about the location of lines because when I change the input frequency from 0 to 4kHz, one line go from the left edge to the middle while the second go from the right to the middle.
However, for many frequencies, there are these two extra lines on the right half-something like |---------------------------------|---|-------| 0 What might be the cause for these two extra lines? Referring to the earlier three screen shots, I have 3 more concerns: 1) the fact that for many of them, i.e. at different frequencies, the line spreads out very much at the bottom (see picture for 1260Hz). 2) sometimes, the line still fluctuates up and down a little-sometimes slowly and sometimes very fast. 3) sometimes there are two or more lines instead of one that are in adjacent bins and may be with a gap in the middle (see picture for 944Hz) - Altera_Forum
Honored Contributor
This matlab code models your work.
amplitude variation from block to block is no more than 1% and depends slightly on frequency value.The line wouldn't be absolute line at the bottom due to quantisation and fft resolution so expect some widening at base but any extra spikes means a bug.% sine function models analogue input % samples taken regularly into digital domain(ADC) % freq = 1 KHz if Fs = 8KHz x = sin(2*pi**1/8); %quantise for 16 bit hardware x = round(x * (2^15-1)); % 256 points fft % random blocks from above stream r =round(rand(1,1)*5000); y = fft(x(r:r+255)); y = round(y/2^7); plot(abs(y)) - Altera_Forum
Honored Contributor
Great, so my screen shot for 1260Hz is OK, but the screen shot for 944Hz is NOT OK.
And those two extra lines on the right also suggests a bug somewhere. I guess the question is where is the bug? - Altera_Forum
Honored Contributor
If you don't window the data before the FFT you will have artifacts from the truncation at the end/beginning of the FFT. This would cause some of the change in magnitude that you are seeing. In addition, there will be a less defined spike at the frequency of interest.
- Altera_Forum
Honored Contributor
True, the problem is truncation but windowing is meant for PSD(power spectral density), not fft per se. PSD breaks up a data stream into overlapping sections then windows each section then does fft on all followed by magnitude averaging over the sections - a pretty invloved computation for hardware.
Applying a window crudely and directly to the stream can improve amp fluctuation since it gives less weight to the side values but thus distorts fft output - Altera_Forum
Honored Contributor
The FFT is not very big. You can easily apply an accurate window with a look-up table.
- Altera_Forum
Honored Contributor
looks like a windowing issue to me.
- Altera_Forum
Honored Contributor
How can I easily apply windowing to it?