2
$\begingroup$

I have a single tone sinusoid, and its fft in scilab is giving me double spikes, why is that?

Please explain me the concept of why is it happening.

clf();
fs=1000;
t=0:1/fs:0.2;
L=length(t);
f=((0:1:L-1)*fs)/L;
l=length(f);
fm=40;
s=sin(2*%pi*fm*t);
plot(t,s)
S=fft(s)
S_abs=abs(S)
figure(2)
plot(f(1:l),S_abs)

Time domain

Frequency domain

$\endgroup$

2 Answers 2

4
$\begingroup$

Welcome!

Actually, in your case windowing only affects the width of your pulse (as you see, your peaks are not impulsive). You can see the difference by just increasing the temporal length of your signal (equivalent to increase the width of your window, assuming that the original signal is the infinite length sinusoid) and taking the fft. The longer your signal, the narrower your pulse.

What causes the double peaks is that the fft function returns the double-sided transform of the signal you are considering. This means that the first half of S contains the positive bandwidth (from 0 to fs/2), while the second half is just its mirrored version (mathematically, this is equivalent to the spectrum from -fs/2 to 0).

Details are given in the fft documentation by Mathworks.

$\endgroup$
6
  • $\begingroup$ I understood the concept of double sided spectrum, but usually double sided spectrum is from -ve to +ve ryt? Here i am i getting both in positive? $\endgroup$ Aug 25 at 13:08
  • $\begingroup$ Btw, thankyou verymuch for your answer $\endgroup$ Aug 25 at 13:13
  • $\begingroup$ You are saying that its due to conjugate symmetry but i am plotting the fft from 0, then how can the spike which originally supposed to be in -ve side appear in positive axis? $\endgroup$ Aug 25 at 13:19
  • 1
    $\begingroup$ From theory we know that FFT is periodic, therefore you are actually looking at one period of the FFT for your signal. You are plotting your fft from 0, good! So you are looking at your fft from 0 to fs. Now, if you wish to visualize the negative part of the spectrum, you can move the portion from fs/2 to fs BEFORE 0 and then consider the x-axis from -fs/2 to fs/2 instead of from 0 to fs. There is no problem in doing that due to periodicity of FFT, it is just a matter of visualization (user's choice!) $\endgroup$
    – northgeist
    Aug 25 at 14:04
  • $\begingroup$ Okok thankyou verymuch, i got it $\endgroup$ Aug 25 at 14:20
6
$\begingroup$

You're experiencing a basic property of the DFT of a real input signal, that it is conjugate symmetric:

Let $x[n], \, n = 0\cdots N-1$ be a real-valued sequence, then the DFT coefficients are conjugate symmetric: $$X[k] = \overline{X[N-k]},\,k = 0\cdots N-1$$

For analysis, we usually discard half of the spectrum because the information is therefore redundant:

figure(2)
S_abs = S_abs(1:(l+1)/2);
f = (0:(L-1)/2)*fs/L; 
plot(f,S_abs)

See also this answer for correct scaling of even and odd length DFT.


Proof of conjugate symmetry:

\begin{align} X[N-k] &= \sum_{n=0}^{N-1}x[n]e^{-j2\pi \frac{N-k}{N}n}\\ &= \sum_{n=0}^{N-1}x[n]e^{+j2\pi \frac{k-N}{N}n}\\ &= \sum_{n=0}^{N-1}x[n]e^{+j2\pi \frac{k}{N}n}e^{-j2\pi n}\quad \left(e^{-j2\pi n} = 1\right)\\ &= \sum_{n=0}^{N-1}x[n]\overline{e^{-j2\pi \frac{k}{N}n}}\\ &= \sum_{n=0}^{N-1}\overline{x[n]e^{-j2\pi \frac{k}{N}n}}\\ &= \overline{X[k]} \end{align}

Where the last step stems from the fact that $x[n]$ is real so $x[n] = \overline{x[n]}$

$\endgroup$
5
  • $\begingroup$ Hi, thankyou verymuch for your answer. $\endgroup$ Aug 25 at 13:04
  • $\begingroup$ I understood that the two spikes are because of symmetry, but than why are both the spikes in the positive range, as opposed to :: one to right of origin and other to the left? $\endgroup$ Aug 25 at 13:06
  • $\begingroup$ You are saying that its due to conjugate symmetry but i am plotting the fft from 0, then how can the spike which originally supposed to be in -ve side appear in positive axis? $\endgroup$ Aug 25 at 13:18
  • $\begingroup$ That's because you defined your axis to show frequencies from 0 to fs. If you want to see the double-sided spectrum with the 0 frequency in the middle, your frequency vector should reflect that. You'll also need to rotate the spectrum: figure(2) f=(-L/2:L/2-1)*fs/L; plot(f, fftshift(S_abs)); $\endgroup$
    – Jdip
    Aug 25 at 13:51
  • $\begingroup$ Okok thankyou verymuch, i got it $\endgroup$ Aug 25 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.