Lab 3 Procesamiento Digital de Señales
Lab 3 Procesamiento Digital de Señales
Lab 3 Procesamiento Digital de Señales
SEMESTRE: IV
CURSO: PROCESAMIENTO DIGITAL DE SEALES
PROFESOR: ING. JUAN CARLOS CUADROS
MACHUCA
TEMA: TERCER LABORATOTIO CONVOLUCIN
ESTUDIANTES:
FECHA: 13/12/2013
PRCTICA 3: CONVOLUCION
I. OBJETIVOS
PC
MATLAB
Toolbox de DSP
hache=(7/8).^(0:Lh-1); %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib);
title('x(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib);
title('h(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek);
title('x(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk);
title('h(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk);
title('x(k)h(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)]);
title('y(n)')
xlabel('n')
grid;
pause;
end;
=
=
1
1
-1
2
1
1
_____________________________________________
y(n)
y(n) = 6
-1
2
1
-2
1
2
-1
1
1
-1
______________________________________________
duracin de
zeros(1,Lx+1)];
title('h(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('h(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x(k)h(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
a. x1(n) * x2(n)
%Solucin ejercicio_4_a
clear all;
% Definicion de las seales a convolucionar
Lx=12; %Longitud de x(n)
equis=[1 4 2 3 5 3 3 4 5 7 6 9]; %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=2; %Longitud de h(n)
hache=[1 1]; %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se
% para visualizar mejor las
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis
stem(ndib,equisdib,'fill');
title('x1(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache
stem(ndib,hachedib,'fill');
title('x2(n)');
pause;
zeros(1,Lx+1)];
x1(n)*x4(n) = (1/2)
%Solucin ejercicio_4_b
clear all;
% Definicion de las seales a convolucionar
Lx=12; %Longitud de x(n)
equis=[1 4 2 3 5 3 3 4 5 7 6 9]; %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=2; %Longitud de h(n)
hache=[0.5 0.5]; %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib,'fill');
title('x1(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('x4(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
end;
d. x1(n) * x3(n)
%Solucin ejercicio_4_d
clear all;
% Definicion de las seales a convolucionar
Lx=12; %Longitud de x(n)
equis=[1 4 2 3 5 3 3 4 5 7 6 9]; %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=3; %Longitud de h(n)
hache=[1 2 1]; %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib,'fill');
title('x1(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('x3(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x1(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('x3(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x1(k)x3(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
zeros(1,Lx+1)];
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
title('x1(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('x6(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x1(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('x6(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x1(k)x6(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
end;
% Dibujo de x(n) y h(n). Se
% para visualizar mejor las
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis
stem(ndib,equisdib,'fill');
title('x8(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache
stem(ndib,hachedib,'fill');
title('x8(n)');
pause;
zeros(1,Lx+1)];
b. x9(n) * x9(n)
Convolucin de dos seales idnticas finitas. La respuesta tiene forma
triangular como en el caso anterior. La duracin de la seal de
convolucin es igual al doble de la duracin de x9(n), menos uno.
%Solucin ejercicio_5_b
clear all;
% Definicion de las seales a convolucionar
Lx=10; %Longitud de x(n)
equis=[ones(1,10)]; %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=10; %Longitud de h(n)
hache=[ones(1,10)]; %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib,'fill');
title('x9(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('x9(n)');
pause;
c. x8(n) * x9(n)
Convolucin de dos seales finitas. La respuesta tiene forma
geomtrica como en los casos anteriores. La duracin de la seal de
convolucin es igual a:
Duracin de y(n) = Duracin de x8(n) + Duracin de x9(n) - 1
%Solucin ejercicio_5_c
clear all;
% Definicion de las seales a convolucionar
Lx=5; %Longitud de x(n)
equis=[ones(1,5)]; %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=10; %Longitud de h(n)
hache=[ones(1,10)]; %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib,'fill');
title('x8(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('x9(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x8(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('x9(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x8(k)x9(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
stem(ndib,equisdib,'fill');
title('x8(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('x9(n-3)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x8(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('x9(n-3-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x8(k)x9(n-3-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('x9(n-4-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x8(k)x9(n-4-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
f. x11(n) * x8(n)
%Solucin ejercicio_5_f
clear all;
% Definicion de las seales a convolucionar
Lx=36; %Longitud de x(n)
equis=sin(pi*(0:Lx-1)/12 + pi/4); %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=5; %Longitud de h(n)
hache=[ones(1,5)]; %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib,'fill');
title('x11(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('x8(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x11(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('x8(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x11(k)x8(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x11(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('x10(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x11(k)x10(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
i. x10(n) * x9(n)
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
j. x10(n) * x10(n)
Se observa la convolucin de dos seales idnticas. La convolucin
que obtenemos en este caso no tiene una forma simtrica. La seal
de convolucin se extiende desde n=0 hasta n=28
%Solucin ejercicio_5_j
clear all;
% Definicion de las seales a convolucionar
Lx=15; %Longitud de x(n)
equis=(7/8).^(0:Lx-1); %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=15; %Longitud de h(n)
hache=(7/8).^(0:Lh-1); %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
zeros(1,Lx+1)];
zeros(1,Lx+1)];
x1(n) = [1 4 2 3 5 3 3 4 5 7 6 9]
x2(n) = [1 1]
x3(n) = [1 2 1]
zeros(1,Lx+1)];
title('x3(k)(x1(n-k)+x2(n-k))')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
figure(2);
yden(n+1)=sum(xdek.*hdenmenosk);
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('x3(n) * [x1(n) + x2(n)]')
xlabel('n')
grid;
x3(n) * x1(n) = [1 6 11 11 13 16 14 13 16 21 25 28 24 9]
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('x2(n)');
grid;
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x3(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('x2(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x3(k)x2(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
figure(3);
yden(n+1)=sum(xdek.*hdenmenosk);
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('x3(n) * x2(n)')
xlabel('n')
grid;
x3(n) * x2(n) = [ 1 3 3 1 ]
Sumamos las convoluciones halladas:
%Solucin ejercicio_6_b_4
clear all;
n=-3:16;
x1n=[zeros(1,3) 1 6 11 11 13 16 14 13 16 21 25 28 24 9
zeros(1,3)];
x2n=[zeros(1,3) 1 3 3 1 zeros(1,13)];
xn=x1n+x2n;
figure(5);
stem(n,xn,'fill');
grid on;
title('x3(n)*x1(n) + x3(n)*x2(n)');
xlabel('n');
x3(n)*x1(n) + x3(n)*x2(n) = [ 2 9 14 12 13 16 14 13 16 21 25 28 24 9
]
x2(n) * 4_d
x1(n) = [1, 4, 2, 3, 5, 3, 3, 4, 5, 7, 6, 9]
x2(n) = [1, 1]
x3(n) = [1, 2, 1]
Del ejercicio _4_a:
x1(n) * x2(n) = [1, 5, 6, 5, 8, 8, 6, 7, 9, 12, 13,
15, 9]
Del ejercicio_4_b: x1(n) * x3(n) = [1, 6, 11, 11, 13, 16, 14, 13, 16, 21,
25, 28, 24, 9]
Resolviendo el primer miembro:
%Solucin ejercicio_6_c_1
clear all;
% Definicion de las seales a convolucionar
Lx=13; %Longitud de x(n)
equis=[1 5 6 5 8 8 6 7 9 12 13 15 9]; %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=3; %Longitud de h(n)
hache=[1 2 1]; %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib,'fill');
title('x(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('h(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('h(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x(k)h(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
%Solucin ejercicio_6_c_2
clear all;
% Definicion de las seales a convolucionar
Lx=2; %Longitud de x(n)
equis=[1 1]; %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=14; %Longitud de h(n)
hache=[1 6 11 11 13 16 14 13 16 21 25 28 24 9]; %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib,'fill');
title('x(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib,'fill');
title('h(n)');
pause;
% Bucle que realiza la convolucion
for n=0:Lx+Lh-1
% Construccion y dibujo de x(k)
xdek=[zeros(1,Lh) equis zeros(1,Lh+1)];
subplot(221)
stem(ndib,xdek,'fill');
title('x(k)')
xlabel('k')
grid;
% Construccion y dibujo de h(n-k)
hdenmenosk=[zeros(1,n+1) hache(Lh:-1:1) zeros(1,Lx+Lh-n)];
subplot(223)
stem(ndib,hdenmenosk,'fill');
title('h(n-k)')
xlabel('k')
grid;
% Dibujo de x(k)h(n-k)
subplot(222)
stem(ndib,xdek.*hdenmenosk,'fill');
title('x(k)h(n-k)')
xlabel('k')
grid;
% Obtencion y dibujo de y(n)
yden(n+1)=sum(xdek.*hdenmenosk);
subplot(224)
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
pause;
end;
figure(5);
stem(-1:Lx+Lh,[0 yden zeros(1,Lx+Lh-n)],'fill');
title('y(n)')
xlabel('n')
grid;
VI. ANEXO
Programa convolucion.m
%********************************************************************
*
%
% Nombre: convolucion.m
%
% Objetivo: calcula la convolucin de dos seales paso
% a paso visualizando los resultados intermedios
%
%
%********************************************************************
*
clear all;
% Definicion de las seales a convolucionar
Lx=48; %Longitud de x(n)
equis=sin(pi*(0:Lx-1)/12 + pi/4); %x(n)
if size(equis) ~= Lx
error('Error: la senhal x(n) esta mal definida')
end;
Lh=15; %Longitud de h(n)
hache=(7/8).^(0:Lh-1); %h(n)
if size(hache) ~= Lh
error('Error: la senhal h(n) esta mal definida')
end;
% Dibujo de x(n) y h(n). Se aaden Lh ceros antes y despues
% para visualizar mejor las seales
ndib=-Lh:Lx+Lh;
subplot(211)
equisdib=[zeros(1,Lh) equis zeros(1,Lh+1)];
stem(ndib,equisdib);
title('x(n)');
subplot(212)
hachedib=[zeros(1,Lh) hache zeros(1,Lx+1)];
stem(ndib,hachedib);
title('h(n)');
pause;