Linear prediction of audio signals
audio signal : speech.wav, handel.wav ** lab11_5.m * mw * 04/25/2007
Contents
Input dialog
prompt = {'Order of predictor p'};
dlg_title = 'lab11_4'; num_lines = 1; def = {'3'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
if isempty(answer)
Np = 3; % default
else
Np = str2num(answer{1}); % prediction order
end
[x,fs,bits]=wavread('speech'); % speech signal
% [x,fs,bits]=wavread('handel'); % audio signal
Lx = length(x); % number of samples
soundsc(x,fs,bits);
MATLAB Signal Processing Toolbox
[bp E] = lpc(x,Np); disp('lpc : Prediction filter coefficients') disp(bp) disp('lpc : Variance of prediction error') disp(E) k = tf2latc(bp); disp('lpc : Reflection coefficients') disp(k)
lpc : Prediction filter coefficients
1.0000 -1.2238 0.2551 -0.1177 0.0778 -0.3082 0.3622 0.0136
lpc : Variance of prediction error
6.4467e-004
lpc : Reflection coefficients
-0.9828
0.4721
0.1603
0.2181
0.1796
0.3789
0.0136
Linear prediction (long term)
Rxx = xcorr(x,'unbiased'); % estimate mean autocorrelation sequence r = Rxx(Lx:Lx+Np+1); % relevant coefficients for Levinson-Durbin alg. Rxx[0],Rxx[1],... [a,E,k] = levinson(r,Np); % Levinson-Durbin alg. (Signal Processing Toolbox) [e g] = latcfilt(k,x); % residuum e[n] (prediction error) (Signal Processing Toolbox) clear g; % delete backward lattice filter output signal Ree = xcorr(e,'unbiased'); % estimate autocorrelation sequence of residuum fprintf('lab11_4 : Reflection coefficients\n') for m=1:Np fprintf([' k',num2str(m),' = %g \n'],k(m)) end fprintf('Audio signal Rxx[0] = %g \n',Rxx(Lx)) fprintf('Residual signal Ree[0] = %g \n',Ree(Lx)) fprintf('Prediction error E = %g \n',E) fprintf('Prediction gain Gp = %g dB\n\n',10*log10(Rxx(Lx)/Ree(Lx))) pause(1+Lx/fs) soundsc(e,fs,bits); % residuum
lab11_4 : Reflection coefficients k1 = -0.982861 k2 = 0.47298 k3 = 0.16021 k4 = 0.218412 k5 = 0.179777 k6 = 0.37979 k7 = 0.0129872 Audio signal Rxx[0] = 0.031681 Residual signal Ree[0] = 0.00064467 Prediction error E = 0.000642065 Prediction gain Gp = 16.9146 dB
Inverse filtering (all-pole filter)
[y g] = latcfilt(k,1,e); % all-pole filter (Signal Processing Toolbox) Ryy = xcorr(y,'unbiased'); % estimate mean autocorrelation sequence pause(1+Lx/fs) soundsc(y,fs,bits); % reconstructed signal
Graphics
figure('Name',['lab11_4 : pth order linear prediction with lattice structure -> p = ',... num2str(Np),' , fs = ',num2str(fs)],'NumberTitle','off'); L2 = 400; t1 = (0:Lx-1)/fs; t2 = 1e3*(0:L2)/fs; subplot(3,2,1), plot(t1,x(1:Lx)),grid xlabel('t in s \rightarrow'), ylabel('x(t) \rightarrow') title('Audio signal (original)') subplot(3,2,2), plot(t2,Rxx(Lx:Lx+L2)/Rxx(Lx)),grid xlabel('\tau in ms \rightarrow'), ylabel('R_{xx}(\tau) / R_{xx}(0) \rightarrow') title('ACF') subplot(3,2,3), plot(t1,e(1:Lx)),grid xlabel('t in s \rightarrow'), ylabel('e(t) \rightarrow') title('Prediction error') subplot(3,2,4), plot(t2,Ree(Lx:Lx+L2)/Rxx(Lx),0,Ree(Lx)/Rxx(Lx),'o'),grid xlabel('\tau in ms \rightarrow'), ylabel('R_{ee}(\tau) / R_{xx}(0) \rightarrow') title('ACF') subplot(3,2,5), plot(t1,y(1:Lx)),grid xlabel('t in s \rightarrow'), ylabel('y(t) \rightarrow') title('Audio signal (restored)') subplot(3,2,6), plot(t2,Ryy(Lx:Lx+L2)/Rxx(Lx)),grid xlabel('\tau in ms \rightarrow'), ylabel('R_{yy}(\tau) / R_{xx}(0) \rightarrow') title('ACF')