%levinsondurbin.m
function [res]=levinsondurbin(a)
%a is the vector withsize 1xn
temp1=a(2:1:length(a));
for j=1:1:length(a)-1
A{j}=toeplitz(a(1:1:j));
end
x{1}=[a(2)/a(1)];
k(1)=(a(3)-a(2)*x{1}(1))/(a(1)-a(2)*x{1}(1));
c{1}=-inv(A{1})*a(2)*k(1) ;
c{1}=[c{1};k(1)];
x{2}=[x{1} ;0];
x{2}=x{2}+c{1};
for r=2:1:length(a)-2
k(r)=(a(r+2)-rev(a,r)*x{r})/(a(1)-[a(2:1:r+1)]*x{r});
c{r}=-1*inv(A{r})*rev(a,r)' *k(r) ;
c{r}=[c{r};k(r)];
x{r+1}=[x{r};0];
x{r+1}=x{r+1}+c{r};
end
res=[1; -1*x{r+1}];
