# Fast fourier transform and frequency domain spike in wrong area

I used MATLAB to produce a simple sine wave over time:

frequency=7
sampling_frequency=1000;
total_time=1-1/sampling_frequency;
step=1/1000;
theta=0;
time=0:step:total_time;

y=Amplitude*sin(2*pi*frequency*time+theta)


I then used the following code to fast fourier transform:

Y=fft(y);
ploty=Y/length(y);
stem(abs(ploty))


I was expecting to see one spike at 7 instead I am getting 2 and not even at 7. One is at 8 and the other at 994. I am totally confused as to why.

## 1 Answer

You see one at index 8 because MATLAB's indexing is one-based, not zero-based as the equations that describe the DFT are. You get two spikes because your input signal is real and is therefore conjugate-symmetric in the frequency domain. If you work out the math, you'll see that the Fourier transform of a $\sin$ has two spikes symmetric about zero frequency. In order to get a single spike, you need to use a complex exponential function at the same frequency instead.

• That is excellent.. you just alleviated 3 hours of headache!! Thanks again!! Ur a star – jayvina Mar 14 '13 at 22:53
• also might need to mention fftshift()? – endolith Mar 15 '13 at 16:13