LAB # 4 HANDOUT - Eastern Mediterranean Universityfaraday.ee.emu.edu.tr/eeng420-lab/lab...

6

Click here to load reader

Transcript of LAB # 4 HANDOUT - Eastern Mediterranean Universityfaraday.ee.emu.edu.tr/eeng420-lab/lab...

Page 1: LAB # 4 HANDOUT - Eastern Mediterranean Universityfaraday.ee.emu.edu.tr/eeng420-lab/lab handouts/lab4.pdf · EEE420 Lab Handout 1 π −π ∫ LAB # 4 HANDOUT 1. THE DISCRETE-TIME

EEE420 Lab Handout

1

π

π−∫

LAB # 4 HANDOUT

1. THE DISCRETE-TIME FOURIER TRANSFORM (DTFT) DTFT of x(n) can be determined by using:

X(ejw)= ( )n

x n∞

=−∞∑ e-jwn

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).

(Hint : use0n

=∑ αn = 1

1 α−)

X(ejw)= ( )n

x n∞

=−∞∑ e-jwn =

0n

=∑ (0.5)n e-jwn =

0n

=∑ (0.5. e-jw)n = 1

1 0.5e jw−−= e

e 0.5

jw

jw −

Ex2: Determine the DTFT of the following finite-duration sequence: x(n)={1,2,3,4,5} ↑

X(ejw)= ( )n

x n∞

=−∞∑ e-jwn = 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')

Page 2: LAB # 4 HANDOUT - Eastern Mediterranean Universityfaraday.ee.emu.edu.tr/eeng420-lab/lab handouts/lab4.pdf · EEE420 Lab Handout 1 π −π ∫ LAB # 4 HANDOUT 1. THE DISCRETE-TIME

EEE420 Lab Handout

2

2. THE DISCRETE FOURIER TRANSFORM (DFT) The discrete fourier transform of x(n) is given by: DFT[x(n)] = X(k) Or,

1

0( ) ( )

Nnk

Nn

X k x n W−

=

= ∑ , 0 ≤ k ≤ N-1

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

1

0( ) ( )

Nkn

Nk

x n X k W−

=

=∑ , 0 ≤ n ≤ N-1

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

Page 3: LAB # 4 HANDOUT - Eastern Mediterranean Universityfaraday.ee.emu.edu.tr/eeng420-lab/lab handouts/lab4.pdf · EEE420 Lab Handout 1 π −π ∫ LAB # 4 HANDOUT 1. THE DISCRETE-TIME

EEE420 Lab Handout

3

1( )

0x n

⎧= ⎨⎩

Ex: Let x(n) be a 4-point sequence , 0 ≤ n ≤ 3 , otherwise Compute the 4-point DFT of x(n).

3

4 40

( ) ( ) nk

kX k x n W

=

=∑

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}

Let X8(k) be an 8-point DFT. (7

8 80

( ) ( ) nk

kX k x n W

=

= ∑ )

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);

Page 4: LAB # 4 HANDOUT - Eastern Mediterranean Universityfaraday.ee.emu.edu.tr/eeng420-lab/lab handouts/lab4.pdf · EEE420 Lab Handout 1 π −π ∫ LAB # 4 HANDOUT 1. THE DISCRETE-TIME

EEE420 Lab Handout

4

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:

x1(n) x2(n)= 3

1 2 40

( ) (( ))m

x m x n m=

−∑

For n=0;

3

1 2 40

( ) ((0 ))m

x m x m=

−∑ = 3

0

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

3

0

{1,8,6,0}m=∑ =15

For n=1;

3

1 2 40

( ) ((1 ))m

x m x m=

−∑ = 3

0

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

3

0

{2,2,8,0}m=∑ =12

For n=2;

3

1 2 40

( ) ((2 ))m

x m x m=

−∑ = 3

0

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

3

0

{3,4, 2,0}m=∑ =9

For n=3;

3

1 2 40

( ) ((3 ))m

x m x m=

−∑ = 3

0

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

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

Page 5: LAB # 4 HANDOUT - Eastern Mediterranean Universityfaraday.ee.emu.edu.tr/eeng420-lab/lab handouts/lab4.pdf · EEE420 Lab Handout 1 π −π ∫ LAB # 4 HANDOUT 1. THE DISCRETE-TIME

EEE420 Lab Handout

5

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)

Page 6: LAB # 4 HANDOUT - Eastern Mediterranean Universityfaraday.ee.emu.edu.tr/eeng420-lab/lab handouts/lab4.pdf · EEE420 Lab Handout 1 π −π ∫ LAB # 4 HANDOUT 1. THE DISCRETE-TIME

EEE420 Lab Handout

6

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)