module DSP.Estimation.Frequency.WLP (wlp, lrp, kay, lw, ckq,) where
import DSP.Basic((^!))
import Data.Array
import Data.Complex
wlp :: (Ix a, Integral a, RealFloat b) => Array a b
-> Array a (Complex b)
-> b
wlp w z = phase (sum [ (w!t :+ 0) * z!t * conjugate (z!(t1)) | t <- [1..(n1)] ])
where n = snd (bounds z) + 1
lrp :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> b
lrp = processArray (\n _ _ -> recip (n1))
kay :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> b
kay = processArray (\n _ t -> kayWin n t)
kayWin :: Fractional b => b -> b -> b
kayWin n t = 6*t*(nt) / (n*(n^!21))
lw :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> b
lw z =
processArray
(\ n ti t -> kayWin n t /
(magnitude (z!ti) * magnitude (z!(ti1)))) z
ckq :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> b
-> b
-> b
ckq z rho sig =
processArray
(\n ->
let num t = sinh (n * th) sinh (t * th) sinh ((nt) * th)
den = (n1) * sinh (n * th)
2 * sinh (0.5 * n * th)
* sinh (0.5 * (n1) * th) / sinh (0.5 * th)
sigRho2 = (sig / rho) ^! 2
th = log (1 + sig^!2 / rho^!2 + sqrt ((sigRho2+1) * sigRho2))
in \_ t -> num t / den) z
processArray ::
(Integral a, Ix a, RealFloat b) =>
(b -> a -> b -> b) -> Array a (Complex b) -> b
processArray f z =
let n = snd (bounds z) + 1
g = f (fromIntegral n)
bnd = (1,n1)
in wlp (listArray bnd
(map (\t -> g t (fromIntegral t)) (range bnd))) z