DSP Practical File
DSP Practical File
TECHNOLOGY
PRACTICAL FILE
2507061
456
7 8 9]
a=
1 2 3
4 5 6
7 8 9
>> b=[4 6 7
793
3 5 7]
b=
4 6 7
7 9 3
3 5 7
>> %addition
>> a+b
ans
5 8 10
11 14 9
10 13 16
>> %subtraction
>> a-b
ans =
-3 -4 -4
-3 -4 3
4 3 2
>> %multiplication
>> a*b
ans =
27 39 34
69 99 85
>> e=b(2,:)
e=
7 9 3
>> f=b(:,2)
f=
>> z=[1 2 3 4]
z=
1 2 3 4
>> z=10:-3:1
z=
10 7 4 1
>> z=0:3:10
z=
0 3 6 9
>> x=zeros(1,3)
x=
0 0 0
x=
0 0 0
4 5 6
1 1 1
>> y=rand(2,2)
y=
0.8147 0.1270
0.9058 0.9134
>> who
a ans b e f x y z
>> whos
a 3x3 72 double
b 3x3 72 double
e 1x3 24 double
f 3x1 24 double
x 3x3 72 double
y 2x2 32 double
z 1x4 32 double
Experiment: 2
Program: Write a program to plot following functions
a) impulse function b)Unit Step c) Ramp function d) sin and cos
function
Software Used: MATLAB 7.6
%--Program to Generate IMPULSE function--%
m = 20
for i = -m:m
if(i==0)
y=1
stem(i,y,'r+')
hold on
else
continue;
end
end
hold off
n=10
for t= -n:1:n
if(t>0)
z=1
plot(t,z,'+');
hold on
else
continue;
end
end
hold off
t = 0:1:10
y=3*t
plot(t,y,'r')
x = 0:.0001:1
f = cos(2*pi*x)
g = sin(2*pi*x)
plot(x,f,'b+');
hold on;
plot(x,g,'r');
hold off;
OUTPUTS:-
impulse function:
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
unit step:
1.8
1.6
1.4
1.2
0.8
0.6
0.4
0.2
0
1 2 3 4 5 6 7 8 9 10
ramp function:
30
25
20
15
10
0
0 1 2 3 4 5 6 7 8 9 10
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
Experiment: 3
Program: Write a program to find out the convolution of two
sequences using in built convolution function.
Software Used: MATLAB 7.6
clc;
clear all;
close all;
m=length(x);
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
ylabel('---->h(n)');grid;
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
subplot(2,2,[3,4]),stem(y);
xlabel('---->n');
ylabel('---->y(n)');grid;
OUTPUT:
1.5
4
---->x(n)
---->h(n)
1
2
0.5
0 0
0 2 4 6 8 0 2 4 6 8
---->n ---->n
convolution of x(n) & h(n) is :
15
10
---->y(n)
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
---->n
Experiment: 4
Program: Write a program to plot Exponential function.
Software Used: MATLAB 7.6
%--Program to Plot Exponential Function--%
c = a+i*b
k=10
n=1:10
x= k*exp(c*n)
y = abs(x)
subplot(2,2,1:2)
stem(n,y)
xlabel('time')
ylabel('Mag.')
title('Magnitude Response')
z = angle(x)
subplot(2,2,3:4)
stem(n,z)
xlabel('time')
ylabel('Phase')
title('Phase Response')
OUTPUT:
a=
10
b=
10
44
x 10 Magnitude Response
3
2
Mag.
0
1 2 3 4 5 6 7 8 9 10
time
Phase Response
4
2
Phase
-2
-4
1 2 3 4 5 6 7 8 9 10
time
EXPERIMENT NO.5
Program: Write a program to implement loops.
Software Used: MATLAB 7.6
%--while loop--%
i=1
while i<5
disp ['hello']
i=i+1;
end
%--if loop--%
a=10;
b=20;
if(a<b)
'yes'
if(a>=b)
'no'
end
end
end
OUTPUT:
i=
['hello']
['hello']
['hello']
['hello']
ans =
yes
x=
y=
10
z=
15
ans =
z is greatest
Method is linear
EXPERIMENT NO.6
Program: write a program to implement fir filter
Software used: matlab 7.6
f = [0 0.6 0.6 1]; m = [1 1 0 0];
b = fir2(30,f,m);
[h,w] = freqz(b);
plot(f,m,w/pi,abs(h))
legend('Ideal','fir2 Designed')
title('Frequency Response Magnitudes')
OUTPUT:
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
EXPERIMENT NO.7
N = 65;
w = window(@blackmanharris,N);
w1 = window(@hamming,N);
w2 = window(@gausswin,N,2.5);
wvtool(w,w1,w2)
OUTPUT:
0.8 0
Magnitude (dB)
Amplitude
0.6
-50
0.4
-100
0.2
0 -150
10 20 30 40 50 60 0 0.2 0.4 0.6 0.8
Samples Normalized Frequency ( rad/sample)
Experiment: 8
%--subplot1--%
t = 0:.0001:1;
y = sin(2*pi*t)
subplot(2,2,1);
plot(t,y)
z = cos(2*pi*t)
subplot(2,2,2);
plot(t,z);
%--subplot2--%
q = 0:.001:1
a = sin(2*pi*q)
subplot(2,2,1:2)
plot(q,a)
xlabel('time')
ylabel('amplitude')
title('sine1')
b = cos(2*pi*q)
subplot(2,2,3)
plot(q,b)
xlabel('time')
ylabel('amplitude')
title('cos')
c = sin(pi*q)
subplot(2,2,4)
plot(q,c)
xlabel('time')
ylabel('amplitude')
title('sine2')
OUTPUT1:
1 1
0.5 0.5
0 0
-0.5 -0.5
-1 -1
0 0.5 1 0 0.5 1
OUTPUT2:
sine1
1
0.5
am plitude
-0.5
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time
cos sine2
1 1
0.5
am plitude
am plitude
0 0.5
-0.5
-1 0
0 0.5 1 0 0.5 1
time time
EXPERIMENT 9:
0.5
Amplitude
-0.5
-1
0 1 2 3 4 5 6
Time, [s]
Autocorrelation function of the sinewave
1000
500
Autocorrelation
-500
0 500 1000 1500 2000 2500
lags
EXPERIMENT 10:
subplot(3,1,1);
plot(x);
title('Pure Sinewave');
grid;
subplot(3,1,2);
plot(Rxy);
grid;
OUTPUT:
Pure Sinewave
1
-1
0 200 400 600 800 1000 1200
Cross correlation Rxy
500
-500
0 500 1000 1500 2000 2500