You are on page 1of 74

Signal Processing Lab, Dept. of ECE, KL University, A.P., India.

13-ES 205

Name: D.SUMADHURI Branch: ECE Section:S11


Id No: 13004443 Roll. No: Group :

Date: Signature of the Instructor Marks awarded:

Signal Processing-Lab-6
DT Sequences and Systems: Frequency-Domain
Representation (DTFT)
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Lab Report

Introduction: A linear and time-invariant system can be represented using its response
to the unit sample sequence. This response, called the unit impulse response h[n] ,

allows us to compute the system response to any arbitrary input x[ n] using the linear
convolution. This convolution representation is based on the fact that any signal can be
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

represented by a linear combination of scaled and delayed unit samples. Similarly, we


can also represent any arbitrary discrete signal as a linear combination of basis signals.
Each basis signal set provides a new signal representation. Each representation has
some advantages and some disadvantages depending upon the type of system under
consideration. However, when the system is linear and time-invariant, only one
representation stands out as the most useful. It is based on the complex exponential

signal set {e jn } and is called the discrete-time Fourier transform (DTFT).


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Objectives:

To compute the discrete time Fourier transform ( DTFT) for DT sequences and
LTI systems.
To determine and display the Magnitude and phase spectrum of given
sequences and LTI systems.
To find out real part and imaginary part of the spectrum.

Requirements: Digital Computer with MATLAB software.


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Basic theory: If x[n] is absolutely summable, that is,


| x[ n] | , then its discrete
time Fourier transform (DTFT) is given by

X [e j ]
n
x[n] e jn

The inverse discrete-time Fourier transform (IDTFT) of X [e j ] is given by


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205


1
2
x[n] X [e j ] e jn d .

In general X [e j ] is a complex function of the real variable and can be written as

X [e j ] X re [e j ] j X im [e j ]

where X re [e j ] and X im [e j ] are, respectively, the real and imaginary parts of

X [e j ] , and are real functions of . X [e j ] can alternately be expressed in the form


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

X [e j ] | X [e j ] | e j []

j
where [] arg X [e ]
The quantity | X [e j ] | is called the magnitude function and the quantity [] is

called the phase function, with both functions again being real functions of . In many
applications, the Fourier transform is called the Fourier spectrum and, likewise,
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

| X [e j ] | and [] are referred to as the magnitude spectrum and phase spectrum,


respectively.

The Fourier Domain Representation of LTI Systems:

The response of an LTI system for any arbitrary sequences in time domain can be

represented by using a convolution sum y[n] x[n] h[n] , where x[n] is input

sequence, h[n] is the impulse response of the


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

system and y[n] is the response of the system. According to the convolution theorem,
the convolution in time domain is multiplication in frequency domain,

Y [e j ] H [e j ] X [e j ] , where X [e j ] is the spectrum of the input sequence and

H [e j ] is the system (or Transfer) function. Fig.1 An LTI

System
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Examples:
Ex1: Determine the DTFT of x[ n] (0.5)n u[ n] analytically. Develop Matlab script for the
same and plot its magnitude, angle, real and imaginary parts. Also show that DTFT is
periodic sequence.
Ans: Analytical Solution
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205


X [e j ]
n
x[n] e jn
n 0
(0.5)n e jn

1
(0.5e j )n
n 0 j
1 0.5e
V6_1: Frequency spectrum (DTFT) using analytical solution

clear all; close all; clc;


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

k = -300:300;

w = (pi/100)*k;

X = exp(j*w) ./ (exp(j*w) - 0.5*ones(size(w)));

magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');

subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Real');
title('Real Part--->');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum Phase Spectrum


2 1
M a g n it u d e ---->

R a d ia n s ---->

0.5
1.5
0
1
-0.5

0.5 -1
-4 -2 0 2 4 -4 -2 0 2 4
frequency in pi units----> frequency in pi units---->
Real Part---> Imaginary Part
2 1
I m a g in a ry ---->

0.5
1.5
R eal

0
1
-0.5

0.5 -1
-4 -2 0 2 4 -4 -2 0 2 4
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Mat lab Script for DTFT of a given sequence using freqz.m function
V6_2.m:

clear all; close all; clc;

k = -300:300;

w = (pi/100)*k;

num = [1];
den = [ 1 -0.5];
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

X = freqz(num, den, w);

magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);

subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');

subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Real');
title('Real Part--->');

subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum Phase Spectrum


2 1

0.5
Magnitude---->

Radians---->

1.5
0
1
-0.5

0.5 -1
-4 -2 0 2 4 -4 -2 0 2 4
frequency in pi units----> frequency in pi units---->
Real Part---> Imaginary Part
2 1

0.5
nary---->

1.5
eal

0
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

From the magnitude and phase spectrums, it is concluded that the spectrum of given
aperiodic sequence is a periodic sequence with period 2 .

Ex2: Determine the frequency response H [e j ] of a system characterized by

n
h[ n] 0.9 u[n] . Plot the magnitude and the phase responses.
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Ans: Analytical Solution

1
H [e j ]
1 0.9e j
1 1
| H [e j ] | , and
(1 0.9 cos ) 2 +(0.9 cos ) 2 1.811.8 cos
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

