Professional Documents
Culture Documents
Pcm
Pcm
Pcm
some different levels and assigning the center value of each level to any sample in the
quantization interval. Quantization approximates the analog sample values with the
nearest quantization values.
The encoder encodes the quantized samples. Each quantized sample is encoded into
an 8-bit codeword
Matlab code:
clc;
closeall;
clearall;
% Signal Generation
n=input('Enter n value for n-bit PCM system : ');
n1=input('Enter number of samples in a period : ');
x=0:2*pi/n1:4*pi; %n1 number of samples have to be selected
L=2^n;
% Sampling Operation
subplot(3,1,2);
stem(s);grid on; title('Sampled Sinal'); ylabel('Amplitude--->'); xlabel('Time--
->');
Quantization Process
codebook is a vector whose length must exceed the length of partition by one.
The function also returns quants, which contains the scalar quantization of sig and
depends on the quantization levels and prescribed values in the codebook.
Index determines on which partition interval, each input value is mapped.
For example:
vmax=8;
vmin = -vmax;
del = (vmax-vmin)/L;% step size = dynamic range/no of levels
part =vmin : del: vmax;% level are between vmin and vmax with difference of del
code1= vmin-(del/2) : del : vmax+(del/2);% Contain Quantized values
[ind,q]=quantiz(s, part, code1); % Quantization process
Vmax = 8
Vmin = -8
del = 16/8 = 2
part = -8: 2 : 8
code1 = -8-1: 2 : 8+1 % -9 : 2 : 9
code1 = -9 -7 -5 -3 -1 1 3 5 7 9
part = -8 -6 -4 -2 0 2 4 6 8
ind = 4 7 8 8 7 5 2 1 1 2 4 7 8
8 7 5 2 1 1 2 4
q = -1 5 7 7 5 1 -5 -7 -7 -5 -1 5 7
7 5 1 -5 -7 -7 -5 -1
-1 5 7 7 5 1 -5 -7 -7 -5 -1 5 7
7 5 1 -5 -7 -7 -5 -1
L1=length(ind);
L2=length(q);
for i=1:L1
if (ind(i)~=0)% To make index as binary decimal so started from 0to N
ind(i)=ind(i)-1;
end
i=i+1;
end
vmin=-8-(2/2)=-9
if q(i) contains -9 value then it should be brought back to with in the levels(-8 to 8 i.e in
the codebook it -7 to 7))
fori=1:L2
if(q(i)==vmin-(del/2))% To make quantize value inbetween the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
plot(x,q,'.');grid on;
hold on;
stairs(x,q);
% Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Encoding Process
figure
code=de2bi(ind,'left-msb');% Convert the decimal to binary
k=1;
fori=1:L1
for j=1:n
coded(k)=code(i,j);% convert code matrix to a coded row vector
j=j+1;
k=k+1;
end
i=i+1;
end
Ind : 3 6 7 7
subplot(2,1,1); grid on; 6 4 1 0 0 1 3 6 7
7 6
stairs(coded); 4 %1 Display0 the 0encoded 1 signal
3
axis([0 100 -2 3]); title('Encoded Signal');
The following output we get if de2bi of ind is performed
ylabel('Amplitude--->');
0 xlabel('Time--->');
1 1
1 1 0
1 1 1
1 1 1
1 1 0
1 0 0
0 0 1
0 0 0
0 0 0
0 0 1
0 1 1
1 1 0
1 1 1
1 1 1
1 1 0
1 0 0
0 0 1
0 0 0
0 0 0
0 0 1
0 1 1
The for loop is used to convert above code vector to coded row vector
for i=1:21
for j=1:3