Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ad60212
added filter_df1 and test_df1
sriyash25 Jun 1, 2018
e059e30
updates from upstream
sriyash25 Jun 12, 2018
e121a40
updates to test_df1 to enable plotting feature
sriyash25 Jun 17, 2018
6c8040c
resolving conflicts
sriyash25 Jun 17, 2018
4ac9bbf
plot feature to test_df1
sriyash25 Jun 17, 2018
ff9050c
reverting conflicts in filter_iir
sriyash25 Jun 17, 2018
9eec818
new interface file fir_pyfda and test file test_pyfda_df1. added func…
sriyash25 Jun 19, 2018
6f1126a
deleted duplicate files. Tests written to mimic pyfda interface
sriyash25 Jun 22, 2018
449cec3
added get_response function to fir_test and fixed work length.
sriyash25 Jun 24, 2018
47156ba
fixed import issues
sriyash25 Jun 26, 2018
0b5e895
updates to interface
sriyash25 Jun 27, 2018
7f6dc6e
renamed file fir_test to fir_temp. new file iir_temp for iir interfaf…
sriyash25 Jun 29, 2018
db07981
added default argument for w in constructor in 'filter_hw'
sriyash25 Jun 29, 2018
2817a1f
changed name runsim() to run_sim()
sriyash25 Jul 9, 2018
2a43497
updates from upstream
sriyash25 Jul 11, 2018
c4500b6
Merge branch 'master' into interface
sriyash25 Jul 11, 2018
358b0f0
added covert method to fda/fir.py and deleted excess files
sriyash25 Jul 13, 2018
51628fd
finishing up convert method for fir
sriyash25 Jul 13, 2018
e8791cd
updates to fir_df1 to incorporate stimulus word format
sriyash25 Jul 15, 2018
58bf66f
minor fixes to fir interface
sriyash25 Jul 16, 2018
2cd187a
minor fixes to hdl_interface and updates to iir interface
sriyash25 Jul 16, 2018
a53e14a
updates to interface
sriyash25 Jul 16, 2018
20f28fb
fixes to convert()
sriyash25 Jul 17, 2018
771663c
fixes to accumulator length
sriyash25 Jul 17, 2018
60add0b
fixed ffd and x length issue
sriyash25 Jul 17, 2018
1715601
output word_format now included
sriyash25 Jul 19, 2018
bee194e
test_df1_sine added
sriyash25 Jul 23, 2018
20add4d
fixed accumulator length for df1_fir filter and completed implementat…
sriyash25 Jul 25, 2018
c25ed41
stop creating trace file
sriyash25 Jul 25, 2018
6152eb7
fixing ffd convert bit-length
sriyash25 Jul 25, 2018
d701902
fixed accumulator bits for fir_df1 implementation
sriyash25 Jul 26, 2018
8338a8f
fixes to test_df1_sine
sriyash25 Jul 26, 2018
ac6cf81
saturation logic added to iir_df1 and fixes to fir_df1
sriyash25 Jul 27, 2018
2cf8b0f
iir_df1 with saturatoin
sriyash25 Jul 28, 2018
aacc087
overflow fix to output
sriyash25 Jul 31, 2018
7fb6914
Jupyter notebook with examples
sriyash25 Aug 1, 2018
9638668
-1 to accumulator bits
sriyash25 Aug 1, 2018
1991d82
fixes to iir df1
sriyash25 Aug 4, 2018
78407ab
fixes to iir_df1 saturation logic and including sos files
sriyash25 Aug 5, 2018
231fcb8
updates from upstream
sriyash25 Aug 5, 2018
0dedc4e
updates from upstream
sriyash25 Aug 5, 2018
66f5a18
updates from master
sriyash25 Aug 5, 2018
097fbe7
updates from master
sriyash25 Aug 5, 2018
0da8f36
adding sos filter
sriyash25 Aug 5, 2018
ba3c606
saturation logic to iir filter
sriyash25 Aug 9, 2018
774f532
info method added
sriyash25 Aug 9, 2018
06e4c91
fixes to fir interface
sriyash25 Aug 9, 2018
093423f
fixes to iir filter
sriyash25 Aug 11, 2018
a14a210
fixed broken iir parallel test
sriyash25 Aug 12, 2018
1c1a96d
updates to tutorial notebook
sriyash25 Aug 12, 2018
c4c0d16
resolving merge conflicts
sriyash25 Aug 12, 2018
3451a5f
resolving merge conflicts to notebook
sriyash25 Aug 12, 2018
18bd6a1
remove duplicate notebook
sriyash25 Aug 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions filter_blocks/fda/filter_hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@ def __init__(self, b=None, a=None):
# A reference to the HDL block
self.hardware = None

def set_coefficients(self, coeff_b, coeff_a=None):
def set_coefficients(self, coeff_b = None, coeff_a = None, sos = None):
"""Set filter coefficients.

Args:
coeff_b (list): list of numerator filter coefficients
coeff_a (list): list of denominator filter coefficients
"""
self.b = tuple(coeff_b)
if coeff_b is not None:
self.b = tuple(coeff_b)

if coeff_a is not None:
self.a = tuple(coeff_a)

if sos is not None:
self.sos = sos

def set_stimulus(self, sigin):
"""Set filter stimulus

Expand Down
88 changes: 36 additions & 52 deletions filter_blocks/fda/fir.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, b = None, a = None):
self.direct_form_type = 1
self.response = []


def get_response(self):
"""Return filter output.

Expand All @@ -32,11 +33,26 @@ def get_response(self):
"""
return self.response

def info(self):
"""Print filter info"""
print("Filter type :", self.filter_type, "\n"
"Filter order :", len(self.b), "\n"
"Arithmatic :", "fixed", "\n"
"Coefficient format :", self.coef_word_format ,"\n"
"Input format :", self.input_word_format ,"\n"
"Accumulator size :", "\n"
"Output format :", self.output_word_format ,"\n"
"Round mode :", "no rounding", "\n"
"Overflow mode :" "no overflow"
)

def run_sim(self):
"""Run filter simulation"""

testfil = self.filter_block()
testfil.run_sim()


def convert(self, **kwargs):
"""Convert the HDL description to Verilog and VHDL.
"""
Expand All @@ -46,7 +62,7 @@ def convert(self, **kwargs):
imax = 2**(w[0]-1)

# small top-level wrapper
def filter_fir_top(hdl, clock, reset, x, xdv, y, ydv):
def filter_fir_top(hdl , clock, reset, x, xdv, y, ydv):
sigin = Samples(x.min, x.max, self.input_word_format)
sigin.data, sigin.data_valid = x, xdv
sigout = Samples(y.min, y.max, self.output_word_format)
Expand All @@ -55,19 +71,21 @@ def filter_fir_top(hdl, clock, reset, x, xdv, y, ydv):
rst = reset
glbl = Global(clk, rst)

# choose appropriate filter
#choose appropriate filter
fir_hdl = fir_df1.filter_fir

fir = fir_hdl(glbl, sigin, sigout, self.b, self.coef_word_format,
shared_multiplier=self._shared_multiplier)

fir.convert(**kwargs)


clock = Clock(0, frequency=50e6)
reset = Reset(1, active=0, async=True)
x = Signal(intbv(0, min=-imax, max=imax))
y = Signal(intbv(0, min=-omax, max=omax))
xdv, ydv = Signal(bool(0)), Signal(bool(0))


if self.hdl_target.lower() == 'verilog':
filter_fir_top(hdl, clock, reset, x, xdv, y, ydv)
Expand All @@ -77,20 +95,22 @@ def filter_fir_top(hdl, clock, reset, x, xdv, y, ydv):
else:
raise ValueError('incorrect target HDL {}'.format(self.hdl_target))



@hdl.block
def filter_block(self):
"""
This elaboration code will select the different structure and
implementations
"""
""" this elaboration code will select the different structure and implementations"""

w = self.input_word_format
w_out = self.output_word_format
#print(self.input_word_format)
#print(self.coef_word_format)
ymax = 2**(w[0]-1)
vmax = 2**(2*w[0])
omax = 2**(w_out[0]-1)
xt = Samples(min=-ymax, max=ymax, word_format=self.input_word_format)
yt = Samples(min=-omax, max=omax, word_format=self.output_word_format)
#yt = Samples(min=-vmax, max=vmax)
xt.valid = bool(1)
clock = Clock(0, frequency=50e6)
reset = Reset(1, active=0, async=True)
Expand All @@ -100,34 +120,39 @@ def filter_block(self):

# set numsample
numsample = len(self.sigin)
# process to record output in buffer
#process to record output in buffer
rec_insts = yt.process_record(clock, num_samples=numsample)


if self.filter_type == 'direct_form':
if self.direct_form_type == 1:
# all filters will need the same interface ports, this should be do able
dfilter = fir_df1.filter_fir
else:
raise NotImplementedError

if self.n_cascades > 0:
filter_insts = [None for _ in range(self.n_cascades)]
for ii in range(self.n_cascades):
pass
# filter_insts[ii] = fir_df1.filter_fir(
# glbl, sigin[ii], sigout[ii], b
# )
else:
filter_insts = dfilter(glbl, xt, yt, self.b, self.coef_word_format)




@hdl.instance
def stimulus():
"""record output in numpy array yt.sample_buffer"""
"record output in numpy array yt.sample_buffer"
for k in self.sigin:
xt.data.next = int(k)
xt.valid = bool(1)

yt.record = True
yt.valid = True
yield clock.posedge
# Collect a sample from each filter
#Collect a sample from each filter
yt.record = False
yt.valid = False

Expand All @@ -139,44 +164,3 @@ def stimulus():
raise StopSimulation()

return hdl.instances()

@hdl.block
def process(self, glbl, smpi, smpo):
"""FIR filter model.

Args:
glbl:
smpi: sample stream input
smpo: sample stream output

Not convertible
"""
assert isinstance(smpi, Samples)
assert isinstance(smpo, Samples)

clock, reset = glbl.clock, glbl.reset
x, y = smpi, smpo
ntaps = len(self.b)
h = tuple(self.b)

xd = [0 for _ in range(len(h))]

@hdl.instance
def beh_proc():
while True:
yield clock.posedge

if x.valid:
xd.insert(0, int(smpi.data))
xd.pop(-1)

sop = 0
for ii in range(ntaps):
sop = sop + (h[ii] * xd[ii])

y.data.next = int(round(sop))
y.valid.next = True
else:
y.valid.next = False

return hdl.instances()
30 changes: 23 additions & 7 deletions filter_blocks/fda/iir.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from myhdl import Signal, intbv, StopSimulation

from .filter_hw import FilterHardware
from ..iir import iir_df1
from ..iir import iir_df1, iir_sos
from filter_blocks.support import Clock, Reset, Global, Samples


class FilterIIR(FilterHardware):
def __init__(self, b=None, a=None):
def __init__(self, b = None, a = None):
"""Contains IIR filter parameters. Parent Class : FilterHardware
Args:
b (list of int): list of numerator coefficients.
Expand Down Expand Up @@ -37,9 +37,22 @@ def run_sim(self):
"""Run filter simulation"""

testfil = self.filter_block()
# testfil.config_sim(trace=True)
#testfil.config_sim(trace=True)
testfil.run_sim()

def info(self):
"""Print filter info"""
print("Filter type :", self.filter_type, "\n"
"Filter order :", len(self.b), "\n"
"Arithmatic :", "fixed", "\n"
"Coefficient format :", self.coef_word_format ,"\n"
"Input format :", self.input_word_format ,"\n"
"Accumulator size :", "\n"
"Output format :", self.output_word_format ,"\n"
"Round mode :", "no rounding", "\n"
"Overflow mode :" "saturate"
)

def convert(self, **kwargs):
"""Convert the HDL description to Verilog and VHDL.
"""
Expand All @@ -60,6 +73,7 @@ def filter_iir_top(hdl , clock, reset, x, xdv, y, ydv):

# choose appropriate filter
iir_hdl = iir_df1.filter_iir

iir = iir_hdl(
glbl, sigin, sigout, self.b, self.a, self.coef_word_format,
shared_multiplier=self._shared_multiplier
Expand All @@ -71,6 +85,7 @@ def filter_iir_top(hdl , clock, reset, x, xdv, y, ydv):
x = Signal(intbv(0, min=-imax, max=imax))
y = Signal(intbv(0, min=-omax, max=omax))
xdv, ydv = Signal(bool(0)), Signal(bool(0))


if self.hdl_target.lower() == 'verilog':
filter_iir_top(hdl, clock, reset, x, xdv, y, ydv)
Expand All @@ -87,7 +102,7 @@ def filter_block(self):
w = self.input_word_format
w_out = self.output_word_format

ymax = 2**(w[0]-1)
ymax = 2**(2*w[0]-1)
vmax = 2**(2*w[0])
omax = 2**(w_out[0]-1)
xt = Samples(min=-ymax, max=ymax, word_format=self.input_word_format)
Expand All @@ -111,10 +126,11 @@ def filter_block(self):

if self.n_cascades > 0:
# TODO: port the SOS iir into the latest set of interfaces
# filter_insts = iir_sos.filter_iir_sos(
# glbl, xt, yt, self.b, self.a, self.coef_word_format
# )
#filter_insts = iir_sos.filter_iir_sos(
# glbl, xt, yt, self.sos, self.coef_word_format
#)
pass

else:
filter_insts = dfilter(
glbl, xt, yt, self.b, self.a, self.coef_word_format
Expand Down
1 change: 1 addition & 0 deletions filter_blocks/fir/fir_df1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


@hdl.block

def filter_fir(glbl, sigin, sigout, b, coef_w, shared_multiplier=False):
"""Basic FIR direct-form I filter.

Expand Down
Loading