% Written by: Daniel Llamocca (2013)
% Discrete-time convolution in MATLAB

clear all; close all; clc;

x = [ 2 9 8 3 2 1]; 
% n = [-1 0 1 2 3 4]
% ax = -1, bx = 4
nx = -1:4;
figure; stem (nx,x,'bo','LineWidth',2,'MarkerSize',6,'MarkerFaceColor','b'); xlabel ('n'); title ('x[n]');

h =  [  9  1 0 2.3 4 1 3 7 13];
% n = [-2 -1 0  1  2 3 4 5  6]
% ah = -2, bh = 6
nh = -2:6;
figure; stem (nh,h,'mo','LineWidth',2,'MarkerSize',6,'MarkerFaceColor','m'); xlabel ('n'); title ('h[n]');

% Limits of y[n]: n= ax + ah : bx+bh
  y = conv(x,h);
  nmin = -1 - 2; nmax = 4 + 6;
  n = nmin:nmax;
  figure; stem(n,y, 'ro','LineWidth',2,'MarkerSize',6,'MarkerFaceColor','r'); xlabel ('n'); title ('y[n]');