Anda di halaman 1dari 87

# 2013

Subject Code171003

Digital Signal
Processing
Laboratory File
B.E. semester -VII (Electronics and
Communication)

Submitted
to

## Communication Engineering Sanjaybhai Rajguru

College of Engineering
Rajkot.

Engineering,
RAJKOT

## This is to certify that

Mr./Ms.
Of
semester ,
Enrollment no.:
satisfactorily completed his term work in
For the term ending in
2013.

has

Date:

Signature of Teacher
Department

## Sanjaybhai Rajguru College of Engineering- Rajkot

Department of Electronics & Communication Engineering
Experiment list for the Subject
Digital Signal Processing
Exp.

Title

No.
To Study Basic MATLAB Commands.

## Write a Program to Generate Continuous and Discrete Time

Signals
2.1 Ramp Signal
2.2 Delayed Ramp Signal
2.3 Unit Step Signal
2.4 Delayed Step Signal
2.5 Exponential Function

## Write a Program to Generate Aliasing Effect

Write a Program to Generate Different Functions
4.1 Circle
4.2 Overdampped Oscillation
4.3 Underdampped Oscillations
4.4 Helix
4.5 Semilog

## Write a Program to Generate

5.1 Sin-Cosine Signals

## 5.2 Sinc Signals

Write a Program to Generate
6.1 Sample And Hold Signals

## 6.2 Impulse Response And Step Response of a Signal

Write a Program For
7.1 To Compute and Plot Z-Transform.
7.2 To Compute and Plot Inverse Z-Transform.

Page
no.

Date

## Write a Program For

8.1 Discrete Fourier Transform Computation
8.2 Inverse Fourier Transform

Sign

## Write a Program to Sketch The Different Window Functions

9.1 Rectangular Window
9.2 Hamming(Carousel Hamming) Window
9.3 Hamming(Causal Whann) Window
9.4 Blackman Window
9.5 Barlett Window

10

## Write a Program for

10.1 Linear convolution by using conv function

11

## 10.2 Linear convolution without using conv function.

Write a Program for
11.1 Auto-Correlation
11.2 Cross-Correlation

2013

Experiment 1
To Study Basic MATLAB
Commands

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of EngineeringRajkot

Lab
Manual

Digital Signal
Processing

Exp. No.
1

Title
To Study About Basic MATLAB Commands.

a=
1

>> b=a'
b=
1

## The transpose of matrix a is stored in matrix b

>> c=b*a
c=
66

78

90

78

93 108

90 108 126
Multiplies matrix b with a stores in c

>> c=a*b
c=
14

32

50

EC
Department

## Sanjaybhai Rajguru College of

Engineering

32

77 122

50 122 194
Multiplies matrix a with b stores in c

>> a=[1 2 3 4 5]
a=
1

>> b=a+3
b=
4

>> c=a+b
c=
5

11 13

>> eye(3)
ans =
1

>> eye(5)

ans =
1

>> zeros(4,4)
ans =
0

>> ones(4,3)
ans =
1

## 4X3 matrix with all elements 1

>> [eye(2);zeros(2)]
ans =
1

## Identical matrix is appended with 2X2 zero matrix

>> [eye(2),zeros(2)]
ans =
1

Identical matrix is appended with the 2X2 zeros matrix and 2X4 matrix is formed

a=
1

>> a(2,1)
ans =
4
nd

st

st

nd

## This gives the value of 2 row and 1 column element

>> a(1,2)
ans =
2
This gives the value of 1 row and 2 column element

c=
1

10

11

12

## It appends a row in the matrix a

>> [a;a;a]
ans =
1

This appends a to itself one after another and forms 9X3 matrix

>> [a,a;a,a]
ans =
1

This appends matrix a on both the directions and forms 6X6 matrix

f=
0.5000

0.4700

0.1000

>> round(f)
ans =
1

>> ceil(f)
ans =
1

## It assigns the highest integer value

>> sum(f)
ans =
1.0700
Sum of all elements stored in matrix

>> fix(f)
ans =

>> floor(f)
ans =
0

## It stores the lower nearest integer value

>> [1 2 3 4].*[1 2 3 4]
ans =
1

16
st

nd

## It directly multiplies each element of 1 matrix with 2 matrix

