Implementation of auto regression model in matlab

1 view (last 30 days)
hii.. I am new to Matlab so excuse me if the questions is silly
I am trying to make a kalman filter in matlab and the reference signal is a second order auto regression signal My question is how do I make the auto regression signal for my input signal of the correct length
The code I tried for generating the AR signal is
y= arx(x,N);
where x is input signal and N is length of the input signal
but on executing I am gettting the error
There are too many parameters to estimate for chosen estimation data size. Reduce model
order or use a larger data set.
Error in ==> dc_kalman_jow_ at 9
y= arx(x,N);
This is my complete code.
please help
clc;
clear all;
close all;
[x fs]=wavread ('speech.wav');
v=rand (size(x));
orig=x+v;
no=orig;
N=length(x);
y= arx(x,N);
for(i=5:N)
z(i)=x(i);
end
F = zeros (5, N);
I = eye (5);
H = zeros (5, N);
P = zeros (5, 5*N);
K = zeros (5, N);
XX = zeros (5, N);
y = zeros (1, N);
vv = zeros (1, N);
yy = zeros (1, N);
Q = 0.0001*eye (5, 5);
R = 0.1;
y= x (1: N);
P (1:5, 1:5) = 0.1*I;
for k=6: N
H(1:5,k)=-[y(k-1);y(k-2);y(k-3);y(k-4);y(k-5)];
F(1:5,k)=-[yy(k-1);yy(k-2);yy(k-3);yy(k-4);yy(k-5)];
K(1:5,k) = P(1:5,5*k-29:5*k-25)*H(1:5,k)*inv(H(1:5,k)'*P(1:5,5*k-29:5*k-25) * H(1:5,k)+R); %Kalman Gain
P(1:5,5*k-24:5*k-20) = P(1:5,5*k-29:5*k-25)-K(1:5,k)*(H(1:5,k)'*P(1:5,5*k-29:5*k-25))+Q; % error covariance matrix
XX(1:5,k) =(I - K(1:5,k)*H(1:5,k)')*XX(1:5,k-1) + (K(1:5,k)*y(k)); % posteriori value of estimate X(k)
esti (k) =y (k)-(H (1:3, k)'*XX (1:3, k));
yy (k) = (F (1:5, k)'*XX (1:5, k)) + esti (k);
end;
for it = 1:1: length(x)
MSE (it) = esti (it) - x (it);
end;
tt = 1:1: length(x);
figure (1); subplot (311); plot(x); title ('ORIGINAL PNAL');
subplot (312); plot (no); title ('Noisy Speech Pnal');
subplot (313); plot (esti); title ('ESTIMATED PNAL');
figure (2); plot (tt, x, tt, esti); title ('Combined plot'); legend ('original’,’ estimated');
figure (3); plot (MSE.^2); title ('Mean square error');
SNR= sum(z.*z)/var(esti-z)
Please tell me how to implement the 2nd order regression model ( http://en.wikipedia.org/wiki/Autoregressive_model) in matlab

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!