-
Notifications
You must be signed in to change notification settings - Fork 0
/
toeplitz_inverse.m
52 lines (45 loc) · 1.31 KB
/
toeplitz_inverse.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function [c_inv, logdet] = toeplitz_inverse(m)
%ASA Returns inverse of a Toeplitz matrix and log det c
% Input is the first column of the Toeplitz matrix
c = m(:, 1)';
N = length(c);
c_inv = zeros(N);
[v, logdet] = alg1_2(c);
c_inv(1, 1:N) = v(N:-1:1);
c_inv(1:N, 1) = v(N:-1:1);
c_inv(N, 1:N) = v(1:N);
c_inv(1:N, N) = v(1:N);
for i = 2 : floor((N-1)/2) + 1
for j = i : N - i + 1
c_inv(i, j) = c_inv(i-1, j-1) + (v(N+1-j) * v(N+1-i) - v(i-1) * v(j-1))/v(N);
% c_inv(i, j)
c_inv(j, i) = c_inv(i, j);
c_inv(N-i+1, N-j+1) = c_inv(i, j);
c_inv(N-j+1, N-i+1) = c_inv(i, j);
end
end
end
function [v, l] = alg1_2(c)
N = length(c);
wiggle = c(2:end)'/c(1);
[z, l] = alg1_3(N-1, wiggle);
l = l + N * log(c(1));
v(N) = 1/((1 + wiggle' * z) * c(1));
v(1:N-1) = v(N) * z(N-1:-1:1);
end
function [z, l] = alg1_3(m, wiggle)
z = zeros(m, 1);
z(1) = -wiggle(1);
beta = 1;
alpha = -wiggle(1);
l = 0;
for i = 1:m-1
beta = (1-alpha^2) * beta;
l = l + log(beta);
alpha = -(wiggle(i+1) + wiggle(i:-1:1)' * z(1:i)) / (beta);
z(1:i) = z(1:i) + alpha * z(i:-1:1);
z(i+1) = alpha;
end
beta = (1-alpha^2) * beta;
l = l + log(beta);
end