>> [1 2 3 4]+[1 2 3 4]
ans =
2

8
st

nd

>> [1 2 3 4].^3
ans =
1

27

64

>> [1 2 3 4]*3
ans =
3

12

## It multiplies each elements of row matrix with 3.

>> pi
ans =
3.1416
The value of pi is displayed

>> eps
ans =
2.2204e-016
The value of e is displayed

>> who
a

ans
Displays all variables used

>> clear a
ans

## >> clear all

Clears all the variables

>> x = -2:1
x=
-2

-1

0 1

## It forms series of integer from -2 to 1 with unit difference

>> x=[1 2 3 4 6 7]
x=
1

>> length(x)
ans =
6
It gives length of series

>> t=0:2:10
t=
0

10

## It gives series from 0 to 10 with difference of 2

>> a=magic(3)
a=
8

Form 3X3 matrix with each row and column having same sum

>> a(2,:)
ans =
3

7
nd

>> a(:,3)
ans =
6
7
2
rd

>> a(2:3,:)
ans =
3

2
nd

rd

>> b=rand(5)
b=
0.9501

0.7621

0.6154

0.4057

0.0579

0.2311 0.4565

0.7919

0.9355

0.3529

0.6068

0.0185

0.9218

0.9169

0.8132

0.4860

0.8214

0.7382

0.4103

0.0099

0.8913

0.4447

0.1763

0.8936

0.1389

## It generates a random 5X5 matrix

>> c=100*rand(3)
c=
20.2765 27.2188 74.6786
19.8722 19.8814 44.5096

60.3792

1.5274 93.1815

## It multiplies each element of random matrix with 100

>> [eye(2);zeros(2);zeros(2)]
ans=
1
0
0
0
0
0

0
1
0
0
0
0

2013

Experiment 2
Write a Program to Generate
Continuous and Discrete Time Signals
2.1 Ramp Signal
2.2 Delayed Ramp Signal
2.3 Unit Step Signal
2.4 Delayed Step Signal
2.5 Exponential Function

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot

EC
Department

## Sanjaybhai Rajguru College of

Engineering

1
3

Exp. No.

Title
Write a Program to Generate Continuous and Discrete Time Signals
2.1 Ramp Signal

## 2.2 Delayed Ramp Signal

2.3 Unit Step Signal
2.4 Delayed Step Signal
2.5 Exponential Function

## 1. WRITE A PROGRAM TO GANERATE RAMP SIGNAL

clc;
clear all;
a=input('enter the value:');
n=0:1:a-1;
g=length(n);
x=n;
subplot(2,1,1);
plot(n,x);
subplot(2,1,2);
stem(n,x);
xlabel('Samples');
ylabel('Amplitude');

EC
Department

Engineering

15

10

10

12

14

0
0

10

12

14

15

A 10
m
pli
tu 5
de

Samples

EC
Department

Engineering

20

## 2. WRITE A PROGRAM TO GENERATE DELAYED RAMP SIGNAL

clc;
clear all;
a=input('enter the value:');
d=input('enter the delay:');
n=1:1:a;
for i=1:1:d
x(i)=0;
end
for i=d:1:a
x(i)=i-d;
end subplot(2,1,1);
plot(n,x);
subplot(2,1,2);
stem(n,x);
xlabel('Sample');
ylabel('Amplitude');

## enter the value:15

enter the delay:3
>>
15

10

10

15

10

15

15

A 10
mp
litu
de 5
0

Sample

## 3. WRITE A PROGRAM TO GENERATE UNIT STEP SIGNAL

clc;
clear all;
a=input('enter the value:');
n=0:1:a-1;
g=length(n);
q=[ones(1,g)]
subplot(2,1,1);
plot(n,q);
subplot(2,1,2);
stem(n,q);
xlabel('Samples');
ylabel('Amplitude');

>>
3
2.5
2
1.5
1

4
5
Samples

A
m
pli
tu
de

1.5
1
0.5
0
0

## 4. WRITE A PROGRAM TO GENERATE DELAYED STEP SIGNAL

clc;
clear all;
a=input('enter the value:');
d=input('enter the delay:');
n=0:1:a-1;
g=length(n);
q=[zeros(1,d),ones(1,g-d)];
subplot(2,1,1);
plot(n,q);
subplot(2,1,2);
stem(n,q);
xlabel('Samples');
ylabel('Amplitude');

