You are on page 1of 25

sh

Digital Signal
Processing

Vikas Kumar
C07558
EECE, 7th SEM
Digital Signal Processing

EXPERIMENT NO. 1

EXPERIMENT 1(a)

Aim : Write a program to generate a sine wave.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
x=linspace(0,2*pi,100);
plot(x,sin(x))
xlabel('x-axistime');
ylabel('sin(x)');
title('sinewave');
axis('equal');
grid on;

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 1
Digital Signal Processing

EXPERIMENT 1(b)

Aim : Write a program to generate space curve.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
x=linspace(0,2*pi,100);
plot3(cos(x),sin(x),x)
xlabel('x');
ylabel('y');
zlabel('z');
zlatitle('spacecurve');
grid on;

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 2
Digital Signal Processing

EXPERIMENT 1(c)

Aim : Write a program to plot a circle.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
r=1;
theta=linspace(0,2*pi,100);
x=r*sin(theta);
y=r*cos(theta);
plot(x,y)
xlabel('x');
ylabel('y');
title('circle');
axis('equal');
grid on;

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 3
Digital Signal Processing

EXPERIMENT 1(d)

Aim : Write a program to plot graphs using subplot command.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
t=linspace(0,2*pi,100);
x=cos(t);
y=sin(t);
z=tan(t);
k=exp(t);
subplot(1,4,1);
plot(t,x)
grid on;
axis('equal');
xlabel('time');
ylabel('cos(t)');
title('graph1');
subplot(1,4,2);
plot(t,y)
grid on;
axis('equal');
xlabel('time');
ylabel('sin(t)');
title('graph2');
subplot(1,4,3);
plot(t,z)
grid on;
axis('equal');
xlabel('time');
ylabel('tan(t)');
title('graph3');
subplot(1,4,4);
plot(t,k)
grid on;
axis('equal');
xlabel('time');
ylabel('exp(t)');
title('graph4');

Manish Bansal
C07521, 7th Sem, EECE. Page 4
Digital Signal Processing

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 5
Digital Signal Processing

EXPERIMENT 1(e)

Aim : Using MATLAB commands perform the various matrix operations.

Apparatus: MATLAB version 7.

>> x=[1,2,3;4,5,6;7,8,9] (x matix of order 3*3)

x=

1 2 3
4 5 6
7 8 9

>> x*x (multiplication of x matrix with itself)

ans =

30 36 42
66 81 96
102 126 150

>>x' (transpose of x matrix)

ans =

1 4 7
2 5 8
3 6 9

>> x*x' (multiplication of x matrix with its transpose)

ans =

14 32 50
32 77 122
50 122 194

>> x.*x' (element by element multiplication)

ans =

1 8 21
8 25 48
21 48 81

Manish Bansal
C07521, 7th Sem, EECE. Page 6
Digital Signal Processing

>> eye(3) (identity matrix of order 3)

ans =

1 0 0
0 1 0
0 0 1

>> diag(x) (diagonal elements of x matrix)

ans =

1
5
9
>> x^2 (multiplication of x matrix with itself)

ans =

30 36 42
66 81 96
102 126 150

>> [eigvec,eigval]=eig(x) (eigen values and eigen vectors of x matrix)

eigvec =

-0.2320 -0.7858 0.4082


-0.5253 -0.0868 -0.8165
-0.8187 0.6123 0.4082

eigval =

16.1168 0 0
0 -1.1168 0
0 0 -0.0000

Manish Bansal
C07521, 7th Sem, EECE. Page 7
Digital Signal Processing

EXPERIMENT NO. 2

EXPERIMENT 2(a)

Aim : Write a program to plot unit impulse function.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
t=-9:1:9;
y=[zeros(1,9),ones(1,1),zeros(1,9)];
stem(t,y);
grid on;

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 8
Digital Signal Processing

EXPERIMENT 2(b)

Aim : Write a program to plot unit step function.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
n=input('enter value of n');
t=0:1:n-1;
y=ones(1,n);
stem(t,y);
grid on;

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 9
Digital Signal Processing

EXPERIMENT 2(c)

Aim : Write a program to plot a ramp function.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
n=input('enter value of n');
t=0:n;
stem(t,t);
grid on;

Output:

enter value of n6

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 10
Digital Signal Processing

EXPERIMENT 2(d)

Aim : Write a program to plot linear convolution function.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
x=input('enter first sequence');
h=input('enter second sequence');
y=conv(x,h);
subplot(1,3,1)
stem(x);
xlabel('t');
ylabel('x');
subplot(1,3,2)
stem(h);
xlabel('t');

