N-th order linear prediction
** lab10_3.m * mw * 04/18/2007
Contents
Input dialog
prompt = {'Order of predictor N','Delay m'};
dlg_title = 'lab10_3'; num_lines = 1; def = {'3','1'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
if isempty(answer)
Np=3; M=1; % default
else
Np = str2num(answer{1}); % prediction order
M = str2num(answer{2}); % delay
end
Impulse response and acf
b = .24192*[1 2 1]; a = [1 -.71 .25]; % denominator and numerator coefficients N = 41; % simulation lenght of impulse response h = impz(b,a,N); % impulse response Rhh = conv(h,flipud(h)); % acf % graphics graph10_h(h,Rhh,'lab10_3 : Impulse response, acf and pds')
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 crosscorrelation function bp = RR\r; % prediction coefficients rr^-1 * r MSEopt = Rhh(N) - bp'*r; % mean power of prediction error fprintf('lab10_3 : Prediction coefficients\n') for k=1:Np fprintf([' b(',num2str(k-1),') = %g \n'],bp(k)) end fprintf('Minimum MSE for m = %g : MSEopt = %g \n',M,MSEopt) fprintf('Prediction gain : Gp = %g \n',Rhh(N)/MSEopt)
lab10_3 : Prediction coefficients b(0) = 1.66263 b(1) = -1.34969 b(2) = 0.516203 Minimum MSE for m = 1 : MSEopt = 0.152914 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)) % graphics graph10_w(x,w,Rxx,Rww,L,'lab10_3 : Sample function and acf')
Estimated mean signal powers Innovation : Rww[0] = 1.00711 Model process: Rxx[0] = 0.984871
Linear prediction error
e = x(Np+1:L); % prediction error for k=1:Np e = e - bp(k)*x(Np+1-k:L-k); end Ree = xcorr(e,'unbiased'); % estimate auto-correlation sequence fprintf(' Model process: Ree[0] = %g \n\n',Ree(L-Np)) % graphics FIG1 = figure('Name',['lab10_3 : Nth order linear prediction -> N = ',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(1:L1+1)),grid xlabel('n \rightarrow'), ylabel('e[n] \rightarrow') title('prediction error') subplot(2,2,4), stem(0:L2,Ree(L-Np:L-Np+L2)/Rxx(L)),grid xlabel('l \rightarrow'), ylabel('R_{ee}[l] / R_{xx}[0] \rightarrow') title('ACF')
Model process: Ree[0] = 0.150561