Digital Signal Processing Reference
In-Depth Information
value
¼
sgn(cmp_code)*(512
þ
(abs(cmp_code)-96)*32
þ
16);
end
if (abs(cmp_code) >
¼
112) & (abs(cmp_code)<128)
value
¼
sgn(cmp_code)*(1024
þ
(abs(cmp_code)-112)*64
þ
32);
end
Program 11.11. Main program for ADPCM coding.
% This program is written for offline simulation.
% file: adpcm.m
clear all; close all
load we.dat
% Provided by the instructor
speech
¼
we;
desig
speech;
lg
¼
length(desig);
¼
% Length of speech data
enc
¼
adpcmenc(desig);
% ADPCM encoding
%ADPCM finished
dec
¼
adpcmdec(enc); % ADPCM decoding
snrvalue
¼
snr(desig,dec) % Calculate signal to noise ratio due to quantization
subplot(3,1,1);plot(desig);grid;
ylabel(
'
Speech
'
);axis([0 length(we) -8000 8000]);
subplot(3,1,2);plot(dec);grid;
ylabel(
'
Quantized speech
'
);axis([0 length(we) -8000 8000]);
subplot(3,1,3);plot(desig-dec);grid
ylabel(
'
Quantized error
'
);xlabel(
'
Sample number
'
);
axis([0 length(we) -1200 1200]);
Program 11.12. MATLAB function for ADPCM encoding.
function iiout
¼
adpcmenc(input)
% This function performs ADPCM encoding.
% function iiout
¼
adpcmenc(input)
% Usage:
% input
¼
input value
% iiout
¼
output index
%
% Quantization tables
fitable
¼
[000111137];
witable
¼
[-0.75 1.13 2.56 4.00 7.00 12.38 22.19 70.13 ];
qtable
¼
[ -0.98 0.62 1.38 1.91 2.34 2.72 3.12 ];
invqtable
[0.031 1.05 1.66 2.13 2.52 2.91 3.32 ];
lgth
¼
length(input);
sr
¼
zeros(1,2); pk
¼
zeros(1,2);
a
¼
zeros(1,2); b
¼
zeros(1,6);
dq
¼
zeros(1,6); ii
¼
zeros(1,lgth);
y
¼
0; ap
¼
0; al
¼
0; yu
¼
0; yl
¼
0; dms
¼
0; dml
¼
0; tr
¼
0; td
¼
0;
for k
¼
1:lgth
sl
¼
input(k);
¼
%
% predict zeros
Search WWH ::
Custom Search