Time Domain Representation of Continuous and Discrete Signals 91
Example 1.20
Create the script fi le explore_window that returns the plots of the truncated or windowed
function f(t) = cos(2πt) using the following window types:
- Hamming
- Hanning
- Blackman
- Kaiser (with β = 3.4)
- Triangular
- Boxcar
- B a r t l e t t
Let us defi ne f(t) = cos(2πt) by using 301 points over the range − 15 ≤ t ≤ 15 , and limit f(t)
using the above-mentioned windows over the range − 10 ≤ t ≤ 10.
Display the plots of the windowed function f(t) over the range − 15 ≤ t ≤ 15 , for the
fi rst three cases and − 10 ≤ t ≤ 10 , for the remaining four.
MATLAB Solution
% Script file: explore _ window
t = -15:0.1:15; % returns a vector with 301 elements
f = cos(2pit); % returns 301 element for f(t)
winpoints = -100:1:100; % 201 window points
WHam=hamming(201);
WHan= hanning(201);
WBlac= blackman(201);
WKai= kaiser(201, 3.4); % Beta = 3.4
WTrian= triang(201);
WRect= boxcar(201);
WBar= bartlett(201);
W1Ham= [zeros(1,50) WHam’ zeros(1,50)]; % Hamming window with 301
points
W1Han = [zeros(1,50) WHan’ zeros(1,50)]; % Hanning window with 301
points
W1Blac = [zeros(1,50) WBlac’ zeros(1,50)]; % Blackman window with 301
points
W1Kai = [ zeros(1,50) WKai’ zeros(1,50)] ; % Kaiser window with 301
points
W1Tria = [ zeros(1,50) WTrian’ zeros(1,50)]; % Triangular window with
301 points
W1Box = [ zeros(1,50) WRect’ zeros(1,50)]; % Boxcar window with 301
points
W1Bar = [ zeros(1,50) WBar’ zeros(1,50)] ; % Bartlett window with 301
points
Hamwin= W1Ham.f; % f(t) is windowed
Hanwin= W1Han.f;
Blackwin =W1Blac.f;
Kaiwin=W1Kai.f;
Triwin=W1Tria.f;
Boxwin=W1Box.f;
Barwin=W1Bar.f;
figure(1)
subplot(3,1,1)
plot(t, Hamwin);ylabel(‘Amplitude’);
title(‘[f(t)Hamming widow] vs.t’)