Professional Documents
Culture Documents
BS Lab
BS Lab
KMM
INDEX
S.No.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Pg.No.
1
2
4
6
9
11
13
15
16
20
25
27
28
29
34
37
40
44
47
Date:
Aim: To write and execute a MATLAB program to perform basic operations on matrices.
Program code:
clc;
close all;
clear all;
%Defining matrices a and b
a=[1 2 3 4;5 6 7 8;9 8 7 6;5 4 3 2]
b=[9 8 7 6;5 4 3 2;1 2 3 4;5 6 7 8]
a+b
%% addition of two matrices
a-b
%% subtraction of two matrices
c=a*b %% multiplication of two matrices
diag(a) %%diagonal elements of a
diag(b) %%daigonal elements of b
diag(c) %% diagonal elements of c
Date:
% signum signal
x1 = 1; x3 = -1;
xsg = x1.*(t>0) + x2.*(t==0) + x3.*(t<0);
subplot(3,3,7); plot(t,xsg);
xlabel('t');ylabel('x(t)'); title('signum signal');
% sinc signal
x = sinc(t); subplot(3,3,8); plot(t,x);
xlabel('t');ylabel('x(t)'); title('sinc signal');
% gaussian signal
xga = exp(-a.*(t.^2));
subplot(3,3,9); plot(t,xga);
xlabel('t');ylabel('x(t)');title('gaussian signal');
OUTPUT OF EXPT:2
1
x(t) 0.5
0
-5
0
t
Parabolic signal
0
-5
0
t
signum signal
Sinusoidal signal
-1
-5
-1
-5
0
t
-1
-5
0
t
x(t) 0.5
0
t
sinc signal
0
-5
0
t
gaussian signal
x(t) 0.5
x(t) 0
x(t) 0
0
-5
x(t) 0
0
t
x(t)
x(t) 0.5
x(t)
0
-5
0
t
0
-5
0
t
Date:
Aim: To write and execute a MATLAB program to perform basic operations on signals.
Program code:
%matlab program to perform operations on signals such as
%Addition, Multiplication, Scaling, Shifting, Folding,
%computation of energy and average power
% Program to perform addition and multiplication of the following two
% signals 1) xa(t)=1; 0<t<1
xb(t) = t; 0<t<1
%
=2; 1<t<2
= 1; 1<t<2
%
=1; 2<t<3
= 3-t; 2<t<3
clc; clear all; close all;
tmin = -1; tmax = 5; dt = 0.1; %setting of time vector
t = tmin:dt:tmax;
x1=1; x2=2; x3=3-t;
xa = x1.*(t>0&t<1) + x2.*(t>=1&t<=2) + x1.*(t>2&t<3);
xb = t.*(t>0&t<1) + x1.*(t>=1&t<=2) +x3.*(t>2&t<3);
xadd = xa + xb; xmul = xa .* xb;
xmin = min([min(xa), min(xb), min(xadd), min(xmul)]);
xmax = max([max(xa), max(xb), max(xadd), max(xmul)]);
%plot of signal xa(t)
subplot(2,3,1); plot(t,xa);
axis([tmin tmax xmin xmax]);
xlabel('t'); ylabel('xa(t)');
title('signal xa(t)');
%plot of signal xb(t)
subplot(2,3,2); plot(t,xb);
axis([tmin tmax xmin xmax]);
xlabel('t'); ylabel('xb(t)');
title('signal xb(t)');
%plot of signal xa(t)+xb(t)
subplot(2,3,3); plot(t,xadd);
axis([tmin tmax xmin xmax]);
xlabel('t'); ylabel('xadd(t)');
title('sum of xa(t) and xb(t)');
signal xa(t)
signal xb(t)
2
xa(t)
2
xb(t)
2
4
t
signal xa(t)
2
xa(t)
2
xb(t)
2
t
2
xadd(t)
1
2
4
t
signal xb(t)
2
4
t
product of xa(t) and xb(t)
3
2
xmul(t)
1
2
t
2
t
Date:
Aim: To write and execute a MATLAB program to performs scaling operations on signals.
Program code:
% matlab program to perform amplitude scaling, time scaling and time
% shifting on the signal x(t) = 1.0+t; for t= 0 to 2
tmin = -3; tmax = 5; dt = 0.2; %setting of time vector
t = tmin:dt:tmax;
y0 = y(t);
y1 = 1.5*y(t);
y2 = 0.5*y(t);
y3 = y(2*t);
y4 = y(0.5*t);
y5 = y(t-2);
y6 = y(t+2); %compute the min and max value for y -axis
ymin = min([min(y0), min(y1), min(y2), min(y3), min(y4), min(y5), min(y6)]);
ymax = max([max(y0), max(y1), max(y2), max(y3), max(y4), max(y5), max(y6)]);
%plot of signal y0(t) %original signal
subplot(3,3,1);plot(t,y0);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('y(t)');title('signal x(t)');
%plot of signal y1(t) %amplified signal
subplot(3,3,2);plot(t,y1);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('1.5y(t)');title('amplified signal x1(t)');
%plot of signal y2(t) %attenuated signal
subplot(3,3,3);plot(t,y2);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('0.5y(t)');
title('attenuted signal x2(t)');
%plot of signal y0(t) %original signal
subplot(3,3,4);plot(t,y0);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('y(t)');
title('signal x(t)');
OUTPUT OF EXPT: 3A
signal x(t)
4
y(t)
4
1.5y(t)
2
2
0
-2
t
signal x(t)
-2
t
signal x(t)
-2
2
t
-2
t
time expanded signal
4
y(0.5*t
2
-2
4
y(t-2)
2
2
0
t
delayed signal
4
y(t)
-2
4
y(2*t)
2
2
0
4
0.5y(t)
2
t
time compressed signal
4
y(t)
-2
t
advanced signal
4
y(t+2
2
-2
2
t
-2
10
OUTPUT OF EXPT:3B
signal x(t)
3
2.5
2.5
2
y(-t)
y(t)
1.5
1.5
0.5
0.5
-2
-2
11
Date:
Aim: To write and execute a MATLAB program to find even &odd parts of signal.
Program code:
tmin = -3; tmax = 3;
dt = 0.1;
t = tmin:dt:tmax;
x1 = exp(2*t);
x2 = exp(-2*t);
if (x2==x1)
disp('The given signal is even signal');
else if (x2 ==(-x1))
disp('The given signal is an odd signal');
else
disp('The given signal is neighter odd nor even signa');
end
end
xe = (x1+x2)/2;
xo = (x1+x2)/2;
ymin = min([min(x1), min(x2), min(xe), min(xo)]);
ymax = max([max(x1), max(x2), max(xe), max(xo)]);
subplot(2,2,1);
plot(t,x1);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('x1(t)');
title('signal x(t)'); subplot(2,2,2);plot(t,x2);
axis([tmin tmax ymin ymax]);
xlabel('t');
ylabel('x2(t)');
title('signal x(-t)');
subplot(2,2,3);
plot(t,xe);
axis([tmin tmax ymin ymax]);
xlabel('t');
ylabel('xe(t)');
title('even part of signal x(t)');
subplot(2,2,4);
12
plot(t,xo);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('xo(t)');
title('odd part of signal x(t)');
OUTPUT OF EXPT: 4
signal x(t)
signal x(-t)
400
x1(t)
400
300
300
x2(t)
200
200
100
100
-2
0
t
-2
xe(t)
0
t
300
300
xo(t)
200
200
100
100
-2
0
t
-2
0
t
13
Date:
Aim: To write and execute a MATLAB program for computation of convolution of two
signals.
Program code:
%x1(t)=exp(-0.7t); 0<=t<=T and x2(t)=1; 0<=t<=T
T = 2;
tmin = 0; tmax = 2*T; dt = 0.01;
t = tmin:dt:tmax;
x1 = exp(-0.7*t).*(t>=0 & t<T);
x2 = 1.*(t>=0 & t<T);
x3 = conv(x1,x2);
n3 = length(x3);
t1 = 0:1:n3-1;
subplot(2,2,1);plot(t,x1);
xlabel('t');ylabel('x1(t)');
title('signal x1(t)');
subplot(2,2,2);plot(t,x2);
xlabel('t');ylabel('x2(t)');
title('signal x2(t)');
subplot(2,2,3:4);plot(t1,x3);
xlabel('t');ylabel('x3(t)');
title('convolved signal of x1(t)&x2(t)');
%deconvolution to get original
x1d = deconv(x3,x2);
x2d = deconv(x3,x1);
ymin = min([min(x1d), min(x2d)]);
ymax = max([max(x1d), max(x2d)]);
figure;subplot(2,1,1);plot(t,x1d);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('x1(t)');
title('extracted signal,x1(t)');
subplot(2,1,2);plot(t,x2d);
axis([tmin tmax ymin ymax]);
xlabel('t');ylabel('x2(t)');
title('extracted signal,x2(t)');
14
OUTPUT OF EXPT: 5
signal x1(t)
signal x2(t)
x1(t)
0.5
x2(t)
0.5
2
t
2
t
100
200
300
400
t
500
600
700
800
extracted signal,x1(t)
1
x1(t)
0.5
0
0
0.5
1.5
2
2.5
t
extracted signal,x2(t)
3.5
0.5
1.5
3.5
x2(t)
0.5
0
2
t
2.5
15
Date:
Aim: To write a program for computation of auto correlation and cross correlation between
signals.
Program code:
clc; clear all; close all;
t = -2:0.01:2; x1 = sin(2*pi*t);
subplot(2,2,1);plot(t,x1); xlabel('t');ylabel('x1(t)');
title('signal x1(t)'); x2 = exp(t);
subplot(2,2,2);plot(t,x2); xlabel('t');ylabel('x2(t)');
title('signal x2(t)'); x3 = exp(-t);
%computation of cross correlation
R13 = conv(x1,x3); n13 = length(R13);
t13 = 0:1:n13-1;
subplot(2,2,3);plot(t13,R13); xlabel('t');ylabel('R13(t)');
title('cross correlation of x1,x2');
%computation of auto correlation
R23 = conv(x2,x3); n23 = length(R23);
t23 = 0:1:n23-1;
subplot(2,2,4);plot(t23,R23); xlabel('t');ylabel('R23(t)');
title('auto correlation of x2');
OUTPUT OF EXPT:6
signal x1(t)
signal x2(t)
0.5
x1(t)
x2(t)
-0.5
-1
-2
-1
0
t
0
-2
0
t
auto correlation of x2
-1
3000
100
2000
R13(t)
R23(t)
1000
-100
-200
200
400
600
800
200
400
t
600
800
16
Date:
Aim: To write a program for computation of linearity and time invariance of LTI system.
Program code:
clc; clear all; close all;
x1 = input('type the samples of x1');
x2 = input('type the samples of x2');
if (length(x1)~=length(x2))
disp('Error: length of x1 and x2 are diffrent');
return;
end
h = input('type the samples of h');
N = length(x1) + length(x2)-1;
disp('the length of the out put signal will be');
disp(N);
%time invariance check
a1 = input('the scale factor a1 is ');
a2 = input('the scale factor a2 is ');
x = a1*x1 + a2*x2;
y01 = conv(x,h);
y1 = conv(x1,h);
y1s = a1*y1;
y2 = conv(x2,h);
y2s = a2*y2;
y02 = y1s + y2s;
disp('input signal x1 is ');disp(x1);
disp('input signal x2 is ');disp(x2);
disp('output sequence y01 is ');disp(y01);
disp('output sequence y02 is ');disp(y02);
if (y01 == y02)
disp('y01=y02.Hence the LTI system is LINEAR');
end
% time invariance check
x = input('type the samples of signal x(n)');
h = input( ' Type the samples of signal h(n) ' );
y = conv(x,h);
disp( ' Enter a POSITIVE number for delay ' );
17
input signal x1 is
1
input signal x2 is
4
64 142 144
99
64 142 144
99
13
28
27
18
13
28
27
18
19
2
x(n)
1
0.5
0.5
1.5
2
2.5
Time Index n
Delayed Input Signal xd(n)
3.5
3.5
2
xd(n)
1
1.5
2
2.5
Time Index n
20
y(n)
10
3
4
Time Index n
Delayed Output Signal yd(n)
30
20
yd(n)
10
3
Time Index n
20
22
-0.5
0
Real Part
0.5
Real part
6
Amplitude
4
0.1
0.2
0.3
0.4
0.5
0.6
/
Imaginary part
0.1
0.2
0.3
0.4
0.7
0.8
0.9
0.7
0.8
0.9
0
Amplitude
-1
-2
-3
0.5
/
0.6
23
Magnitude Spectrum
6
Magnitude
4
0.1
0.2
0.3
0.4
0.5
0.6
/
Phase Spectrum
0.7
0.8
0.9
0.2
0.3
0.4
0.7
0.8
0.9
0
Phase(radians)
-0.5
-1
0.1
0.5
0.6
/
Impulse Response of LTI system
1
0.9
0.8
0.7
0.6
h(n)
0.5
0.4
0.3
0.2
0.1
0
10
15
20
25
30
time index n
35
40
45
50
24
2.5
2
1.5
1
0.5
0
10
15
20
25
30
time index n
35
40
45
50
Imaginary Part
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.5
0
Real Part
0.5
25
GIBB'S PHENOMENON
EXPT. NO: 9
Date:
1.5
0.5
sq(t) 0
-0.5
-1
-1.5
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
t
26
No of harmonics = 40
Synthesized Square Wave Using Fourier Series
1.5
0.5
sq(t)
-0.5
-1
-1.5
0
0.1
0.2
0.3
0.4
0.5
t
0.6
0.7
0.8
0.9
No of harmonics = 100
Synthesized Square Wave Using Fourier Series
1.5
0.5
sq(t)
0
-0.5
-1
-1.5
0.1
0.2
0.3
0.4
0.5
t
0.6
0.7
0.8
0.9
27
Date:
-1.5
-1
-0.5
0
x
0.5
1.5
4/t sin(2 t)
8
6
4
2
0
-2
-6
-4
-2
t
.
28
Date:
0.
-0.5
-1
-6
-4
-2
0
t
29
Date:
figure;
zplane(num,den)
title ( ' Pole-Zero Map of the LTI system in Z-Plane' );
if max(radpole) >= 1
disp (' ALL the POLES do not lie within the Unit Circle ');
disp (' Oooooops..The given LTI system is NOT a stable system ');
end;
OUTPUT OF EXPT: 12
type the numerator polynomial vector [1 0.8 0.8],
type the denominator polynomial vector [1 0 0.49]
Transfer function:
s^2 + 0.8 s + 0.8
----------------s^2 + 0.49
zeros are at
0 - 0.7000i
31
0.8944
0 - 0.7000i
0.6
Imaginary Axis
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-0.4
-0.35
-0.3
-0.25
-0.2
-0.15
-0.1
-0.05
Real Axis
Impulse Response of the LTI system
32
1
0.8
0.6
0.4
0.2
h(t)
0
-0.2
-0.4
-0.6
-0.8
-1
0.5
1.5
2.5
t
3.5
4.5
Imaginary Part
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.5
0.5
Real Part
33
Impulse Response
1
0.8
0.6
Amplitude
0.4
0.2
-0.2
-0.4
0
10
15
20
25
n (samples)
34
Date:
Aim: To write a program for simulation of Gaussian noise and to compute mean, meansqure,
skew, kurtosis, psd, and pdf of Gaussian noise.
Program code:
clc; clear all; close all; x1 = randn(1,5000);
x2 = randn(1,5000);
figure; plot( x1 , x2 , ' . ' )
title('Scatter Plot of Gaussian Distributed Random Numbers');
x1 = rand(1,5000); x2 = rand(1,5000);
figure; plot( x1 , x2 , ' . ' );
title('Scatter Plot of Uniform Distributed Random Numbers');
x3 = rand(1,100000); figure; subplot(2,1,1); hist(x3)
title('Uniform Distribution');
y = randn(1,100000);
subplot(2,1,2); hist(y)
title('Gaussian Distribution')
ymu = mean(y)
ymsq = sum(y .^ 2 ) / length(y)
ysigma = std(y)
yvar = var(y)
yskew = skewness(y)
ykurt = kurtosis(y)
OUTPUT OF EXPT 13:
ymu = 0.0038 ,ymsq = 1.0043, ysigma = 1.0022 ,yvar =1.0043, yskew = -0.0178 ykurt =
3.0212
35
3
2
1
0
-1
-2
-3
-4
-4
-3
-2
-1
36
Uniform Distribution
15000
10000
5000
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Gaussian Distribution
x 10
3
2
1
0
-5
-4
-3
-2
-1
37
Date:
Program code:
clc; clear all; close all;
t = -5 : 0.0001 : 5;
F1 = 3; F2 = 23;
x = cos(2*pi*F1*t) + cos(2*pi*F2*t);
figure(1); plot( t , x );
axis ( [-0.4 0.4 -2 2 ] );
xlabel('Time t (sec)'), ylabel('x(t)');
title ('Continuous time signal: x(t) = cos(2\piF_1t) + cos(2\piF_2t)');
% Case 1
Fs1 = 1.4 * F2; ts1 = 1 / Fs1;
n1 = -0.4 : ts1 : 0.4;
xs1 = cos(2*pi*F1*n1) + cos(2*pi*F2*n1);
figure(2); stem( n1 , xs1 )
hold on; plot( t , x , 'r:' );
axis ( [-0.4 0.4 -2 2 ] ); hold off
xlabel('Time Sample (n)'), ylabel('Amplitude');
title ('Discrete Time Signal');
legend( ' Fs < 2Fmax ' );
% Case 2
Fs2 = 2 * F2; ts2 = 1/Fs2;
n2 = -0.4 : ts2 : 0.4;
xs2 = cos(2*pi*F1*n2) + cos(2*pi*F2*n2);
figure(3);stem( n2 , xs2 )
hold on; plot( t , x , 'r:' );
axis ( [-0.4 0.4 -2 2 ] ); hold off
xlabel('Time Sample (n)'), ylabel('Amplitude');
title ('Discrete Time Signal');
legend( ' Fs = 2Fmax ' );
% Case 3
Fs3 = 7 * F2; ts3 = 1/Fs3; n3 = -0.4 : ts3 : 0.4;
xs3 = cos(2*pi*F1*n3) + cos(2*pi*F2*n3);
figure(4); stem( n3 , xs3 );
hold on; plot( t , x , 'r: ' );
axis ( [-0.4 0.4 -2 2 ] ); hold off
xlabel('Time Sample (n)'), ylabel('Amplitude');
38
F2t)
1 + cos(2
2
1.5
0.5
x(t)
0
-0.5
-1
-1.5
-2
-0.4
-0.3
-0.2
-0.1
0.1
0.2
0.3
0.4
Time t (sec)
-0.3
-0.2
-0.1
0
0.1
Time Sample (n)
0.2
0.3
0.4
39
-0.3
-0.2
-0.1
0.1
0.2
0.3
0.4
-0.3
-0.2
-0.1
0
0.1
Time Sample (n)
0.2
0.3
0.4
40
1.5
0.5
x(n)
-0.5
-1
-1.5
10
15
20
25
30
35
40
45
50
42
Autocorrelation Signal R
xx
(l)
100
80
60
40
20
(l)
x
Rx
0
-20
-40
-60
-80
-20
-15
-10
-5
0
Lag Index l
10
15
20
43
44
end;
end;
Cyd = ifft( fft(y,M) .* fft(d,M)) / M;
r = Cyd * ( M / L ); figure(1);
plot( n , x , 'b' ); axis( [ 1 80 -3 3 ] )
xlabel( 'n' ); ylabel( 'x(n)' ); title( ' Periodic Signal x(n) ' )
figure(2);
subplot(2,1,1); plot( n , y , 'r' );
grid; axis( [ 1 96 -3 3 ] ); xlabel( 'n' ); ylabel( 'y(n)' );
title( ' Noisy Signal y(n) ' )
subplot(2,1,2); stem( n , d ); grid; axis( [ 1 96 -0.5 1.5 ] );
xlabel( 'n' ); ylabel( 'd(n)' );
title( ' Impulse Train d(n) ' )
figure(3); plot( n , r , 'k' ); axis( [ 1 80 -3 3 ] )
xlabel( 'n' ); ylabel( 'r(n)' );
title('Extracted Periodic Signal r(n)')
figure(4); plot( n , x , 'b' ); hold on;
axis( [ 1 80 -3 3 ] )
plot( n , r , 'r:' ); hold off; axis( [ 1 80 -3 3 ] )
legend( 'x(n)' , 'r(n)' )
46
x(n)
0
-1
-2
-3
10
20
30
40
n
50
60
70
80
-2
10
20
30
10
20
30
40
50
60
n
Impulse Train d(n)
70
80
90
70
80
90
1.5
1
d(n)
0.5
0
-0.5
40
50
n
60
47
r(n)
-1
-2
-3
10
20
30
40
n
50
60
70
80
3
x(n)
r(n)
2
-1
-2
-3
10
20
30
40
50
60
70
80
EXPT. NO: 17
Date:
49
100
80
Power
60
40
20
10
20
30
40
50
60
Frequency f
70
80
90
100
OUTPUT OF EXPT:17
4
3.5
x 10
2.5
abs(Sxx)2
1.5
0.5
10
20
30
40
50
60
Frequency( f)
70
80
90
100
50