I think I missed class when this was explained ...
Anyway as part of a bigger project I have to implement a LPC to predict 2-3 future values of a sinusoidal process. I wrote a small Matlab m-file to calculate the predictor coefficients and plot the resulting predicted values.
It does look well so far when moving around $y(x) \cong 0$ but the values around the maxima/minima $y(x) \cong \pm 1$ are completely off (it predicts into the opposite direction):
I'm using the variables 'phi' to set sort of a operation point and 'unk' to set the starting point from where values should start to get predicted.
Here my m-file:
N = 100; % samples fs = 60; % sample-frequency [Hz] Ts = 1/fs; % sample-time [s] unk = 10; % future values to predict (mostly used to set x(k) where we start predicting from) P = 10; % predictor order phi = 0; % default phase-offset phi = pi/2; k = 0:1/N:2; x = sin(2*pi*fs*k*Ts+phi); % reference values x_pred = x(1:101); % intialize with x ... % last 'unk' values will be replaced by the predicted ones x_kn = x_pred(1:end-unk); % values we already know (we will try to predict last 'unk' values) coeffs = aryule(x_kn, P); % get 'P' filter coeffs using the known input 'x_kn' values for i = 1:unk % x^ = -vec(a) * vec(x_kn)' nextValue = -coeffs(2:end) * ... % P - 1 coefficient vector x_pred(length(x_kn)-1+i: ... % last value we actually know (at pos len(x_kn)) -1: ... % reverse iterate ... length(x_kn)-P+i)'; % until P values before len(x_kn) x_pred(length(x_kn)+i) = nextValue; % now we know the value at len(x_kn)+1 end figure(1); plot(0:length(x_kn)+unk-1 ,x_pred, 0:length(x)-1, x); grid; legend('predicted', 'real');