0.9 sin
H [e j ] arctan
1 0.9 cos

V6_3.m:

clear all; close all; clc;

k = -300:300;
w = (pi/100)*k;
H = exp(j*w) ./ (exp(j*w) - 0.9*ones(size(w)));
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

magH = abs(H);
angH = angle(H);

subplot(2,1,1); plot(w/pi,magH,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,1,2); plot(w/pi,angH,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum
15
M a g n itu d e ---->

10

0
-3 -2 -1 0 1 2 3
frequency in pi units---->
Phase Spectrum
2
R a d ia n s ---->

-1

-2
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Ex3: An LTI system is specified by the difference equation y[n] 0.8y[n 1] x[n]

(a) Determine H [e j ] .

(b) Calculate and plot the steady-state response yss [n] to x[ n] cos[0.05 n]u[n]
Ans: Analytical Solution
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

1
(a) H [e j ]
1 0.8e j

(b) In the steady state the input is x[ n] cos[0.05 n]u[n] with frequency

0 0.05 and 0 0O . The response of the system is


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

1
H [e j 0.05 ] 4.0928e j 0.5377
1 0.8e j 0.05
Therefore
yss [n] 4.0928 cos(0.05 n 0.5377) 4.0928 cos [0.05 ( n 3.42)]
This means that at the output the sinusoid is scaled by 4.0928 and shifted by 3.42.

V6_4.m:
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

clear all; close all; clc;

k = -300:300;
w = (pi/100)*k;

H = exp(j*w) ./ (exp(j*w) - 0.9*ones(size(w)));

magH = abs(H);
angH = angle(H);

figure();
subplot(2,1,1); plot(w/pi,magH,'r','LineWidth',1.5); grid
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

xlabel('frequency in pi units---->'); ylabel('Magnitude---->');


title('Magnitude Spectrum');

subplot(2,1,2); plot(w/pi,angH,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');

Steady state response to the input sequence x[n] = cos(0.05*pi*n);

b = 1; a = [1,-0.8];
n = 0:100;
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

x = cos(0.05*pi*n);

y = filter(b,a,x);

figure();
subplot(2,1,1); stem(n,x,'r','LineWidth',1.5);
xlabel('n'); ylabel('x[n]'); title('Input sequence');

subplot(2,1,2); stem(n,y,'b','LineWidth',1.5);
xlabel('n'); ylabel('y[n]'); title('Output sequence');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum
15
M a g n it u d e ---->

10

0
-3 -2 -1 0 1 2 3
frequency in pi units---->
Phase Spectrum
2
R a d ia n s ---->

-1
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Input sequence
1

0.5
x [n]

-0.5

-1
0 10 20 30 40 50 60 70 80 90 100
n
Output sequence
5
y [n ]

0
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Laboratory Exercise-6
Exercise1: Determine the DTFT analytically for following sequences.
n

(a) x[ n] {2 1 0 1 2} (b) x[ n] 1
2
u[n 2] (c) x[ n] (0.8) | n |
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

(d) h[ n] [n] 6 [ n 1] 3 [n 2]

a)
clear all; close all; clc;

k = -300:300;

w = (pi/100)*k;
X = -2*exp(2*j*w)-exp(j*w)+exp(-j*w)+2*exp(-2*j*w);

magX = abs(X);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

angX = angle(X);
realX = real(X);
imagX = imag(X)

subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Real');
title('Real Part--->');

subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum Phase Spectrum


6 2
M a g n itu d e ---->

R a d ia n s ---->

1
4
0
2
-1

0 -2
-4 -2 0 2 4 -4 -2 0 2 4
frequency in pi units----> frequency in pi units---->
-16
x 10 Real Part---> Imaginary Part
4 10
Im a g in a ry ---->

2 5
Real

0 0

-2 -5
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

b)
clear all; close all; clc;

k = -300:300;

w = (pi/100)*k;
X =exp(j*w)./(exp(j*w)-0.5)+0.5*exp(2*j*w)+0.5*exp(j*w);

magX = abs(X);
angX = angle(X);
realX = real(X);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

imagX = imag(X)

subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');

subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Real');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

title('Real Part--->');

subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum Phase Spectrum


3 1
Magnitude---->

0.5
Radians---->

2
0
1
-0.5

0 -1
-4 -2 0 2 4 -4 -2 0 2 4
frequency in pi units----> frequency in pi units---->
Real Part---> Imaginary Part
3 0.4
ginary---->

0.2
2
Real

0
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

c)
clear all; close all; clc;

k = -300:300;

w = (pi/100)*k;
X =-1+1./(1-(0.8*exp(j*w)))+1./(1-(0.8*exp(-j*w)));

magX = abs(X);
angX = angle(X);
realX = real(X);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

imagX = imag(X)

subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');

subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Real');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

title('Real Part--->');

subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum Phase Spectrum


10 1
Magnitude---->

0.5
Radians---->

5 0

-0.5

0 -1
-4 -2 0 2 4 -4 -2 0 2 4
frequency in pi units----> frequency in pi units---->
Real Part---> Imaginary Part
10 1
inary---->

