N-th order linear prediction

with prediction filter in lattice structure ** lab11_2.m * mw * 04/25/2007

Contents

Input dialog, delay

prompt = {'Order of predictor p'};
dlg_title = 'lab11_2'; 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 input
end
M = 1;  % delay

Impulse response and acf

b = .242*[1 2 1]; a = [1 -.71 .25];  % numerator and denominator coefficients
N = 41;                  % simulated lenght of impulse response
h = impz(b,a,N);         % impulse response
Rhh = conv(h,flipud(h)); % acf
graph10_h(h,Rhh,'lab11_2 : Impulse response and acf') % graphics

N-th order prediction coefficients and error signal power

RR = zeros(Np,Np);       % time auto-correlation matrix
for m=0:Np-1
    RR(1+m,1+m) = Rhh(N);
    for n=m+1:Np-1
        RR(1+m,1+n) = Rhh(N+n-m);
        RR(1+n,1+m) = RR(1+m,1+n);
    end
end
r = Rhh(N+M:N+M+Np-1);    % time cross-correlation function
bp = RR\r;                % prediction coefficients rr^-1 * r
MSEopt = Rhh(N) - bp'*r;  % mean power of prediction error
fprintf('lab11_2 : Prediction coefficients\n')
for k=1:Np
    fprintf([' b',num2str(k),' = %g \n'],bp(k))
end
fprintf('Minimum MSE for M = %g : MSEopt = %g \n\n',M,MSEopt)
fprintf('Prediction gain : Gp = %g \n',Rhh(N)/MSEopt)
lab11_2 : Prediction coefficients
 b1 = 1.66263 
 b2 = -1.34969 
 b3 = 0.516203 
Minimum MSE for M = 1 : MSEopt = 0.153016 

Prediction gain : Gp = 6.53952 

Sample function

L = 10001;                   % number of samples
w = randn(1,L);              % normally distributed white noise
x = filter(b,a,w);           % normally distributed colored noise
Rww = xcorr(w,'unbiased');   % estimate autocorrelation sequence
Rxx = xcorr(x,'unbiased');   % estimate autocorrelation sequence
fprintf('Estimated mean signal powers \n')
fprintf(' Innovation        Rww[0] = %g \n',Rww(L))
fprintf(' Model process     Rxx[0] = %g \n',Rxx(L))

graph10_w(x,w,Rxx,Rww,L,'lab11_2 : Sample function and acf') % graphics
Estimated mean signal powers 
 Innovation        Rww[0] = 1.01196 
 Model process     Rxx[0] = 1.01581 

Linear prediction with lattice structure

r = Rhh(N:N+Np+1);
k = lev_dur(r,Np);               % reflexion coefficients
% [A,E,K] = levinson(r,Np); % MATLAB Signal Processing Toolbox
[e G] = latcfilt(k,x); clear G;
Ree = xcorr(e,'unbiased');       % estimate autocorrelation sequence
fprintf('Reflexion coefficients\n')
for m=1:Np
    fprintf([' k',num2str(m),' = %g \n'],k(m))
end
fprintf(' Prediction error  Ree[0] = %g \n\n',Ree(L))
Reflexion coefficients
 k1 = -0.788526 
 k2 = 0.669952 
 k3 = -0.516203 
 Prediction error  Ree[0] = 0.155329 

Graphics - Model process and prediction error

FIG1 = figure('Name',['lab11_2 : pth order linear prediction with lattice structure -> p = ',...
    num2str(Np)],'NumberTitle','off');
L1 = 60; L2 = 20;
subplot(2,2,1), stem(0:L1,x(1:L1+1)),grid
xlabel('n \rightarrow'), ylabel('x[n] \rightarrow')
title('Model process')
subplot(2,2,2), stem(0:L2,Rxx(L:L+L2)/Rxx(L)),grid
xlabel('l \rightarrow'), ylabel('R_{xx}[l] / R_{xx}[0] \rightarrow')
title('ACF')
subplot(2,2,3), stem(0:L1,e(Np+1:Np+L1+1)),grid
xlabel('n \rightarrow'), ylabel('e[n] \rightarrow')
title('Prediction error')
subplot(2,2,4), stem(0:L2,Ree(L:L+L2)/Rxx(L)),grid
xlabel('l \rightarrow'), ylabel('R_{ee}[l] / R_{xx}[0] \rightarrow')
title('ACF')