5.2. FOURIER SERIES AND ITS APPLICATIONS 129
5.2 FOURIER SERIES AND ITS APPLICATIONS
In this section, the representation of periodic signals based on Fourier series is considered. Pe-
riodic signals can be represented by a linear combination of an infinite sum of sine waves, as ex-
pressed by the trigonometric Fourier series representation, Equation (5.5). Periodic signals can
also be represented by an infinite sum of harmonically related complex exponentials, as expressed
by the exponential Fourier series representation, Equation (5.1). In this lab, both of these series
representations are implemented. In particular, the focus is placed on how to compute Fourier
series coefficients numerically.
L5.1 FOURIER SERIES SIGNAL DECOMPOSITION AND
RECONSTRUCTION
is example helps one to gain an understanding of Fourier series decomposition and recon-
struction for periodic signals. e first step involves estimating x.mt/, which is a numerical
approximation of the periodic input signal. Although programming environments deploy dis-
crete values internally, a close analog approximation of a continuous-time signal can be obtained
by using a very small t. at is to say, for all practical purposes, when t is taken to be very
small, the analog signal is simulated. In this example, four input signals are created by using the
MATLAB functions listed in Table 5.1.
Table 5.1: MATLAB functions for generating various waveforms or signals
Waveform Type MATLAB Function
Square wave square(T), T denotes period
Triangular wave sawtooth (T,Width), Width=0.5
Sawtooth wave sawtooth (T,Width), Width=0
Half- wave rectifi ed sine wave
sin(2
*
pi
*
f
*
t) for 0 t < T/2
0 for T/2 t < T
f = 1/T denotes frequency
Half period is sine wave and the other half is made zero
Open MATLAB (version 2015b or a later version), start a new MATLAB script in the
HOME panel, and select the New Script. Write the MATLAB code to generate these sig-
nals: sin , square , sawtooth , and triangular . Note square and sawtooth MAT-
LAB functions are not supported by the MATLAB Coder toward generating corresponding C
codes. For such functions, these functions need to be written from scratch. Use a switch structure
to select different types of input waveforms. Set the switch parameter w to serve as the input. Set
the amplitude of signal A, period of signal T , and number of Fourier coefficients N as control
parameters. Determine the Fourier coefficients a
0
; a
n
, and b
n
by using Equations (5.14)–(5.16).
130 5. FOURIER SERIES
Figure 5.1: L5_1 function for the Fourier series signal decomposition and reconstruction exam-
ple.
5.2. FOURIER SERIES AND ITS APPLICATIONS 131
en, reconstruct the signal from its Fourier coefficients using Equation (5.5). Determine the
error between the original signal and the reconstructed signal by simply taking the absolute
values of x.t/ Ox.t / via the MATLAB function abs . Finally, determine the maximum and
average errors by using the functions max and sum . Save the script using the name L5_1; see
Figure 5.1. Next, write a test script for verification purposes. Open a New Script, write your code,
and save it using the name L5_1_testbench as noted in Figure 5.2.
Figure 5.2: L5_1_testbench .
132 5. FOURIER SERIES
Run L5_1_testbench for different A , T , w , and N values and observe the results. Follow
the steps as outlined for L3_1 to generate the corresponding C code and then place it into the
shell provided. Figure 5.3 shows the initial screen of the app on an Android smartphone. Enter
values for Delta , A , T , and N , select the input signal and the desired output to be plotted,
then press COMPUTE. Figures 5.55.9 show a
n
, b
n
, periodic signal x.t/, reconstructed signal
Ox.t/, and the error. Note that a
0
, Maximum, Error, and Average Error are displayed in the main
screen of the app.
Figure 5.3: Smartphone app screen. Figure 5.4: Parameter settings.
5.2. FOURIER SERIES AND ITS APPLICATIONS 133
Figure 5.5: Plot of a
n
coefficients.
Figure 5.6: Plot of b
n
coefficients.

Get Anywhere-Anytime Signals and Systems Laboratory, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.