forsyde / forsyde-shallow

ForSyDe's Haskell-embedded Domain Specific Language
https://forsyde.github.io/forsyde-shallow/
BSD 3-Clause "New" or "Revised" License
12 stars 10 forks source link

firSY process in Utility.FIR does not implement a FIR as expected. #29

Closed Rojods closed 3 years ago

Rojods commented 3 years ago

the code present in ForSyDe.Shallow.Utility.FIR does not implement a simple FIR as expected. If we follow the agreed definition for FIR's with m taps and coefficients h, where h(0) is the least shifted or delayed tap and h(m) is the most shifted or delayed tap,

y(k) = \sum_{i = 0,...,m} h(i)*x(k - i)

one would expect the following definitions for coefficients and signals,

coef = vector [1.0, 0.5]
s = signal [1.0, 0.5, 1.0, 0.5]
y = firSY coef s

to result in {1.0, 1.0, 1.25, 1.0} by the mathematical definition. However, our result is reproducibly {0.0,0.5,1.25,1.0,1.25}. The right result is easy to be checked by hand, but can also be checked out in other famous digital design aware environments like Matlab,

D = tf([1 0.5], [1 0], 1)
s = [1 0.5 1 0.5]
[y, t] = lsim(D, s)

that gives us y = [1;1;1.25;1], as expected.

The culprit in this case seems to be the fact that all signals are delayed between the unzip and zip constructors, whereas the definition requires the very first piece of the signal to flow without any delays. The evidence for this is the 0.0 at the beginning of the simulated signal which should never happen.

Rojods commented 3 years ago

Solved by merging #31