Module 4
Module 4
Method 1: Manually derive the expression for Fourier coefficients, (a o, an, bn, Cn, θn )
and then plot using the following MATLAB code
clc; clear; clf;
n= 1:10; an(1) = 0.504; an(n+1) = 0.504*2./(1+16*n.^2);
bn(1) = 0; bn(n+1) = 0.504*8*n./(1+16*n.^2);
cn(1) = an(1);
cn(n+1) = sqrt(an(n+1).^2+bn(n+1).^2);
thetan(1) = 0; thetan(n+1) = atan2(-bn(n+1),an(n+1));
n=[0,n];
subplot(2,2,1); stem(n,an,'k'); ylabel('an'); xlabel('n');
subplot(2,2,2); stem(n,bn,'k'); ylabel('bn'); xlabel('n');
subplot(2,2,3); stem(n,cn,'k'); ylabel('cn'); xlabel('n');
subplot(2,2,4); stem(n,thetan,'k'); ylabel('\theta[rad]'); xlabel('n');
O/P -----> All the coefficients will be plotted against n
Manually derive the expression for Exponential Fourier coefficients for a periodic signal
and then plot using the following MATLAB code
n= -10:10; dn = 0.504./(1+j*4*n);
subplot(2,1,1); stem(n,abs(dn),'k'); ylabel('|dn|'); xlabel('n');
subplot(2,1,2); stem(n,angle(dn),'k'); ylabel('\angle dn [rad]');xlabel('n');
Method 2: write code to compute Fourier series coefficients either by creating m-function
file or directly in m-script file: A sample of MATLAB code is here for your reference:
wo = 1; h = 0.001; To = 2*pi/wo; t = 0:h:(To-h);
y = 1 + 6*cos(wo*t) + 3*sin(2*wo*t).*cos(wo*t)+ 2*sin(3*wo*t)+5*cos(5*wo*t);
N = length(y); co = sum(y)/(N-1);
for n = 1:10
aa(n) = 2*sum(y.*cos(n*wo*t))/(N-1); bb(n) = 2*sum(y.*sin(n*wo*t))/(N-1);
end
cn = sqrt(aa.^2+bb.^2); thetan = atan(-bb./aa);
Exercises:
1) For the above example, plot Fourier series expanded signal x(t) vs. continuous time t
and also plot each (at least 5) Fourier series terms w. r. t. continuous time t, explicitly
in the same graph sheet, and observe the role of Amplitude and Phase Spectra in Wave
shaping. (Use inline functions if necessary)
2) For the above example, find and sketch the Fourier series coefficients of the signal
x(-t). Compare the results with the F.S of x(t).
3) For the above example, find and sketch the Fourier series coefficients for the time
compressed / expanded signal. And observe the change in the Fourier spectra.
Compare the results with the F.S of x(t).
4) For the above example, find and sketch the Fourier Spectra for the time delayed
x(t-0.5) / time advanced x(t+0.5) signals. And observe the change in the Fourier
spectra. Compare the results with the F.S of x(t).
5) State with reasons whether the following signals are periodic or aperiodic. For periodic
signals, find the period and state which of the harmonics are present in the series.
a) 3 sint + 2 sin3t b) 2+5sin4t + 4cos7t c) 2sin3t + 7cosπt
5t 6t t
d) 7cosπt + 5sin2πt e) 3cos 2 t + 5 cos2t f) sin + 3 cos + 3 sin + 30 o
2 5 7
15t
g) sin 3t + cos h) (3sin2t + sin5t)2 i) (5sin2t)3
4
6) Find and sketch the Fourier Spectra for the following signals and repeat the exercises
1) to 4) for the same x(t)
1 e-t/10
A)
-1
x(t) t2
B)
-5 -4 -3 -2 -1 0 1 2 3 4 5 t (secs)
-32 0 32 n (integer)
In this case, Period No = 32 and Ωo = 2π/32 = π/16
1
Fourier coefficients, Dr, can be calculated as Dr = x[n]e − jr ( / 16 ) n
32 n =( 32 )
Method 1: By direct computation : Following MATLAB code can be used
No = 32; n= 0:No-1;
xn =[ones(1,5) zeros(1,23) ones(1,4)]; % signal definition for one period
for r=0:31,
xr(r+1) = sum(xn.*exp(-j*r*2*(pi/No)*n))/No;
end
r=n;
subplot(2,1,1); stem(r,real(xr),'k'); ylabel('absXr'); xlabel('r');
xr=round(1000*xr)/1000; %to avoid computational error
subplot(2,1,2); stem(r,angle(xr),'k'); ylabel('angleXr'); xlabel('r');
Exercises:
1) For the above example, plot Fourier series expanded signal x[n] vs. dicrete time n and
plot each (at least 5) Fourier series terms w. r. t. discrete time n, explicitly in the same
graph sheet, and observe the role of Amplitude and Phase Spectra in Wave shaping.
(Use inline functions if necessary)
2) Verify by plotting as well as analytically whether the following signals are periodic?
a) 3 sinn + 2 sin3n b) 2+5sin4πn + 4cos7πn c) 2sin3n + 7cosπn
15n
d) 7cosπn + 5sin2πn e) 3cos 2 πn+ 5 cos2πn f) sin 3n + cos
4
5n 6n n
g) sin + 3 cos + 3 sin + 30 o
2 5 7
3) Find the discrete time Fourier series (DTFS) and sketch their spectra |D r| and /_Dr for
0 ≤ r ≤ No-1 for the following periodic signal:
a) x[n] =4 cos2.4πn + 2sin3.2πn
b) x[n] =cos2.2πn + cos3.3πn
c) x[n] = 2cos3.2π(n-3)
d) x[n] e) x[n] an
3 1
Exercises:
➢ Discuss / Evaluate /comprehend, how the Fourier spectrum modifies, when the following
properties are applied to the above rectangle signal, [Use MATLAB, wherever necessary]
a) Scalar addition b) Scalar Multiplication c) Conjugation
d) addition of two different time domain signals e) Time shifting
f) Time scaling (compression, expansion, reversal g) Frequency shifting
h) Time Convolution i) Frequency convolution
➢ Compute the Fourier transform of unit triangle signal and sketch the spectra :
➢ Compute the Fourier transform of unit half triangle signal x(t) shown in figure P7-13
and sketch the spectra.
➢ Use the above exercise information, (F.T of standard signals, and properties) to find
the Fourier transform of the signals xi(t) (i =1,2,3,4,5) shown in figure P7-13 and
sketch the spectra.
➢ Use first principle and the above exercise information, (F.T of standard signals,
and properties) to find the Fourier transform of the signals shown in figure P7-14,
P7-15, P7-16 and sketch the spectra.
F.T of Discrete time signals: By using fft and fftshift command :
➢ Compute the Fourier transform of unit rectangle discrete signal and plot the spectra :
Following MATLAB code can be used
% Generation of unit rectangular discrete signal
n= [-8:8]; M=9
p=inline('((n>=-(M/2))&(n<=(M/2)))','n','M');
stem(n,p(n,M))
% Demonstration of getting Fourier spectra using fft command
N=1024;
% Generally this value is 2 to the power some integer: fft
algorithm uses it. If the periodicity is other than "2 to the
power some integer" there is a need of padding with zeroes in the
sequence to achieve this.
% vary this value to 512, 256, 128 and see
x=[ones(1,(M+1)/2) zeros(1,N-M) ones(1,(M-1)/2)];
X=fft(x);
omega = [-N/2:(N/2)-1]*2*pi/N; % to generate 512 samples of
frequency in –pi to pi region.
subplot(2,1,1);
plot([omega-2*pi omega omega+2*pi], fftshift(abs([X X X])),'r.-');
X=round(1000*X)/1000; %to avoid computational error
subplot(2,1,2);
plot([omega-2*pi omega omega+2*pi],fftshift(angle([X X X])),'k');
Exercises:
➢ Discuss / Evaluate /comprehend, how the Fourier spectrum modifies, when the following
properties are applied to the above rectangle signal, [Use MATLAB, wherever necessary]
b) Scalar addition b) Scalar Multiplication c) Conjugation
d) addition of two different time domain signals e) Time shifting
f) Time scaling (compression, expansion, reversal g) Frequency shifting
h) Time Convolution i) Frequency convolution
➢ Compute the Fourier transform of γnu[n] signal and sketch the spectra with γ = -0.8 :
➢ Compute the Fourier transform of the signals, shown in figure P9-12, P9-13, using
first principle (direct computation) OR using fft and the above exercise information,
(F.T of standard signals , and properties) and sketch the spectra.
➢ Compute the Fourier transform of triangle signal x(n) shown in fig. P9-16 a) and
sketch the spectra. Use the above exercise information, (F.T of standard signals, and
properties) to find the Fourier transform of the signals x(n) shown in fig. P9-16 b), c)
and d). Also sketch the spectra.
➢ Read the spectra, and find the inverse Fourier Transform of the following signals,
shown in figure P9-13, and P9-14, and sketch the discrete signal x(n). The signal is
represented in the Fourier domain (which is periodic function with 2π).
➢ Compute the Fourier transform of signals x(n) shown in figure P9-22 a) and sketch
the spectra. Use the above exercise information, (F.T of standard signals, and
properties) to find the Fourier transform of the signals x(n) shown in figure P9-22,
P9-26, P9-27. Also sketch the spectra.
%%%%% END %%%%%