I was able to solve the indices problem and correctly solve the levinson recursion equations. Posting just in case someone needs this in the future!
P = zeros(1,3);
alpha = zeros(1,3);
a(1,1) = -autocorr(2)/autocorr(1);
P(1) = autocorr(1);
P(2) = autocorr(1) - ((autocorr(2)^2)/autocorr(1));
for N = 1:numlag-2
sum = 0;
for j = 1:N
sum = sum + a(N,j)*autocorr(N+2-j);
end
alpha(N,1) = autocorr(N+2) + sum;
for i = 1:N
a(N+1,i) = a(N,i) - (alpha(N)/P(N+1))*a(N,N+1-i);
end
a(N+1,i) = a(N,i) - (alpha(N)/P(N+1))*a(N,N+1-i);
a(N+1,N+1) = - alpha(N)/P(N+1);
P(N+2) = P(N+1) - (alpha(N))^2/P(N+1);
zerochecker = abs(P(2) - P(1));
if zerochecker < 0.5
N = 0;
break
end
check = abs(abs(P(N+2)) - abs(P(N+1)));
if check < 1
break
end
end
As a BONUS I am posting my autocorrelation sequence below:
function [autocorr] = corr(numlag,dataD,n)
for ii = 1:numlag
lag = ii - 1;
for iii = 1:n-lag
seq1(iii,ii) = dataD(iii).* dataD(iii+lag);
numer = sum(seq1);
end
autocorr_unrounded = round(numer,2)';
end
autocorr = autocorr_unrounded/n;
end
Best Answer