You are on page 1of 5

n = [0:25];

x1 = zeros(1,26);
for m=0:10,
x1 = x1 + (m-1).*(impseq(2.*m,0,25)-impseq(2.*m+1,0,25));
end
subplot(3,2,1);
stem(n,x1);
title('Sequence in Problem 2.1a')
% P2.1b
n = [-25:25];
x2 = n.^2.*(stepseq(-5,-25,25)-stepseq(6,-25,25)) + 10*impseq(0,-25,25)
+ 20*0.5.^n.*(stepseq(4,-25,25)-stepseq(10,-25,25));
subplot(3,2,2);
stem(n,x2);
title('Sequence in Problem 2.1b')
% P2.1c
n = [0:20];
x3 = 0.9.^n.*cos(0.2*pi.*n + pi/3);
subplot(3,2,3);
stem(n,x3);
title('Sequence in Problem 2.1c')
% P2.1d
n = [0:100];
x4 = 10.*cos(0.008*pi.*n.^2) + randn(size(n));
subplot(3,2,4);
stem(n,x4);
title('Sequence in Problem 2.1d')
% P2.1e
x5 = [2,1,2,3];
x5 = x5' * ones(1,5);
% Plots 5 periods
x5 = (x5(:))';
n = [0:size(x5)];
subplot(3,2,5);
stem(x5);
title('Sequence in Problem 2.1e')

prob:2
clear; clc;
% P2.2
x = [1,-2,4,6,-5,8,10];
n = [-4:2];
subplot(3,2,1); stem(n,x); title('Original Sequence');
% P2.2a
[x11,n11] = sigshift(x,n,-2);
[x12,n12] = sigshift(x,n,4);
[x1,n1] = sigadd(3*x11,n11,x12,n12);
[x1,n1] = sigadd(x1,n1,-2*x,n);
subplot(3,2,2); stem(n1,x1); title('Sequence in Problem 2.2a');
% P2.2b
[x21,n21] = sigshift(x,n,-5);

[x22,n22] = sigshift(x,n,-4);
[x2,n2] = sigadd(5*x21,n21,4*x22,n22);
[x2,n2] = sigadd(x2,n2,3*x,n);
subplot(3,2,3); stem(n2,x2); title('Sequence in Problem 2.2b');
% P2.2c
[x31,n31] = sigshift(x,n,-4);
[x32,n32] = sigshift(x,n,1);
[x33,n33] = sigmult(x31,n31,x32,n32);
[x31,n31] = sigfold(x,n);
[x31,n31] = sigshift(x31,n31,2);
[x32,n32] = sigmult(x31,n31,x,n);
[x3,n3] = sigadd(x33,n33,x32,n32);
subplot(3,2,4); stem(n3,x3); title('Sequence in Problem 2.2c');
% P2.2d
[x41,n41] = sigshift(x,n,-2);
x42 = cos(0.1*pi*n);
[x42,n42] = sigmult(x42,n,x41,n41);
x43 = 2*exp(0.5*n);
[x41,n41] = sigmult(x43,n,x,n);
[x4,n4] = sigadd(x42,n42,x41,n41);
subplot(3,2,5); stem(n4,x4); title('Sequence in Problem 2.2d');
% P2.2e
x5 = zeros(size(n));
for k = 1:5,
[x51,n51] = sigshift(x,n,k);
x52 = n.*x51;
x5 = sigadd(x5,n51,x52,n51);
end
subplot(3,2,6); stem(n51,x5); title('Sequence in Problem 2.2e');
%colordef white

% Default Color Scheme

P:3

clear; clc;
% P2.3b
n = -20:20;
x = cos (0.3*pi*n);
% Periodic Sequence T = 20/3
subplot(2,1,1); plot(n,x,'ko-');title('cos(0.3\pin)');xlabel('n');
% P2.3c
x = cos (0.3*n);
% Non-Periodic Sequence
subplot(2,1,2); plot(n,x,'ko-');title('cos(0.3n)');xlabel('n');

prob:4