## enter the value:15

enter the delay:3
>>
1
0.8
0.6
0.4
0.2
0

10

12

14

0
0

6
8
Samples

10

12

14

1
0.8
A
m 0.6
pli
tu 0.4
de

0.2

## 5. WRITE A PROGRAM TO GENERATE EXPONENTIAL FUNCTION

clc;
clear all;
close all;
k=input('Enter the slope :');
t=0:0.01:k-1;
n=exp(10*t);
plot(t,n);
Enter the slope :1.5
>>
150

100

50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

## 6. WRITE A POGRAM TO GENERATE Sin-Cos SIGNALS

clc;
clear all;
f=input('enter the freq.:');
t=0:1/(100*f):(8/f);
x=sin(2*pi*f*t);
y=cos(2*pi*f*t);
subplot(2,1,1);
plot(t,x);
subplot(2,1,2);
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
enter the freq.:20
>>
1
0.5
0
-0.5
-1

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

-1
0

0.05

0.1

0.15

0.2
Time

0.25

0.3

0.35

0.4

1
0.5
A
m
0
pli
tu
de -0.5

Experiment 3
Write a Program to Generate Aliasing
Effect

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot

EC
Department

## Sanjaybhai Rajguru College of

Engineering

1
2

Exp. No.
3

Title
Write a Program to Generate Aliasing Effect

## WRITE A PROGRAM TO GENERATE ALLISING EFFECT

clc;
clear all; close all;
t=0:1/(100*50):2/10;
x1=cos(2*pi*10*t);
x2=cos(2*pi*50*t);
x3=x1+x2;
subplot(3,2,1);
plot(t,x1);
subplot(3,2,2);
plot(t,x2);
subplot(3,2,3);
plot(t,x3);
n=0:1:7;
x4=cos(2*pi*n*(10/40));
x5=cos(2*pi*n*(50/40));
x6=x4+x5;
subplot(3,2,4);
plot(n,x4);
subplot(3,2,5);
plot(n,x5);
subplot(3,2,6);
plot(n,x6);

EC
Department

Engineering

3
0

-1

0.05

0.1

0.15

0.2

-1

-2

0.05

0.1

0.15

0.2

-1

-1

-2

0.05

0.1

0.15

0.2

## 2. WRITE A PROGRAM TO GENERATE ALLISING EFFECT

clc;
clear all; close all; t=0:1/
(360*100):10/360; x1=sin(2*pi*240*t)
+3*sin(2*pi*360*t); subplot(2,1,1);
plot(t,x1); n=0:1:4; x2=sin(2*pi*n*(240/600))
+3*sin(2*pi*n*(360/600)); subplot(2,1,2);
plot(n,x2);

4
2
0
-2
-4

0.005

0.01

0.015

0.02

0.025

0.03

2
1
0
-1
-2

0.5

1.5

2.5

3.5

Experiment 4
Write a Program to Generate Different
Functions
4.1 Circle
4.2 Overdampped Oscillation
4.3 Underdampped Oscillations
4.4 Helix
4.5 Semilog

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot

EC
Department

## Sanjaybhai Rajguru College of

Engineering

Exp. No.

Title
Write a Program to Generate Different Functions
4.1 Circle

## 4.2 Overdampped Oscillation

4.3 Underdampped Oscillations
4.4 Helix
4.5 Semilog

## 1. WRITE A POGRAM TO GENERATE CIRCLE

clc;
clear all; close all;
theta=0:0.01:100;
x=r*cos(theta);
y=r*sin(theta);
plot(x,y);
grid;

EC
Department

Engineering

34

>>
15

10

-5

-10

-15
-15

-10

-5

10

15

## 2. WRITE A PROGRAM TO GENERATE OVERDAMPPED OSCILLATION

clc;
clear all;
close all;
a=input('Enter the variable : ');
t=0:1:100;
x=sin(t);
y=exp(a*t);
z=x.*y;
plot(t,z);
xlabel('Time');
ylabel('Amplitude');
title('Overdmpped Oscillations');
grid;

## Enter the variable : 0.05

>>
Overdmpped Oscillations
150

100

50
A
m
pli
tu
de

-50

-100

-1500

10

20

30

40

