# UNIVERSITY INSTITUTE OF ENGINEERING AND TECHNOLOGY

KURUKSHETRA UNIVERSITY KURUKSHETRA DEPT. OF ELECTRONICS & COMMUNICATION ENGINEERING PRACTICAL FILE

Digital Signal Processing

Submitted To : Ms. Rajni

Submitted By: Pawan Garg 2507061 Ece(B) 4th year

INDEX Sr. No.
1.

Experiment Name

Date

Remark

Write a program to implement matrix algebra. Write a program to plot following functions a)impulse function b)Unit Step c) Ramp function

.

2.

3.

Write a program to find out the convolution of two sequences using in built convolution function. Write a program to plot Exponential function.

4.

5.

Write a program to implement loops. To Implement FIR/Digital Filter. Study different window functions available in signal processing toolbox and their controlling parameters. Study of plots, subplots including functioning of hold on and off. Write a program to implement autocorrelation function Write a program to implement crosscorrelation function

6.

7.

8.

9. 10.

Experiment: 1
Program: Write a program to implement Matrix Algebra. Software Used: MATLAB 7.6
>> a=[1 2 3 456 7 8 9] a= 1 4 7 2 5 8 3 6 9

>> b=[4 6 7 793 3 5 7] b= 4 7 3 6 9 5 7 3 7

>> %addition >> a+b ans 5 11 10 8 10 14 13 9 16

