Академический Документы
Профессиональный Документы
Культура Документы
LAB RECORD
K.Sahithi
09071A0489
Operations on the matrix
1
2
3
0 - 1.0000i
2.0000 - 4.0000i
-3.0000 - 4.0000i
AIM:Create a row matrix, find sum of elements of matrix
PROCEDURE:
b=[4 5 7 9 4]
sum(b)
b=
4 5 7 9 4
s=
29
PROCEDURE:
m=mean(b)
m=
5.8000
PROCEDURE:
l=length(b)
l=
5
PROCEDURE:
m1=max(b)
m2=min(b)
m1 =
9
m2 =
4
PROCEDURE:
p=prod(b)
p=
5040
PROCEDURE:
s1=sign(b)
s1 =
1 1 1 1 1
PROCEDURE:
f=find(b)
f=
1 2 3 4 5
PROCEDURE:
a1=sort(b,'ascend')
d=sort(b,'descend')
a1 =
4 4 5 7 9
d=
9 7 5 4 4
OPERATIONS ON MXN MATRICES
AIM:Create a mxn matrix & measure its size
PROCEDURE:
1 2 3 4
5 6 7 8
9 10 11 12
3 4
m2 =
1 2
3 4
5 6
7 8
m2 =
1 2
3 4
5 6
m2 =
1 2 10
3 4 11
5 6 12
AIM:To make a 5x3 matrix into a 4x3 matrix:
PROCEDURE:
m3=[1 2 3;4 5 6;7 8 9;10 11 12;13 14 15]
m3(5,: )=[]
m3 =
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
m3 =
1 2 3
4 5 6
7 8 9
10 11 12
1 2
4 5
7 8
10 11
AIM:To create a 6x6 matrix & change it into 2x18, 18x2, 9x4, 4x9,
12x3, 3x12, 1x36, 36x1:
PROCEDURE:
h=[1 2 3 4 5 6;2 3 4 5 6 7;3 4 5 6 7 8;4 5 6 7 8 9;5 6 7 8 9 10;6 7 8 9 10 11]
r1 =
r1 =
Columns 1 through 9
1 3 5 2 4 6 3 5 7
2 4 6 3 5 7 4 6 8
Columns 9 through 18
4 6 8 5 7 9 6 8 10
5 7 9 6 8 10 7 9 11
r2=reshape(h,18,2)
r2 =
1 4
2 5
3 6
4 7
5 8
6 9
2 5
3 6
4 7
5 8
6 9
7 10
3 6
4 7
5 8
6 9
7 10
8 11
r3=reshape(h,9,4)
r3 =
1 5 4 8
2 6 5 9
3 7 6 10
4 3 7 6
5 4 8 7
6 5 9 8
2 6 5 9
3 7 6 10
4 8 7 11
r4=reshape(h,4,9)
r4 =
1 5 4 3 7 6 5 9 8
2 6 5 4 8 7 6 10 9
3 2 6 5 4 8 7 6 10
4 3 7 6 5 9 8 7 11
r5=reshape(h,12,3)
r5 =
1 3 5
2 4 6
3 5 7
4 6 8
5 7 9
6 8 10
2 4 6
3 5 7
4 6 8
5 7 9
6 8 10
7 9 11
r6=reshape(h,3,12)
r6 =
1 4 2 5 3 6 4 7 5 8 6 9
2 5 3 6 4 7 5 8 6 9 7 10
3 6 4 7 5 8 6 9 7 10 8 11
r7=reshape(h,36,1)
r7 =
1
2
3
4
5
6
2
3
4
5
6
7
3
4
5
6
7
8
4
5
6
7
8
9
5
6
7
8
9
10
6
7
8
9
10
11
r8=reshape(h,1,36)
r8 =
Columns 1 through 9
1 2 3 4 5 6 2 3 4
Columns 10 through 18
5 6 7 3 4 5 6 7 8
Columns 19 through 27
4 5 6 7 8 9 5 6 7
Columns 28 through 36
8 9 10 6 7 8 9 10 11
1 2 3
1 0 1
7 8 9
y=[1 2 3;4 5 6;8 9 4]
y=
1 2 3
4 5 6
8 9 4
2 4 6
5 5 7
15 17 13
0 0 0
-3 -5 -5
-1 -1 5
33 39 27
9 11 7
111 135 105
1 4 9
4 0 6
56 72 36
y=
1 2 3
4 5 6
8 9 4
1 1 1
0 0 0
0 0 0
LOGICAL OPERATIONS ON MATRICES
1 1 1
1 0 1
1 1 1
1 1 1
1 1 1
1 1 1
0 0 0
0 1 0
0 0 0
GENERATION OF SIGNALS
t=0:4
y=[1 zeros(1,4)]
stem(t,y,'m')
axis([-5 5 0 2])
title('ploting an impulse at t=0')
grid
AIM: To generate a unit step function
Procedure:
t=-100:100;
x=zeros(1,length(t))
for i=1:length(t)
if t(i)==0
j=i;
end
end
x(j:length(t))=1;
axis([-100 100 0 2])
plot(t,x,'-.m')
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-3
x 10
AIM: To generate sinusoidal pulse train
Procedure:
f=1000
i=10;
T=i/f;
t=0:T/f:T;
x=sin(2*pi*f*t);
plot(t,x)
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
AIM: To generate sawtooth pulse
Procedure:
t=0:200
x=zeros(1,length(t));
x(1:200)=t(1:200);
plot(t,x,'--r')
Title:triangular pulse
AIM: To generate sawtooth pulse train
Procedure:
t=0:500;
x=zeros(1,length(t));
x(1:500)=t(1:500);
y1=zeros(1,1000);
y1=x;
for k=1:3
y1(k*length(t)+1:k*length(t)+length(t))=y1(1:length(t))
end
plot(y1,'--r')
500
450
400
350
300
250
200
150
100
50
0
0 500 1000 1500 2000 2500
AIM: To generate triangular pulse train
Procedure:
t=0:200;
x=zeros(1,length(t));
x(1:100)=t(1:100);
x(101:200)=100-t(1:100);
y1=zeros(1,1000);
y1=x;
for k=1:3
y1(k*length(t)+1:k*length(t)+length(t))=y1(1:length(t))
end
plot(y1,'--r')
100
90
80
70
60
50
40
30
20
10
0
0 100 200 300 400 500 600 700 800 900
AIM: To generate ramp function
Procedure:
%ramp
t=0:100;
x=t;
plot(t,x,'--r')
100
90
80
70
60
50
40
30
20
10
0
0 10 20 30 40 50 60 70 80 90 100
AIM: To generate sinc function
Procedure:
f=10
T=1/f
t=-pi:T:pi
x=sin(2*pi*t)./t
plot(t,x,'-.C')
7
x 10
4
3.5
2.5
1.5
0.5
-0.5
-1
-0.01 -0.008 -0.006 -0.004 -0.002 0 0.002 0.004 0.006 0.008 0.01
ADDITION OF SIGNALS
AIM: To generate add two sine signals
Procedure:
f1=1000
i=10
T1=i/f1
t1=0:T1/f1:T1
y=sin(2*pi*f1*t1)
f2=1000
i=5
T2=i/f2
t2=0:T2/f:T2
y1=sin(2*pi*f2*t2)
y2=y1+y
subplot(3,1,1)
plot(t1,y)
subplot(3,1,2)
plot(t2,y1)
subplot(3,1,3)
plot(t2,y2)
Title: addition of two sinusoidal signals
-1
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
1
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-3
x 10
2
-2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-3
x 10
Substracion of signals
AIM: To substarct a sine signal from another sine signal
Procedure:
f1=1000
i=10
T1=i/f1
t1=0:T1/f1:T1
y=sin(2*pi*f1*t1)
f2=1000
i=5
T2=i/f2
t2=0:T2/f2:T2
y1=sin(2*pi*f2*t2)
y2=y1-y
subplot(3,1,1)
plot(t1,y)
subplot(3,1,2)
plot(t2,y1)
subplot(3,1,3)
plot(t2,y2)
-1
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
1
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-3
x 10
2
-2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-3
x 10
Multiplication of signals
AIM: To multiply two sine signals
Procedure:
f1=1000
i=10
T1=i/f1
t1=0:T1/f1:T1
y=sin(2*pi*f1*t1)
f2=1000
i=5
T2=i/f2
t2=0:T2/f2:T2
y1=sin(2*pi*f2*t2)
y2=y1.*y
subplot(3,1,1)
plot(t1,y)
subplot(3,1,2)
plot(t2,y1)
subplot(3,1,3)
plot(t2,y2)
Title: multiplication of 2 sinusoidal waves
-1
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
1
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-3
x 10
1
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-3
x 10
SAWTOOTH PULSE TRAIN TRANSFORMATION
AIM: To scale and shift a sawtooth pulse train
2X(t):
PROCEDURE:
t=0:2000;
x=zeros(1,length(t));
x(1:500)=t(1:500);
y1=zeros(1,1000);
y1=x;
for k=1:3
y1(k*(length(t)/4)+1:k*(length(t)/4)+(length(t)/4))=y1(1:(length(t)/4))
end
subplot(3,2,1)
plot(t,y1,'--r')
subplot(3,2,2)
plot(t,2*y2,'--c')
Title: Amplitude scaling sawtooth pulse train
X(-t):
PROCEDURE:
t=0:2000;
x=zeros(1,length(t));
x(1:500)=t(1:500);
y1=zeros(1,1000);
y1=x;
for k=1:3
y1(k*(length(t)/4)+1:k*(length(t)/4)+(length(t)/4))=y1(1:(length(t)/4))
end
subplot(3,2,1)
plot(t,y1,'--r')
subplot(3,2,2)
plot(-t,y2,'--c')
PROCEDURE:
t=0:2000;
x=zeros(1,length(t));
x(1:500)=t(1:500);
y1=zeros(1,1000);
y1=x;
for k=1:3
y1(k*(length(t)/4)+1:k*(length(t)/4)+(length(t)/4))=y1(1:(length(t)/4))
end
subplot(3,2,1)
plot(t,y1,'--r')
subplot(3,2,2)
plot(t/3,y2,'--c')
Title: time scaling for sawtooth function
X(t-2):
PROCEDURE:
t=0:2000;
x=zeros(1,length(t));
x(1:500)=t(1:500);
y1=zeros(1,1000);
y1=x;
for k=1:3
y1(k*(length(t)/4)+1:k*(length(t)/4)+(length(t)/4))=y1(1:(length(t)/4))
end
subplot(3,2,1)
plot(t,y1,'--r')
subplot(3,2,2)
plot(t-2,y2,'--c')
TRIANGULAR PULSE TRAIN TRANSFORMATION
Procedure:
t=0:40
x=zeros(1,length(t))
x(1:20)=t(1:20)
x(21:40)=20-t(1:20)
y1=zeros(1,200)
y1=x
for k=1:4
y1(k*(length(t)/2)+1:k*(length(t)/2)+(length(t)/2))=y1(1:(length(t)/2))
end
subplot(3,2,1)
plot(t,x,'--r')
subplot(3,2,2)
plot(t,x-4,'--m')
20 20
10
10
0
0 -10
0 10 20 30 40 0 10 20 30 40
X(t-2):
Procedure:
t=0:40
x=zeros(1,length(t))
x(1:20)=t(1:20)
x(21:40)=20-t(1:20)
y1=zeros(1,200)
y1=x
for k=1:4
y1(k*(length(t)/2)+1:k*(length(t)/2)+(length(t)/2))=y1(1:(length(t)/2))
end
subplot(3,2,1)
plot(t,x,'--r')
subplot(3,2,2)
plot(t-2,x,'--m')
20 20
10 10
0 0
0 10 20 30 40 -20 0 20 40
SINE WAVE TRANSFORMATION
Procedure:
f=2000
i=20
T=i/f
t=0:T/f:T
x=sin(2*pi*f*t)
subplot(3,1,2)
plot(t,x,'--c')
subplot(3,1,1)
plot((t-2),x,'--m')
-1
-2 -1.998 -1.996 -1.994 -1.992 -1.99 -1.988 -1.986
1
-1
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
RECTANGULAR PULSE TRANSFORMATION
Procedure:
t=-200:200
x1=zeros(1,length(t))
x2=zeros(1,length(t))
for i=1:length(t)
if t(i)==0
j==i
end
end
x1(j+50:length(t))=1
x2(j-50:length(t))=1
x3=x2-x1
subplot(2,3,1)
plot(t/3,x3,'--m')
subplot(2,3,2)
plot(2*t,-x3,'--r')
TO FIND EVEN AND ODD PARTS OF A SIGNAL
AIM: To find even and odd parts of IMPULSE SIGNAL
PROCEDURE:
t=[0 1 2 3]
x=[-3 2 1 3]
t1=-fliplr(t)
t(1)=[]
t2=[t1 t]
y=zeros(1,length(t2))
y(length(x):length(y))=x
y1=fliplr(y)
ye=((y+y1)/2)
yo=((y-y1)/2)
subplot(3,1,1)
plot(t2,y)
subplot(3,1,2)
plot(t2,ye)
subplot(3,1,3)
plot(t2,yo)
-5
-3 -2 -1 0 1 2 3
2
-2
-4
-3 -2 -1 0 1 2 3
2
-2
-3 -2 -1 0 1 2 3
AIM: To find even and odd parts of STEP SIGNAL
PROCEDURE:
t=-50:50;
x=zeros(1,length(t));
k=0;
for i=1:length(t)
if t(i)==0
j=i;
while j<length(t)
k=k+1;
x(j:j+10)=k;
j=j+10;
end
end
end
x1=fliplr(x);
xe=(x+x1)/2;
xo=(x-x1)/2;
subplot(3,1,1)
plot(t,x)
subplot(3,1,2)
plot(t,xe)
subplot(3,1,3)
plot(t,xo)
TITLE(even and odd parts of step signal)
AIM: To find even and odd parts of SINE SIGNAL
PROCEDURE:
f=1000
i=10
T=i/f
t=0:T/f:T
x=sin(2*pi*f*t)
t1=-fliplr(t)
t(1)=[]
t2=[t1 t]
y=zeros(1,length(t2))
y(length(x):length(y))=x
y1=fliplr(y)
ye=((y+y1)/2)
yo=((y-y1)/2)
subplot(3,1,1)
plot(t2,y)
subplot(3,1,2)
plot(t2,ye)
subplot(3,1,3)
plot(t2,yo)
PROCEDURE:
x=input('enter first sequence')
n1=input('enter the time axis values of 1st sequence')
y=input('enter the values of 2nd sequence')
n2=input('enter time axis values for 2nd sequence')
a=zeros(min(length(x),length(y)),length(x)+length(y)-1)
for i=1:min(length(x),length(y))
a(i,i:i+length(y)-1)=y
end
for i=1:min(length(x),length(y))
a(i,:)=x(i)*a(i,:)
end
for i=1:length(x)+length(y)-1
c(i)=sum(a(:,i))
end
n=min(n1)+min(n2):max(n1)+max(n2)
stem(n,c)
z=conv(x,y)
title('convolution of signals')
1 2 3 4
n1 =
-1 0 1 2
y=
4 7 8 9
n2 =
0 1 2 3
convolution of signals
70
60
50
40
30
20
10
0
-1 0 1 2 3 4 5
LINEARITY
AIM:to check the system for linearity
PROCEDURE:
x=input(' enter coefficients of input vector')
y=input('enter coefficients of output vector')
n=input('enter no of elements of input sequence')
x1=rand(1,n);
x2=rand(1,n);
y1=filter(x,y,x1);
y2=filter(x,y,x2);
y3=filter(x,y,x1+x2);
y4=y1+y2;
if max(abs(y4-y3)<10^-14)
disp('system is linear')
else
disp('system is non linear')
end
INPUT:
enter coefficients of input vector[1 1]
x=
1 1
y=
1
n=
20
OUTPUT:
system is linear
AIM:to check the a system for linearity
PROCEDURE:
x=input(' enter coefficients of input vector')
y=input('enter coefficients of output vector')
n=input('enter no of elements of input sequence')
x1=rand(1,n)
x2=rand(1,n)
y1=filter(x,y,x1.^2)
y2=filter(x,y,x2.^2)
y3=filter(x,y,x1+x2.^2)
y4=y1+y2
if max(abs(y4-y3)<10^-14)
disp('system is linear')
else
disp('system is non linear')
end
INPUT:
enter coefficients of input vector[2 4]
x=
2 4
OUTPUT:
system is non linear
TIME VARIANCE
PROCEDURE:
x=input(' enter coefficients of input vector')
y=input('enter coefficients of output vector')
\n=input('enter no of elements of input sequence')
x1=[rand(1,n) zeros(1,n)];
x3=fliplr(x1)
x2=zeros(1,length(x3));
y1=filter(x,y,x3)
y2=zeros(1,length(y1));
x2(2:length(x3))=x1(1:length(x3)-1)
y2(2:length(y1))=y1(1:length(y1)-1)
y3=filter(x,y,x2);
if y2==y3
disp('time invariant system')
else
disp('time variant system')
end
INPUT:
enter coefficients of input vector1
x=
1
enter coefficients of output vector1
y=
1
enter no of elements of input sequence10
n=
10
OUTPUT:
Time variant system
AIM:To check whether the system is time variant
PROCEDURE:
x=input(' enter coefficients of input vector')
y=input('enter coefficients of output vector')
n=input('enter no of elements of input sequence')
x1=[rand(1,n) zeros(1,n)];
x2=zeros(1,length(x1));
y1=filter(x,y,x1)
y2=zeros(1,length(y1));
x2(2:length(x1))=x1(1:length(x1)-1)
y2(2:length(y1))=y1(1:length(y1)-1)
y3=filter(x,y,x2);
if y2==y3
disp('time invariant system')
else
disp('time variant system')
end
INPUT:
enter coefficients of input vector[1 1]
x=
1 1
enter coefficients of output vector[2]
y=
2
enter no of elements of input sequence10
n=
10
OUTPUT:
Time invariant system
STABILITY
PROCEDURE:
a=input('enter the coefficients of output function')
b=input('enter the coeficients of input function')
p=roots(a)
q=roots(b)
if real(q(:))<0
disp('sys is stable')
else
disp('system is unstable')
end
INPUT:
enter the coefficients of output function[1 3 2]
a=
1 3 2
enter the coeficients of input function[1 5 6]
b=
1 5 6
OUTPUT:
p=
-2
-1
q=
-3.0000
-2.0000
System is stable
AIM: Computation of unit impulse response
PROCEDURE:
x=input('enter coeff of i/p vector')
y=input('enter coeff of o/p vector')
t=-10:10
x1=zeros(1,length(t));
for i=1:length(t);
if t(i)>=0;
x1(i)=1;
end
end
h=filter(x,y,x1)
subplot(2,1,1)
stem(t,x1)
subplot(2,1,2)
stem(t,h)
xlabel('time axis')
ylabel('impulse response')
INPUT:
enter coeff of i/p vector[1 1]
x=
1 1
enter coeff of o/p vector1
y =1
OUTPUT:
AIM: Computation of unit step response
PROCEDURE:
INPUT:
enter coeff of i/p vector[1 1]
x=
1 1
enter coeff of o/p vector1
y=
1
GIBBS PHENOMENON
AIM: To find gibbs phenomenon
PROCEDURE:
fs=input('enter the sampling frequency');
f=input('enter the duration of signal');
t=linspace(0,f,fs);
x=zeros(1,length(t));
q=x;
for i=1:length(t)/2
x(i)=1;
x(i+length(t)/2)=-1;
end
n=input('enter num of sine waves');
for i=0:n-1
k=1/(2*i+1);
for j=1:length(t)
q(j)=q(j)+k*sin(t(j)/k);
end
end
subplot(2,1,1)
plot(t,x)
axis([0 f -2 2])
subplot(2,1,2)
plot(t,q)
INPUT:
enter the sampling frequency100
enter the duration of signal6
enter num of sine waves4
OUTPUT:
FOURIER TRANSFORM
AIM: To find the fourier transform of given signal
PROCEDURE:
syms w k f
f=1000
T=1/f;
t=-5*T:T/100:5*T;
x=exp(-1000*abs(t));
p=sym(-2);
q=sym(2);
r=exp(p*abs(k));
r1=subs(r,k,0)
s1=int(exp(q*k-j*w*k),k,-inf,0);
s2=int(exp(p*k-j*w*k),k,0,inf);
s=s1+s2
w=(-5*2*pi*f:2*pi*f/100:5*2*pi*f)/f;
fs=subs(s,w);
subplot(2,1,1)
plot(t,x)
xlabel('time')
ylabel('given signal')
subplot(2,1,2)
plot(w,fs)
xlabel('freqency')
ylabel('magnitude of fourier transform of given signal)
OUTPUT:
g
STATINARITY
AIM: To check a random process for stationarity
PROCEDURE:
syms A w t k theta
p=sym(2)
a=input('enter upper limit')
b=input('enter lower limit')
x1=int(cos(p*w*t+w*k+p*theta),theta)
x=subs(x1,theta,a)-subs(x1,theta,b)
y=int(cos(w*k),theta,b,a)
r=x+y;
disp('auto corelation function ')
disp(r)
INPUT:
p=
2
enter upper limit4
a=
4
enter lower limit2
b=
2
OUTPUT:
x1 =
1/2*sin(2*w*t+w*k+2*theta)
x=
1/2*sin(2*w*t+w*k+8)-1/2*sin(2*w*t+w*k+4)
AIM:checking for mean of random process
PROCEDURE:
syms A w t theta k
rv=input('enter random variable')
a=input('enter lower limit of random variable');
b=input('enter upper limit of random variable');
d=1/(b-a);
X=input('enter the random process')
M=d*int(X,theta,a,b);
disp('the mean of random process is');
disp(M);
INPUT:
enter random variabletheta
rv =
theta
OUTPUT:
enter lower limit of random variable-pi
enter upper limit of random variablepi
enter the random process a*cos(w*t+theta)
X=
-pi*cos(w*t+theta)
PROCEDURE:
syms w k thetas
p=sym(-2)
q=sym(2)
r=exp(p*abs(k))
r1=subs(r,k,0)
R1=int(exp(q*k-j*w*k),k,-inf,0)
R2=int(exp(p*k-j*w*k),k,0,inf)
R=R1+R2
int(R,w,-inf,inf)
disp('area enclosed ')
disp(R/(2*pi))
OUTPUT:
p=
-2
q=
2
r=
exp(-2*abs(k))
r1 =
1
R1 =
-1/(-2+i*w)
R2 =
1/(2+i*w)
R=
-1/(-2+i*w)+1/(2+i*w)
ans =
2*pi
area enclosed
1/2*(-1/(-2+i*w)+1/(2+i*w))/pi
AIM: Checking for causality
PROCEDURE:
a=input('enter the numerator coefficients')
b=input('enter the denominator coefficients')
r1=input('enter the lower bound')
r2=input('enter the upper bound')
if r2==inf
disp('system is causal')
else
disp('system is not causal')
end
INPUT:
enter the numerator coefficients[1 2 1]
a=
1 2 1
b=
1 5 6
r1 =
r2 =
OUTPUT:
system is not causal