Understand Fourier Series, Fourier Cosine Series, Fourier Sine Series, partial sums, even odd symmetry. Hands-on simulation with Matlab code given.
Fourier analysis and Fourier Synthesis:
Fourier analysis – a term named after the French mathematician Joseph Fourier, is the process of breaking down a complex function and expressing it as a combination of simpler functions. The reverse process of combining simpler functions to reconstruct the complex function is termed as Fourier Synthesis.
Mostly, the simpler functions are chosen to be sine and cosine functions. Thus, the term “Fourier analysis” expresses a complex function in terms of sine and cosine terms and the term “Fourier Analysis” reconstructs the complex function from the sine and cosine terms.
Frequency is the measure of number of repetitive occurrences of a particular event. By definition, a sine wave is a smooth curve that repeats at a certain frequency. Thus, the term “frequency” and sine are almost synonymous. A cosine wave is also a sine wave but with 90* phase shift. Therefore, when you talk about sine and cosine functions, you are taking in terms of “frequencies”. That is why in signal processing, the Fourier analysis is applied in frequency (or spectrum) analysis.
Fourier series, Continuous Fourier Transform, Discrete Fourier Transform, and Discrete Time Fourier Transform are some of the variants of Fourier analysis.
Fourier series:
Applied on functions that are periodic. A periodic function is broken down and expressed in terms of sine and cosine terms. In mathematics, the term “series” represents a sum of sequence of numbers. For example we can make a series with a sequence of numbers that follows Geometric Progression (common ratio between the numbers)
Common ratio =3 : 1+ 3 + 9 + 27 + …
An infinite series is a series that has infinite number of terms. If the elements of the infinite series has a common ratio less than 1, then there is a possibility of the sum converging at a particular value. Fourier series falls under the category of trigonometric infinite series, where the individual elements of the series are expressed trigonometrically. The construct of the Fourier series is given by
Here f(x) is the complex periodic function we wish to break down in terms of sine and cosine basis functions. The coefficients a0, a1,… and b1, b2,… can be found by
Functions and Symmetry:
It is necessary to classify the functions according to its symmetry properties. Doing so will save computation time and effort. Functions either fall into odd symmetry or even symmetry or no symmetry category. Symmetry can be ascertained by plotting the function in a graph paper and folding it along the y axis. Symmetry of a function is always with respect to y axis.
Even Symmetry:
Mathematically depicted as f(x) = f(-x). The value of the given function f(x) at a given positive value x is same at corresponding negative value –x. If plotted on a graph paper and folded along the y-axis, the left half and the right half of the function matches with each other (mirror image).
For even symmetry functions, only the cosine terms exist in Fourier Series expansion. The bn coefficients vanishes all-together (i.e, no sine basis). This leads to what is called Fourier Cosine Series.
Odd Symmetry:
Mathematically depicted as f(x) = -f(-x). The value of the given function f(x) at a given positive value x is same but with a sign change at corresponding negative value –x. If plotted on a graph paper and folded along the y-axis, the left half of the graph will look like inverted (upside down) mirror image of the right half.
For odd symmetry functions, only the sine terms exists in Fourier Series expansion. The an coefficients vanishes all-together (no cosine basis). This leads to what is called Fourier Sine Series.
Thus, knowing the symmetry could save us a lots of computation time and effort, as we do not have to calculate half the number of coefficients if symmetry exists.
Partial Sum and Convergence of Fourier Series:
Fourier Series is a class of infinite series, meaning that there are infinite terms in the expansion.We cannot go on calculating the terms indefinitely. To decompose a complex function using Fourier Series expansion, one has to limit the number of terms we wish to obtain and this process affects convergence. Convergence is based on certain criteria. There exists a separate branch of mathematics called Classical Harmonic Analysis that deals with this subject. Convergence is usually calculated over a partial sum – the sum of all terms upto which we have calculated the coefficients.
Example:
Consider the following periodic function :
Investigation of the function plot reveals that this function exhibits anti-symmetry (odd symmetry). So it is enough if we compute only the sine terms in the Fourier expansion.
Computing the Fourier Sine Series:
Thus the complete Fourier expansion of the given function f(x) is given by
Note that the sine term vanishes when n is even (n=0,2,4,…,). Thus the above expansion can be simplified to
Matlab Simulation:
The following Matlab simulation computes the Fourier series expansion of the above mentioned function. The partial sum is plotted till an error criteria is satisfied.
The function f(x) either stays at +1 or at -1. The partial sum is calculated for each iteration and compared with either +1 or -1 and till the error reaches a small value of 0.01.
%Author Mathuranathan Viswanathan for https://gaussianwaves.com
%Creative Commons CC-BY-NC-SA
%If you use this piece of code you must attribute the author
clearvars;clc;
time=linspace(-pi,pi,1000);
partial_sum=0;
%Complex Function represented in terms of time and amplitude value
t=[-pi,-pi,0,0,pi,pi];
value=[0,-1,-1,1,1,-1];
handle1=line(t,value,'color','r','linewidth',2);
grid on;hold on;
axis([-pi pi -1.5 1.5])
%Since the given complex function exhibits odd periodic extension
%only Bn term is valid with n=1,3,5,...
for n=1:2:200 %Odd terms to consider for partial sums
%Plot 1 period of the given function
partial_sum=partial_sum+(4/(n*pi))*sin(n*time); %Fourier Series Expansion using Sine terms
error=mean((abs(partial_sum)-1).^2); %Error Criteria
handle2=plot(time,partial_sum,'k','linewidth',2);
title(['Square Wave Partial Sum: n = ',num2str(n),' Error = ',num2str(error)])
pause
set(handle2,'Visible','off');
if error<0.01
break
end
end
The plots below shows that the error gets minimized as more and more terms are included in the series expansion.
Understanding the Plots:
In the first plot, the original square wave (red color) is decomposed into first three terms (n=3) of the Fourier Series. The plot in black color shows how the reconstructed (Fourier Synthesis) signal will look like if the three terms are combined together. As you progress further by increasing the number of terms ( n= 7, 15, 41, …) the plot in the black color increasingly resembles the original square wave.
Note the ringing effect at the corners of the black plot as the number of decomposed terms (n) is increased. This phenomenon is called Gibbs Phenomenon. Remember that the Fourier Series is an infinite series with indefinite number of terms. Since we cannot calculate all the infinite number of terms we have to stop at some point. This truncation of the number of decomposed terms leads to Gibbs Phenomenon. Read more on Gibss Phenomenon and its simulation in Matlab here.
Rate this article: Note: There is a rating embedded within this post, please visit this post to rate it.
For further reading
Similar articles
[1] Understanding Fourier Series
[2] Introduction to digital filter design
[3] Design FIR filter to reject unwanted frequencies
[4] FIR or IIR ? Understand the design perspective
[5] How to Interpret FFT results – complex DFT, frequency bins and FFTShift
[6] How to interpret FFT results – obtaining magnitude and phase information
[7] Analytic signal, Hilbert Transform and FFT
[8] FFT and spectral leakage
[9] Moving average filter in Python and Matlab
Books by the author
it’s very understandable blog post thank you for sharing. We need more
what if the function is not a square wave and an unknown function? How do we do the expansion?
YOU MUST PRESS ENTER TO REACH N=45 FOR A PERFECT SQUARE WAVE!
WHAT ABOUT DISCRETE FOURIER SERIES?
how do you change the value of n. I understand its going through a loop with increment of 2 to 200. but its not letting me plot the n values for 3, 5, 7, 15. Its only plotting when n=1
In the for loop the value of n starts from 1 and increments by 2. Therefore, the partial sums are calculated for odd values of n (1,3,5,7,..,199).
The plots shown here are for n=3,7,15,55. I have used a “pause” command in the for loop. The loop pauses for every plot. That is why you are seeing the plot only for value n=1. You need to hit a key on your keyboard or click your mouse, for getting the plots for other values of n.