50
Time

60

70

80

90

100

## 3. WRITE A PROGRAM TO GENERATE UNDERDAMPPED OSCILLATIONS

clc;
clear all;
close all;
a=input('Enter the variable : ');
t=0:1:100;
x=sin(t);
y=exp(-a*t);
z=x.*y;
plot(t,z);
xlabel('Time');
ylabel('Amplitude');
title('Underdmpped Oscillations');
grid;

## Enter the variable : 0.05

>>
Underdmpped Oscillations
1
0.8
0.6
0.4
A 0.2
m
pli
tu
0
de

-0.2
-0.4
-0.6
-0.8
0

10

20

30

40

50
Time

60

70

80

90

100

clc;
clear all;
close all;
t=0:0.04:100;
x=cos(t);
y=sin(t);
z=t;
plot3(x,y,z)
>>

100
80
60
40
20
0
1

0.5

0.5

-0.5
-1

-1

-0.5

## 5. WRITE A PROGRAM TO GENERATE SEMILOG

clc;
clear all; close
all;
x=0:0.04:100;
y=x.^2;
subplot(3,1,1);
semilogx(x,y);
grid;
subplot(3,1,2);
semilogy(x,y);
grid;
subplot(3,1,3);
loglog(x,y);
xlabel('X axis');
ylabel('Y axis');
grid;

10000
5000
0
-2
10
10
10
10
10

-1

10

10

10

10

-5

10

20

30

40

50

60

70

80

90

100

Y
0
ax 10
is
10

-5
-2

10

-1

10

10

X axis

10

10

>>

Experiment 5
Write a Program to Generate
5.1 Sin-Cosine Signals
5.2 Sinc
Signals

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot
EC
Department

## Sanjaybhai Rajguru College of

Engineering

1
1

Exp. No.

Title
Write a Program to Generate

5.2 Sinc Signals

## 1. WRITE A PROGRAM TO GENERATE SIN-COSINE AND SINC SIGNALS.

clc;
clear all;
close all;
f=input('Enter the value of signal frequency:');
fs=input('Enter the value of sampling frequency:');
a=input('Enter the amplitude of signal:');
t=-1:1/fs:1;
x=a*sin(2*pi*f*t);
subplot(3,1,1);
plot(t,x);
grid on;
xlabel('Time index & Samples');
ylabel('Amplitude');
y=a*cos(2*pi*f*t);
subplot(3,1,2);

EC
Department

## Sanjaybhai Rajguru College of

Engineering

plot(t,y);
grid on;
xlabel('Time index & Samples');
ylabel('Amplitude');
z=a*sinc(2*pi*f*t);
subplot(3,1,3);
plot(t,z);
axis([-0.5 0.5 -1 3]);
grid on;
xlabel('Time index & Samples');
ylabel('Amplitude');

EC
Department

Engineering

4
5

## Enter the value of signal frequency:5

Enter the value of sampling frequency:1000
Enter the amplitude of signal:2
>>

Experiment 6
Write a Program to Generate
6.1 Sample and Hold Signals
6.2 Impulse Response and Step
Response of a Signal

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot

EC
Department

## Sanjaybhai Rajguru College of

Engineering

Exp. No.

Title
Write a Program to Generate

## 6.1 Sample And Hold Signals

6.2 Impulse Response And Step Response of a Signal

1) Write a program to generate continuous and sampled signal with holding function.
clc;
clear all;
t=0:0.5:25;
y=sin(t);
plot(t,y);
title('SINE WAVE & SAMPLED OUTPUT');
xlabel('TIME');
ylabel('AMPLITUDE');
hold on;
stem(t,y);
hold on;
stairs(t,y);

EC
Department

Engineering

OUTPUT:-

EC
Department

Engineering

4
9

## 2) WRITE A PROGRAM FOR IMPULSE RESPONSE AND STEP RESPONSE OF A

SIGNAL.

clc;
clear all;
close all;
n=input('Enter the number of samples:');
p=[0.8 0.44 -0.36 -0.02];
d=[1 0.7 -0.45 -0.6];
imp=[1 zeros(1,n-1)];
stp=[ones(1,n)];
k=0:1:n-1;
ir=filter(p,d,imp);
subplot(2,1,1);
stem(k,ir);
title('Impulse Response');
grid on;
axis([0 50 -1 1.5]);
str=filter(p,d,stp);
subplot(2,1,2);
stem(k,str);
title('Step Response');

