You are on page 1of 30

 

 
 
 
 
 
 
 
 
 
Kurukshetra University,
  Kurukshetra
Dept. of Electronics & Communication Engineering 
 

  Practical
 
File
 
 
 
 
 
 
 

Digital Signal  
 
 

Processing  
 
 
 
 
 
Submitted By:
 
Ashwani Dhiman
 
2505162
ECE 4th Yr.
INDEX 
 
Sr.  Experiment Name  Date Remark
No. 
1.  Write a program to implement Matrix   
Algebra. 
2.  Write a program to plot following   
functions a)impulse function b)Unit 
Step c) Ramp function 
 
3.  Write a program to plot Exponential   
function. 
4.  Write a program to plot Sinusoidal   
function. 
5.  Write a program to find out the   
convolution of two sequences using in 
built convolution function. 
6.  Write a program to implement loops.  
7.  Study  of  plots,  subplots  including   
functioning of hold on and off. 
 
8.  Define a function to compute DTFT of a   
finite length signal. Plot the magnitude 
and phase plots using subplots. Use this 
function to obtain DTFT of a 21 point 
triangular pulse over the domain ‐ 
10<n<10. Plot the results over ‐p<w<p. 
9.  To Implement FIR/Digital Filter.  
10.  Study different window functions available in   
signal processing toolbox and their controlling 
parameters. 
 
Experiment: 1 
 
Program: Write a program to implement Matrix Algebra. 
 
Software Used: MATLAB 7.5 
 
 
Program: 
 
a=[1 2 3 
4 5 6 
7 8 9] 
 
a = 
 
     1     2     3 
     4     5     6 
     7     8     9 
 
%--Transpose--%

>> b = a.' 
 
b = 
 
     1     4     7 
     2     5     8 
     3     6     9 
 
%--Addition--%
 
>> c = a+b 
 
c = 
 
     2     6    10 
     6    10    14 
    10    14    18 
 
%--Multiplication--%
 
>> d = a*b 
 
d = 
 
    14    32    50 
    32    77   122 
    50   122   194 
 
%--Find out any element--%
 
>> e=d(2,3) 
 
e = 
 
   122 
 
%--Display a Row--% 
d(:,2) 
 
ans = 
 
    32 
    77 
   122 
 
%--Display a Column--%
 
d(3,:) 
 
ans = 
 
    50   122   194 
 

 
Experiment: 2 
 
Program: Write a program to plot following functions 
a) impulse function b)Unit Step c) Ramp function 
 
Software Used: MATLAB 7.5 
 
%--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
Result for Impulse Function: 
 
m = 
    20 
 
y = 
     1 
 
 

 
 
 

 
%--Program for UNIT Step function--%

n=10
for t= -n:1:n
if(t>0)
z=1
plot(t,z,'+');
hold on
else
continue;
end
end
hold off
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Result for Unit Step Function: 
 
n = 
      10 
 
z = 
       1 
 
z = 
       1 
 
z = 
       1 
 
z = 
       1 
 
z = 
       1 
 
z = 
       1 
 
z = 
       1 
 
z = 
       1 
 
z = 
       1 
 
z = 
       1 
 
 
 
Output Graph for UNIT STEP Function. 
 
N = 10 
 
 

 
 
 

 
%--Program to Plot RAMP function--%

t = 0:1:10
y=3*t
plot(t,y,'r')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Result of Ramp Function: 
 
 
t = 
 
     0     1     2     3     4     5     6     7     8     9    10 
 
 
y = 
 
     0     3     6     9    12    15    18    21    24    27    30 
 
 

 
 
 

 
Experiment: 3 
 
Program: Write a program to plot Exponential function. 
 
Software Used: MATLAB 7.5 
 
 
%--Program to Plot Exponential Function--%

a= input('enter the value of a')


b = input('enter the value of b')
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')
Result: 
 
 
 

 
 

 
Experiment: 4 
 
Program: Write a program to plot Sinusoidal function. 
 
Software Used: MATLAB 7.5 
 
 
%--Program to plot Sine and Cosine--%
 
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; 
Output graph of Sine and Cosine function. 

 
 
 
 
 
 

 
Experiment: 5 
 
Program: Write a program to find out the convolution of two 
sequences using in built convolution function. 
 
Software Used: MATLAB 7.5 
 
 
%--Convolution of two sequences--%
 
x=input('Enter the first sequence');
h = input('Enter second sequence');
k=input('Starting loc of x');
l=input('Starting loc of h');
a=length(x);
b=length(h);
N=a+b-1;
j=k+l;

