Digital Signal Processing Reference
In-Depth Information
lg ¼ length(sig);
% Length of the speech data
t ¼ [0:1:lg-1];
% Time index
sig ¼ 5*sig/max(abs(sig));
% Normalized signal to the range between -5 to 5
Emax ¼ max(abs(sig));
Erms ¼ sqrt( sum(sig .* sig) / length(sig))
k ¼ Erms/Emax
disp( ' 20*log10(k) ¼ > ' );
k
¼
20*log10(k)
bits
¼
input(
input number of bits
¼
>
);
'
'
lg
length(sig);
% Encoding
for x
¼
1:lg
[indx(x) qy]
¼
¼
mtrdenc(bits, 5, sig(x));
end
disp( ' Finished and transmitted ' );
% Decoding
for x ¼ 1:lg
qsig(x) ¼ mtrddec(bits, 5, indx(x));
end
disp( ' decoding nished ' );
qerr ¼ sig-qsig; % Calculate quantization errors
subplot(3,1,1);plot(t, sig);grid
ylabel( ' Speech ' );axis([0 length(we) -5 5]);
subplot(3,1,2);plot(t, qsig);grid
ylabel( ' Quantized speech ' );axis([0 length(we) -5 5]);
subplot(3,1,3);plot(qerr);grid
axis([0 length(we) -0.5 0.5]);
ylabel( ' Qunatized error ' );xlabel( ' Sample number ' );
disp( ' signal to noise ratio due to quantization noise ' )
snr(sig,qsig); % Calculate signal to noise ratio due to quantization
Program 11.2. MATLAB program for m -law encoding and decoding.
close all; clear all
disp(
load speech
le
);
'
'
load we.dat;
% Provided by your instructor
lg
¼
length(we);
% Length of the speech data
we
¼
5*we/max(abs(we));
% Normalize the speech data
we_nor ¼ we/max(abs(we));
% Normalization
t ¼ [0:1:lg-1];
% Time index
disp( ' mulaw companding ' )
mu ¼ input( ' input mu ¼ > ' );
for x ¼ 1:lg
ymu(x) ¼ mulaw(we_nor(x),1,mu);
end
disp( ' nished mu-law companding ' );
disp( ' start to quantization ' )
bits ¼ input( ' input bits ¼ > ' );
% Midtread quantization and encoding
Search WWH ::




Custom Search