close all;
clear all;
clc;
set(0,'defaultaxesfontsize',12);
k = -8:8;
h = inline('(n==-1+3) + 3/4*(n==0+3) + 1/2*(n==1+3) + 1/5*(n==2+3)','n');
x = inline('1/2*(n==-2) + 3/4*(n==-1) + (n==0) + 3/4*(n==1) + 1/2*(n==2)','n');

f = 1;
figure(f)
subplot(2,1,1)
stem(k,x(k));
axis([-8 8 0 1])
ylabel('y1')
text(-2,x(-2)+0.1,'\color{red}x[-2]','FontSize',12)
text(-1,x(-1)+0.1,'\color{blue}x[-1]','FontSize',12)
text(0+0.15,x(0)-0.05,'\color{red}x[0]','FontSize',12)
text(1,x(1)+0.1,'\color{blue}x[1]','FontSize',12)
text(2,x(2)+0.1,'x[2]','FontSize',12)
xlabel('n')
grid


subplot(2,1,2)
stem(k,h(k));
axis([-8 8 0 1])
ylabel('y2')
%text(-1+0.2,h(-1)-0.05,'\color{red}h[-1]','FontSize',12)
%text(0+0.2,h(0),'\color{blue}h[0]','FontSize',12)
%text(1+0.2,h(1),'h[1]','FontSize',12)
%text(2+0.2,h(2),'\color{red}h[2]','FontSize',12)
xlabel('n')
grid
%

%print -depsc2 cap2_ex1.eps;

f=f+1;
    
    figure(f)
    subplot(3,1,1)
    stem(k,x(k));
    axis([-8 8 0 2])    
    ylabel('y1')
    %text(-2-0.1,x(-2)+0.3,'\color{red}x[-2]','FontSize',12)
    %text(-1-0.1,x(-1)+0.3,'\color{blue}x[-1]','FontSize',12)
    %text(0-0.1,x(0)+0.3,'\color{red}x[0]','FontSize',12)
    %text(1-0.1,x(1)+0.3,'\color{blue}x[1]','FontSize',12)
    %text(2-0.1,x(2)+0.3,'x[2]','FontSize',12)
    xlabel('x1')
    grid


for n = k
    
    subplot(3,1,2)
    stem(k,h(n-k));
    axis([-8 8 0 2])
    ylabel('y2')
    
    %text(n-2,h(2)+0.3,'\color{red}h[2]','FontSize',12)
    %text(n-1,h(1)+0.3,'h[1]','FontSize',12)
    %text(n+0,h(0)+0.3,'\color{blue}h[0]','FontSize',12)
    %text(n+1,h(-1)+0.3,'\color{red}h[-1]','FontSize',12)
    xlabel('x2')
    grid on;
    
    subplot(3,1,3);
    stem(n,sum(x(k).*h(n-k)),'k');
    hold on;
    axis([-8 8 0 2])
    ylabel('y3')
    xlabel('x3')
    grid on;
    pause
    %eval(sprintf('print -depsc2 %s_%d.eps','cap2_ex1',n+9));
end