how can i quantize the normal distribution using uniform PCM?

조회 수: 5 (최근 30일)
Zaref Li
Zaref Li 2021년 11월 17일
답변: Raikantwar Hrashikesh 2022년 4월 8일
sinusoidal signal, there is quantization code for 8 levels and 16 levels using PCM scheme. However, I want to do this for N(0,1) distribution as well. Do I just need to make changes in the "a" variable in this code?
echo on
t=[0:0.01:10];
a=sin(t);
[sqnr8,aquan8,code8]=u_pcm(a,8);
[sqnr16,aquan16,code16]=u_pcm(a, 16);
pause % Press a key to see the SQNR for N = 8.
sqnr8
pause % Press a key to see the SQNR for N = 16.
sqnr16
pause % Press a key to see the plot of the signal and its quantized versions.
plot(t,a,' -',t,aquan8,' - . ',t,aquan16,' -',t,zeros(1,length(t)))
function [sqnr,a_quan,code]=u_pcm(a,n)
%U_PCM uniform PCM encoding of a sequence
% [SQNR,A_QUAN,CODE]=U_PCM(A,N)
% a=input sequence.
% n=number of quantization levels (even).
% sqnr=output SQNR (in dB).
% a_quan=quantized output before encoding.
% code=the encoded output.
amax=max(abs(a));
a_quan=a/amax;
b_quan=a_quan;
d=2/n;
q=d.*[0:n-1];
q=q-((n-1)/2)*d;
for i=1:n
a_quan(find((q(i)-d/2 <= a_quan) & (a_quan <= q(i)+d/2)))=...
q(i).*ones(1,length(find((q(i)-d/2 <= a_quan) & (a_quan <= q(i)+d/2))));
b_quan(find( a_quan==q(i) ))=(i-1).*ones(1,length(find( a_quan==q(i) )));
end
a_quan=a_quan*amax;
nu=ceil(log2(n));
code=zeros(length(a),nu);
for i=1:length(a)
for j=nu:-1:0
if ( fix(b_quan(i)/(2^j)) == 1)
code(i,(nu-j)) = 1;
b_quan(i) = b_quan(i) - 2^j;
end
end
end
sqnr=20*log10(norm(a)/norm(a-a_quan));

답변 (1개)

Raikantwar  Hrashikesh
Raikantwar Hrashikesh 2022년 4월 8일
idk

카테고리

Help CenterFile Exchange에서 PCM에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by