|
Here is the Matlab code
n0=10; n=-n0:n0; u1=(n-4)>=0; f=(-1/2).^n; f1=f.*u1; x=f1; u2=(2-n)>=0; h=(4).^n; h2=h.*u2; h=h2; k1=-n0:n0;
y=conv(x,h) length_output=length(x)+length(h)-1;
k2=linspace(-2*n0,2*n0,length_output);
figure(1); clf; subplot(2,2,1); xlabel('k'); ylabel('x[k]'); title('System Input'); stem(k1,x,'filled'); grid;
subplot (2,2,2);
xlabel('k'); ylabel('h[k]'); title ('System Unit Impulse Response'); stem(k1,h,'filled'); grid;
subplot (2,1,2); stem (k2, y, 'filled'); grid; xlabel('k'); ylabel('y[k]');
title ('System Output Via Convolution');
And here is how the final plot looked.
|