0% found this document useful (0 votes)
189 views1 page

Uniform PCM

This MATLAB code performs PCM encoding on a sampled signal. It quantizes the signal into a number of levels specified by ql, calculates the quantization values and quantization error, and outputs the encoded stream and the signal to quantization noise ratio (SQNR). It then plots the quantization error and quantization intervals on graphs.

Uploaded by

Uday Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views1 page

Uniform PCM

This MATLAB code performs PCM encoding on a sampled signal. It quantizes the signal into a number of levels specified by ql, calculates the quantization values and quantization error, and outputs the encoded stream and the signal to quantization noise ratio (SQNR). It then plots the quantization error and quantization intervals on graphs.

Uploaded by

Uday Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

function [enstream,SQNR]=uni_pcm(ql,s)

% ql is the number of Quantization levels


% s is the sampled sequence
noB=log2(ql);
enstream=0;
no=length(s);
qval(no)=0;
Qe(no)=0;
qint=(max(s)-min(s))/ql; %% qint: Quantization interval
for i=1:length(s)
intvno=ceil((max(s)-s(i))/qint); %% intvno: Interval No
if intvno==0
intvno=intvno+1;
end
qval(i)=(((max(s)-intvno*qint)+(max(s)-(intvno-1)*qint))/2); %% q
val: Quantization value
% beq=dec2bin(intvno-1,noB); %% beq refers to binary eqvivalant
Qe(i)=s(i)-qval(i);
end
disp('Signal to Quantization Noise ratio is : ');
SQNR=0.75*(2^(noB-1)-1)^2;
disp(SQNR);
plot(1:length(s),Qe);
figure
for i=min(s):qint:(max(s)-qint)
for j=i:0.001:(i+qint)
plot(j,i+(qint*0.5));
hold on
end
end

You might also like