1. Consider a signal x(n)={1,2,3,4}, write a MATLAB code to perform the following operations.
a. Amplitude Inversion
b. Amplitude scaling with a scaling factor of 3.
c. Clamping with value 4.
clc;
clear all;
x=[1 2 3 4];
n=[0 1 2 3];
x1=-x;
subplot(1,3,1)
stem(n,x1) %plot discrete time sequence
xlabel('n')
ylabel('-x(n)')
title('Amplitude Inversion')
x2=3.*x;
subplot(1,3,2)
stem(n,x2)
xlabel('n')
ylabel('3x(n)')
title('Amplitude Scaling')
x3=x+4;
subplot(1,3,3)
stem(n,x3)
xlabel('n')
ylabel('x(n)')
title('Clamping with 4')
2. Consider a signal x(n)={1,2,3,4}, write a MATLAB code to perform the following
a. Time inversion
b. Time shift
c. Time scaling
clc;
clear all;
x=[1 2 3 4];
n=[0 1 2 3];
n1=-n;
n2=n+2;
n3=3.*n;
subplot(2,2,1)
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('X(n)')
subplot(2,2,2),stem(n1,x);
xlabel('n')
ylabel('x(-n)')
title('Time Inversion')
subplot(2,2,3),stem(n2,x);
xlabel('n')
ylabel('x(n+2)')
title('Time shifting')
subplot(2,2,4),stem(n3,x);
xlabel('n')
ylabel('3x(n)')
title('Time Scaling')
3. Write a MATLAB code to generate even and odd parts of the signal x(t)=1+t+t2+t3+t4+t5.
clc;
clear all;
t=0:1:2
x1=1+t+t.^2 +t.^3+t.^4+t.^5
t1=-t;
x2=1+t1.^1+t1.^2 +t1.^3+t1.^4+t1.^5
xe=0.5*(x1+x2)
xo=0.5*(x1-x2)
subplot(2,1,1), plot(t,xe)
xlabel('t');
ylabel('xe(t)');
title('even part');
subplot(2,1,2), plot(t,xo)
xlabel('t');
ylabel('xo(t)');
title('odd part');
OUTPUT:
t=
0 1 2
x1 =
1 6 63
x2 =
1 0 -21
xe =
1 3 21
xo =
0 3 42
4. Write a MATLAB code to check whether the systems represented by the following difference
equations with input x(n) and output y(n) are linear or not.
a. y(n) = 2x(n)[u(n) − u(n − 7]
b. y(n) = log10 |x(n)|
(a)
n=0:1:10;
x=1:1:11;
x1=2.*x;
x2=3.^x;
u=1.*(n>=0);
u1=1.*(n>=7)+0.*(n<7);
y1=(2.*x1).*(u-u1) + (2.*x2).*(u-u1)
y2=(2.*(x1+x2)).*(u-u1)
if(y1==y2)
disp('Linear system')
else
disp('Non Linear System')
end
(b)
n=[0 1 2 3];
x=[1 2 3 4];
x1=2.*x;
x2=3.^x;
y1=log(x1)+log(x2)
y2=log(x1+x2)
if(y1==y2)
disp('Linear system')
else
disp('Non Linear System')
end
1). WRITE A MATLAB CODE TO FIND CONVOLUTION OF TWO DIFFERENT
TIME SEQUENCES.
X1= [1 2 3 4 5] AND X2= [1 2 1 1].
clc;
clear all;
close all;
disp('ENG20EC0062')
x1=[1 2 3 4 5];
x2=[1 2 1 1];
con=conv(x1,x2)
2). WRITE A MATLAB CODE TO FIND THE AUTOCORRELATION OF THE
SEQUENCE x(n) = Sin(n).
clc;
clear all;
close all;
disp('ENG20EC0062')
n=0:1:10;
x=sin(n);
subplot(2,1,1)
stem(x)
xlabel('n')
ylabel('sin(n)')
title('ENG20EC0062')
R11=xcorr(x,x);
subplot(2,1,2)
stem(R11)
xlabel('T')
ylabel('R (T)')
title('Auto correlation function')
3).WRITE A MATLAB CODE TO FIND Z-TRANSFORMS AND INVERSE Z-
TRANSFORMS OF GIVEN SEQUENCES. X(n) =cos(n*w).
clc;
clear all;
close all;
syms n w
disp('ENG20EC0062')
x1 = n + 1
y1=ztrans(x1)
iztrans(y1)
x2=cos(n*w)
y2=ztrans(x2)
iztrans(y2)
4). WRITE A MATLAB CODE TO GET FOURIER TRANSFORM OF A
RECTANGULAR PULSE.
clc;
clear all;
close all;
disp('ENG20EC0062')
syms a b t
x = rectangularPulse(a,b,t);
FT = fourier(x)
5). WRITE A MATLAB CODE TO GENERATE EXPONENTIAL FOURIER
SERIES OF A PERIODIC FULL WAVE RECTIFIED SIGNAL.
clc;
clear all;
close all;
syms n
disp('ENG20EC0062')
t=0:0.5:2*pi;
x=abs(sin(t));
T=2;
W=2*pi/T;
x1 = x.*exp(-1i.*t*n*W);
Cn=x1/T