Last active
June 1, 2016 11:45
-
-
Save christiaanb/384008f5b04ad1d5cb2c8a8ced44bb63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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