DSP Manual 2014

download DSP Manual 2014

If you can't read please download the document

description

no

Transcript of DSP Manual 2014

2013

Subject Code171003Digital Signal ProcessingLaboratory File

B.E. semester -VII (Electronics and Communication)

Submitted to Department of Electronics and Communication Engineering Sanjaybhai Rajguru College of EngineeringRajkot.

Sanjaybhai Rajguru College of Engineering, RAJKOT

This is to certify thatMr./Ms. Of semester , Enrollment no.: has satisfactorily completed his term work in For the term ending in 2013.

Date:

Signature of Teacher Head of the DepartmentSanjaybhai Rajguru College of Engineering- RajkotDepartment of Electronics & Communication Engineering

Experiment list for the Subject

Digital Signal Processing

Exp. No.TitleDatePage no.Sign1To Study Basic MATLAB Commands.

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

3Write a Program to Generate Aliasing Effect

4Write a Program to Generate Different Functions

4.1 Circle

4.2 Overdampped Oscillation

4.3 Underdampped Oscillations

4.4 Helix

4.5 Semilog

5Write a Program to Generate

5.1 Sin-Cosine Signals

5.2 Sinc Signals

6Write a Program to Generate

6.1 Sample And Hold Signals

6.2 Impulse Response And Step Response of a Signal

7Write a Program For

7.1 To Compute and Plot Z-Transform.

7.2 To Compute and Plot Inverse Z-Transform.

8Write a Program For

8.1 Discrete Fourier Transform Computation

8.2 Inverse Fourier Transform

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

10Write a Program for

10.1 Linear convolution by using conv function

10.2 Linear convolution without using conv function.

11Write a Program for

11.1 Auto-Correlation

11.2 Cross-Correlation

2013

Experiment 1

To Study Basic MATLAB Commands

Digital Signal ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotLab ManualDigital Signal Processing

EC DepartmentSanjaybhai Rajguru College of Engineering

Exp. No.Title1To Study About Basic MATLAB Commands.

>> a=[1 2 3;4 5 6;7 8 9]

a =

1 2 3

4 5 6

7 8 9

This forms a 3X3 matrix labeled as a

>> b=a' b =1 4 7

2 5 8

3 6 9

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

32 77 122

50 122 194

Multiplies matrix a with b stores in c

>> a=[1 2 3 4 5]

a =

1 2 3 4 5

One dimensional array is defined as a

>> b=a+3 b =4 5 6 7 8

3 is added to each element of a

>> c=a+b c =5 7 9 11 13

Both array a and b are stored in c

>> eye(3)

ans =

1 0 0

0 1 0

0 0 1

Identical matrix formed

>> eye(5)

ans =

1 0 0 0 0

0 1 0 0 0

0 0 1 0 0

0 0 0 1 0

0 0 0 0 1

5X5 identical matrix formed

>> zeros(4,4)

ans =

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

4X4 matrix with all elements 0

>> ones(4,3)

ans =

1 1 1

1 1 1

1 1 1

1 1 1

4X3 matrix with all elements 1

>> [eye(2);zeros(2)]

ans =

1 0

010000

Identical matrix is appended with 2X2 zero matrix

>> [eye(2),zeros(2)]

ans =

1 0 0 0

0 1 0 0

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

>> a=[1 2 3;4 5 6;7 8 9]

a =

1 2 3

4 5 6

7 8 9

This forms a 3X3 matrix labeled as a

>> a(2,1)

ans =

4

This gives the value of 2nd row and 1st column element

>> a(1,2)

ans =

2

This gives the value of 1st row and 2nd column element

>> c=[a;10 11 12]

c =

123456789101112

It appends a row in the matrix a

>> [a;a;a]

ans =

1 2 3

4 5 6

7 8 9

1 2 3

4 5 6

7 8 9

1 2 3

4 5 6

7 8 9

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

>> [a,a;a,a]

ans =

1 2 3 1 2 3

4 5 6 4 5 6

7 8 9 7 8 9

123123456456789789

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

>> f=[0.5 0.47 0.1]

f =

0.5000 0.4700 0.1000

It defines a row matrix with non integer elements

>> round(f)

ans =

1 0 0

It assigns the nearest integer value

>> ceil(f)

ans =

1 1 1

It assigns the highest integer value

>> sum(f)

ans =

1.0700

Sum of all elements stored in matrix

>> fix(f)

ans =

0 0 0

The integer value is stored and the decimal value is discarded

>> floor(f)

ans =

0 0 0

It stores the lower nearest integer value

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

ans =

1 4 9 16

It directly multiplies each element of 1st matrix with 2nd matrix

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

ans =

2 4 6 8

It directly adds each element of 1st matrix with 2nd matrix

>> [1 2 3 4].^3 ans =1 8 27 64

It makes cube of each elements of row matrix

>> [1 2 3 4]*3 ans =3 6 9 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

Your variables are:

a b c f ansDisplays all variables used

>> clear a

Your variables are: ansb c f Clear the variable a

>> 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 2 3 4 6 7

>> length(x)

ans =

6

It gives length of series

>> t=0:2:10 t =

0 2 4 6 8 10

It gives series from 0 to 10 with difference of 2

>> a=magic(3)

a =

8 1 6

3 5 7

4 9 2

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

>> a(2,:)

ans =

3 5 7

It displays 2nd row with all elements

>> a(:,3)

ans =

6

7

2

It displays 3rd column with all elements

>> a(2:3,:)

ans =

3 5 7

4 9 2

It displays 2nd and 3rd row with all elements

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

100100000000EC DepartmentSanjaybhai Rajguru College of Engineering13

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 ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering2

Exp. No.Title

2Write 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 DepartmentSanjaybhai Rajguru College of Engineering