grid on;
axis([0 50 -0.5 1.5]);

## Enter the number of samples:50

>>

Experiment 7
Write a Program For
7.1 To Compute and Plot ZTransform.
7.2 To Compute and Plot Inverse
Z- Transform.

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot
EC
Department

## Sanjaybhai Rajguru College of

Engineering

Exp. No.

Title
Write a Program For

## 7.1 To Compute and Plot Z-Transform.

7.2 To Compute and Plot Inverse Z-Transform.

## 1) TO COMPUTE AND PLOT Z-TRNSFORM.

clc;
clear all;
close all;
num=input('Enter the values of numerator co-efficient:-');
den=input('Enter the values of denominator co-efficient:-');
[z,p,k]=tf2zp(num,den);
m=abs(p);
disp('zeros are at');disp(z);
disp('poles are at');disp(p);
disp('gain constant');disp(m);
zplane(num,den);
title('\bf Z-Transform','fontsize',12);

EC
Department

Engineering

## Enter the values of numerator co-efficient:-[3,2,1]

Enter the values of denominator co-efficient:-[1,2,2]
zeros are at
-0.3333 + 0.4714i
-0.3333 - 0.4714i
poles are at
-1.0000 + 1.0000i
-1.0000 - 1.0000i
gain constant
1.4142
1.4142
O/p:-

EC
Department

Engineering

5
4

## 2) TO COMPUTE AND PLOT INVERSE Z-TRNSFORM.

clc;
clear all;
close all;
z=input('Enter the values of zeros:-');
p=input('Enter the values of poles:-');
k=input('Enter the values of constant:-');
[num,den]=zp2tf(z,p,k);
disp('coefficient of numerator are:-');
disp(num);
disp('coefficient of denominator are:-');
disp(den);

## O/p:Coefficient of numerator are:8 -48

coefficient of denominator are:1

-7

Experiment 8
Write a Program For
8.1 Discrete Fourier Transform
Computation
8.2 Inverse Fourier Transform

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot

EC
Department

## Sanjaybhai Rajguru College of

Engineering

Exp. No.

Title
Write a Program For

## 8.1 Discrete Fourier Transform Computation

8.2 Inverse Fourier Transform

## 1. WRITE A PROGRAM FOR DISCRETE FOURIER TRANSFORM COMPUTATION.

clc;
clear all;
close all;
n=input('Enter the value of N:');
fs=input('Enter the sampling frequency:');
f=input('Enter the value of signal frequency:');
t=0:1/fs:1;
x=sin(2*pi*f*t);
y=fft(x,n);
ymag=abs(y(1,1:n/2));
yang=angle(y(1,1:n/2));
subplot(3,1,1);
plot(x);
title('Input signal');
xlabel('Time');
ylabel('Amplitude');
subplot(3,1,2);
stem(ymag);
title('Magnitude Response');
xlabel('Time');
EC
Department

## Sanjaybhai Rajguru College of

Engineering

ylabel('Magnitude');
subplot(3,1,3);
stem(yang);
title('Phase Response');
xlabel('Time');
ylabel('Angle');

>>

EC
Department

Engineering

5
8

## 2. WRITE A PROGRAM FOR INVERSE FOURIER TRANSFORM

clc;
clear all;
close all;
n=input('Enter the value of N:');
fs=input('Enter the sampling frequency:');
f=input('Enter the value of signal frequency:');
t=0:1/fs:1;
x=sin(2*pi*f*t);
y=fft(x,n);
z=ifft(y,n);
zmag=abs(z(1,1:n/2));
zang=angle(z(1,1:n/2));
subplot(2,2,1);
plot(x);
title('Input signal');
xlabel('Time');
ylabel('Amplitude');
subplot(2,2,2);
stem(zmag);
title('Magnitude Response');
xlabel('Time');
ylabel('Magnitude');
subplot(2,2,3);
stem(zang);

title('Phase Response');
xlabel('Time');
ylabel('Angle');
subplot(2,2,4);
stem(y);
title('Forier Transform');
xlabel('Time');
ylabel('Amplitude');

>>

