Está en la página 1de 6

TallerÊ1ÊMatlabÊ- ProcesamientoÊdeÊSeñalesÊÊ BayrónÊDavidÊMoralesÊ-6000408

miércoles, 8 de septiembre de 2021 10:02 a. m.

Para el desarrollo de este taller se crearon scripts para cada una de las operaciones, como:
• Suma
1. X5 [n] = 3 x1 [2n - 4] + 1⁄4 x2 [3 - n] + x4 [n + 1]
• Resta
2. X7 [n] = x1 [n] * x2 [n] – x3 [n] * x4 [n] • Multiplicación
• Desplazamiento
• Diezmado
Recordar: • Interpolación
- d [n] = Señal Delta Dirac
- u [n] = Señal Escalón Unitario El código general y el de dichas funciones se encuentra al final del documento

Solución
Se grafican las señales
clc, clear, close;

x1=[0, 1, 2, 3, -3, -2, -1, 0];

x2=[6, 5, 4, 3, 2, 1, 0, -1, -2];


n2= -3:1:5;

x3= [2, -2, 1, -1, 3, -3, 0, 5, -5];


n3= -2:1:6;

x4= [3, 2, 1, 0, 1, 0, 1, 2, 3, 4];


n4= -5:1:4;

%Graficas
subplot(4, 1, 1)
grafica1 = stem(x1, 'filled');
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x1[n]');
legend('x1[n]');

subplot(4, 1, 2)
grafica2 = stem(n2,x2, 'filled');
grafica2.Color = 'magenta';
grafica2.LineStyle='-';
title('x2[n]');
legend('x2[n]');

subplot(4, 1, 3)
grafica3 = stem(n3,x3, 'filled');
grafica3.Color = 'red';
grafica3.LineStyle='-';
title('x3[n]');
legend('x3[n]');

subplot(4, 1, 4)
grafica4 = stem(n4,x4, 'filled');
grafica4.Color = 'green';
grafica4.LineStyle='-';
title('x4[n]');
legend('x4[n]');

1. X5 [n] = 3 x1 [2n - 4] + 1⁄4 x2 [3 - n] + x4 [n + 1]

3 x1 [2n - 4]
%3x1[2n-4]
figure
%x1[n]
subplot(4, 1, 1)
grafica1 = stem(n1,x1);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x1[n]');
legend('x1[n]');
%x1[n-4]
subplot(4, 1, 2)
[x, n] = desplazamiento(x1, n1, -4);
grafica1 = stem(n, x);
grafica1.Color = 'red';
grafica1.LineStyle='-';
title('x1[n-4]');
legend('x1[n-4]');
%x1[2n-4]
subplot(4, 1, 3)
[x, n] = desplazamiento(x1, n1, -4);
[x, n] = diezmado(x, n, 2);
grafica1 = stem(n,x);
grafica1.Color = 'red';
grafica1.LineStyle='-';
title('x1[2n-4]');
legend('x1[2n-4]');
%3x1[2n-4]
subplot(4, 1, 4)
[x, n] = desplazamiento(x1, n1, -4);
[x, n] = diezmado(x, n, 2);
grafica1 = stem(n, 3*x);
grafica1.Color = 'red';
grafica1.LineStyle='-';
title('3x1[2n-4]');
legend('3x1[2n-4]');

1⁄4 x2 [3 - n]
%1/4x2[3-n]
figure
%x2[n]
subplot(4, 1, 1)
grafica1 = stem(n2,x2);
grafica1.Color = 'magenta';
%1/4x2[3-n]
figure
%x2[n]
subplot(4, 1, 1)
grafica1 = stem(n2,x2);
grafica1.Color = 'magenta';
grafica1.LineStyle='-';
title('x2[n]');
legend('x2[n]');
%x2[n+3]
subplot(4, 1, 2)
[x, n] = desplazamiento(x2, n2, -3);
grafica1 = stem(n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x2[n+3]');
legend('x2[n+3]');
%x2[-n+3]
subplot(4, 1, 3)
[x, n] = desplazamiento(x2, n2, -3);
grafica1 = stem(-n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x2[-n+3]');
legend('x2[-n+3]');
%1/4x2[-n+3]
subplot(4, 1, 4)
[x, n] = desplazamiento(x2, n2, -3);
x= (1/4)*x;
n=-n;
grafica1 = stem(n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('1/4x2[-n+3]');
legend('1/4x2[-n+3]');

x4 [n + 1]

%x4[n+1]
figure
%x4[n]
subplot(3, 1, 1)
grafica1 = stem(n4,x4);
grafica1.Color = 'red';
grafica1.LineStyle='-';
title('x4[n]');
legend('x4[n]');
%x4[n+1]
subplot(3, 1, 2)
[x, n] = desplazamiento(x4, n4, -1);
grafica1 = stem(n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x4[n+1]');
legend('x4[n+1]');

X5 [n] = 3 x1 [2n - 4] + 1⁄4 x2 [3 - n] + x4 [n + 1]

%3x1[2n-4]+1⁄4 x2[3-n] x4[n+1]


%x4[n+1]
figure
subplot(2, 1, 1)
[ax, an] = desplazamiento(x4, n4, -1);
grafica1 = stem(an,ax);
grafica1.Color = 'cyan';
grafica1.LineStyle='-';
title('Operaciones previas');

hold on;
%1/4x2[-n+3]
[bx, bn] = desplazamiento(x2, n2, -3);
bx= (1/4)*bx;
bn= -1*bn;
grafica1 = stem(bn,bx);
grafica1.Color = 'magenta';
grafica1.LineStyle='-';

hold on;
%3x1[2n-4]
[cx, cn] = desplazamiento(x1, n1, -4);
[cx, cn] = diezmado(cx, cn, 2);
cx= 3*cx;
grafica1 = stem(cn, cx);
grafica1.Color = 'green';
grafica1.LineStyle='-';
legend('x4[n+1]', '1/4 x2 [3 - n]', '3x1[2n-4]');

%3x1[2n-4]+1⁄4 x2[3-n] x4[n+1]


subplot(2, 1, 2)
[dx, dn] = suma(ax, an, cx, cn);
[x, n] = suma(fliplr(bx), fliplr(bn), dx, dn);
grafica1 = stem(n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('3x1[2n-4]+1⁄4 x2[3-n] x4[n+1]');
legend('3x1[2n-4]+1⁄4 x2[3-n] x4[n+1]');

1. X7 [n] = x1 [n] * x2 [n] – x3 [n] * x4 [n]


x1 [n] * x2 [n]

%x1[n]*x2[n]
figure
%x1[n] | x2[n]
subplot(2, 1, 1)
grafica1 = stem(n1,x1);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
hold on;
grafica2 = stem(n2, x2);
grafica2.Color = 'magenta';
grafica2.LineStyle='-';
title('Operaciones Previas');
legend('x1[n]', 'x2[2]');
%x1[n]*x2[n]
subplot(2, 1, 2)
[ax, an] = multiplicar(x1, n1, x2, n2);
grafica1 = stem(an,ax);
grafica1.Color = 'red';
grafica1.LineStyle='-';
title('x1[n]*x2[2]');
legend('x1[n]*x2[2]]');

x3 [n] * x4 [n]

%x3[n]*x4[n]
figure
%x3[n] | x4{n]
subplot(2, 1, 1)
grafica1 = stem(n3,x3);
grafica1.Color = 'red';
grafica1.LineStyle='-';
hold on;
grafica2 = stem(n4, x4);
grafica2.Color = 'green';
grafica2.LineStyle='-';
title('Operaciones Previas');
legend('x3[n]', 'x4[2]');
%x1[n]*x2[n]
subplot(2, 1, 2)
[bx, bn] = multiplicar(x3, n3, x4, n4);
grafica1 = stem(bn,bx);
grafica1.Color = 'cyan';
grafica1.LineStyle='-';
title('x3[n]*x4[2]');
legend('x3[n]*x4[2]]');

X7 [n] = x1 [n] * x2 [n] – x3 [n] * x4 [n]

%x1 [n] * x2 [n] – x3 [n] * x4 [n]


figure
%x1[n]*x2[n] | x3[n]*x4[n]
subplot(2, 1, 1)
grafica1 = stem(an,ax);
grafica1.Color = 'red';
grafica1.LineStyle='-';
hold on;
grafica2 = stem(bn, bx);
grafica2.Color = 'cyan';
grafica2.LineStyle='-';
title('Operaciones Previas');
legend('x1[n]*x2[2]]', 'x3[n]*x4[2]]');
%x1[n]*x2[n]
subplot(2, 1, 2)
[x, n] = resta(ax, an, bx, bn)
grafica1 = stem(n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x1[n]*x2[n] - x3[n]*x4[n]');
legend('x1[n]*x2[n] - x3[n]*x4[n]');

Código General Funciones

• Primer punto • Segundo punto • Suma • Resta

function [x, n] = suma(x1, n1, x2, n2) function [x, n] = resta(x1, n1, x2, n2)
• Primer punto • Segundo punto • Suma • Resta

function [x, n] = suma(x1, n1, x2, n2) function [x, n] = resta(x1, n1, x2, n2)

clc, clear, close all, home; clc, clear, close all, home; if find(~n2)>find(~n1) if find(~n2)>find(~n1)
disp('if') disp('if')
A = zeros(1,find(~n2)-find(~n1)); A = zeros(1,find(~n2)-find(~n1));
x1=[0, 1, 2, 3, -3, -2, -1, 0]; x1=[0, 1, 2, 3, -3, -2, -1, 0];
A=[A, x1]; A=[A, x1];
n1=0:1:7; n1=0:1:7;
B= zeros(1,(size(A,2)-size(x2,2))); B= zeros(1,(size(A,2)-size(x2,2)));
B=[x2, B]; B=[x2, B];
x2=[6, 5, 4, 3, 2, 1, 0, -1, -2]; x2=[6, 5, 4, 3, 2, 1, 0, -1, -2]; else else
n2= -3:1:5; n2= -3:1:5; disp('Else') disp('Else')
A = zeros(1,find(~n1)-find(~n2)); A = zeros(1,find(~n1)-find(~n2));

x3= [2, -2, 1, -1, 3, -3, 0, 5, -5]; x3= [2, -2, 1, -1, 3, -3, 0, 5, -5]; A=[A, x2] A=[A, x2];

n3= -2:1:6; n3= -2:1:6; B= zeros(1,(size(A,2)-size(x1,2))); B= zeros(1,(size(A,2)-size(x1,2)));


B=[x1, B] B=[x1, B];
end end
x4= [3, 2, 1, 0, 1, 0, 1, 2, 3, 4]; x4= [3, 2, 1, 0, 1, 0, 1, 2, 3, 4];
x = A+B x = A-B
n4= -5:1:4; n4= -5:1:4;
posterior = 1:1:size(x, 2)+1-find(~n1)-1; posterior = 1:1:size(x, 2)+1-find(~n1)-1;
anterior =(-find(~n1))+1:0; anterior =(-find(~n1))+1:0;
% %Graficas %x1[n]*x2[n] n = [anterior posterior] n = [anterior posterior];
%figure figure end end
% subplot(4, 1, 1) %x1[n] | x2[n]
% grafica1 = stem(x1, 'filled'); subplot(2, 1, 1)
% grafica1.Color = 'blue'; grafica1 = stem(n1,x1);
% grafica1.LineStyle='-'; grafica1.Color = 'blue';

% title('x1[n]'); grafica1.LineStyle='-'; • Multiplicación • Desplazamiento


% legend('x1[n]'); hold on;
% grafica2 = stem(n2, x2); function [x, n] = multiplicar(x1, n1, x2, n2) function [x, n] = desplazamiento(x1, n1, d)

% subplot(4, 1, 2) grafica2.Color = 'magenta'; if find(~n2)>find(~n1) if find(~n1)<=abs(d)

% grafica2 = stem(n2,x2, 'filled'); grafica2.LineStyle='-'; A = zeros(1,find(~n2)-find(~n1)); if(d>0)

% grafica2.Color = 'magenta'; title('Operaciones Previas'); A=[A, x1]; A = zeros(1,(size(x1,2)+find(~n1)-d));

% grafica2.LineStyle='-'; legend('x1[n]', 'x2[2]'); B= zeros(1,(size(A,2)-size(x2,2))); x=[x1, A];

% title('x2[n]'); %x1[n]*x2[n] B=[x2, B]; n = -size(x, 2)-1:-1:0;

% legend('x2[n]'); subplot(2, 1, 2) else else

% [ax, an] = multiplicar(x1, n1, x2, n2); A = zeros(1,find(~n1)-find(~n2)); A = zeros(1,abs(d)-find(~n1)+1);

% subplot(4, 1, 3) grafica1 = stem(an,ax); A=[A, x2]; x=[A, x1];

% grafica3 = stem(n3,x3, 'filled'); grafica1.Color = 'red'; B= zeros(1,(size(A,2)-size(x1,2))); n = 0:1:size(x, 2)-1;

% grafica3.Color = 'red'; grafica1.LineStyle='-'; B=[x1, B]; end

% grafica3.LineStyle='-'; title('x1[n]*x2[2]'); end else

% title('x3[n]'); legend('x1[n]*x2[2]]'); x = A.*B; n = n1+d;

% legend('x3[n]'); posterior = 1:1:size(x, 2)+1-find(~n1)-1; x= x1;

% anterior =(-find(~n1))+1:0; end

% subplot(4, 1, 4) n = [anterior posterior]; end

% grafica4 = stem(n4,x4, 'filled'); end

% grafica4.Color = 'green'; %x3[n]*x4[n]


% grafica4.LineStyle='-'; figure
% title('x4[n]'); %x3[n] | x4{n]
• Diezmado
% legend('x4[n]'); subplot(2, 1, 1)
grafica1 = stem(n3,x3);
grafica1.Color = 'red';
%3x1[2n-4] function [x, n] = diezmado(x1, n1, i)
grafica1.LineStyle='-';
figure A =[x1(find(~n1))];
hold on;
%x1[n] for j=find(~n1)+i:i:size(x1, 2)
grafica2 = stem(n4, x4);
subplot(4, 1, 1) A=[A, x1(j)];
grafica2.Color = 'green';
grafica1 = stem(n1,x1); end
grafica2.LineStyle='-';
grafica1.Color = 'blue'; for j=find(~n1)-i:-i:size(x1,2)-find(~n1)
title('Operaciones Previas');
grafica1.LineStyle='-'; A=[x1(j), A];
legend('x3[n]', 'x4[2]');
title('x1[n]'); end
%x1[n]*x2[n]
legend('x1[n]'); x=A;
subplot(2, 1, 2)
%x1[n-4] posterior = 1:1:size(x, 2)-find(~n1);
[bx, bn] = multiplicar(x3, n3, x4, n4);
subplot(4, 1, 2) anterior =(-find(~n1))+1:0;
grafica1 = stem(bn,bx);
[x, n] = desplazamiento(x1, n1, -4); n = [anterior posterior];
grafica1.Color = 'cyan';
grafica1 = stem(n, x); end
grafica1.LineStyle='-';
grafica1.Color = 'red';
title('x3[n]*x4[2]');
grafica1.LineStyle='-';
legend('x3[n]*x4[2]]');
title('x1[n-4]');
legend('x1[n-4]');
Evidencias
%x1[2n-4]
subplot(4, 1, 3)
[x, n] = desplazamiento(x1, n1, -4);
%x1 [n] * x2 [n] – x3 [n] * x4 [n]
[x, n] = diezmado(x, n, 2);
figure
grafica1 = stem(n,x);
%x1[n]*x2[n] | x3[n]*x4[n]
grafica1.Color = 'red';
subplot(2, 1, 1)
grafica1.LineStyle='-';
grafica1 = stem(an,ax);
title('x1[2n-4]');
grafica1.Color = 'red';
legend('x1[2n-4]');
grafica1.LineStyle='-';
%3x1[2n-4]
hold on;
subplot(4, 1, 4)
grafica2 = stem(bn, bx);
[x, n] = desplazamiento(x1, n1, -4);
grafica2.Color = 'cyan';
[x, n] = diezmado(x, n, 2);
grafica2.LineStyle='-';
grafica1 = stem(n, 3*x);
title('Operaciones Previas');
grafica1.Color = 'red';
legend('x1[n]*x2[2]]', 'x3[n]*x4[2]]');
grafica1.LineStyle='-';
%x1[n]*x2[n]
title('3x1[2n-4]');
subplot(2, 1, 2)
legend('3x1[2n-4]');
[x, n] = resta(ax, an, bx, bn)
grafica1 = stem(n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x1[n]*x2[n] - x3[n]*x4[n]');
%1/4x2[3-n]
legend('x1[n]*x2[n] - x3[n]*x4[n]');
figure
%x2[n]
subplot(4, 1, 1)
subplot(4, 1, 1)
grafica1 = stem(n2,x2);
grafica1.Color = 'magenta';
grafica1.LineStyle='-';
title('x2[n]');

legend('x2[n]');
%x2[n+3]
subplot(4, 1, 2)
[x, n] = desplazamiento(x2, n2, -3);
grafica1 = stem(n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x2[n+3]');
legend('x2[n+3]');

%x2[-n+3]
subplot(4, 1, 3)
[x, n] = desplazamiento(x2, n2, -3);
grafica1 = stem(-n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x2[-n+3]');
legend('x2[-n+3]');
%1/4x2[-n+3]

subplot(4, 1, 4)
[x, n] = desplazamiento(x2, n2, -3);
x= (1/4)*x;
n=-n;
grafica1 = stem(n,x);
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('1/4x2[-n+3]');
legend('1/4x2[-n+3]');

%x4[n+1]
figure
%x4[n]
subplot(3, 1, 1)

grafica1 = stem(n4,x4);
grafica1.Color = 'red';
grafica1.LineStyle='-';
title('x4[n]');
legend('x4[n]');
%x4[n+1]
subplot(3, 1, 2)
[x, n] = desplazamiento(x4, n4, -1);
grafica1 = stem(n,x);

grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('x4[n+1]');
legend('x4[n+1]');

%3x1[2n-4]+1?4 x2[3-n] x4[n+1]


%x4[n+1]
figure
subplot(2, 1, 1)
[ax, an] = desplazamiento(x4, n4, -1);
grafica1 = stem(an,ax);
grafica1.Color = 'cyan';
grafica1.LineStyle='-';
title('Operaciones previas');

hold on;

%1/4x2[-n+3]
[bx, bn] = desplazamiento(x2, n2, -3);
bx= (1/4)*bx;
bn= -1*bn;
grafica1 = stem(bn,bx);
grafica1.Color = 'magenta';
grafica1.LineStyle='-';

hold on;
%3x1[2n-4]
[cx, cn] = desplazamiento(x1, n1, -4);

[cx, cn] = diezmado(cx, cn, 2);


cx= 3*cx;
grafica1 = stem(cn, cx);
grafica1.Color = 'green';
grafica1.LineStyle='-';
legend('x4[n+1]', '1/4 x2 [3 - n]', '3x1[2n-4]');

%3x1[2n-4]+1?4 x2[3-n] x4[n+1]


subplot(2, 1, 2)
[dx, dn] = suma(ax, an, cx, cn);
[x, n] = suma(fliplr(bx), fliplr(bn), dx, dn);

grafica1 = stem(n,x);
grafica1.Color = 'blue'
grafica1.Color = 'blue';
grafica1.LineStyle='-';
title('3x1[2n-4]+1/4 x2[3-n] x4[n+1]');
legend('3x1[2n-4]+1/4 x2[3-n] x4[n+1]');

%[x, n]=suma(bx, bn, cx, cn)

También podría gustarte