I am looking forward to understand FFT more deeply. While testing with code and math I found I am having a problem in understanding two points.

First we can give to the input of FFT only $x$ or $jy$ or $x+jy$. If we applied real signals $x$ then the output will always be complex $X+jY$. But normally when I learned about the FFT of cosine it is said to be two symmetric deltas in the real domain with +ve sign while the sine signal will give two assymetric deltas in the imaginary domain (1st image).

But instead looking at both the plots of the real and imaginary side of $X+jY$ separately for both sine and cosine signals (2nd Image). Nothing shows that sine is in the imaginary domain, instead they have almost similar outputs.

enter image description here

How can I look or interpret the separate plots of the real and imaginary part of X+jY and its relation to what we have in the first image which we always assume to be the absolute of |$X+jY$| = |X(f)| (3rd plot) in which the sine is plotted in real domain as we can't draw it in imaginary domain in reality in software.

Second point is that I have a problem with confirming the plotting amplitude with amplitudes I see in math. I did a mathematical and code illustration to explain what I mean.

$$sin(2 \pi f_0 t) = \frac{e^{j \pi f_0 t}- e^{-j \pi f_0 t}}{2j}$$ $$X1(f) = \int_{-\infty}^{\infty} sin(2 \pi f_0 t) e^{-j2 \pi f t} \,dt = \int_{-\infty}^{\infty} \frac{1}{2j} [e^{j 2 \pi f_0 t} - e^{-j 2 \pi f_0 t}] e^{-j 2 \pi f t}\,dt $$

$$= \frac{1}{2j} \int_{-\infty}^{\infty} e^{-j 2 \pi (f-f_0) t} \,dt - \frac{1}{2j} \int_{-\infty}^{\infty} e^{-j 2 \pi (f+f_0) t} \,dt$$

$$ =\frac{1}{2j} [(x_1 - j y_1) - (x_2 - j y_2)] = \frac{1}{2} [(y_2 - y_1) + j(x_2 - x_1)]$$

$$|X1(f)| = \frac{1}{2} \sqrt{(y_2-y_1)^2 + (x_2-x_1)^2} $$

while for cosine, $$cos(2 \pi f_0 t) = \frac{e^{j \pi f_0 t} + e^{-j \pi f_0 t}}{2}$$ $$X2(f) = \int_{-\infty}^{\infty} cos(2 \pi f_0 t) \,dt = \frac{1}{2} \int_{-\infty}^{\infty} e^{-j 2 \pi (f-f_0) t} \,dt + \frac{1}{2} \int_{-\infty}^{\infty} e^{-j 2 \pi (f+f_0) t} \,dt $$ $$=\frac{1}{2} [(x_1 - j y_1) + (x_2 - j y_2)] = \frac{1}{2} [(x_1 + x_2) - j(y_1 + y_2)]$$ $$|X2(f)| = \frac{1}{2} \sqrt{(x_1 + x_2)^2 + (y_1 + y_2)^2}$$

From that I would assume that the amplitude of cos plots is greater than the amplitude of the sine plots \begin{align} I\{X1(f)\} < R\{X2(f)\},\: R\{X1(f)\} < I\{X2(f)\}, \: |X1(f)| < |X2(f)| \end{align}

Instead the results was exactly the inverse in the code,

f = 5; fs = 1000;
t = 1 : 1 / fs : 2;
xreal = cos(2*pi*f*t);
xreal2 = sin(2*pi*f*t);

y1 = fft(xreal, 1024);
realT_realF = real(y1);
realT_compF = imag(y1);

y12 = fft(xreal2, 1024);
realT_realF2 = real(y12);
realT_compF2 = imag(y12);

f1 = 1 : 1/1024 : 2;
title('cos - Real Frequency');
idx1 = find(realT_realF==max(realT_realF),1)+100;
idx2 = max(realT_realF) - 0.2 * max(realT_realF);

title('cos - Complex Frequency');

title('sin - Real Frequency');

title('sin - Complex Frequency');

title('cos - |X(f)|');

title('sin - |X(f)|');

Spectrum of Cosine and Sine for both the Real and Imaginary parts Separately

<span class=$|X(f)|$ for both sine and cosine signals" />


2 Answers 2


You've run into "spectral leakage". There are four types of Fourier Transform: the FFT is an implementation of the "Discrete Fourier Transform" NOT the regular continuous time Fourier Transform. These are fairly different things.

For a quick fix: make sure that your sine/cosine waves have an integer number of periods inside your FFT window. You can easily achieve this by setting your sample rate to 1024 (instead of 1000), which will give a frequency resolution of exactly 1 Hz. You may also want to choose a higher frequency (maybe 100Hz) which makes it easier to see on the graphs.

Here is how this looks like with $f = 100Hz$, $f_s = 1024Hz$ and $nfft = 1024$. Note the y-axis scale. The "fuzzy" graphs have a scale $10^{-12}$, i.e. it's just numerical noise.

enter image description here


@Mour_Ka Your first figure (which looks astoundingly similar to figures in my publications) is a three-dimensional spectral plot showing the phase relationships of the spectral components in real-valued sine and cosine waves. Each of the bold arrows on the right side of the figure represents a complex exponential term in "Euler's relationships".

This topic of "complex exponentials" is a bit difficult to understand when you first encounter them in the literature of DSP. I think it would help you to carefully and slowly read my blog at:



Your Answer

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

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