n=j:1:N+j-1;
y=conv(x,h);
display(y);
subplot(2,2,3:4)
stem(n,y)

u=k:1:a+k-1;
subplot(2,2,1)
stem(u,x)

v=l:1:b+l-1;
subplot(2,2,2)
stem(v,h)
 
 
 
 
 
 
Result: 
 
 
Enter the first sequence2505162 
Enter second sequence2505165 
Starting loc of x3 
Starting loc of h‐1 
 
y = 
 
  6.2758e+012 
 
>> 
 
 

 
EXPERIMENT NO.6 
 
Program: Write a program to implement loops. 
 
Software Used: MATLAB 7.5 
 
%‐‐for loop‐‐% 
 
a = zeros(3,2) 
for  m= 1:3 
    for n=1:3 
        a(m,n)=1/(m+n‐1); 
    end 
end 
 
%‐‐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 
 
%‐‐ifelseif‐‐% 
x=5 
y=10 
z=15 
if((x>y)&(x>z)) 
    'x is greatest of the three' 
elseif(y>z) 
    'y is greatest' 
else 
    'z is greatest' 
End 
 
%‐‐switch‐‐% 
method = 'Bilinear'; 
 
switch lower(method) 
   case {'linear','bilinear'} 
      disp('Method is linear') 
   case 'cubic' 
      disp('Method is cubic') 
    otherwise 
        disp('hello! method is not there') 
end 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RESULT:‐ 
 
a = 
 
     0     0 
     0     0 
     0     0 
 
i = 
 
     1 
 
['hello'] 
['hello'] 
['hello'] 
['hello'] 
 
ans = 
 
yes 
 
x = 
 
     5 
 
y = 
 
    10 
 
z = 
 
    15 
 
ans = 
z is greatest 
 
Method is linear 
 
Experiment: 7 
 
Program: Study of plots, subplots including functioning of hold 
on and off. 
Software Used: MATLAB 7.5 
 
Program: 
%‐‐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') 
Result: 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Experiment: 8 
 
Program:  Define  a  function  to  compute  DTFT  of  a  finite  length 
signal.  Plot  the  magnitude  and  phase  plots  using  subplots.  Use 
this function to obtain DTFT of a 21 point triangular pulse over 
the domain ‐ 10<n<10. Plot the results over ‐p<w<p. 
 
Software Used: MATLAB 7.5 
 
 
Program: 
 
%--DTFT--%

num = [.008 -.033 .05 -.033 .008]


den = [1 2.37 2.7 1.6 .41]
n = [0:pi/256:pi]
y=freqz(num,den,n)
subplot(3,3,1:2)
plot(n,abs(y))
ylabel('Mag.')
xlabel('freq.')
title('Magnitude Response')
subplot(3,3,4:5)
plot(n,angle(y))
ylabel('Phase')
xlabel('freq.')
title('Phase Response')

n = -10:10
width=1
x= sawtooth(n,width)
subplot(3,3,6)
plot(x)
xlabel('time')
ylabel('amp')
title('Triangular pulse')

mag = freqz(x)
subplot(3,3,7:8)
plot(abs(mag))
ylabel('Mag of triangular pulse')
xlabel('freq.')
title('Magnitude Response')

subplot(3,3,9)
plot(angle(mag))
xlabel('freq.')
ylabel('phase')
title('Phase Response')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Result: 
 
 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
Experiment: 9 
 
Program: To Implement FIR/Digital Filter. 
 
Software Used: MATLAB 7.5 
 
 
 
%--FIR Filter--%

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')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Result: 
 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Experiment: 10 
 
Program:  Study different window functions available in signal
processing toolbox and their controlling parameters.
 
Software Used: MATLAB 7.5 
 
 
 
 
%-- WINDOW FUNCTION--%

 
N = 62;
w = window(@chebwin,N);
w1 = window(@hamming,N);
w2 = window(@gausswin,N,2.5);
w3 = window(@hann,N);
w4 = window(@kaiser,N,2.5);
wvtool(w,w1,w2,w3,w4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Result: 
 

Time domain Frequency domain


40
1
20

0.8 0

Magnitude (dB)
-20
Amplitude

0.6
-40

0.4 -60

-80
0.2
-100

0 -120
10 20 30 40 50 60 0 0.2 0.4 0.6 0.8
Samples Normalized Frequency ( ×π rad/sample)

You might also like