1st and 2nd order linear prediction
** lab10_1.m * mw * 04/19/2007
Contents
Impulse response and acf of 2nd order system
b = .242*[1 2 1]; a = [1 -.71 .25]; % numerator and denominator coefficients N = 21; % simulation lenght of impulse response h = impz(b,a,N); % impulse response Rhh = conv(h,flipud(h)); % acf % graphics graph10_h(h,Rhh,'lab10_1 : Impulse response, acf and pds')
1st and 2nd order 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('lab10_1 : Prediction coefficients and error signal power\n\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)
lab10_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 Rxx = xcorr(x,'unbiased'); % estimate autocorrelation sequence fprintf('Estimated mean signal power \n') fprintf(' Innovation : Rww[0] = %g \n',Rww(L)) fprintf(' Model process : Rxx[0] = %g \n\n',Rxx(L)) % graphics graph10_w(x,w,Rxx,Rww,L,'lab10_1 : Sample function and estimated acf')
Estimated mean signal power Innovation : Rww[0] = 1.00225 Model process : Rxx[0] = 1.04142
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 power \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,Ree_2,L,'lab10_1 : Prediction error signal and acf')
Estimated mean prediction error power 1st order : Ree[0] = 0.382525 2nd order : Ree[0] = 0.213315