module DSP.Estimation.Spectral.ARMA (arma_mywe) where
import Data.Array
import Data.Complex
import DSP.Correlation
arma_mywe ::
(RealFloat b, Integral i, Ix i) =>
Array i (Complex b) -> i -> i -> Array i (Complex b)
arma_mywe x p q = a'
where r = array (q2*p+1,q+p) [ (k, rxx_u x k) | k <- [(q2*p+1)..(q+p)] ]
a' = array (1,p) [ (k, a!(p,k)) | k <- [1..p] ]
a = array ((1,1),(p,p)) [ ((k,i), ak k i) | k <- [1..p], i <- [1..k] ]
b = array ((1,1),(p1,p1)) [ ((k,i), bk k i) | k <- [1..(p1)], i <- [1..k] ]
rho = array (1,p1) [ (k, rhok k) | k <- [1..(p1)] ]
ak 1 1 = r!(q+1) / r!q
ak k i | i==k = (r!(q+k) + sum [ a!(k1,l) * r!(q+kl) | l <- [1..(k1)] ] ) / rho!(k1)
| otherwise = a!(k1,i) + a!(k,k) * b!(k1,ki)
bk 1 1 = r!(q1) / r!q
bk k i | i==k = (r!(qk) + sum [ b!(k1,l) * r!(qkl) | l <- [1..(k1)] ] ) / rho!(k1)
| otherwise = b!(k1,i) + b!(k,k) * a!(k1,ki)
rhok 1 = (1 a!(1,1) * b!(1,1)) * r!q
rhok k = (1 a!(k,k) * b!(k,k)) * rho!(k1)