Convergence and learning curve of 2nd order LMS predictor

** lab15_3.m * mw * 05/14/2007

Contents

Input dialog

prompt = {'Order of predictor p'};
dlg_title = 'lab15_3'; 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
sound(x,fs,bits);

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)
[e1 g] = latcfilt(k,x);     % residuum e[n] (prediction error) (Signal Processing Toolbox)
clear g;                   % delete backward lattice filter output signal
Re1e1 = xcorr(e1,'unbiased'); % estimate autocorrelation sequence of residuum
fprintf('lab15_3 : 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',Re1e1(Lx))
fprintf('Prediction error    E      = %g \n',E)
fprintf('Prediction gain     Gp     = %g dB\n\n',10*log10(Rxx(Lx)/Re1e1(Lx)))
pause(1+Lx/fs)
sound(e1,fs,bits);        % residuum
lab15_3 : Reflection coefficients
 k1 = -0.982861 
 k2 = 0.47298 
 k3 = 0.16021 
Audio signal        Rxx[0] = 0.031681 
Residual signal     Ree[0] = 0.000816771 
Prediction error    E      = 0.000814322 
Prediction gain     Gp     = 15.887 dB

Simulation of adaptiv system

.alpha - convergence parameter, .beta - weighting parameter of variance estimator .sig2 - variance, .N - FIR filter order (N+1 coefficients) .Mode - mode for updating FIR filter coefficients, Mode = 'e*x' no sign function used Mode = 'x*sign(e)','e*sign(x)' and 'sign(e*x)' uses sign function

p = Np;  % prediction order (FIR filter order + 1)
lms = struct('alpha',1/16,'beta',1/32,'b',zeros(p,1),'e',0,'x',zeros(p,1),...
             'sig2',0.01,'Mode','e*x');
% noise = 10^(-10/10)*randn(1,M); % AWGN
[y,e2,lms,SAVEb] = lms_algorithm([0 x(1:Lx-1)'],x,lms); % LMS algorithm
pause(1+Lx/fs)
sound(e2,fs,bits);        % residuum

Graphics

figure('Name',['lab15_3 : pth order linear prediction -> 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,e1(1:Lx)),grid
xlabel('t in s \rightarrow'), ylabel('e_{LTP}(t) \rightarrow')
title('Prediction error - long term prediction')
subplot(3,2,4), plot(t2,Re1e1(Lx:Lx+L2)/Rxx(Lx),0,Re1e1(Lx)/Rxx(Lx),'o'),grid
xlabel('\tau in ms \rightarrow'), ylabel('R_{ee,LTP}(\tau) / R_{xx}(0) \rightarrow')
title('ACF with long term prediction)')
subplot(3,2,5), plot(t1,e2(1:Lx)),grid
xlabel('t in s \rightarrow'), ylabel('e_{LMS}(t) \rightarrow')
title('Prediction error with LMS algorithm')
Re2e2 = xcorr(e2,'unbiased');  % estimate mean autocorrelation sequence
subplot(3,2,6), plot(t2,Re2e2(Lx:Lx+L2)/Rxx(Lx),0,Re2e2(Lx)/Rxx(Lx),'o'),grid
xlabel('\tau in ms \rightarrow'), ylabel('R_{ee,LMS}(\tau) / R_{xx}(0) \rightarrow')
title('ACF with LMS algorithm')
figure('Name',['lab15_3 : pth order linear prediction -> p = ',...
    num2str(Np),' , fs = ',num2str(fs)],'NumberTitle','off');
subplot(3,1,1), plot(t1,SAVEb(1,1:Lx)),grid
xlabel('t in s \rightarrow'), ylabel('sig2(t) \rightarrow')
title('power estimates')
subplot(3,1,2), plot(t1,SAVEb(2,1:Lx)),grid
xlabel('t in s \rightarrow'), ylabel('b_0(t) \rightarrow')
title('FIR filter coefficient')
subplot(3,1,3), plot(t1,SAVEb(3,1:Lx)),grid
xlabel('t in s \rightarrow'), ylabel('b_1(t) \rightarrow')