From 600a48ac61fd1fdd7cbcfd538acc6f56d6ba4b63 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Thu, 29 Jun 2017 12:08:43 +0200 Subject: [PATCH] dsp.fir: cleanup --- artiq/gateware/dsp/fir.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/artiq/gateware/dsp/fir.py b/artiq/gateware/dsp/fir.py index 4efa46e44..516ca5c7f 100644 --- a/artiq/gateware/dsp/fir.py +++ b/artiq/gateware/dsp/fir.py @@ -78,14 +78,14 @@ class ParallelFIR(Module): self.coefficients = cs = [int(round(c*(1 << c_shift))) for c in coefficients] assert max(bits_for(c) for c in cs) <= w.B + max_out = sum(abs(c)*(1 << w.A - 1) for c in cs) + assert max_out <= (1 << w.P - 1) - 1, (bits_for(max_out), w) ### # Delay line: increasing delay x = [Signal((w.A, True), reset_less=True) for _ in range(n + p - 1)] - assert sum(abs(c)*(1 << w.A - 1) for c in cs) <= (1 << w.P - 1) - 1 - for xi, xj in zip(x, self.i[::-1]): self.comb += xi.eq(xj) for xi, xj in zip(x[len(self.i):], x): @@ -110,7 +110,8 @@ class ParallelFIR(Module): else: self.comb += o0.eq(o + m) assert min(js) - tap >= 0 - js = [j for j in js if (p - 1 - j - tap) % p not in cull_delays] + js = [j for j in js + if (p - 1 - j - tap) % p not in cull_delays] if not js: continue self.comb += q.eq(reduce(add, [x[j - tap] for j in js])) @@ -129,6 +130,7 @@ class FIR(ParallelFIR): def halfgen4_cascade(rate, width, order=None): """Generate coefficients for cascaded half-band filters. + Coefficients are normalized to a gain of two per stage to compensate for the zero stuffing.