module Feldspar.Processing.Filters where
import Prelude ()
import Feldspar
import Feldspar.Data.Vector
import Feldspar.Data.Queue
recurrenceI
:: ( Pushy m fvec a
, Finite fvec
, Seqy m ivec a
, Syntax a, Syntax b
, MonadComp m
)
=> fvec
-> ivec
-> (Pull a -> b)
-> Seq m b
recurrenceI ii vec body = Seq len $ do
next <- init
buf <- initQueue2 ii
return $ \i -> do
a <- next i
iff (length ii /= 0)
(putQ buf a)
(return ())
withQ buf (return . body)
where
Seq len init = toSeq vec
recurrenceIO
:: ( Pushy m fvec a
, Finite fvec
, Seqy m ivec a
, Pushy m bvec b
, Finite bvec
, Syntax a, Syntax b
, MonadComp m
)
=> fvec
-> ivec
-> bvec
-> (Pull a -> Pull b -> b)
-> Seq m b
recurrenceIO ii vec io body = Seq len $ do
next <- init
ibuf <- initQueue2 ii
obuf <- initQueue2 io
return $ \i -> do
a <- next i
iff (length ii /= 0)
(putQ ibuf a)
(return ())
b <- withQ ibuf $ \ib ->
withQ obuf $ \ob ->
shareM $ body ib ob
iff (length io /= 0)
(putQ obuf b)
(return ())
return b
where
Seq len init = toSeq vec
fir :: (Pully fvec a, Seqy m ivec a, Syntax a, Num a, MonadComp m)
=> fvec
-> ivec
-> Seq m a
fir bs inp = recurrenceI (replicate (length bs) 0) inp $ \i ->
scProd bs i
iir :: ( Pully bvec a, Pully fvec a
, Seqy m ivec a, Syntax a
, Fractional a
, MonadComp m
)
=> a
-> bvec
-> fvec
-> ivec
-> Seq m a
iir a0 as bs inp = recurrenceIO
(replicate (length bs) 0)
inp
(replicate (length as) 0)
(\i o -> 1 / a0 * (scProd bs i scProd as o))
firPull :: (Pully vec1 a, Pully vec2 a, Syntax a, Num a)
=> vec1
-> vec2
-> Pull a
firPull bs = map (scProd bs . reverse) . tail . inits