MatLAB - Theory - Fourier Analysis PDF
MatLAB - Theory - Fourier Analysis PDF
”
Electronics and Circuit Analysis using MATLAB.
Ed. John Okyere Attia
Boca Raton: CRC Press LLC, 1999
FOURIER ANALYSIS
In this chapter, Fourier analysis will be discussed. Topics covered are Fou-
rier series expansion, Fourier transform, discrete Fourier transform, and fast
Fourier transform. Some applications of Fourier analysis, using MATLAB,
will also be discussed.
g (t ) = g (t ± Tp ) (8.1)
Tp
where
2π
w0 = (8.4)
Tp
and the Fourier coefficients a n and bn are determined by the following equa-
tions.
t o + Tp
2
an =
Tp ∫ g(t ) cos(nw t )dt 0 n = 0, 1,2, … (8.5)
to
a0
Equation (8.3) is called the trigonometric Fourier series. The term in
2
Equation (8.3) is the dc component of the series and is the average value of
g (t ) over a period. The term a n cos(nw0 t ) + bn sin(nw0 t ) is called the n-
th harmonic. The first harmonic is obtained when n = 1. The latter is also
called the fundamental with the fundamental frequency of ωo . When n = 2,
we have the second harmonic and so on.
∞
a0
g (t ) = + ∑ A cos(nw0 t + Θ n ) (8.7)
2 n =1 n
where
An = a n2 + bn2 (8.8)
and
b
Θ n = − tan −1 n (8.9)
an
where
2
a0
A =
2
(8.11)
2
dc
The following example shows the synthesis of a square wave using Fourier
series expansion.
Using Fourier series expansion, a square wave with a period of 2 ms, peak-to-
peak value of 2 volts and average value of zero volt can be expressed as
4 ∞ 1
g (t ) = ∑
π n =1 (2n − 1)
sin[(2n − 1)2πf 0 t ] (8.12)
where
f 0 = 500 Hz
if a (t ) is given as
4 12 1
a (t ) = ∑ sin[(2n − 1)2πf 0 t ] (8.13)
π n =1 (2n − 1)
Solution
MATLAB Script
By using the Euler’s identity, the cosine and sine functions of Equation (8.3)
can be replaced by exponential equivalents, yielding the expression
∞
g (t ) = ∑c n exp( jnw0 t ) (8.14)
n =−∞
where
Tp / 2
1
cn =
Tp ∫ g (t ) exp(− jnw t )dt 0 (8.15)
−t p / 2
and
2π
w0 =
Tp
1 2 b
cn = a n + bn2 ∠ − tan −1 ( n ) (8.16)
2 an
If an input signal x n (t )
passes through a system with transfer function H ( w) , then the output of the
system y n (t ) is
∞
y n (t ) = ∑ H ( jnwo )cn exp( jnwo t ) (8.21)
n =−∞
The following two examples show how to use MATLAB to obtain the coeffi-
cients of Fourier series expansion.
Example 8.2
For the full-wave rectifier waveform shown in Figure 8.3, the period is 0.0333s
and the amplitude is 169.71 Volts.
(a) Write a MATLAB program to obtain the exponential Fourier series
coefficients cn for n = 0,1, 2, .. , 19
(b) Find the dc value.
(c) Plot the amplitude and phase spectrum.
diary ex8_2.dat
% generate the full-wave rectifier waveform
f1 = 60;
inv = 1/f1; inc = 1/(80*f1); tnum = 3*inv;
t = 0:inc:tnum;
g1 = 120*sqrt(2)*sin(2*pi*f1*t);
g = abs(g1);
N = length(g);
%
% obtain the exponential Fourier series coefficients
num = 20;
for i = 1:num
for m = 1:N
cint(m) = exp(-j*2*pi*(i-1)*m/N)*g(m);
end
c(i) = sum(cint)/N;
end
cmag = abs(c);
cphase = angle(c);
%print dc value
disp('dc value of g(t)'); cmag(1)
% plot the magnitude and phase spectrum
f = (0:num-1)*60;
subplot(121), stem(f(1:5),cmag(1:5))
title('Amplitude spectrum')
xlabel('Frequency, Hz')
subplot(122), stem(f(1:5),cphase(1:5))
title('Phase spectrum')
xlabel('Frequency, Hz')
diary
dc value of g(t)
ans =
107.5344
Figure 8.4 shows the magnitude and phase spectra of Figure 8.3.
Example 8.3
g (t ) = e −2 t −1≤ t < 1
g (t + 2) = g ( t )
(i) Show that its exponential Fourier series expansion can be expressed as
∞
( −1) n (e 2 − e −2 )
g (t ) = ∑ 2(2 + jnπ ) exp( jnπt ) (8.22)
n =−∞
g(t)
0 2 4 t(s)
Solution
(i)
∞
g (t ) = ∑c n exp( jnwo t )
n =−∞
where
Tp / 2
1
cn =
Tp ∫ g (t ) exp( − jnw t )dto
− Tp / 2
and
2π 2π
wo = = =π
Tp 2
1
1
cn = ∫ exp( −2t ) exp( − jnπt )dt
2 −1
( −1) n (e 2 − e −2 )
cn =
2(2 + jnπ )
thus
for n = -10:10
for m = 1:tpts
g1(n+11,m) = ((0.5*cst*((-1)^n))/(2+j*n*pi))*(exp(j*n*pi*dt*(m-
1)));
end
end
for m = 1: tpts
g2 = g1(:,m);
g3(m) = sum(g2);
end
g = g3';
t = -4:0.05:4.0;
plot(t,g)
xlabel('Time, s')
ylabel('Amplitude')
title('Approximation of g(t)')
where
j = −1 and
f denotes frequency
g (t ) = g (t ± nTp ) (8.25)
where
Tp = period
∞
1 1
G( f ) =
Tp
∑c δ( f n −
Tp
) (8.26)
n =−∞
where
Tp / 2
1
cn =
Tp ∫ g (t ) exp( − j 2πnf o t )dt (8.27)
−t p / 2
g (t ) ⇔ G ( f ) (8.28)
Linearity
where
a and b are constants
G (t ) ⇔ g ( − f ) (8.31)
Time shifting
Frequency Shifting
exp( j 2 f C t ) g (t ) ⇔ G ( f − f C ) (8.33)
dg (t )
⇔ j 2πfG ( f ) (8.34)
dt
Integration in the time domain
t
1 G (0)
∫ g (τ )dτ ⇔ j 2πf
G( f ) +
2
δ ( f ) δ (f) (8.35)
−∞
g1 ( t ) g 2 ( t ) ⇔ ∫ G ( λ )G
1 2 ( f − λ ) dλ (8.36)
−∞
∫ g (τ ) g
1 2 (t − τ )dτ ⇔ G1 ( f )G2 ( f ) (8.37)
−∞
Fourier series links a continuous time signal into the discrete-frequency do-
main. The periodicity of the time-domain signal forces the spectrum to be dis-
crete. The discrete Fourier transform of a discrete-time signal g[ n] is given
as
N −1
G[ k ] = ∑ g[n]exp( − j 2πnk / N ) k = 0,1, …, N-1 (8.38)
n=0
N −1
g[n] = ∑ G[ k ]exp( j 2πnk / N ) n = 0,1,…, N-1 (8.39)
k =0
where
1
NT = (8.40)
F
NT is also equal to the record length. The time interval, T, between samples
should be chosen such that the Shannon’s Sampling theorem is satisfied. This
means that T should be less than the reciprocal of 2 f H , where f H is the
highest significant frequency component in the continuous time signal g (t )
from which the sequence g[ n] was obtained. Several fast DFT algorithms
require N to be an integer power of 2.
A discrete-time function will have a periodic spectrum. In DFT, both the time
function and frequency functions are periodic. Because of the periodicity of
DFT, it is common to regard points from n = 1 through n = N/2 as positive,
In general, if the time-sequence is real-valued, then the DFT will have real
components which are even and imaginary components that are odd. Simi-
larly, for an imaginary valued time sequence, the DFT values will have an odd
real component and an even imaginary component.
− j 2π
WN = e N
= e − j 2 πFT (8.41)
N −1
G[ k ] = ∑ g[n]W kn
N (8.42)
n=0
and
N −1
g[n] = ∑ G[ k ]W − kn
N (8.43)
k =0
The Fast Fourier Transform, FFT, is an efficient method for computing the
discrete Fourier transform. FFT reduces the number of computations needed
for computing DFT. For example, if a sequence has N points, and N is an in-
tegral power of 2, then DFT requires N 2 operations, whereas FFT requires
N N
log 2 ( N ) complex multiplication, log 2 ( N ) complex additions and
2 2
N
log 2 ( N ) subtractions. For N = 1024, the computational reduction from
2
DFT to FFT is more than 200 to 1.
The FFT can be used to (a) obtain the power spectrum of a signal, (b) do digi-
tal filtering, and (c) obtain the correlation between two signals.
fft ( x )
fft ( x , N )
is also MATLAB command that can be used to obtain N-point fft. The vector
x is truncated or zeros are added to N, if necessary.
The MATLAB functions for performing inverse fft is
ifft ( x ).
[z , z ] = fftplot ( x, ts)
m p
is used to obtain fft and plot the magnitude zm and z p of DFT of x. The
sampling interval is ts. Its default value is 1. The spectra are plotted versus
the digital frequency F. The following three examples illustrate usage of
MATLAB function fft.
Example 8.4
Given the sequence x[n] = ( 1, 2, 1). (a) Calculate the DFT of x[n] . (b)
Use the fft algorithm to find DFT of x[ n] . (c) Compare the results of (a)
and (b).
Solution
N −1
G[ k ] = ∑ g[n]W kn
N
n=0
2
G[0] = ∑ g[n]W30 = 1 + 2 + 1 = 4
n =0
2
G[1] = ∑ g[n]W3n = g[0]W30 + g[1]W31 + g[2]W32
n=0
= 1 + 2(−05
. − j0866
. ) + (−05
. + j0866
. ) = −05
. − j0866
.
2
G[2] = ∑ g[n]W32n = g[0]W30 + g[1]W32 + g[2]W34
n =0
= 1 + 2(−05
. + j0866
. ) + (−05
. − j0866
. ) = −05
. + j 0866
.
MATLAB Script
diary ex8_4.dat
%
x = [1 2 1];
xfft = fft(x)
diary
xfft =
4.0000 -0.5000 - 0.8660i -0.5000 + 0.8660i
(c) It can be seen that the answers obtained from parts (a) and (b) are
identical.
Signal g (t ) is given as
Solution
1 1
g (t ) = 4e − 2 t e j 20πt + e − j 20πt u(t )
2 2
2 2
G( f ) = +
2 + j 2π ( f − 10) 2 + j 2π ( f + 10)
MATLAB Script
% DFT of g(t)
% Sample 1, Sampling interval of 0.05 s
ts1 = 0.05; % sampling interval
fs1 = 1/ts1; % Sampling frequency
n1 = 1000; % Total Samples
m1 = 1:n1; % Number of bins
sint1 = ts1*(m1 - 1); % Sampling instants
freq1 = (m1 - 1)*fs1/n1; % frequencies
gb = (4*exp(-2*sint1)).*cos(2*pi*10*sint1);
gb_abs = abs(fft(gb));
subplot(121)
(d) From Figure 8.7, it can be seen that with the sample interval of 0.05 s,
there was no aliasing and spectrum of G[ k ] in part (b) is almost the same
Example 8.6
g (t ) = sin(2πf 1 t ) + 0.5n(t )
where
f 1 = 100 Hz
Solution
A representative program that can be used to plot the noisy signal and obtain
the power spectral density is
MATLAB Script
subplot(212), plot(f,pyy(1:128)),
title('power spectral density'),
xlabel('frequency in Hz')
The plot of the noisy signal and its spectrum is shown in Figure 8.8. The am-
plitude of the noise and the sinusoidal signal can be changed to observe their
effects on the spectrum.
SELECTED BIBLIOGRAPHY
EXERCISES
8 A ∞ ( −1) n +1
g (t ) = 2 ∑ 2 cos((2n − 1) w0 t )
π n =1 4 n − 1
where
1
w0 =
Tp
g(t)
2Tp
Tp
-A
g(t)
4
t(s)
0 1 2 3 4 5 6 7 8
8.3 For the half-wave rectifier waveform, shown in Figure P8.3, with a
period of 0.01 s and a peak voltage of 17 volts.
v(t)
-2 0 2 4 6 t(s)
3Ω VR(t)
V(t)
8.5 If the periodic waveform shown in Figure 8.5 is the input of the
circuit shown in Figure P8.5.
(a) Derive the mathematical expression for v C ( t ).
8Ω
g(t) 4Ω 2F VC(t)
h[n] = (0 − 1 − 1 0 1 1 0)
g (t ) = e −5t u(t )
(c) Compare the results obtained from parts (a) and (b).