Safe Haskell | None |
---|---|

Language | Haskell2010 |

- data DSignal delay a
- dsignal :: a -> DSignal n a
- delay :: forall a n m. KnownNat m => Vec m a -> DSignal (n - m) a -> DSignal n a
- delayI :: (Default a, KnownNat m) => DSignal (n - m) a -> DSignal n a
- feedback :: (DSignal ((n - m) - 1) a -> (DSignal ((n - m) - 1) a, DSignal n a)) -> DSignal ((n - m) - 1) a
- fromSignal :: Signal a -> DSignal 0 a
- toSignal :: DSignal delay a -> Signal a
- unsafeFromSignal :: Signal a -> DSignal n a
- dsample :: DSignal t a -> [a]
- dsampleN :: Int -> DSignal t a -> [a]
- dfromList :: [a] -> DSignal 0 a

# Delay-annotated synchronous signals

A synchronized signal with samples of type `a`

, synchronized to "system"
clock (period 1000), that has accumulated `delay`

amount of samples delay
along its path.

dsignal :: a -> DSignal n a Source

Create a constant `DSignal`

from a combinational value

`>>>`

[4, 4, 4, 4, ...`dsample (dsignal 4)`

delay :: forall a n m. KnownNat m => Vec m a -> DSignal (n - m) a -> DSignal n a Source

Delay a `DSignal`

for `m`

periods.

delay3 :: DSignal (n - 3) Int -> DSignal n Int delay3 = delay (0 :> 0 :> 0 :> Nil)

`>>>`

[0,0,0,1,2,3]`dsampleN 6 (delay3 (dfromList [1..]))`

delayI :: (Default a, KnownNat m) => DSignal (n - m) a -> DSignal n a Source

Delay a `DSignal`

for `m`

periods, where `m`

is derived from the context.

delay2 :: DSignal (n - 2) Int -> DSignal n Int delay2 = delayI

`>>>`

[0,0,1,2,3,4]`dsampleN 6 (delay2 (dfromList [1..])`

feedback :: (DSignal ((n - m) - 1) a -> (DSignal ((n - m) - 1) a, DSignal n a)) -> DSignal ((n - m) - 1) a Source

Feed the delayed result of a function back to its input:

mac :: DSignal 0 Int -> DSignal 0 Int -> DSignal 0 Int mac x y =`feedback`

(mac' x y) where mac' :: DSignal 0 Int -> DSignal 0 Int -> DSignal 0 Int -> (DSignal 0 Int, DSignal 1 Int) mac' a b acc = let acc' = a * b + acc in (acc, delay (`singleton`

0) acc')

`>>>`

[0,1,5,14,30,55]`dsampleN 6 (mac (dfromList [1..]) (dfromList [1..]))`

# Signal <-> DSignal conversion

fromSignal :: Signal a -> DSignal 0 a Source

`Signal`

s are not delayed

sample s == dsample (fromSignal s)

unsafeFromSignal :: Signal a -> DSignal n a Source