You are on page 1of 5

MATLAB PROGRAMS

 Generating step, ramp, impulse, exponential and sin waves: -

n=-5:0.5:5; n=-5:0.5:5;
x1=1; N=5;
x2=0; f=1/5;
y=x1.*(n>=0)+x2.*(n<0); y=sin(2*pi*f*n);
subplot(1,5,1); subplot(1,5,5);
stem(n,y); stem(n,y);
xlabel('time'); xlabel('time');
ylabel('amplitude'); ylabel('amplitude');
title('unit step'); title('sin');
n=-5:0.5:5;
x1=n;
x2=0;
y=x1.*(n>=0)+x2.*(n==0);
subplot(1,5,2);
stem(n,y);
xlabel('time');
ylabel('amplitude');
title('unit ramp');
n=-5:0.5:5;
x1=1;
x2=0;
y=x1*(n==0)+x2*(n~=0);
subplot(1,5,3);
stem(n,y);
xlabel('time');
ylabel('amplitude');
title('unit impulse');
n=-5:0.5:5;
A=0.8;
x=(A).^n;
subplot(1,5,4);
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('exp');
 MATLAB program to find the even and odd parts of the signal x(n)=0.5 n

n = -4 :1:4;
A=0.5;
x1=A.^n;
x2=A.^(-n);
xe=(x1+x2)/2;
subplot(1,4,3);
stem(n,xe);
grid on;
xlabel('n');
ylabel('xe');
title('even part');
xo=(x1-x2)/2;
subplot(1,4,4);
stem(n,xo);
grid on;
xlabel('n');

ylabel('xo');
title('odd part');
x=x1;
subplot(1,4,1);
stem(n,x);
grid on;
xlabel('n');
ylabel('x');
title('x(n)signal');
x3=x2;
subplot(1,4,2);
stem(n,x3);
grid on;
xlabel('n');
ylabel('x');
title('x(-n)signal');
 Write a MATLAB program to perform convolution of the following
discrete time signals.
x1(n)=1; 1<n<10 x2(n)=1; 2<n<10

x1=[2,3,4,5,6,7,8,9];
x2=[3,4,5,6,7,8,9];
n1=length(x1);
n2=length(x2);
x=max(n1,n2);
x3=cconv(x1,x2,x);
subplot(1,2,1);
stem(x3);
grid on;
xlabel('n');
ylabel('x3');
title('circular convolution');
x4=conv(x1,x2);
subplot(1,2,2);
stem(x4);
grid on;
xlabel('n');
ylabel('x3');
title('linear convolution');

 MATLAB program to perform amplitude scaling and time shift on the


signal x(n+2); for n =0 to 2.

n=0:2;
x=[1,2,3];
subplot(2,1,1);
stem(n,x);
title('Signal x(n)');
grid on;
m=n-2;
y=2*x;
subplot(2,1,2);
stem(m,y);
title('signal 2x(n+2)');
grid on;
 Write a MATLAB program to find one-sided Z-transform of the
following standard causal signals.
(i) a (ii) an (iii) 1+n(0.4)n-1

syms n a;
f=a;
F=ztrans(f);
disp('z transform of “a” is');
disp(F)
f1=a^n;
F1=ztrans(f1);
disp('z transform of “a^n” is');
disp(F1)
f2=1+n*(0.4)^n-1;
F2=ztrans(f2);
disp('z transform of “1+n*(0.4)^n-1” is');
disp(F2)

OUTPUT: -

z transform of “a” is

z/(z - 1)^2

z transform of “a^n” is

-z/(a - z)

z transform of “1+n*(0.4)^n-1” is

(10*z)/(5*z - 2)^2
 Write a MATLAB program to perform convolution of signals x1(n) =
(0.4) n u(n) and x2(n)= (0.5)n u(n). Using z-transform and then to perform
deconvolution using the result of convolution to extract x1(n) and x2(n).

syms n ;
x1=(0.4^n);
x2=(0.5^n);
x1z=ztrans(x1);
x2z=ztrans(x2);
x3z=x1z*x2z;
con12=iztrans(x3z);
disp('convolution of x1(n) and x2(n)');
disp(con12)
decon_x1z=x3z/x2z;
decon_x1n=iztrans(decon_x1z);
disp('the deconvolution result of x1(n) is');
disp(decon_x1n)
decon_x2z=x3z/x1z;
deconx1n=iztrans(decon_x2z);
disp('the deconvolution result of x2(n) is');
disp(deconx1n)

OUTPUT

convolution of x1(n) and x2(n)

5*(1/2)^n - 4*(2/5)^n

the deconvolution result of x1(n) is

(2/5)^n

the deconvolution result of x2(n) is

(1/2)^n

You might also like