0.5
Real

5 0
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

d)
clear all; close all; clc;

k = -300:300;

w = (pi/100)*k;
X =1+6*exp(-j*w)+3*exp(-2*j*w)

magX = abs(X);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

angX = angle(X);
realX = real(X);
imagX = imag(X)

subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Real');
title('Real Part--->');

subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum Phase Spectrum


10 4
M agnitude---->

Radians ---->

8 2

6 0

4 -2

2 -4
-4 -2 0 2 4 -4 -2 0 2 4
frequency in pi units----> frequency in pi units---->
Real Part---> Imaginary Part
10 10
Im aginary ---->

5
5
Real

0
0
-5
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Exercise2: The following finite duration sequences are called windows and are very
useful in DSP. Develop Matlab codes for frequency response and plot them. Use N=25.

1, N21 n N21
Rectangular Window: RN [n]
0, elsewhere
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

|n|
1 , for N21 n N21
Triangular Window: TN [n] ( N 1) / 2
0, elsewhere

n
Hamming Window: 0.54 0.46 cos , for N21 n N21
H N [n] ( N 1) / 2
0, elsewhere

Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

For rectangular window

t=-12:1:12;
w=rectwin(t);subplot(1,1,1);
stem(t,y1);ylabel('Amplitude --.');
xlabel('(b) n --.');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

0.9

0.8

0.7

0.6
Amplitude --.

0.5

0.4

0.3
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

For triangular window

t=-12:1:12;
y1=1-(abs(t)/12);subplot(2,2,1);
stem(t,y1);ylabel('Amplitude --.');
xlabel('n');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

0.9

0.8

0.7

0.6
mplitude --.

0.5
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

For Hamming window:

n=-12:1:12;
y1=0.54+0.46*cos(pi*n)/12;
stem(n,y1);ylabel('Amplitude --.');
xlabel('n');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

0.7

0.6

0.5
Amplitude --.

0.4

0.3
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Exercise3: Determine the transfer function of the following difference equations


analytically: Develop Matlab scripts for the magnitude and phase responses and plot.

1 4 1 1
(a) y[ n] x[n m]
5 m 0
(b) y[n]
2
y[n 1] x[n] x[n 1]
4

a) k= -300:300;
w = (pi/100)*k;
H =0.2+0.2*exp(-j*w)+0.2*exp(-2*j*w)+0.2*exp(-3*j*w)+0.2*exp(-4*j*w);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

magH = abs(H);
angH = angle(H);

subplot(2,1,1); plot(w/pi,magH,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,1,2); plot(w/pi,angH,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum
1
Magnitude---->

0.5

0
-3 -2 -1 0 1 2 3
frequency in pi units---->
Phase Spectrum
4
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

b) clear all; close all; clc;

k = -300:300;
w = (pi/100)*k;
H =4-exp(-j*w)./4-(2*exp(-j*w));

magH = abs(H);
angH = angle(H);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

subplot(2,1,1); plot(w/pi,magH,'r','LineWidth',1.5); grid


xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,1,2); plot(w/pi,angH,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum
8

6
Magnitude---->

0
-3 -2 -1 0 1 2 3
frequency in pi units---->
Phase Spectrum
1
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Exercise4: Consider an LTI system with frequency response

1 e j 2
j ]
H [e ,
1 12 e j
2

n
Determine the output y[n] for all n if the input for all n is x[n] sin 4 analytically.
Develop Matlab scripts for the magnitude and phase responses and plot

Matlab code:

clear all; close all; clc;


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

% ------------------------------------------------------------

k = -300:300; % Select No. of points for both negative


% and positive spectrum
w = (pi/100)*k; % [0, pi] axis divided into 701 points.

% % Demo using analytical solution


H =(1- exp(-2*j*w)) ./ (1+0.5*exp(-2*j*w));

magH = abs(H);
angH = angle(H);
% ------------------------------------------------------------
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

% Plot the frequency response


figure();
subplot(2,1,1); plot(w/pi,magH,'r','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');

subplot(2,1,2); plot(w/pi,angH,'b','LineWidth',1.5); grid


xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
% ------------------------------------------------------------
% % Steady state response to the input sequence x[n] = sin(0.25*pi*n);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

b = [1,-1]; a = [1,0.5];
n = 0:100;

x = sin(0.25*pi*n);

y = filter(b,a,x);

figure();
subplot(2,1,1); stem(n,x,'r','LineWidth',1.5);
xlabel('n'); ylabel('x[n]'); title('Input sequence');

subplot(2,1,2); stem(n,y,'b','LineWidth',1.5);
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

xlabel('n'); ylabel('y[n]'); title('Output sequence');


Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Magnitude Spectrum
4

3
Magnitude---->

0
-3 -2 -1 0 1 2 3
frequency in pi units---->
Phase Spectrum
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

Input sequence
1

0.5
x[n]

-0.5

-1
0 10 20 30 40 50 60 70 80 90 100
n
Output sequence
1
Signal Processing Lab, Dept. of ECE, KL University, A.P., India.
13-ES 205

You might also like