You are on page 1of 6

clc

clear
%problem1
n1=0:3;
x1=(0.6.^n1);
h1=flip(x1);
Z1=conv(flip(x1),h1)

Z1 = 1×7
0.0467 0.1555 0.3888 0.8640 1.0800 1.2000 1.0000

figure
stem(-6:0,Z1)
xlabel('n');
ylabel('z(n)');
title('problem 1');

%problem2
x2=[-1 1 -1 1 -1 1];
nx2=-4:1;
y2=[-1 1 -1 1 -1 1];
ny2=-3:2;
[ryx,nyx]=conv_m(y2,ny2,flip(x2),nx2)

ryx = 1×11
-1 2 -3 4 -5 6 -5 4 -3 2 -1
nyx = 1×11
-7 -6 -5 -4 -3 -2 -1 0 1 2 3

1
ryx2 = xcorr(y2,x2)

ryx2 = 1×11
-1.0000 2.0000 -3.0000 4.0000 -5.0000 6.0000 -5.0000 4.0000

figure
stem(nyx,ryx)
xlabel('n');
ylabel('ryx');
title('problem 2');

%problem3
n3=0:2;
x3a=exp(0.6*n3);
x3=[0 0 0 x3a 0];
[xe, xo, m] = evenodd(flip(x3),-3:3);
figure
subplot(2,2,1)
stem(m,xe,'r','filled','markersize',3)
title('Even Part')
xlabel('n'), ylabel('xe(n)')
subplot(2,2,2)
stem(m,xo,'b','filled','markersize',3)
title('Odd Part')
xlabel('n'), ylabel('xo(n)')
subplot(2,2,3)

2
stem(-3:3,flip(x3),'b','filled','markersize',3)
title('x(-n)')
xlabel('n'), ylabel('x(-n)')

%problem 4
n4=-3:3;
x4=exp((0.2+(pi/4)*1j)*n4);
x4c= conj(x4);
figure
subplot(2,1,1);
stem(n4,real(x4c),'r');
title('real part of x*[n]');xlabel('n')
subplot(2,1,2);
stem(n4,imag(x4c),'m');
title('imaginary part of x*[n]');xlabel('n')

3
%problem 5
n5=-3:3;
x5=exp((0.1-(pi/3)*1j)*n5);
x5c= conj(x5);
x5f=flip(x5c);
figure
subplot(2,1,1);
stem(n5,real(x5f),'r');
title('real part of x*[-n]');xlabel('n')
subplot(2,1,2);
stem(n5,imag(x5f),'m');
title('imaginary part of x*[-n]');xlabel('n')

4
function [y,ny] = conv_m(x,nx,h,nh)
% Modified convolution routine for signal processing
% --------------------------------------------------
% [y,ny] = conv_m(x,nx,h,nh)
% [y,ny] = convolution result
% [x,nx] = first signal
% [h,nh] = second signal
%
nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h));
ny = [nyb:nye]; y = conv(x,h);
end

function [xe, xo, m] = evenodd(x,n2)


if any(imag(x) ~= 0)
error('x is not a real sequence')
end
m = -fliplr(n2);
m1 = min([m,n2]); m2 = max([m,n2]); m = m1:m2;

5
nm = n2(1)-m(1); n1 = 1:length(n2);
x1 = zeros(1,length(m)); x1(n1+nm) = x; x = x1;
xe = 0.5*(x + fliplr(x)); xo = 0.5*(x - fliplr(x));
end

You might also like