Digital Signal Processing Reference
In-Depth Information
% rvalue ¼ output value from the mu-law expander
%
y ¼ y/vmax; % Normalization
% mu-law expanding
rvalue ¼ sign(y)*(vmax/mu)*((1 þ mu)^abs(y) -1);
Program 11.5. MATLAB function for midread quantizer encoding.
function [indx, pq ]
¼
mtrdenc(NoBits,Xmax,value)
% function pq
mtrdenc(NoBits, Xmax, value)
% This routine is created for simulation of midtread uniform quantizer.
%
% NoBits: number of bits used in quantization.
% Xmax: overload value.
% value: input to be quantized.
% pq: output of quantized value
% indx: integer index
%
% Note: the midtread method is used in this quantizer.
%
¼
if NoBits ¼¼ 0
pq ¼ 0;
indx ¼ 0;
else
delta ¼ 2*abs(Xmax)/(2^NoBits-1);
Xrmax ¼ delta*(2^NoBits/2-1);
if abs(value) >
¼
Xrmax
tmp
¼
Xrmax;
else
tmp
¼
abs(value);
end
indx
¼
round(tmp/delta);
indx*delta;
if value < 0
pq ¼ -pq;
indx ¼ -indx;
end
end
Program 11.6. MATLAB function for midtread quantizer decoding.
pq
¼
function pq ¼ mtrddec(NoBits,Xmax,indx)
% function pq ¼ mtrddec(NoBits, Xmax, value)
% This routine is the dequantizer.
%
% NoBits: number of bits used in quantization.
% Xmax: overload value.
% pq: output of quantized value
% indx: integer index
%
Search WWH ::




Custom Search