0% found this document useful (0 votes)
194 views6 pages

Lab 4

This document provides a 3-sentence summary of each section: 1. The DTFT and IDTFT are introduced and examples are provided to calculate the DTFT of sequences and evaluate it at discrete points, plotting the results. 2. The DFT and IDFT are defined mathematically and M-files are provided to compute the DFT and IDFT of sequences. Examples are worked out to calculate the 4-point and 8-point DFTs of sequences. 3. Circular shifting of sequences is defined and an M-file is provided to implement circular shifts. An example works out the circular shift of a 11-point sequence over 15 points. 4. Circular convolution
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
194 views6 pages

Lab 4

This document provides a 3-sentence summary of each section: 1. The DTFT and IDTFT are introduced and examples are provided to calculate the DTFT of sequences and evaluate it at discrete points, plotting the results. 2. The DFT and IDFT are defined mathematically and M-files are provided to compute the DFT and IDFT of sequences. Examples are worked out to calculate the 4-point and 8-point DFTs of sequences. 3. Circular shifting of sequences is defined and an M-file is provided to implement circular shifts. An example works out the circular shift of a 11-point sequence over 15 points. 4. Circular convolution
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EEE420 Lab Handout

LAB # 4 HANDOUT
1. THE DISCRETE-TIME FOURIER TRANSFORM (DTFT)

DTFT of x(n) can be determined by using:



X(ejw)= x(n) e-jwn
n =

IDTFT of X(ejw) can be determined by using:



x(n)= X(ejw) ejwn dw

Ex1:
Determine the DTFT of x(n)=(0.5)nu(n).

1
(Hint : use n = )
n =0 1

1 e jw
X(ejw)=
n =
x(n) e-jwn =
n =0
(0.5)n e-jwn =
n =0
(0.5. e-jw)n =
1 0.5e jw
=
e jw 0.5
Ex2:
Determine the DTFT of the following finite-duration sequence: x(n)={1,2,3,4,5}


X(ejw)= x(n) e-jwn
n =
= ejw + 2 + 3e-jw + 4e-j2w + 5e-j3w

Ex3:
Evaluate X(ejw) in Ex1 at 501 equispaced points between [0,) and plot its
magnitude, angle, real and imaginary parts.

In command window:

w = [0:1:500]*pi/500; % [0, pi] axis divided into 501 points.


X = exp(j*w) ./ (exp(j*w) - 0.5*ones(1,501));
magX = abs(X); angX = angle(X);
realX = real(X); imagX = imag(X);
subplot(2,2,1); plot(w/pi,magX); grid
xlabel('frequency in pi units'); title('Magnitude Part');
ylabel('Magnitude')
subplot(2,2,3); plot(w/pi,angX); grid
xlabel('frequency in pi units'); title('Angle Part');
ylabel('Radians')
subplot(2,2,2); plot(w/pi,realX); grid
xlabel('frequency in pi units'); title('Real Part');
ylabel('Real')
subplot(2,2,4); plot(w/pi,imagX); grid
xlabel('frequency in pi units'); title('Imaginary Part');
ylabel('Imaginary')

1
EEE420 Lab Handout

2. THE DISCRETE FOURIER TRANSFORM (DFT)

The discrete fourier transform of x(n) is given by:


DFT[x(n)] = X(k)
Or,
N 1
X (k ) = x(n)WNnk , 0 k N-1
n=0

The inverse discrete fourier transform of an N point DFT X(k) is given by:
x(n) = IDFT[X(k)]
Or,
N 1
x(n) = X (k )WN kn , 0 n N-1
k =0

Mfile:

function [Xk] = dft(xn,N)


% Computes Discrete Fourier Transform
% -----------------------------------
% [Xk] = dft(xn,N)
% Xk = DFT coeff. array over 0 <= k <= N-1
% xn = N-point finite-duration sequence
% N = Length of DFT
%
n = [0:1:N-1]; % row vector for n
k = [0:1:N-1]; % row vecor for k
WN = exp(-j*2*pi/N); % Wn factor
nk = n'*k; %creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFT matrix
Xk = xn * WNnk; % row vector for DFT coefficients

Mfile:

function [xn] = idft(Xk,N)


% Computes Inverse Discrete Transform
% -----------------------------------
% [xn] = idft(Xk,N)
% xn = N-point sequence over 0 <= n <= N-1
% Xk = DFT coeff. array over 0 <= k <= N-1
% N = length of DFT
%
n = [0:1:N-1]; % row vector for n
k = [0:1:N-1]; % row vecor for k
WN = exp(-j*2*pi/N); % Wn factor
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^(-nk); % IDFT matrix
xn = (Xk * WNnk)/N; % row vector for IDFT values