Experiment 9
Write a Program to Sketch the
Different
Window
Functions
9.1 Rectangular Window
9.2 Hamming(Carousel
Hamming) Window
9.3 Hamming(Causal Whann)
Window
9.4 Blackman Window
9.5 Barlett Window
Digital Signal Processing
EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot

EC
Department

## Sanjaybhai Rajguru College of

Engineering

Exp. No.

Title
Write a Program to Sketch The Different Window Functions
9.1 Rectangular Window

## 9.2 Hamming(Carousel Hamming) Window

9.3 Hamming(Causal Whann) Window
9.4 Blackman Window
9.5 Barlett Window

## Sketch the different window functions

1) Rectangular window
clc;
clear all;
N=input('Enter the Length:');
a=N-1/2; n=a:1:a;
g=length(n);
w=ones(1,g);
subplot(2,1,1);
plot(n,w);
subplot(2,1,2);
stem(n,w);

EC
Department

Engineering

EC
Department

Engineering

63

## 2) Hamming(Carousel Hamming) window.

clc;
clear all;
close all;
x=input('Enter the length:-');
n=0:1:(x-1);
g=length(n);
for(i=1:1:x)
whann(i)=(0.5-(0.5*cos(2*pi*n(i)/(x-1))));
end
subplot(2,1,1);
plot(n,whann);
subplot(2,1,2);
stem(n,whann);

## 3) Hamming(Causal Whann) window.

clc;
clear all;
close all;
x=input('Enter the length:-');
a=(x-1)/2;
n=0:1:(x-1);
g=length(n);
for(i=1:1:x)
t(i)=n(i)-a;
wb2=[1-((abs(t(i)))/a)]
end
subplot(2,1,1);
plot(n,wb2);
subplot(2,1,2);
plot(n,wb2);

## OUTPUT:Enter the length:-30

4) Blackman window.
clc;
clear all;
close all;
m=input('Enter the length:-');
n=0:1:(m-1);
g=length(n);
for i=1:1:m
wr(i)=[0.42-(0.5*cos(2*pi*n(i)/(m-1)))+0.08*cos(4*pi*n(i)/(m-1))];
end
subplot(2,1,1);
plot(n,wr);
subplot(2,1,2);
stem(n,wr);
title('BLACKMAN WINDOW');

## OUTPUT:Enter the length:-30

5) Barlett window.
clc;
clear all;
close all;
N=input('Enter the length:-');
a=(N-1)/2;
n=0:1:N-1;
g=length(n);

for i=1:1:N
t(i)=n(i)-a;
wb(i)=(1-(abs(t(i))/a));
end
subplot(2,1,1);
plot(n,wb);
subplot(2,1,2);
stem(n,wb);
title('BARLETT WINDOW');

## OUTPUT:Enter the length:-30

Experiment 10
Write a Program for
10.1 Linear convolution by using
conv
functi
on
10.2 Linear convolution without using
conv
function.

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot

EC
Department

## Sanjaybhai Rajguru College of

Engineering

1
2

Exp. No.

Title
Write a Program for

10

## 10.1 Linear convolution by using conv function

10.2 Linear convolution without using conv function.

## 1) Write a program for linear convolution by using conv function.

clc;
clear all;
x=input('SEQUENCE X(N) >> ');
h=input('SEQUENCE H(N) >> ');
N1=length(x);
N2=length(h);
N=N1+N2-1;
y=conv(x,h);
disp('OUTPUT SEQUENCE Y[N] >> ');
disp(y); subplot(3,1,1);
stem(x,'r*','Linewidth',1.5);
xlabel('n\rightarrow');
ylabel('X[N]\rightarrow');
title('\bf Input Sequence x[n]','Fontsize',12);
subplot(3,1,2);
stem(h,'r*','Linewidth',1.5);
xlabel('n\rightarrow');

EC
Department

## Sanjaybhai Rajguru College of

Engineering

ylabel('h[N]\rightarrow');
title('\bf Input Sequence h[n]','Fontsize',12);
subplot(3,1,3);
stem(y,'rx','Linewidth',1.5);
xlabel('n\rightarrow');
ylabel('h[N]\rightarrow');
title('\bf Output Sequence y[n]','Fontsize',12);

EC
Department

Engineering

7
4

OUTPUT:-

