Anda di halaman 1dari 7

Discrete Time Systems in Time Domain

Task 1: A LTI system is described by the difference equation

𝑦(𝑛) − 0.5𝑦(𝑛 − 1) + 0.25𝑦(𝑛 − 2) = 𝑥(𝑛) + 2𝑥(𝑛 − 1) + 𝑥(𝑛 − 3)


a. Write MATLAB code to plot the impulse response of the system for 0 ≤ 𝑛 ≤ 100.
clc;
close all;
clear all;
n = 0:100;
b = [1 2 1];
a = [1 -0.5 0.25];
x = [1 zeros(1,100)];
h = filter(b,a,x);
stem(n,h,'r')
xlabel('n')
ylabel('magnitude')
title('Impulse response of y(n)-0.5y(n-1)+ 0.25y(n-2)= x(n)+ 2x(n-1)+x(n-3)')

Impulse response of y(n)- 0.5y(n-1)+ 0.25y(n-2)= x(n)+ 2x(n-1)+ x(n-3)


2.5

1.5
magnitude

0.5

-0.5
0 10 20 30 40 50 60 70 80 90 100
n

b. Is the system stable or not?


System is stable.
n = 0:100;
b = [1 2 1];
a = [1 -0.5 0.25];
x = [1 zeros(1,100)];
h = filter(b,a,x);
sum(abs(h))

ans =

6.5714

c. Write MATLAB code to plot the step response of the system for 0 ≤ 𝑛 ≤ 100.
clc;
close all;
clear all;
n = 0:100;
b = [1 2 1];
a = [1 -0.5 0.25];
x = ones(1,101);
s = filter(b,a,x);
stem(n,s,'r')
xlabel('n')
ylabel('magnitude')
title('Step response of y(n)- 0.5y(n-1)+ 0.25y(n-2)= x(n)+ 2x(n-1)+ x(n-3)')
Step response of y(n)- 0.5y(n-1)+ 0.25y(n-2)= x(n)+ 2x(n-1)+ x(n-3)
6

4
magnitude

0
0 10 20 30 40 50 60 70 80 90 100
n

d. If the input to the system is 𝑥(𝑛) = [5 + 3 cos(0.2𝜋𝑛) + 4 sin(0.6𝜋𝑛)]𝑢(𝑛). Write MATLAB code to
plot the response 𝑦(𝑛) 𝑓𝑜𝑟 0 ≤ 𝑛 ≤ 200.
clc;
close all;
clear all;
n = 0:200;
b = [1 2 1];
a = [1 -0.5 0.25];
x = (5 + 3*cos((0.2*pi).*n) + 4*sin((0.6*pi).*n)).*ones(1,201);
h = filter(b,a,x);
stem(n,h,'r')
xlabel('n')
ylabel('magnitude')
title('Output Signal')
Output Signal
50

45

40

35

30
magnitude

25

20

15

10

0
0 20 40 60 80 100 120 140 160 180 200
n

e. Draw block diagram representation of the system.

𝑦(𝑛) − 0.5𝑦(𝑛 − 1) + 0.25𝑦(𝑛 − 2) = 𝑥(𝑛) + 2𝑥(𝑛 − 1) + 𝑥(𝑛 − 3)

In MATLAB, the function filter is used to solve the difference equation numerically, given the input and
the difference equation co-efficients. In simple it is

>> y=filter(b,a,x)

where b=[b0, b1, b2,…bM] and a=[a0, a1, a2, … , aN] and x is input sequence. The output y has the
same length as the input x. The co-efficient a0 must not be zero.
Task 2: A discrete system is realized by the structure as shown in Fig 3.

1- Write the system’s difference equation.

11.1𝑦[𝑛] + 10.1𝑦[ 𝑛 − 1] + 11𝑦[𝑛 − 2] + 𝑦[𝑛 − 3] = 𝑥[𝑛]+x[n-1]+x[n-2]+x[n-3]

2- Write MATLAB code to plot its impulse response 𝑓𝑜𝑟 0 ≤ 𝑛 ≤ 20.

clc
close all;
clear all;
n = 0:20;
b = [1 1 1 1];
a = [11.1 10.1 11 1];
x = [1 zeros(1,20)];
h = filter(b,a,x);
stem(n,h)
xlabel('n')
ylabel('magnitude')
title('Impulse response')
Impulse response
0.1

0.08

0.06

0.04
magnitude

0.02

-0.02

-0.04

-0.06

-0.08
0 2 4 6 8 10 12 14 16 18 20
n

3- Write MATLAB code to plot its step response 𝑓𝑜𝑟 0 ≤ 𝑛 ≤ 20.

clc
close all;
clear all;
n = 0:20;
b = [1 1 1 1];
a = [11.1 10.1 11 1];
u = ones(1,21);
u1 = filter(b,a,u);
stem(n,u1)
xlabel('n')
ylabel('magnitude')
title('Step response')
Step response
0.18

0.16

0.14

0.12
magnitude

0.1

0.08

0.06

0.04

0.02

0
0 2 4 6 8 10 12 14 16 18 20
n

4- Is the system causal?

h=

Columns 1 through 9

0.0901 0.0081 -0.0066 0.0799 -0.0669 -0.0177 0.0752 -0.0449 -0.0321

Columns 10 through 18

0.0669 -0.0250 -0.0407 0.0558 -0.0082 -0.0441 0.0433 0.0051 -0.0436

Columns 19 through 21

0.0307 0.0148 -0.0399

As h[n] is not zero for n less than zero thus system is not causal.

Anda mungkin juga menyukai