?? test_5_speech.m
字號(hào):
clc; clear; clf;
p = 'D:\adorel\a_master_DC\standard_test_audio\';
filename = 'speech.wav';
file = strcat(p,filename);
[I_all,fs,nbits, opts] = wavread(file);
[m,n] = size(I_all);
if n > 1, % then stereo record..
I_all = (I_all(:,1) + I_all(:,2) )./2;
end;
Ns = length(I_all); I = I_all;
Ns = 1000;I = I_all(1000:1000+Ns-1);
a = I;
t=(0:Ns-1).*(1/fs);
% 1. Quantize using equal-length intervals and no compander.
V = max(a);
nbits_out = 8;
step = 2 * V / 2^(nbits_out -1); % one bit is for sign...
range = [-V:step:V];
for i=1:length(a),
aq(i) = f_quantization(a(i),range);
end;
figure(1);
subplot(211), plot(t,a); hold on; stairs(t,aq,'r');
title('quantization without compression');
% 2. Use same partition and codebook, but compress
% before quantizing and expand afterwards.
mu=255; V = max(a);
ac = compand(a, mu, V, 'mu/compressor');
for i = 1:length(a),
outq(i) = f_quantization(ac(i),range);
end;
aexp = compand(outq, mu, max(outq),'mu/expander');;
figure(2);
subplot(311), plot(t,a, t,ac,'r');
title('original and compressed signal (red)');
subplot(312), plot(t,ac); hold on; stairs(t, outq,'r');
title('Compressed and quantized signal (red)');
subplot(313), plot(t,a, t, aexp,'r'); xlabel('time[s]');
title('original and expanded signal (red)');
% 3. view details...
n1 = Ns/2; n2 = n1 + 100; n =[n1:n2];
clf; figure(3);
subplot(211), plot(n,a(n)); hold on; plot(n, aq(n),'r');
title('original and quantized signal (red)');
subplot(212), plot(n,a(n), n, aexp(n),'r');
title('original and expanded signal (red)');
MSE_1 = sum((aq - a').^2)/ length(a);
MSE_2 = sum((aexp - a').^2) / length(a);
MSE_1 / MSE_2
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -