Name: Masood Salik BSEE-14-18 Convergence / Existence of DTFT and Gibbs Phenomenon

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Name: Masood Salik

BSEE-14-18

Convergence / Existence of DTFT and Gibbs Phenomenon


MATLAB Assignment
Consider the ideal lowpass filter
1, |𝑤| < 𝑤𝑐
𝐻(𝑒 𝑗𝑤 ) = {
0, otherwise
Its impulse response can be calculated from (2) and is given by
𝑠𝑖𝑛𝑤𝑐 𝑛
ℎ[𝑛] = , −∞ < 𝑛 < ∞ (Note: Its non-causal and hence not realizable)
𝜋𝑛

𝑗𝑤
𝑠𝑖𝑛𝑤𝑐 𝑛 −𝑗𝑤𝑛
=> 𝐻(𝑒 )= ∑ 𝑒
𝜋𝑛
𝑛=−∞
Next, we see how the above sum converges to ideal lowpass filter as the number of
terms in the sum is increased.
1. Write a MATLAB program to plot (using subplot) the partial sums 𝐻𝑀 (𝑒 𝑗𝑤 ) =
𝑠𝑖𝑛𝑤𝑐 𝑛
∑𝑀
𝑛=−𝑀 𝑒 −𝑗𝑤𝑛 for 𝑤 ∈ [−𝜋, 𝜋] for 𝑀 = 1, 𝑀 =3, M=7, M=19, M=50. Note that
𝜋𝑛
as 𝑀 → ∞, 𝐻𝑀 (𝑒 𝑗𝑤 ) should converge to 𝐻(𝑒 𝑗𝑤 ).

Output:
2. Comment on the frequency of oscillations as 𝑀 is increased.
With increase in M, Oscillations are damped.

3. Comment on the maximum overshoot. How much is the maximum overshoot?


For M =1 , we get the Maximum Overshoot of 13.7%.

4. Doest the maximum overshoot decreases as 𝑀 is increased?


The Maximum overshoot decreases with the increase in value of M. it became 7.23%
for M=200

5. Comment on the convergence of the partial sum at the point of discontinuity for
different values of 𝑀

Matlab Code:

%% ========================================================================
%%Code Modified by Masood Salik

% The Fourier series approximation of a square wave signal existing between


% -Tau/2 to Tau/2 and period of T0 will have the form:
%
% Original signal to be approximated:
% :
% __________:__________ A
% | : |
% | : |
% | : |
% __________| : |__________
% -T0/2 -Tau/2 0 Tau/2 T0/2
% :
% :
%
% Its Fourier series approximation:
%
% Inf
% ___
% A*Tau \ / sin(pi*n*Tau/T0) \
% r(t) = ------- | | ------------------ exp^(j*n*2*pi/T0*t) |
% T0 /___ \ (pi*n*Tau/T0) /
% n = -Inf
%
% The left term inside summation are the Fourier series coeffs (Cn). The
% right term is the Fourier series kernel.
% Tau: range of square wave, T: period of the square wave,
% t: time variable, n: number of retained coefficients.
%
%% Observations:
% 1) As number of retained coefficients tends to infinity, the approximated
% signal value at the discontinuity converge to half the sum of values on
% either side.
% 2) Ripples does not decrease with increasing coefficients with
% approximately 9% overshoot.
% 3) Energy in the error between original and approximated signal, reduces
% as the number of retained coefficients are increased.
%
%% References:
% [1] Oppenheim, Willsky, Nawab, "Signals and Systems", PHI, Second edition
% [2] Dean K. Frederick and A. Bruce Carlson, "Fourier series" section in
% Linear systems in communication and control
%% Last Modified: Sept 24, 2013.
%% Copyright (c) 2013-2014 | Ankit A. Bhurane
%% =========================================================================

clc; clear all; close all;

% Specification
A = 1; % Peak-to-peak amplitude of square wave
Tau = 1; % Total range in which the square wave is defined (here -0.5 to
0.5)
T0 = 2; % Period (time of repeatation of square wave), here 10
C = 200; % Coefficients (sinusoids) to retain
N = 1001; % Number of points to consider
t = linspace(-(T0-Tau),(T0-Tau),N); % Time axis
X = zeros(1,N); X(t>=-Tau/2 & t<=Tau/2) = A; % Original signal
R = 0; % Initialize the approximated signal
k = -C:C; % Fourier coefficient number axis
f = zeros(1,2*C+1); % Fourier coefficient values

% Loop for plotting approximated signals for different retained coeffs.


for c = 0:C % Number of retained coefficients
for n = -c:c % Summation range (See equation above in comments)

% Sinc part of the Fourier coefficients calculated separately


if n~=0
Sinc = (sin(pi*n*Tau/T0)/((pi*n*Tau/T0))); % At n NOTEQUAL to 0
else
Sinc = 1; % At n EQUAL to 0
end
Cn = (A*Tau/T0)*Sinc; % Actual Fourier series coefficients
f(k==n) = Cn; % Put the Fourier coefficients at respective places
R = R + Cn*exp(1j*n*2*pi/T0.*t); % Sum all the coefficients
end

R = real(R); % So as to get rid of 0.000000000i (imaginary) factor


Max = max(R); Min = min(R); M = max(abs(Max),abs(Min)); % Maximum error
Overshoot = ((M-A)/A)*100; % Overshoot calculation

if c==1
subplot(3,2,c); plot(t,X,t,R,'m','LineWidth',3); axis tight; grid
on;
xlabel('w/pi'); ylabel('Amplitude');
title(['Approximation for N = ', num2str(c),...
'. Overshoot = ',num2str(Overshoot),'%'])
else if c==3
subplot(3,2,2);
plot(t,X,t,R,'m','LineWidth',3); axis tight; grid on;
xlabel('w/pi'); ylabel('Amplitude');
title(['Approximation for N = ', num2str(c),...
'. Overshoot = ',num2str(Overshoot),'%'])
else if c==7
subplot(3,2,3);
plot(t,X,t,R,'m','LineWidth',3); axis tight; grid on;
xlabel('w/pi'); ylabel('Amplitude');
title(['Approximation for N = ',
num2str(c),...
'. Overshoot = ',num2str(Overshoot),'%'])
else if c==19

subplot(3,2,4); plot(t,X,t,R,'m','LineWidth',3); axis tight; grid on;


xlabel('w/pi');
ylabel('Amplitude');

title(['Approximation for N = ', num2str(c),...


'. Overshoot =
',num2str(Overshoot),'%'])

else if c==50

subplot(3,2,5); plot(t,X,t,R,'m','LineWidth',3); axis tight; grid on;

xlabel('w/pi'); ylabel('Amplitude');

title(['Approximation for N = ', num2str(c),...

'. Overshoot = ',num2str(Overshoot),'%'])

else if c==200

subplot(3,2,6); plot(t,X,t,R,'m','LineWidth',3); axis tight; grid on;

xlabel('w/pi'); ylabel('Amplitude');

title(['Approximation for N = ', num2str(c),...

'. Overshoot = ',num2str(Overshoot),'%'])


end

end
end
end
end
end

R = 0; % Reset the approximation to calculate new one


end

%% ========================================================================

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy