.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/connectmultiplesfgs.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_connectmultiplesfgs.py: ======================== Connecting multiple SFGs ======================== It is sometimes useful to create several SFGs and later on connect them. One reason is using the SFG generators. Although connecting several SFGs is rather straightforward, it is also of interest to "flatten" the SFGs, i.e., get a resulting SFG not containing other SFGs but the operations of these. To do this, one will have to use the method :func:`~b_asic.sfg.SFG.connect_external_signals_to_components`. This example illustrates how it can be done. .. GENERATED FROM PYTHON SOURCE LINES 16-35 .. code-block:: Python from b_asic.sfg_generators import wdf_allpass from b_asic.sfg import SFG from b_asic.special_operations import Input, Output # Generate allpass branches for fifth-ordet LWDF filter allpass1 = wdf_allpass([0.2, 0.5]) allpass2 = wdf_allpass([-0.5, 0.2, 0.5]) in_lwdf = Input() allpass1 <<= in_lwdf allpass2 <<= in_lwdf out_lwdf = Output((allpass1 + allpass2) * 0.5) # Create SFG of LWDF with two internal SFGs sfg_with_sfgs = SFG( [in_lwdf], [out_lwdf], name="LWDF with separate internals SFGs for allpass branches" ) .. GENERATED FROM PYTHON SOURCE LINES 36-37 The resulting SFG looks like: .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python sfg_with_sfgs .. raw:: html
%3 in0 in0 in0.0 in0:e->in0.0 sfg0 WDF allpass section (sfg0) in0.0->sfg0 sfg1 WDF allpass section (sfg1) in0.0->sfg1 add0 add0 sfg0->add0 0 sfg1->add0 1 out0 out0 cmul0 cmul0 cmul0->out0:w add0->cmul0


.. GENERATED FROM PYTHON SOURCE LINES 41-43 Now, to create a LWDF where the SFGs are flattened. Note that the original SFGs ``allpass1`` and ``allpass2`` currently cannot be printed etc after this operation. .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python allpass1.connect_external_signals_to_components() allpass2.connect_external_signals_to_components() flattened_sfg = SFG([in_lwdf], [out_lwdf], name="Flattened LWDF") .. GENERATED FROM PYTHON SOURCE LINES 49-50 Resulting in: .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python flattened_sfg .. raw:: html
%3 in0 in0 in0.0 in0:e->in0.0 sym2p0 sym2p0 in0.0->sym2p0 0 sym2p3 sym2p3 in0.0->sym2p3 0 add0 add0 sym2p0->add0 0 0 t0 t0 sym2p0->t0 1 sym2p2 sym2p2 sym2p3->sym2p2 0 0 t3 t3 sym2p3->t3 1 out0 out0 cmul0 cmul0 cmul0->out0:w sym2p1 sym2p1 sym2p1->sym2p0 1 0 t4 t4 sym2p1->t4 1 add0->cmul0 t0->sym2p1 0 sym2p2->add0 1 0 t1 t1 sym2p2->t1 1 sym2p4 sym2p4 sym2p4->sym2p2 1 0 t2 t2 sym2p4->t2 1 t1->sym2p4 0 t2->sym2p4 1 t3->sym2p3 1 t4->sym2p1 1


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.030 seconds) .. _sphx_glr_download_examples_connectmultiplesfgs.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: connectmultiplesfgs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: connectmultiplesfgs.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: connectmultiplesfgs.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_