1st and 2nd order linear prediction

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

Contents

Impulse response, acf and prediction

b = .242*[1 2 1]; a = [1 -.71 .25]; % numerator and denominator
N = 21;                  % simulated lenght of impulse response
h = impz(b,a,N);         % impulse response
Rhh = conv(h,flipud(h)); % acf
% prediction coefficients and error signal power
b0_1 = Rhh(N+1) / Rhh(N);    % 1st order
MSEopt_1 = Rhh(N) - b0_1*Rhh(N+1);
D = Rhh(N)^2 - Rhh(N+1)^2;   % 2nd order
b0_2 = (Rhh(N)*Rhh(N+1)-Rhh(N+2)*Rhh(N+1)) / D;
b1_2 = (Rhh(N)*Rhh(N+2)-Rhh(N+1)^2) / D;
MSEopt_2 = Rhh(N) - b0_2*Rhh(N+1) - b1_2*Rhh(N+2);
fprintf('lab11_1 : Prediction coefficients and error signal power\n')
fprintf(' 1st order : b0 = %g ; MSEopt = %g \n',b0_1,MSEopt_1)
fprintf(' 2nd order : b0 = %g ; b1 = %g ; MSEopt = %g \n\n',b0_2,b1_2,MSEopt_2)
graph10_h(h,Rhh,'lab11_1 : Impulse response and acf') % graphics
lab11_1 : Prediction coefficients and error signal power
 1st order : b0 = 0.788526 ; MSEopt = 0.378472 
 2nd order : b0 = 1.3168 ; b1 = -0.669952 ; MSEopt = 0.2086 

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 of white noise
Rxx = xcorr(x,'unbiased');   % estimate autocorrelation sequence of filtered noise
fprintf('Estimated mean signal powers \n')
fprintf(' Innovation    : Rww[0] = %g \n',Rww(L))
fprintf(' Model process : Rxx[0] = %g \n\n',Rxx(L))

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

Linear prediction

e_1 = x(2:L)-b0_1*x(1:L-1);               % 1st order prediction error
Ree_1 = xcorr(e_1,'unbiased');            % estimate acf
e_2 = x(3:L)-b0_2*x(2:L-1)-b1_2*x(1:L-2); % 2nd order prediction error
Ree_2 = xcorr(e_2,'unbiased');            % estimate acf
fprintf('Estimated mean prediction error powers \n')
fprintf(' 1st order : Ree[0] = %g \n',Ree_1(L-1))
fprintf(' 2nd order : Ree[0] = %g \n\n',Ree_2(L-2))
% graphics
graph10_e(e_1,e_2,Ree_1/Rxx(L),Ree_2/Rxx(L),L,'lab11_1 : Prediction error signal and acf')
Estimated mean prediction error powers 
 1st order : Ree[0] = 0.378724 
 2nd order : Ree[0] = 0.209594 

1st order lattice filter implementation

k1 = - Rhh(N+1) / Rhh(N);
[u1,v] = latcfilt(k1,x);
Ruu_1 = xcorr(u1,'unbiased');

2nd order lattice filter implementation

k2 = -(Rhh(N)*Rhh(N+2)-Rhh(N+1)^2)/(Rhh(N)^2-Rhh(N+1)^2);
[u2,v] = latcfilt([k1 k2],x);
Ruu_2 = xcorr(u2,'unbiased');
fprintf('Estimated mean prediction error powers - lattice structure \n')
fprintf(' 1st order : Ree[0] = %g \n',Ruu_1(L))
fprintf(' 2nd order : Ree[0] = %g \n\n',Ruu_2(L))
graph11_u(u1,u2,Ruu_1/Rxx(L),Ruu_2/Rxx(L),L,...
    'lab11_1 : Prediction error signal and acf - lattice structure') % graphics
Estimated mean prediction error powers - lattice structure 
 1st order : Ree[0] = 0.378686 
 2nd order : Ree[0] = 0.209553