Skip to content
Snippets Groups Projects
Commit 41115f33 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Add simulation-based test for FIR generators

parent f4cb6655
No related branches found
No related tags found
1 merge request!273Add simulation-based test for FIR generators
Pipeline #93743 passed
import numpy as np
from b_asic.core_operations import ( from b_asic.core_operations import (
Addition, Addition,
ConstantMultiplication, ConstantMultiplication,
...@@ -8,6 +10,8 @@ from b_asic.sfg_generators import ( ...@@ -8,6 +10,8 @@ from b_asic.sfg_generators import (
transposed_direct_form_fir, transposed_direct_form_fir,
wdf_allpass, wdf_allpass,
) )
from b_asic.signal_generator import Impulse
from b_asic.simulation import Simulation
from b_asic.special_operations import Delay from b_asic.special_operations import Delay
...@@ -38,7 +42,8 @@ def test_wdf_allpass(): ...@@ -38,7 +42,8 @@ def test_wdf_allpass():
def test_direct_form_fir(): def test_direct_form_fir():
sfg = direct_form_fir([0.3, 0.5, 0.7]) impulse_response = [0.3, 0.5, 0.7]
sfg = direct_form_fir(impulse_response)
assert ( assert (
len( len(
[ [
...@@ -52,6 +57,12 @@ def test_direct_form_fir(): ...@@ -52,6 +57,12 @@ def test_direct_form_fir():
assert len([comp for comp in sfg.components if isinstance(comp, Addition)]) == 2 assert len([comp for comp in sfg.components if isinstance(comp, Addition)]) == 2
assert len([comp for comp in sfg.components if isinstance(comp, Delay)]) == 2 assert len([comp for comp in sfg.components if isinstance(comp, Delay)]) == 2
sim = Simulation(sfg, [Impulse()])
sim.run_for(4)
impulse_response.append(0.0)
assert np.allclose(sim.results['0'], impulse_response)
impulse_response = [0.3, 0.4, 0.5, 0.6, 0.3]
sfg = direct_form_fir( sfg = direct_form_fir(
(0.3, 0.4, 0.5, 0.6, 0.3), (0.3, 0.4, 0.5, 0.6, 0.3),
mult_properties={'latency': 2, 'execution_time': 1}, mult_properties={'latency': 2, 'execution_time': 1},
...@@ -59,9 +70,15 @@ def test_direct_form_fir(): ...@@ -59,9 +70,15 @@ def test_direct_form_fir():
) )
assert sfg.critical_path_time() == 6 assert sfg.critical_path_time() == 6
sim = Simulation(sfg, [Impulse()])
sim.run_for(6)
impulse_response.append(0.0)
assert np.allclose(sim.results['0'], impulse_response)
def test_transposed_direct_form_fir(): def test_transposed_direct_form_fir():
sfg = transposed_direct_form_fir([0.3, 0.5, 0.7]) impulse_response = [0.3, 0.5, 0.7]
sfg = transposed_direct_form_fir(impulse_response)
assert ( assert (
len( len(
[ [
...@@ -75,9 +92,20 @@ def test_transposed_direct_form_fir(): ...@@ -75,9 +92,20 @@ def test_transposed_direct_form_fir():
assert len([comp for comp in sfg.components if isinstance(comp, Addition)]) == 2 assert len([comp for comp in sfg.components if isinstance(comp, Addition)]) == 2
assert len([comp for comp in sfg.components if isinstance(comp, Delay)]) == 2 assert len([comp for comp in sfg.components if isinstance(comp, Delay)]) == 2
sim = Simulation(sfg, [Impulse()])
sim.run_for(4)
impulse_response.append(0.0)
assert np.allclose(sim.results['0'], impulse_response)
impulse_response = [0.3, 0.4, 0.5, 0.6, 0.3]
sfg = transposed_direct_form_fir( sfg = transposed_direct_form_fir(
(0.3, 0.4, 0.5, 0.6, 0.3), (0.3, 0.4, 0.5, 0.6, 0.3),
mult_properties={'latency': 2, 'execution_time': 1}, mult_properties={'latency': 2, 'execution_time': 1},
add_properties={'latency': 1, 'execution_time': 1}, add_properties={'latency': 1, 'execution_time': 1},
) )
assert sfg.critical_path_time() == 3 assert sfg.critical_path_time() == 3
sim = Simulation(sfg, [Impulse()])
sim.run_for(6)
impulse_response.append(0.0)
assert np.allclose(sim.results['0'], impulse_response)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment