Digital Signal Processing Reference
In-Depth Information
2.5 MATLAB PROGRAMS
Program 2.3. MATLAB function for uniform quantization encoding.
function [ I, pq] ¼ biquant(NoBits,Xmin,Xmax,value)
% function pq ¼ biquant(NoBits, Xmin, Xmax, value)
% This routine is created for simulation of the uniform quantizer.
%
% NoBits: number of bits used in quantization
% Xmax: overload value
% Xmin: minimum value
% value: input to be quantized
% pq: output of quantized value
% I: coded integer index
L ¼ 2^NoBits;
delta ¼ (Xmax-Xmin)/L;
I ¼ round((value-Xmin)/delta);
if ( I ¼¼ L)
I ¼ I-1;
end
if I<0
I
¼
0;
end
pq
I*delta;
Program 2.4. MATLAB function for uniform quantization decoding.
¼
Xmin
þ
function pq ¼ biqtdec(NoBits,Xmin,Xmax,I)
% function pq ¼ biqtdec(NoBits,Xmin, Xmax, I)
% This routine recovers the quantized value.
%
% NoBits: number of bits used in quantization
% Xmax: overload value
% Xmin: minimum value
% pq: output of quantized value
% I: coded integer index
L
2^NoBits;
delta
¼
(Xmax-Xmin)/L;
pq ¼ Xmin þ I*delta;
Program 2.5. MATLAB function for calculation of signal to quantization noise ratio.
¼
function snr ¼ calcsnr(speech, qspeech)
% function snr ¼ calcsnr(speech, qspeech)
% This routine was created to calculate SNR.
%
% speech: original speech waveform
% qspeech: quantized speech
% snr: output SNR in dB
%
qerr ¼ speech-qspeech;
Search WWH ::




Custom Search