## SEQUENCE X(N) >> [1 2 3 4]

SEQUENCE H(N) >>[1 1 1 1]

## 2) Write a program for linear convolution without using conv function.

clc;
clear all;
x=input('SEQUENCE X(N) >> ');
h=input('SEQUENCE H(N) >> ');
N1=length(x);
N2=length(h);
N=N1+N2-1;
for k=1:N
y(k)=0;
for j=max(1,(k+1)-N2):min(k,N1)
y(k)=y(k)+(x(j)*h(k+1-j));
end;
end;
disp('OUTPUT SEQUENCE Y[N] >> ');
disp(y); subplot(3,1,1);
stem(x,'r*','Linewidth',1.5);
xlabel('n\rightarrow');
ylabel('X[N]\rightarrow');
title('\bf Input Sequence x[n]','Fontsize',12);
subplot(3,1,2);
stem(h,'r*','Linewidth',1.5);
xlabel('n\rightarrow');

ylabel('h[N]\rightarrow');
title('\bf Input Sequence h[n]','Fontsize',12);
subplot(3,1,3);
stem(y,'rx','Linewidth',1.5);
xlabel('n\rightarrow');
ylabel('h[N]\rightarrow');
title('\bf Output Sequence y[n]','Fontsize',12);

OUTPUT:-

## SEQUENCE X(N) >> [1 2 3 4]

SEQUENCE H(N) >>[1 1 1 1]

2013

Experiment 11
Write a Program for
11.1 Auto-Correlation
11.2 Cross-Correlation

## Digital Signal Processing

EC Department
Sanjaybhai Rajguru College of Engineering- Rajkot

EC Department

Sanjaybhai Rajguru

College of Engineering

Exp. No.

Title
Write a Program for

11

11.1 Auto-Correlation
11.2 Cross-Correlation

## 1) Write a program for cross correlation.

clc;
clear all;
x=input('SEQUENCE X(N)
>>

');

h=input('SEQUENCE
H(N)

>>

');

N1=length(x);
N2=length(h);
N=N1+N2-1;
y=xcorr(x,h);
disp('OUTPUT SEQUENCE
Y[N] >> '); disp(y);
subplot(3,1,1);
stem(x,'r*','Linewidth',1.5);
xlabel('n\rightarrow');
ylabel('X[N]\rightarrow');
title('\bf Input Sequence x[n]','Fontsize',12);
subplot(3,1,2);
stem(h,'r*','Linewidth',
1.5);
xlabel('n\rightarrow');
ylabel('h[N]\rightarro
EC
Department

## Sanjaybhai Rajguru College of

Engineering

8
1

w');
title('\bf Input Sequence h[n]','Fontsize',12);

EC
Department

## Sanjaybhai Rajguru College of

Engineering

8
2

subplot(3,1,3);
stem(y,'rx','Linewidth'
,1.5);
xlabel('n\rightarrow');
ylabel('h[N]\rightarro
w');
title('\bf Output Sequence y[n]','Fontsize',12);

## OUTPUT:SEQUENCE X(N) >>

[1 2 3 4] SEQUENCE
H(N) >>[5 6 7 8]

## 2) Write a program for auto correlation.

clc;
clear all;
x=input('SEQUENCE X(N)
>>

');

h=input('SEQUENCE
H(N)

>>

');

N1=length(x);
N2=length(
h);
N=N1+N21;
y=xcorr(x);
disp('OUTPUT SEQUENCE
Y[N] >> '); disp(y);
subplot(3,1,1);
stem(x,'r*','Linewidth',1.5);
xlabel('n\rightarrow');
ylabel('X[N]\rightarrow');
title('\bf Input Sequence x[n]','Fontsize',12);
subplot(3,1,2);
stem(h,'r*','Linewidth',
1.5);
xlabel('n\rightarrow');
ylabel('h[N]\rightarro
w');

## title('\bf Input Sequence h[n]','Fontsize',12);

subplot(3,1,3);
stem(y,'rx','Linewidth'
,1.5);
xlabel('n\rightarrow');

ylabel('h[N]\rightarrow');
title('\bf Output Sequence y[n]','Fontsize',12);

OUTPUT:-

## SEQUENCE X(N) >>

[1 2 3 4] SEQUENCE
H(N) >>[1 2 3 4]