>> enter the value:15

15

10

5

00 2 4 6 8 10 12 14

15

Amplitude10

5

00 2 4 6 8 10 12 14Samples

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

5

00 5 10 15

15

Amplitude10

5

00 5 10 15Sample

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');

enter the value:10

>>

3

2.5

2

1.5

10 1 2 3 4 5 6 7 8 9

2

Amplitude1.5

1

0.5

00 1 2 3 4 5 6 7 8 9Samples

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

00 2 4 6 8 10 12 14

1

0.8

Amplitude0.6

0.4

0.2

00 2 4 6 8 10 12 14Samples

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

00 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

-10 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4

1

Amplitude0.5

0

-0.5

-10 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4

TimeEC DepartmentSanjaybhai Rajguru College of Engineering12

Experiment 3

Write a Program to Generate Aliasing

Effect

Digital Signal ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering

Exp. No.Title3Write 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);

1 1

0 0

-10 0.05 0.1 0.15 0.2

2 -10 0.05 0.1 0.15 0.2

1

0 0

-20 0.05 0.1 0.15 0.2

1 -10 2 4 6 8

2

0 0

-10 2 4 6 8 -20 2 4 6 8

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

-40 0.005 0.01 0.015 0.02 0.025 0.03

2

1

0

-1

-20 0.5 1 1.5 2 2.5 3 3.5 4EC DepartmentSanjaybhai Rajguru College of Engineering5

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 ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering

Exp. No.Title

4Write 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; r=input('enterthe radius:'); x=r*cos(theta); y=r*sin(theta);plot(x,y);

grid;

enterthe radius:15

>>

15

10

5

0

-5

-10

-15-15 -10 -5 0 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

>>

150 Overdmpped Oscillations

100

50

Amplitude0

-50

-100

-150 0 10 20 30 40 50 60 70 80 90 100

Time

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

>>

1

0.8

0.6

0.4

Amplitude0.2

0

-0.2

-0.4

-0.6

-0.8 Underdmpped Oscillations

0 10 20 30 40 50 60 70 80 90 100

Time

4. WRITE A PROGRAM TO GENERATE HELIX

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

01

0.5

0

-0.5

-1 -1

0-0.5

10.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 -1 0 1 210 10 10510 10 10

0

10

-5100 10 20 30 40 50 60 70 80 90 100510

0Y axis10

-510-2 -1 0 1 210 10 10 10 10X axis >>EC DepartmentSanjaybhai Rajguru College of Engineering11

Experiment 5

Write a Program to Generate

5.1 Sin-Cosine Signals

5.2 SincSignals

Digital Signal ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering2

Exp. No.Title

5Write a Program to Generate

5.1 Sin-Cosine Signals

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 DepartmentSanjaybhai 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');

Enter the value of signal frequency:5

Enter the value of sampling frequency:1000

Enter the amplitude of signal:2

>>

EC DepartmentSanjaybhai Rajguru College of Engineering5

Experiment 6

Write a Program to Generate

6.1 Sample and Hold Signals

6.2 Impulse Response and StepResponse of a Signal

Digital Signal ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering2

Exp. No.Title

6Write 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 DepartmentSanjaybhai Rajguru College of Engineering

OUTPUT:-

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

>>EC DepartmentSanjaybhai Rajguru College of Engineering6

Experiment 7

Write a Program For

7.1 To Compute and Plot Z- Transform.

7.2 To Compute and Plot InverseZ- Transform.

Digital Signal ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering2

Exp. No.Title

7Write a Program For

7.1 To Compute and Plot Z-Transform.

7.2 To Compute and Plot Inverse Z-Transform.

clc; 1) TO COMPUTE AND PLOT Z-TRNSFORM.

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 DepartmentSanjaybhai Rajguru College of 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 constant1.4142

1.4142

O/p:-

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 -7EC DepartmentSanjaybhai Rajguru College of Engineering5

Experiment 8

Write a Program For

8.1 Discrete Fourier TransformComputation

8.2 Inverse Fourier Transform

Digital Signal ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering2

Exp. No.Title

8Write 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 DepartmentSanjaybhai Rajguru College of Engineering

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

xlabel('Time');

ylabel('Angle');

>>

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');

>>

EC DepartmentSanjaybhai Rajguru College of Engineering6

Experiment 9

Write a Program to Sketch theDifferent

WindowFunctions

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 ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering2

Exp. No.Title

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

clc; 1) Rectangular window

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 DepartmentSanjaybhai Rajguru College of Engineering

OUTPUT:-

Enter the length:21

clc; 2) Hamming(Carousel Hamming) window.

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

OUTPUT:-

Enter the length:-30

clc; 3) Hamming(Causal Whann) window.

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

clc; 4) Blackman window.

clear all;

close all;

m=input('Enter the length:-');

n=0:1:(m-1); g=length(n); for i=1:1:mwr(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

clc; 5) Barlett window.

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

EC DepartmentSanjaybhai Rajguru College of Engineering12

Experiment 10

Write a Program for

10.1 Linear convolution by usingconv

functi on

10.2 Linear convolution without using

convfunction.

Digital Signal ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- RajkotEC DepartmentSanjaybhai Rajguru College of Engineering2

Exp. No.Title

10Write a Program for

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 DepartmentSanjaybhai 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);

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:Ny(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 for11.1 Auto-Correlation11.2 Cross-Correlation

Digital Signal ProcessingEC DepartmentSanjaybhai Rajguru College of Engineering- Rajkot

EC Department Sanjaybhai Rajguru College of Engineering 8EC DepartmentSanjaybhai Rajguru College of Engineering

Exp. No.Title

11Write a Program for

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]\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) >>[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+N2-1; 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]\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 2 3 4]