matlab question A discrete-time signal has the following unit-pulse response: h[
ID: 666763 • Letter: M
Question
matlab question
A discrete-time signal has the following unit-pulse response:
h[n]=0.5^n -0.25^n for n0
Correspondingly, the following difference equation describes the behavior of the system:
y[n+2]-0.75y[n+1]+0.125y[n]=0.25x[n+1]
use the Matlab function RECUR to calculate the response of the system to a unit step input, x[n]=u[n]. Consider 0 n 20
Show the matlab command window and code. Show plot of the output with the axis labled.
The recur function is below:
"The Matlab function recur can be found in a zip file at the Mathworks site at the following location:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=2148
Extract the file recur.m to the current directory shown at the top of the Matlab window."
or you can copy and paste the recur function from that link into a text and make it a .m file.
The recur function is setup like this...
function y = recur(a,b,n,x,x0,y0);
Explanation / Answer
Ok.....I found the recur function from the given mathqorks URL..you provided.....
Given equation y[n+2]-0.75y[n+1]+0.125y[n]=0.25x[n+1]
so we will rearrange function..such that y[n] ==> y[n] = (-y[n+2] + 0.75y[n+1] + 0.25x[n+1])/0.125
----------------------------------------------------------
function y = recur(a,b,n,x,x0,y0); //recur function
N = length(a);
M = length(b)-1;
if length(y0) ~= N,
error('Lengths of a and y0 must match')
end
if length(x0) ~= M,
error('Length of x0 must match length of b-1')
end
y = [y0 zeros(1,length(n))];
x = [x0 x];
a1 = a(length(a):-1:1); % eleemnts reversing
b1 = b(length(b):-1:1);
for i=N+1:N+length(n),
y(i) = -a1*y(i-N:i-1) +a1*0.75 *y(i-N:i-2) + b1*0.25*x(i-N:i-N+M); //function calculates all points
plot(x,y(i)) % Here plotting
end
y = y(N+1:N+length(n));
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.