Second-order IIR Filter with Schedule

from b_asic.core_operations import Addition, ConstantMultiplication
from b_asic.schedule import Schedule
from b_asic.signal_flow_graph import SFG
from b_asic.special_operations import Delay, Input, Output

in1 = Input("IN1")
c0 = ConstantMultiplication(5, in1, "C0")
add1 = Addition(c0, None, "ADD1")
# Not sure what operation "Q" is supposed to be in the example
T1 = Delay(add1, 0, "T1")
T2 = Delay(T1, 0, "T2")
b2 = ConstantMultiplication(0.2, T2, "B2")
b1 = ConstantMultiplication(0.3, T1, "B1")
add2 = Addition(b1, b2, "ADD2")
add1.input(1).connect(add2)
a1 = ConstantMultiplication(0.4, T1, "A1")
a2 = ConstantMultiplication(0.6, T2, "A2")
add3 = Addition(a1, a2, "ADD3")
a0 = ConstantMultiplication(0.7, add1, "A0")
add4 = Addition(a0, add3, "ADD4")
out1 = Output(add4, "OUT1")

sfg = SFG(inputs=[in1], outputs=[out1], name="Second-order direct form IIR filter")

The SFG looks like

sfg
%3 in0 IN1 (in0) cmul0 C0 (cmul0) in0->cmul0 add0 ADD1 (add0) cmul0->add0 0 out0 OUT1 (out0) add2 ADD4 (add2) add2->out0 add0.0 add0->add0.0 add1 ADD2 (add1) add1->add0 1 t0 T1 (t0) add0.0->t0 cmul1 A0 (cmul1) add0.0->cmul1 t0.0 t0->t0.0 cmul1->add2 0 add3 ADD3 (add3) add3->add2 1 cmul2 A1 (cmul2) cmul2->add3 0 cmul3 A2 (cmul3) cmul3->add3 1 t1.0 t1.0->cmul3 cmul4 B2 (cmul4) t1.0->cmul4 t1 T2 (t1) t1->t1.0 t0.0->cmul2 t0.0->t1 cmul5 B1 (cmul5) t0.0->cmul5 cmul4->add1 1 cmul5->add1 0


Set latencies and execution times

sfg.set_latency_of_type(ConstantMultiplication.type_name(), 2)
sfg.set_latency_of_type(Addition.type_name(), 1)
sfg.set_execution_time_of_type(ConstantMultiplication.type_name(), 1)
sfg.set_execution_time_of_type(Addition.type_name(), 1)

Create schedule

schedule = Schedule(sfg, cyclic=True)
schedule.show()
secondorderdirectformiir

Total running time of the script: (0 minutes 0.286 seconds)

Gallery generated by Sphinx-Gallery