Skip to content

Instantly share code, notes, and snippets.

@christiaanb
Last active June 1, 2016 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiaanb/384008f5b04ad1d5cb2c8a8ced44bb63 to your computer and use it in GitHub Desktop.
Save christiaanb/384008f5b04ad1d5cb2c8a8ced44bb63 to your computer and use it in GitHub Desktop.
module FIR_transposed where
import CLaSH.Prelude
-- "Normal"
fir1 coeffs us x = (us',y)
where
us' = (x +>> us)
y = fold (+) (zipWith (*) us coeffs)
-- Transposed
fir2 coeffs us x = (us',y)
where
ms = map (x*) coeffs
us' = zipWith (+) (us <<+ 0) ms
y = head us
-- Transposed v2
fir3 coeffs us x = (us',y)
where
ms = map (x*) coeffs
us' = zipWith (+) (tail us) (init ms) :< last ms
y = head us
t1 :: Signal (Signed 16) -> Signal (Signed 16)
t1 = mealy (fir1 (2:>3:>(-2):>8:>Nil)) (repeat 0)
t2 :: Signal (Signed 16) -> Signal (Signed 16)
t2 = mealy (fir2 (2:>3:>(-2):>8:>Nil)) (repeat 0)
t3 :: Signal (Signed 16) -> Signal (Signed 16)
t3 = mealy (fir3 (2:>3:>(-2):>8:>Nil)) (repeat 0)
testInput :: Signal (Signed 16)
testInput = stimuliGenerator (2:>3:>(-2):>8:>Nil)
-- >>> sampleN 4 (t1 testInput)
-- [0,4,12,1]
-- >>> sampleN 4 (t2 testInput)
-- [0,4,12,1]
-- >>> sampleN 4 (t3 testInput)
-- [0,4,12,1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment