# Plotting Spectrum Analysis

I am working on a spectrum analyzing simulator, which is meant to compute and plot the FFT of a sine wave carrier signal of $16 Hz$.

From my practicals with a spectrum analyzer, I know that the spike shows up on the $16Hz$ mark. But after computing my own FFT and passing the magnitude of the FFT to a plotter in Matlab, I get two spikes, one at the beginning and the other at the end.

My sample rate is $2048$ samples per second, and what I plotted was the respective $abs(FFT)$ against a frequency step of $16/2048$. Doing the fftshift only moves the spike to the $8Hz$ mark and not $16Hz$.

I've tried computing FFT in different programming languages and with different tools (java jtransform, Matlab, C language, Excel, two java written classes for FFT by different universities).

I dont think my FFT result are wrong, I think it has to do with the plotting. I do not understand why my plot does not look like it would in real life. From my description and information, can you see any problems that would cause my plot to be wrong?

Generic FFTs use complex-valued input arrays and provide complex-valued output arrays, so they can differentiate positive and negative frequencies for complex-valued signals. For real-valued signals, which is what it sounds like your case may be, this means that the positive and negative frequencies are mirrors of each other, so the spike at 16Hz will be mirrored by a spike at -16Hz. Matlab's FFT function output array has the positive frequencies first followed by the negative frequencies, so one would expect two spikes: the first at 16Hz, and the second wrapped to -16Hz which will be almost at the end of the array.

fftshift should have "unfolded" the output array so that the negative frequencies plot on the left, with DC (0Hz) in the center, and positive frequencies on the right. You should still see two spikes, one at -16 Hz and one at +16Hz, symmetric about zero.

For a Spectrum Analysis using matlab FFT function you need get the first half values from your absolute FFT result and you leave to get two spikes, take a look in the Nyquist Shannon sampling theorem.

Maybe are you confusing about FFT size and Sample rate, when you say:

My sample rate is 2048 samples per second

Are you right ? for me 2048 is your FFT size and not the Sample rate

against a frequency step of 16/2048

If i understood well it is your frequency resolution, if it is true are you limited by your sample rate and you never will be able to find 16Hz from the FFT!

• Ok ederwander, here is more explanation. I took 2048 samples of my sine wave (the wave in its entirety is 1sec long), thats why i concluded that my sampling rate is 2048. computing the absolute of the FFT of thses 2048 samples also returned a 2048 sized array of values (thats my FFT size). Now, if im to plot the first half of these results (1024 of them), what precisely do i plot them against to get the 16hz. – Naz_Jnr Dec 26 '13 at 23:04
• Nice, are you in the right way, but we really need know your sample rate, if you tell me i can help you better ... – ederwander Dec 27 '13 at 0:22
• if the definition of sampling rate is the number of samples of a wave taken per second, then my sampling rate is 2048. If otherwise, let me know what u mean by sampling rate so i can be ask d question better – Naz_Jnr Dec 27 '13 at 2:09
• When you record one signal the sample rate are defined by the number of samples per second, I really don't believe that your signal are sampled in 2048hz are you confusing the sample rate with frame size analysis, use wavread function from matlab to get the sample rate from your audio – ederwander Dec 27 '13 at 2:27
• yes, I have checked it out, my sampling rate is 2048hz. I did this for a greater accuracy. is there a disadvantage in this, and wat do I do next. – Naz_Jnr Dec 27 '13 at 22:24