module DSP.Correlation (rxy, rxy_b, rxy_u, rxx, rxx_b, rxx_u, test) where
import Data.Array
import Data.Complex
rxy :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> Array a (Complex b)
-> a
-> Complex b
rxy x y k =
if k >= 0
then sum [ x!(i+k) * conjugate (y!i) | i <- [0..(n-1-k)] ]
else conjugate (rxy y x (-k))
where n = snd (bounds x) + 1
rxy_b :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> Array a (Complex b)
-> a
-> Complex b
rxy_b x y k = rxy x y k / fromIntegral n
where n = snd (bounds x) + 1
rxy_u :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> Array a (Complex b)
-> a
-> Complex b
rxy_u x y k = rxy x y k / fromIntegral (n - abs k)
where n = snd (bounds x) + 1
rxx :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> a
-> Complex b
rxx x k = rxy x x k
rxx_b :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> a
-> Complex b
rxx_b x k = rxy_b x x k
rxx_u :: (Ix a, Integral a, RealFloat b) => Array a (Complex b)
-> a
-> Complex b
rxx_u x k = rxy_u x x k
xt, yt :: Array Int (Complex Double)
xt = array (0,4)
[ (0, 1 :+ 0),
(1, 0 :+ 1),
(2, (-1) :+ 0),
(3, 0 :+ (-1)),
(4, 1 :+ 0) ]
yt = array (0,4)
[ (0, 1 :+ 0),
(1, (-1) :+ 0),
(2, 1 :+ 0),
(3, (-1) :+ 0),
(4, 1 :+ 0) ]
rt :: [Complex Double]
rt = map (rxy_b xt yt) [ 0, 1, 2 ]
test :: Bool
test = rt == [ (0.2 :+ 0.0), (0.0 :+ 0.0), (0.0 :+ 0.2) ]