Manish Bansal
C07521, 7th Sem, EECE. Page 11
Digital Signal Processing

ylabel('h');
subplot(1,3,3)
stem(y);
xlabel('t');
ylabel('y');
display('the result is: ');
y
grid on;

Output:

enter first sequence[1,2,3,4]


enter second sequence[1,1,1,1]

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 12
Digital Signal Processing

Result:

the result is:


y=

1 3 6 10 9 7 4

EXPERIMENT 3

Manish Bansal
C07521, 7th Sem, EECE. Page 13
Digital Signal Processing

Aim : Write a program to perform linear convolution and plot a graph for the
resultant function.

Apparatus: MATLAB version 7.

Program Code:

clc;
clear all;
close all;
a=input('enter the value of a');
b=input('enter the value of b');
m1=input('enter the range of a');
m2=input('enter the range of b');
stem(m1,a)
figure;
stem(m2,b)
figure;
m=m1(1,1)+m2(1,1);
n=m1(1,end)+m2(1,end);
j=[m:1:n];
c=conv(a,b);
stem (j,c)
c

Output:

enter the value of a[2,3,4,5,6]


enter the value of b[-4,-7,-5,3]
enter the range of a[-1:1:3]
enter the range of b[-2:1:1]

c=

-8 -26 -47 -57 -70 -55 -15 18

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 14
Digital Signal Processing

Manish Bansal
C07521, 7th Sem, EECE. Page 15
Digital Signal Processing

Manish Bansal
C07521, 7th Sem, EECE. Page 16
Digital Signal Processing

EXPERIMENT 4(a)

Aim : Write a program to calculate inverse z-transform of a given sequence.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
a=[1,0.2,0.5];
b=[1,-0.5];
n=4;
a=[a zeros(1,n-1)];
x=deconv(a,b);
stem(x);
x
grid on;

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 17
Digital Signal Processing

Result:

the result is
x=

1.0000 0.7000 0.8500 0.4250 0.2125

Manish Bansal
C07521, 7th Sem, EECE. Page 18
Digital Signal Processing

EXPERIMENT 4(b)

Aim : Write a program to calculate inverse z-transform of a given sequence.

Apparatus: MATLAB version 7.

Program Code:
clc;
clear all;
close all;
a=[2,3,4];
b=[1,-1.5,-3.5];
n=5;
b=[b zeros(1,n-1)];
x=deconv(b,a);
disp(x);
stem(x);
x
grid on;

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 19
Digital Signal Processing

Result:

the result is
x=

0.5000 -1.5000 -0.5000 3.7500 -4.6250

Manish Bansal
C07521, 7th Sem, EECE. Page 20
Digital Signal Processing

EXPERIMENT 5(a)

Aim : Write a sequence to calculate DFT of a given sequence using MATLAB


software.

Apparatus: MATLAB version 7.

Program Code:

clc;
close all;
clear all;
x=input('input the sequence');
y=input('enter the length of the sequence');
z=fft(x,y);
stem(z);
z

Command Window:

input the sequence [1,2,3,4,5]


enter the length of the sequence 8

z=

Columns 1 through 4

15.0000 -5.4142 - 7.2426i 3.0000 + 2.0000i -2.5858 - 1.2426i

Columns 5 through 8

3.0000 -2.5858 + 1.2426i 3.0000 - 2.0000i -5.4142 + 7.2426i


>>

Manish Bansal
C07521, 7th Sem, EECE. Page 21
Digital Signal Processing

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 22
Digital Signal Processing

EXPERIMENT 5(b)

Aim : Write a sequence to calculate IDFT of a given sequence using MATLAB


software.

Apparatus: MATLAB version 7.

Program Code:

clc;
close all;
clear all;
x=input('input the sequence');
y=input('enter the length of the sequence');
z=ifft(x,y);
stem(z);
z

Command Window:

input the sequence[1,2,3,4,5]


enter the length of the sequence 8

z=

Columns 1 through 4

1.8750 -0.6768 + 0.9053i 0.3750 - 0.2500i -0.3232 + 0.1553i

Columns 5 through 8

0.3750 -0.3232 - 0.1553i 0.3750 + 0.2500i -0.6768 - 0.9053i

Manish Bansal
C07521, 7th Sem, EECE. Page 23
Digital Signal Processing

Output Window:

Manish Bansal
C07521, 7th Sem, EECE. Page 24

You might also like