Nth order linear prediction for 2nd order AR process

** lab11_3.m * mw * 04/20/2007

Contents

Input dialog, delay

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

Impulse response and acf

b = .7969; 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_3 : Impulse response and acf') % graphics

N-th order prediction coefficients and error signal power

RR = zeros(Np,Np);       % time autocorrelation 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_3 : 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_3 : Prediction coefficients
 b1 = 0.71 
 b2 = -0.25 
 b3 = -5.02227e-017 
 b4 = 9.17829e-018 
 b5 = 5.97545e-019 
 b6 = -1.69703e-018 
 b7 = 2.39018e-018 
Minimum MSE for M = 1 : MSEopt = 0.63505 

Prediction gain : Gp = 1.5747 

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_3 : Sample function and acf') % graphics
Estimated mean signal powers 
 Innovation   : Rww[0] = 0.987717 
 Model process: Rxx[0] = 0.991522 

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(' Model process: Ree[0] = %g \n\n',Ree(L))
Reflexion coefficients
 k1 = -0.568 
 k2 = 0.25 
 k3 = 8.74123e-017 
 k4 = -3.44782e-017 
 k5 = 3.831e-018 
 k6 = 5.20126e-019 
 k7 = 2.29457e-018 
 Model process: Ree[0] = 0.627249 

Graphics - Model process and prediction error

FIG1 = figure('Name',['lab11_3 : 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')