clear; clc;
% P2.4
x = [1,-2,4,6,-5,8,10];
n = [-4:2];
% P2.4a
[x11,n11] = sigshift(x,n,-2);
[x12,n12] = sigshift(x,n,4);
[x1,n1] = sigadd(3*x11,n11,x12,n12);
[x1,n1] = sigadd(x1,n1,-2*x,n);
[xe,xo,m] = evenodd(x1,n1);
figure(1);
subplot(2,2,1); stem(n1,x1,'ko'); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe,'ko'); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')
xlabel('n'); ylabel('xo(n)');
% P2.4b
[x21,n21] = sigshift(x,n,-5);
[x22,n22] = sigshift(x,n,-4);
[x2,n2] = sigadd(5*x21,n21,4*x22,n22);
[x2,n2] = sigadd(x2,n2,3*x,n);
[xe,xo,m] = evenodd(x2,n2);
figure(2);
subplot(2,2,1); stem(n2,x2,'ko'); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe,'ko'); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')
xlabel('n'); ylabel('xo(n)');
% P2.4c
[x31,n31] = sigshift(x,n,-4);
[x32,n32] = sigshift(x,n,1);
[x33,n33] = sigmult(x31,n31,x32,n32);
[x31,n31] = sigfold(x,n);
[x31,n31] = sigshift(x31,n31,2);
[x32,n32] = sigmult(x31,n31,x,n);
[x3,n3] = sigadd(x33,n33,x32,n32);
[xe,xo,m] = evenodd(x3,n3);
figure(3);
subplot(2,2,1); stem(n3,x3,'ko'); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe,'ko'); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')
xlabel('n'); ylabel('xo(n)');
% P2.4d
[x41,n41] = sigshift(x,n,-2);
x42 = cos(0.1*pi*n);
[x42,n42] = sigmult(x42,n,x41,n41);
x43 = 2*exp(0.5*n);

[x41,n41] = sigmult(x43,n,x,n);
[x4,n4] = sigadd(x42,n42,x41,n41);
[xe,xo,m] = evenodd(x4,n4);
figure(4);
subplot(2,2,1); stem(n4,x4,'ko'); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe,'ko'); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')
xlabel('n'); ylabel('xo(n)');
% P2.4e
x5 = zeros(size(n));
for k = 1:5,
[x51,n51] = sigshift(x,n,k);
x52 = n.*x51;
x5 = sigadd(x5,n51,x52,n51);
end
[xe,xo,m] = evenodd(x5,n51);
figure(5);
subplot(2,2,1); stem(n51,x5,'ko'); title('Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,2,2); stem(m,xe,'ko'); title('Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(2,2,4); stem(m,xo,'ko'); title('Odd Part')
xlabel('n'); ylabel('xo(n)');

prob:5

clear; clc;
% P2.5
n = 0:10;
x = 10*exp(-j*0.4*pi*n);
[xe, xo, m] = evenoddcomplex(x,n);
subplot(3,2,1); stem(n,real(x),'ko'); title('Real Original Sequence')
xlabel('n'); ylabel('x(n)');
subplot(3,2,3); stem(m,real(xe),'ko'); title('Real Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(3,2,5); stem(m,real(xo),'ko'); title('Real Odd Part')
xlabel('n'); ylabel('xo(n)');
subplot(3,2,2); stem(n,imag(x),'ko'); title('Imaginary Original
Sequence')
xlabel('n'); ylabel('x(n)');
subplot(3,2,4); stem(m,imag(xe),'ko'); title('Imaginary Even Part')
xlabel('n'); ylabel('xe(n)');
subplot(3,2,6); stem(m,imag(xo),'ko'); title('Imaginary Odd Part')
xlabel('n'); ylabel('xo(n)');

p:6

% P2.6a
%colordef white
% Default Color Scheme
n = -50:50;
x = sin(0.125*pi*n);
subplot(2,2,1); plot(n,x,'ko-'); title('Original Signal
sin(0.125\pin)');
[y,m] = dnsample(x,n,4);
subplot(2,2,3); plot(m,y,'ko-'); title('Down-Sampled Signal by a factor
of 4');
axis([m(1),m(end),-1,1]);
% P2.6b
x = sin(0.5*pi*n);
subplot(2,2,2); plot(n,x,'ko-'); title('Original Signal sin(0.5\pin)');
[y,m] = dnsample(x,n,4);
subplot(2,2,4); plot(m,y,'ko-'); title('Down-Sampled Signal by a factor
of 4');
axis([m(1),m(end),-1,1]);

p:7
% P2.7
clear; clc;
n1 = 0:20;
x1 = 0.9.^n1;
subplot(3,2,1); stem(n1,x1,'ko'); title('First given sequence x1(n)');
axis([-20 20 0 1]);
[x1f,n1f] = sigfold(x1,n1);
% obtain x1(-n)
n2 = -20:0;
x2 = 0.8.^(-n2);
subplot(3,2,2); stem(n2,x2,'ko'); title('Second given sequence
x2(n)');
axis([-20 20 0 1]);
[x2f,n2f] = sigfold(x2,n2);
% obtain x2(-n)
[r,nr] = conv_m(x1,n1,x1f,n1f);
% auto-correlation
subplot(3,2,3); stem(nr,r,'ko'); title('Auto-Correlation x1(n)*x1(n)');
[r,nr] = conv_m(x2,n2,x2f,n2f);
% auto-correlation
subplot(3,2,4); stem(nr,r,'ko'); title('Auto-Correlation x2(n)*x2(n)');
[r,nr] = conv_m(x1f,n1f,x2,n2);
% cross-correlation
subplot(3,1,3); stem(nr,r,'ko'); title('Cross-Correlation');

You might also like