# Two-Sided Frequency Spectrum

I am trying to make FFT simulation in Matlab by generating noise added two sinus waves in 60Hz and 100Hz.

After adding the noise into these signals then I have applied the FFT as I put my Matlab code below.

But I am in difficulty interpreting the FFT plot which shows two spectral peaks in the plot diagram below.

Could you please explain how to interpret this spectrum? Why we see two peaks in the spectrum? How can we reduce the spectral to show only the frequencies of 60Hz and 100Hz?

%%%% Noise_Added_Two_Sinus%%%
>> f1=60;
>> f2=100;
>> fs=512;
>> t=0:1/fs:2-1/fs;
>> x1=2.4*sin(2*pi*f1*t);
>> x2=0.96*sin(2*pi*f2*t);
>> y=x1+x2+randn(size(t));
>> F=fft(y);
>> plot(abs(F))


• Plot only half of F. The other half is redundant (negative frequency complex conjugate mirror) given strictly real input data to an FFT. – hotpaw2 Apr 20 '16 at 12:20
• Also, to get exactly 2 peaks, the length of the FFT has to be an exact integer multiple of the periods of both sinusoids. Otherwise you will have to do some interpolation. – hotpaw2 Apr 20 '16 at 12:22
• @tuner you should scale the X-axis so it would show the natural frequencies. Then you would find out that the leftern half represents negative exponentials. They are summed together with the positive ones to form sinusoids. – Dole Apr 20 '16 at 15:10
• I wrote a post about that in my blog behindthesciences.com/signal-processing/… where it says "Representing the spectrum centered in 0 Hz ", it tells you how to do it in Matlab. – Behind The Sciences Apr 21 '16 at 6:00
• Your question has beeen answered. Do not hesitate to vote for the useful ones and accept the most suitable – Laurent Duval Feb 9 '17 at 17:22

First of all, you should totally fix the $x$-axis :)

Now, as you only have two sine waves, you should expect to have peaks at their exact frequencies (that is, at $\pm 60\textrm{ Hz}$ and $\pm 100\textrm{ Hz}$). The FFT function in MATLAB gives you the Discrete Fourier Transform of your signal within $0$ and $F_s$, where $F_s$ is your sampling frequency -and given that you represent your signal with samples, even if you are not aware of it, you have one. Anyway, to make visualization easier, we focus on the interval $[-\frac{F_s}{2},\frac{F_s}{2}]$; that way, your spectrum will be centered around the $0$ frequency -use the function fftshift for that. So, now, once you fix the $x$-axis according to your sampling frequency, you will find that the peaks are at the frequencies you have defined for your sine waves.

When it comes to the little ripples in the lower part of your spectrum, that's just disturbance caused by the noise. Since you are adding noise to the signal by the randn function, your noise follows a Gaussian distribution, translating into white noise for your signal. That is why your entire spectrum is showing sings of being slightly disturbed.

By the way, after fftshift, just get rid of the first half of your vector and you'll end up with positive frequencies.

• I think this is the simplest explanation of what is going on here. – MathieuL May 23 '16 at 14:03
• @MathieuL I saw your edit, I think it's best to let the answer himself/herself add the details you think should be included for clarity. By commenting for instance. – Gilles May 23 '16 at 14:13
• @Gilles Okay no problem. – MathieuL May 23 '16 at 14:17
• @CharlosM I think you should mention the working mechanics in Matlab, that the FFT will center the highest frequency and put the D.C. on the sides. Sure you mention fftshift , but I find that your lacks explanation about why you "fix" the X-axis – MathieuL May 23 '16 at 14:19

The Fourier transform of a real-valued signal has Hermitian Symmetry to $f=0$. Always.

This is a direct result of applying the Fourier transform. This really should not surprise you; if it does, I can only encourage you to manually calculate the Fourier transform of e.g. $\cos(2\pi f_{0} t)$ by considering the trigonometric functions as sum of complex oscillations, i.e. considering Euler's formula:

\begin{align*} \cos(t) &= \frac 12 \left(e^{it}+e^{-it}\right)\\ \mathcal{F}\left\{\cos(t)\right\}&= \int\limits_{-\infty}^{\infty}\cos(t)e^{i2\pi f t}\,dt\\ &=\frac12\int\limits_{-\infty}^{\infty}\left(e^{it}+e^{-it}\right)e^{i2\pi f t}\,dt\tag{*} \end{align*}

The last line shows that the result of the integral must be conjugate-symmetrical to $f=0$.

• Your reply is inaccurate, almost a mistake. First of all, your main assertion "The Fourier transform of a real-valued signal is symmetrical to f=0. Always." implies a simple symmetry (i.e., F(x)=F(-x) ), but that's incorrect - the Fourier transform of a real signal possesses a Hermitian symmetry. Also, manually calculating transforms of specific functions isn't a rigorous way to prove such an assertion. There are plenty of proper proofs on Internet for the Hermitian symmetry of the Fourier transform of a real-valued signal, and a link to one of these would've been more appropriate. – Sagie Apr 20 '16 at 14:19
• @user2934229that is very true; should've used $\sin$ as an example to avoid the ambiguity of "symmetric". Will fix immediately! – Marcus Müller Apr 20 '16 at 14:29
• @MarcusMüller your assertion on the symmetry is correct. But you should have better said the "magnitude" of the Fourier transforms of "real" valued signals are "even" functions of the frequency hence are symmetric about the frequency origin i.e. $|X(\omega)| = |X(-\omega)|$. This is true for both the continuous time and the discrete time cases, the latter also being periodic in $2\pi$. – Fat32 Apr 20 '16 at 23:52
• @Fat32 My assertion would've be right if I used the term "spectrum" instead of "Fourier transform", I agree. I didn't, and since I needed to explain where things are happening, I can't just replace the latter by the first term. – Marcus Müller Apr 21 '16 at 8:22

Using a simple code for displaying the FFT of real signals (FFTR.m), in a one-sided fashion, trying to directly have amplitudes on the $y$-axis, let us just change the final part of your code:

%%%% Noise_Added_Two_Sinus%%%
f1=60;
f2=100;
fs=512;
t=0:1/fs:2-1/fs;
x1=2.4*sin(2*pi*f1*t);
x2=0.96*sin(2*pi*f2*t);
y=x1+x2+randn(size(t));

time_Sampling = 1/fs;
[fft_R,fft_Axe] = FFTR(y',time_Sampling);
[fft_R_Max,fft_R_Idx] = max(fft_R);
figure; hold on
h1 = plot(fft_Axe,fft_R,'x');axis tight;grid on;xlabel('Frequency (Hz)');ylabel('Amplitude (a. u.)');
h2 = plot(fft_Axe(fft_R_Idx),fft_R(fft_R_Idx),'ro');
set([h1,h2],'LineWidth',6)


you get:

I try to keep single points, to avoid interpret linear segments between frequency bins.