I want to do two things.
- Estimating Coefficients of AR model using LMS
- Using Coefficients found in step 1 and predict future samples of a signal using AR equation. I don't have a desired signal so I can't use future samples as well.
The equation of Autoregressive model is $$x(n) = \sum_{i=1}^p a_i x(n-i) + e(n)$$
where $p$ indicates the AR model order ($p=30$ in my case) and $\mathbf{a}$ shows the AR coefficients $\{a_1, a_2, a_3, a_4,\ldots, a_{30}\} $.
And LEAST MEANS SQUARE (LMS) algorithm is as follows:
Order=30; % AR model order
M=30; % No of filter coefficients same as AR model order
mu=0.001; % Learning rate/ step size
x=signal(1,1:700); % length of signal is 700 samples, x= input signal
N=length(x);
Predicted_signal=zeros(1,N);
w=zeros(1,M); % weights / filter coefficients
for n=M:N
pp=n-M+1;
x1=x(n:-1:pp);
Predicted_signal(n)=(w*x1');
e(n)=x(n)-Predicted_signal(n); %e(n)=d(n)-y(n); reference signal - actual signal
w=w+2*mu*e(n)*x1;
w1(n-M+1,:)=w(1,:); % filter coefficients
end
Coefficients (weights/ w) found in previous code to be used in AR equation.
ts = prediction starting point that is 436th sample
Predicted_signal_ar= orignal_signal(1,1:436);
for i=1:Order
t=ts-i;
prediction1(1,i)=(w(1,i)*Predicted_signal_ar(t)); %% putting lms coefficients in AR equation
end
s1(1,a)=sum(prediction1(1,:));
Predicted_signal_ar(1,ts)=s1(1,a);
There is some error in my code and I am not sure what is it. The above code should give me close to actual Coefficients which then I pass to step 2 for AR prediction. In results of 2nd step there is a sudden jump in prediction of first few points and prediction performance is also poor.