Beruflich Dokumente
Kultur Dokumente
Dasmarinas, Cavite
COLLEGE OF ENGINEERING, ARCHITECTURE, AND TECHNOLOGY
ELECTRONICS ENGINEERING
Experiment No. 6
Different Equation
OBJECTIVES:
This experiment will enable the students to learn the concept of solving difference equation by
using the filter function in Matlab. The impulse response of a system will be obtained using the filter
function or by using the impz function in Matlab.
PROCEDURE:
A function called filter is available to solve difference equations numerically, given the input and
difference equation coefficients. It is invoked by
𝑦 = 𝑓𝑖𝑙𝑡𝑒𝑟(𝑏, 𝑎, 𝑥)
where, b = [b0, b1, …, bM]
a = [a0, a1, …, aN]
x = input sequence array
To compute and plot impulse response, MATLAB provides the function impz and is invoked by
ℎ = 𝑖𝑚𝑝𝑧(𝑏, 𝑎, 𝑛)
Sample Problem:
Given the following difference equation
Sample Problem:
Given the following difference equation:
OUTPUT:
Approach 2:
>> %to obtain impulse response using filter
>> x = impseq(0, -20, 100);
>> h = filter (b, a, x);
>> subplot(3, 1, 1); stem (n, h);
>> title(‘Impulse Resposne’); xlabel(‘n’); ylabel(‘h(n)’);
OUTPUT:
Task:
A DL-LTI system is described by a second order equation
𝑦(𝑛) − 0.5𝑦(𝑛 − 1) + 0.25𝑦(𝑛 − 2) = 𝑥(𝑛) + 2𝑥(𝑛 − 1) + 𝑥(𝑛 − 3)
a. Calculate and plot the impulse response of the system over 0 … 100
b. Calculate and plot the system response to the input,
𝑥(𝑛0 = [5 + 3 cos(0.2𝜋𝑛) + 4 sin(0.6𝜋𝑛)𝑢(𝑛) 𝑜𝑣𝑒𝑟 0 … 100
OUTPUT:
CODES:
function [x,n] = impseq(n0,n1,n2)
%Programmed By: Moldez, Zharina if ((n0 < n1) | (n0 > n2) | (n1 >
Lorraine C. n2))
%ECE42 error('arguments must satisfy n1
%ECET423La <= n0 <= n2')
%April 26, 2019 end
%Instructor: Engr. Katrina Acapulco n = [n1:n2];
x = [(n-n0) == 0];
clc FOR STEPSEQ:
%Programmed By: Moldez, Zharina
%Impulse Response Lorraine C.
b= [1,2,0,1]; %ECE42
a = [1,-0.5,0.25] ; %ECET423La
n=[0:100]; %April 26, 2019
x = impseq(0,0,100); %Instructor: Engr. Katrina Acapulco
h=filter(b,a,x); function [x,n] = impseq(n0,n1,n2)
subplot(2,1,1); if ((n0 < n1) | (n0 > n2) | (n1 >
stem(n,h); n2))
title('Impulse error('arguments must satisfy n1
Response');xlabel('n');ylabel('h(n)' <= n0 <= n2')
); end
grid on; n = [n1:n2];
x = [(n-n0) == 0];
%System Response function [x,n]=stepseq(n0,n1,n2)
nx=(5+3*cos(0.2*pi*n)+4*sin(0.6*pi*n if((n0<n1)|(n0>n2)|(n1>n2))
)).*stepseq(0,0,100); error('arguments must satisfy
yfilter = filter(b,a,nx); n1<=n0,n<=n2')
subplot(2,1,2); end
stem(n,yfilter); n=[n1:n2];
title('System x=[(n-n0)>=0];
Response');xlabel('n');ylabel('y(n)'
); FOR IMPSEQ:
grid on; function [x,n] = impseq(n0,n1,n2)
if ((n0 < n1) | (n0 > n2) | (n1 >
FOR IMPSEQ: n2))
%Programmed By: Moldez, Zharina error('arguments must satisfy n1
Lorraine C. <= n0 <= n2')
%ECE42 end
%ECET423La n = [n1:n2];
%April 26, 2019 %x = [zeros(1,(n0-n1)), 1,
%Instructor: Engr. Katrina Acapulco zeros(1,(n2-n0))];
x = [(n-n0) == 0];
ANALYSIS AND DISCUSSION:
CONCLUSION: