# dsp practical file

Mar 31, 2015

## Documents

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: 1Program: 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,:) e= 7 9 3

>> %display a column >> f=b(:,2) f= 6 9 5 >> 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=[zeros(1,3); 4 5 6; ones(1,3)] x= 0 4 1 0 5 1 0 6 1

>> y=rand(2,2) y= 0.8147 0.9058 >> who Your variables are: a ans b e f x y z 0.1270 0.9134

>> 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

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

%--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 %--Program to Plot RAMP function--% t = 0:1:10 y=3*t plot(t,y,'r') %--Program to plot Sine and Cosine function --% 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:1 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:2 1 .8 1 .6 1 .4 1 .2 1 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

5

0 0 1 2 3 4 5 6 7 8 9 10

sin and cos function:1 0.8 0.6 0.4 0.2 0 -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.6clc; clear all; close all; disp('linear convolution program'); x=input('enter i/p x(n):'); m=length(x); h=input('enter i/p h(n):'); n=length(h); x=[x,zeros(1,n)]; subplot(2,2,1), stem(x); title('i/p sequencce x(n)is:'); xlabel('---->n'); ylabel('---->x(n)');grid; h=[h,zeros(1,m)]; subplot(2,2,2), stem(h); title('i/p sequencce h(n)is:');

xlabel('---->n'); ylabel('---->h(n)');grid; disp('convolution of x(n) & h(n) is y(n):'); y=zeros(1,m+n-1); for i=1:m+n-1 y(i)=0; for j=1:m+n-1 if(jh(n) ---->x(n) 2 0 2 1.5 1 0.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

2

2.5

3

3.5 ---->n

4

4.5

5

5.5

6

Experiment: 4 Program: Write a program to plot Exponential function. Software Used: MATLAB 7.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,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: enter the value of a10 a= 10 enter the value of b10 b= 10x 1044

M agnitude Res pons e

3

2 M ag. 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

EXPERIMENT NO.5 Program: Write a program to implement loops.Software Used: MATLAB 7.6 %--while loop--% i=1 while iy)&(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

OUTPUT: i= 1 ['hello'] ['hello'] ['hello'] ['hello'] ans = yes x= 5 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.6f = [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:F requenc y Res pons e M agnitudes 1.4 Ideal fir2 Des igned

1.2

1

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 Program: Study different window functions available in signalprocessing toolbox and their controlling parameters.

Software Used: MATLAB 7.6N = 65; w = window(@blackmanharris,N); w1 = window(@hamming,N); w2 = window(@gausswin,N,2.5); wvtool(w,w1,w2)

OUTPUT:Time domain 50 1 0 M agnitude ( dB) Fr equenc y domain

0.8 Am plitude

0.6

- 50

0.4

- 100 0.2

0

- 150 10 20 30 40 Samples 50 60

0

0.2 0.4 0.6 0.8 Nor maliz ed Fr equenc y ( vT r ad/s ample)

Experiment: 8 Program: Study of plots, subplots including functioning of hold on and off. Software Used: MATLAB 7.6%--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 0.5 0 -0 . 5 -1

1 0.5 0 -0 . 5 -1

0

0.5

1

0

0.5

1

OUTPUT2:s ine1 1 am plit ude 0.5 0 -0.5 -1

0

0.1

0.2 c os

0.3

0.4

0.5 t im e 1 am plit ude

0.6

0.7

0.8 s ine2

0.9

1

1 am plit ude 0.5 0 -0.5 -1

0.5

0

0.5 t im e

1

0

0

0.5 t im e

1

EXPERIMENT 9:

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

OUTPUT:S inwave of frequenc y 1000Hz [FS = 8000Hz ] 1 0.5 A m plitude 0 -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

EXPERIMENT 10:

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

Rxy=xcorr(x,y); % Estimate the cross correlation subplot(3,1,2);

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

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

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Related Documents
##### ROBOTICS PRACTICAL FILE
Category: Documents
##### Ajay Practical File
Category: Documents
##### Oos Practical File
Category: Documents
##### Unix practical file
Category: Technology
##### Practical File[1]
Category: Documents
##### Oops practical file
Category: Technology