>> %subtraction >> a-b ans = -3 -3 4 -4 -4 3 -4 3 2 >> %multiplication >> a*b ans = 27 69 39 99 34 85 111 159 136 >> %display a row >> e=b(2.2) f= 6 9 5 >> z=[1 2 3 4] .:) e= 7 9 3 >> %display a column >> f=b(:.

3) x= 0 0 0 >> x=[zeros(1.9058 >> who Your variables are: a ans b e f x y z 0. ones(1.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 4 1 0 5 1 0 6 1 >> y=rand(2.3).2) y= 0.9134 . 4 5 6.1270 0.8147 0.

>> whos Name a ans b e f x y z Size 3x3 3x3 3x3 1x3 3x1 3x3 2x2 1x4 Bytes Class 72 double 72 double 72 double 24 double 24 double 72 double 32 double 32 double Attributes .

y.'r+') hold on else continue.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. end end hold off %--Program for UNIT Step function--% n=10 for t= -n:1:n if(t>0) z=1 .6 %--Program to Generate IMPULSE function--% m = 20 for i = -m:m if(i==0) y=1 stem(i.

. hold on.z. hold on else continue.0001:1 f = cos(2*pi*x) g = sin(2*pi*x) plot(x.g.'b+'). plot(x.'+').'r') %--Program to plot Sine and Cosine function --% x = 0:.y. end end hold off %--Program to Plot RAMP function--% t = 0:1:10 y=3*t plot(t.'r'). hold off.f.plot(t.

OUTPUTS:impulse function: 1 0 .2 0 1 2 3 4 5 6 7 8 9 10 .3 0 .6 0 .8 0 .7 0 .6 -0 .2 0 0 .4 -0 .8 0 .1 0 -1 -0 .5 0 .6 1 .2 0 .8 1 .4 0 .6 0 .4 0 .6 0 .8 -0 .4 1 .9 0 .8 1 unit step: 2 1 .4 0 .2 0 .2 1 0 .

2 0.1 0.ramp function: 30 25 20 15 10 5 0 0 1 2 3 4 5 6 7 8 9 10 sin and cos function: 1 0.2 -0.7 0.4 -0.5 0.4 0.8 0.6 0.6 0.2 0 -0.4 0.8 0.9 1 .6 -0.8 -1 0 0.3 0.

2.1). close all.2.zeros(1.Experiment: 3 Program: Write a program to find out the convolution of two sequences using in built convolution function. stem(h). Software Used: MATLAB 7. title('i/p sequencce h(n)is:'). clear all. h=input('enter i/p h(n):'). m=length(x).grid.2). disp('linear convolution program').6 clc.n)]. stem(x). . subplot(2. x=[x. title('i/p sequencce x(n)is:'). subplot(2. ylabel('---->x(n)').zeros(1. xlabel('---->n'). n=length(h).m)]. h=[h. x=input('enter i/p x(n):').

disp('convolution of x(n) & h(n) is y(n):').4]).2. end end end subplot(2.grid.stem(y).grid.[3. for j=1:m+n-1 if(j<i+1) y(i)=y(i)+x(j)*h(i-j+1). ylabel('---->y(n)'). y=zeros(1. . xlabel('---->n'). title('convolution of x(n) & h(n) is :').xlabel('---->n').m+n-1). ylabel('---->h(n)'). for i=1:m+n-1 y(i)=0.

5 2 2.5 ---->n 4 4.5 6 .OUTPUT: i/p sequencce x(n)is: 6 4 ---->h(n) ---->x(n) 2 0 2 1.5 0 2 4 ---->n 6 8 0 0 2 4 ---->n 6 8 i/p sequencce h(n)is: convolution of x(n) & h(n) is : 15 10 ---->y(n) 5 0 1 1.5 3 3.5 5 5.5 1 0.

') title('Magnitude Response') z = angle(x) subplot(2.2.3:4) stem(n.1:2) stem(n.6 %--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. Software Used: MATLAB 7.y) xlabel('time') ylabel('Mag.Experiment: 4 Program: Write a program to plot Exponential function.z) xlabel('time') ylabel('Phase') title('Phase Response') .

1 0 1 2 3 4 6 tim e P has e Res pons e 5 7 8 9 10 4 2 P has e 0 -2 -4 1 2 3 4 5 tim e 6 7 8 9 10 .OUTPUT: enter the value of a10 a= 10 enter the value of b10 b= 10 x 10 44 M agnitude Res pons e 3 2 M ag.

b=20. end %--if loop--% a=10.6 %--while loop--% i=1 while i<5 disp ['hello'] i=i+1.5 Program: Write a program to implement loops.EXPERIMENT NO. Software Used: MATLAB 7. if(a<b) 'yes' if(a>=b) 'no' end end %--if else if--% x=5 y=10 z=15 .

switch lower(method) case {'linear'.'bilinear'} disp('Method is linear') case 'cubic' disp('Method is cubic') otherwise disp('hello! method is not there') end .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'.

OUTPUT: i= 1 ['hello'] ['hello'] ['hello'] ['hello'] ans = yes x= 5 y= 10 z= 15 ans = z is greatest Method is linear .

6 0.6 1].f.'fir2 Designed') title('Frequency Response Magnitudes') . b = fir2(30.6 f = [0 0.abs(h)) legend('Ideal'.EXPERIMENT NO. m = [1 1 0 0].w/pi.w] = freqz(b).m).m. [h.6 Program: write a program to implement fir filter Software used: matlab 7. plot(f.

3 0.6 0.7 0.8 0.4 0.2 0.8 0.1 0.4 0.4 Ideal fir2 Des igned 1.5 0.2 0 0 0.9 1 .6 0.2 1 0.OUTPUT: F requenc y Res pons e M agnitudes 1.

w2) .N.7 Program: Study different window functions available in signal processing toolbox and their controlling parameters.6 N = 65. w = window(@blackmanharris. w1 = window(@hamming.N). Software Used: MATLAB 7.N).w1.2.EXPERIMENT NO. w2 = window(@gausswin.5). wvtool(w.

100 0.4 0.150 10 20 30 40 Samples 50 60 0 0.2 0 .6 .6 0.OUTPUT: Time domain 50 1 0 M agnitude ( dB) Fr equenc y domain 0.50 0.4 .8 Am plitude 0.8 Nor maliz ed Fr equenc y ( vT r ad/s ample) .2 0.

2).0001:1. plot(t.6 %--subplot1--% t = 0:.001:1 a = sin(2*pi*q) subplot(2. %--subplot2--% q = 0:. Software Used: MATLAB 7.2.z). subplots including functioning of hold on and off.2.1:2) plot(q.Experiment: 8 Program: Study of plots.y) z = cos(2*pi*t) subplot(2.2.1).a) xlabel('time') . y = sin(2*pi*t) subplot(2. plot(t.

3) plot(q.b) xlabel('time') ylabel('amplitude') title('cos') c = sin(pi*q) subplot(2.2.4) plot(q.2.c) xlabel('time') ylabel('amplitude') title('sine2') .ylabel('amplitude') title('sine1') b = cos(2*pi*q) subplot(2.

5 0 -0.9 1 1 am plit ude 0.1 0.5 t im e 1 .5 -1 0 0.5 0 -0 .2 c os 0.5 1 OUTPUT2: s ine1 1 am plit ude 0.5 0 -0 .6 0.7 0.5 1 0 0.3 0.5 -1 0.4 0. 5 -1 1 0.5 0 0.5 t im e 1 am plit ude 0.5 0 -0.8 s ine2 0. 5 -1 0 0.5 t im e 1 0 0 0.OUTPUT1: 1 0.

6 N=1024. grid. % Plot the autocorrelation grid. % Plot x(n) title('Sinwave of frequency 1000Hz [FS=8000Hz]'). % Prepare the figure plot(t. Rxx=xcorr(x). x(n) t=[1:N]*(1/FS). % Generate the signal.x).1. xlabel('Time.EXPERIMENT 9: Program: Write a program to implement autocorrelation function. % Prepare the figure plot(Rxx). Software Used: MATLAB 7. [s]'). xlabel('lags'). .1). % Sample index numbers x=sin(2*pi*f1*n/FS). title('Autocorrelation function of the sinewave'). % Sampling Frequency n=0:N-1. % Number of samples f1=1.2). % Frequency of the sinewave FS=200. ylabel('Amplitude'). ylabel('Autocorrelation').1. % Prepare a time axis subplot(2. % Estimate its autocorrelation subplot(2.

5 A m plitude 0 -0.OUTPUT: S inwave of frequenc y 1000Hz [FS = 8000Hz ] 1 0.5 -1 0 1 3 4 Tim e. [s ] A utoc orrelation func tion of the s inewave 2 5 6 1000 A utoc orrelation 500 0 -500 0 500 1000 lags 1500 2000 2500 .

1). grid.y). plot(x).6 N=1024. % Sampling index x=sin(2*pi*f*n/FS).2). Rxy=xcorr(x. % Frequency of the sinewave FS=200. % Number of samples to generate f=1.1.N). Software Used: MATLAB 7. title('Pure Sinewave').EXPERIMENT 10: Program: Write a program to implement crosscorrelation function. % Estimate the cross correlation subplot(3. % Generate y(n) subplot(3. % Generate x(n) y=x+10*randn(1. % Sampling frequency n=0:N-1.1. .

title('Cross correlation Rxy'). . grid.plot(Rxy).

OUTPUT: Pure S ewave 1 ¡ 0 -1 0 500 0 -500 0 500 1000 1500 2000 2500 200 400 ¢ 600 ¤£   Cross orrelat on R   800 1000 1200 .