2
EEE420 Lab Handout

Ex:
Let x(n) be a 4-point sequence

1 ,0n3
x(n) =
0 , otherwise

Compute the 4-point DFT of x(n).


3
X 4 (k ) = x(n)W4nk
k =0

Solution (In command window):

x=[1,1,1,1]; N=4;
X=dft(x,N);
magX=abs(X), phaX=angle(X)*180/pi

idft(X,N)

So, X4(k)={4,0,0,0}

Ex:

x(n)={1,1,1,1,0,0,0,0}

7
Let X8(k) be an 8-point DFT. ( X 8 (k ) = x(n)W8nk )
k =0

Solution (In command window):

x=[1,1,1,1,zeros(1,4)]; N=8;
X=dft(x,N)

idft(X,N)

3. CIRCULAR SHIFT OF A SEQUENCE

M-file:

function y=cirshift(x,m,N)
if length(x)>N
error('N must be >= length of x')
end
x=[x zeros(1,N-length(x))];
n=[0:1:N-1];
n=mod(n-m,N);
y=x(n+1);

3
EEE420 Lab Handout

Ex:

Given an 11-point sequence x(n)=10(0.8)n , 0 n 10, determine x((n-6))15. [N=15]

Solution (In command window):

n=0:10; x=10*(0.8).^n;
y=cirshftt(x,6,15);
n=0:14; x=[x, zeros(1,4)];
subplot(2,1,1); stem(n,x); title(original sequence)
xlabel(n); ylabel(x(n));
subplot(2,1,2); stem(n,y);
title(circularly shifted sequence N=15)
xlabel(n); ylabel(x((n-6) mod 15));

4. CIRCULAR CONVOLUTION

Ex:

Let x1(n)={1,2,2} and x2(n)={1,2,3,4}. Compute the 4-point circular convolution

x1(n) x2(n).

Solution:
3
x1(n) x2(n)= x (m) x ((n m))
m =0
1 2 4

For n=0;
3 3 3

x1 (m) x2 ((0 m))4 =


m =0
[{1, 2, 2, 0}.{1, 4,3, 2}] =
m=0
{1,8, 6, 0} =15
m =0

For n=1;
3 3 3

x (m) x ((1 m))


m =0
1 2 4 = [{1, 2, 2, 0}.{2,1, 4,3}] = {2, 2,8, 0} =12
m=0 m =0

For n=2;
3 3 3

x1 (m) x2 ((2 m))4 =


m =0
[{1, 2, 2, 0}.{3, 2,1, 4}] =
m=0
{3, 4, 2, 0} =9
m =0

For n=3;
3 3

x (m) x ((3 m))


m =0
1 2 4 = [{1, 2, 2, 0}.{4,3, 2,1}] =14
m =0

Hence, x1(n) x2(n)={15,12,9,14}

4
EEE420 Lab Handout

M-file:

function y = circonvt(x1,x2,N)
% N-point circular convolution between x1 and x2: (time-
domain)
% ------------------------------------------------------------
-
% [y] = circonvt(x1,x2,N)
% y = output sequence containing the circular convolution
% x1 = input sequence of length N1 <= N
% x2 = input sequence of length N2 <= N
% N = size of circular buffer
% Method: y(n) = sum (x1(m)*x2((n-m) mod N))

% Check for length of x1


if length(x1) > N
error('N must be >= the length of x1')
end

% Check for length of x2


if length(x2) > N
error('N must be >= the length of x2')
end

x1=[x1 zeros(1,N-length(x1))];
x2=[x2 zeros(1,N-length(x2))];

m = [0:1:N-1];
x2 = x2(mod(-m,N)+1);
H = zeros(N,N);

for n = 1:1:N
H(n,:) = cirshftt(x2,n-1,N);
end

y = x1*H';

Ex:

Take the sequences that we had before x1(n)={1,2,2} and x2(n)={1,2,3,4}. Compute
the 4-point circular convolution x1(n) x2(n).

Solution (In command window):

x1=[1,2,2]; x2=[1,2,3,4];
y=circonvt(x1,x2,4)

5
EEE420 Lab Handout

Ex:

Take the sequences that we had before x1(n)={1,2,2} and x2(n)={1,2,3,4}. Compute
the 5-point circular convolution.

x1=[1,2,2]; x2=[1,2,3,4];
y=circonvt(x1,x2,5)

Ex:

Take the sequences that we had before x1(n)={1,2,2} and x2(n)={1,2,3,4}. Compute
the 6-point circular convolution.

x1=[1,2,2]; x2=[1,2,3,4];
y=circonvt(x1,x2,6)

You might also like