0% found this document useful (0 votes)
33 views19 pages

18uec173 - Experiment 2

Uploaded by

Divya Sureka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views19 pages

18uec173 - Experiment 2

Uploaded by

Divya Sureka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Digital Signal Processing Lab

Laboratory report submitted for the partial fulfillment


of the requirements for the degree of

Bachelor of Technology
in
Electronics and Communication Engineering

by

Sankalp Jain - 18UEC173

Course Coordinator
Dr. Navneet Upadhyay

Department of Electronics and Communication Engineering


The LNM Institute of Information Technology, Jaipur

September 2020
Copyright
c The LNMIIT 2020
All Rights Reserved
Contents

Chapter Page

1 Experiment - 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Aim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Software Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3.1 Quantization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3.1.1 Types of Quantization . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.4 Code and Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4.1 Part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4.2 Part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.3 Part 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4.4 Part 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4.5 Quantization Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4.6 Encoder Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.4.7 Simulink Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

iii
Chapter 1

Experiment - 2

1.1 Aim

a) Quantization and Encoding.


b) Simulink based Quantization.

1.2 Software Used

MATLAB

1.3 Theory

1.3.1 Quantization

The digitization of analog signals involves the rounding off of the values which are approximately
equal to the analog values. The method of sampling chooses a few points on the analog signal and then
these points are joined to round off the value to a near stabilized value. Such a process is called as
Quantization.

1.3.1.1 Types of Quantization

There are two types of Quantization - Uniform Quantization and Non-uniform Quantization.
The type of quantization in which the quantization levels are uniformly spaced is termed as a Uniform
Quantization. The type of quantization in which the quantization levels are unequal and mostly the
relation between them is logarithmic, is termed as a Non-uniform Quantization
There are two types of uniform quantization. They are Mid-Rise type and Mid-Tread type.

1
1.4 Code and Result
1.4.1 Part 1

2
clc;
clear all;
close all;
Fs=8000;
f=3000;
A=1;
N=5;
n1=0:1:5*Fs/f-1;
x=A*cos(2*pi*f*n1/Fs);
subplot(5,1,1);
stem(n1,x);
title("Input Signal for Fs=100000");
xlabel("No. of Samples");
ylabel("Amplitude");

L=[8 16 32 64];
for i=1:4
y=quant(x,L(i));
t=sprintf("Quantised for L=%d red=quantized, blue=sampled",L(i));
subplot(5,1,i+1);
stem(y);
hold on;
stem(x);
title(t);
end

1
1.4.2 Part 2

4
clc;
clear all;
close all;
Fs=8000;
f=3000;
A=1;
N=5;
n1=0:1:5*Fs/f-1;
x=A*cos(2*pi*f*n1/Fs);
L=[16 32 64];

mse=zeros(1,3);
for i=1:3
y=quant(x,L(i));
mse(i)=mean((y-x).*(y-x));
end
figure;
stem(L,mse);
title("(Qe) vs L");
ylabel("Quantisation Noise Power(Qe)");
xlabel("No. of Levels(L)");

sqnr=zeros(1,3);
for i=1:3
y=quant(x,L(i));
mse(i)=mean((y-x).*(y-x));
c=(A*A)/(2*mse(i));
sqnr(i)=10*log10(c);
end

figure;
stem(L,sqnr);
title("SQNR in dB vs No. of Levels");
ylabel("SQNR in dB");
xlabel("No. of Levels(L)");

1
2
1.4.3 Part 3

7
clc;
clear all;
close all;
Fs=8000;
f=3000;
A=0;
N=5;
n1=0:1:5*Fs/f-1;
L=64;
b=6;
z=zeros(1,10);
sqnr_db_pr=zeros(1,10);
sqnr_db_th=zeros(1,10);
for i=1:10
A=A+0.1;
x=A*cos(2*pi*f*n1/Fs);
y=quant(x,L);
z(i)=A;
mse=mean((y-x).*(y-x));
c=(A*A)/(2*(mse));
sqnr_db_th(i)=6.02*b + 1.76;
sqnr_db_pr(i)=10*log10(c);
end

subplot(1,2,1);
stem(z,sqnr_db_pr);
title("SQNR in dB Practical");
subplot(1,2,2);
stem(z,sqnr_db_th);
title("SQNR in dB Theoritical");

1
Published with MATLAB® R2020a

2
1.4.4 Part 4

10
clc;
clear all;
close all;
Fs=8000;
f=3000;
A=1;
N=5;
n1=0:1:5*Fs/f-1;
L=8;
x=A*cos(2*pi*f*n1/Fs);
y=quant(x,L);
stem(y);
hold on;
stem(x);
t=sprintf("Quantised for L=8 red=quantized, blue=sampled");
title(t);
z=encoder(y,L);
display(z);

z =

1×13 cell array

Columns 1 through 7

{'111'} {'000'} {'011'} {'110'} {'000'} {'110'}


{'011'}

Columns 8 through 13

{'000'} {'111'} {'000'} {'011'} {'110'} {'000'}

1
Published with MATLAB® R2020a

2
1.4.5 Quantization Function

function[y]= quant(x,L)
Max=max(x);
Min=min(x);
step_size=(Max-Min)/(L);
Lx=length(x);
y=zeros(1,Lx);
for i=1:Lx
index=round(((x(i)-Min)./step_size));
y(i)=index.*step_size + Min;

end
end

Not enough input arguments.

Error in quant (line 2)


Max=max(x);

Published with MATLAB® R2020a

13
1.4.6 Encoder Function

function [p] = encoder(q,L)


Max=max(q);
Min=min(q);
step_size=(Max-Min)/(L-1);
Lq= length(q);
for i=1:Lq
a=(q(i)-Min)./step_size;
st{i}=dec2bin(a,3);
end
p=strcat(st);
end

Not enough input arguments.

Error in encoder (line 2)


Max=max(q);

Published with MATLAB® R2020a

14
1.4.7 Simulink Part

15
16

You might also like