Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Commits
3f9dd294
Commit
3f9dd294
authored
1 year ago
by
Oscar Gustafsson
Browse files
Options
Downloads
Patches
Plain Diff
Fix issue with first-order WDF allpass sections
parent
b07dc0ac
No related branches found
No related tags found
1 merge request
!278
Fix issue with first-order WDF allpass sections
Pipeline
#93867
passed
1 year ago
Stage: test
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/sfg_generators.py
+3
-4
3 additions, 4 deletions
b_asic/sfg_generators.py
test/test_sfg_generators.py
+102
-0
102 additions, 0 deletions
test/test_sfg_generators.py
with
105 additions
and
4 deletions
b_asic/sfg_generators.py
+
3
−
4
View file @
3f9dd294
...
@@ -13,7 +13,6 @@ from b_asic.core_operations import (
...
@@ -13,7 +13,6 @@ from b_asic.core_operations import (
Name
,
Name
,
SymmetricTwoportAdaptor
,
SymmetricTwoportAdaptor
,
)
)
from
b_asic.port
import
InputPort
,
OutputPort
from
b_asic.signal
import
Signal
from
b_asic.signal
import
Signal
from
b_asic.signal_flow_graph
import
SFG
from
b_asic.signal_flow_graph
import
SFG
from
b_asic.special_operations
import
Delay
,
Input
,
Output
from
b_asic.special_operations
import
Delay
,
Input
,
Output
...
@@ -51,7 +50,7 @@ def wdf_allpass(
...
@@ -51,7 +50,7 @@ def wdf_allpass(
-------
-------
Signal flow graph
Signal flow graph
"""
"""
np_coefficients
=
np
.
squeeze
(
np
.
asarray
(
coefficients
))
np_coefficients
=
np
.
atleast_1d
(
np
.
squeeze
(
np
.
asarray
(
coefficients
))
)
order
=
len
(
np_coefficients
)
order
=
len
(
np_coefficients
)
if
not
order
:
if
not
order
:
raise
ValueError
(
"
Coefficients cannot be empty
"
)
raise
ValueError
(
"
Coefficients cannot be empty
"
)
...
@@ -143,7 +142,7 @@ def direct_form_fir(
...
@@ -143,7 +142,7 @@ def direct_form_fir(
--------
--------
transposed_direct_form_fir
transposed_direct_form_fir
"""
"""
np_coefficients
=
np
.
squeeze
(
np
.
asarray
(
coefficients
))
np_coefficients
=
np
.
atleast_1d
(
np
.
squeeze
(
np
.
asarray
(
coefficients
))
)
taps
=
len
(
np_coefficients
)
taps
=
len
(
np_coefficients
)
if
not
taps
:
if
not
taps
:
raise
ValueError
(
"
Coefficients cannot be empty
"
)
raise
ValueError
(
"
Coefficients cannot be empty
"
)
...
@@ -211,7 +210,7 @@ def transposed_direct_form_fir(
...
@@ -211,7 +210,7 @@ def transposed_direct_form_fir(
--------
--------
direct_form_fir
direct_form_fir
"""
"""
np_coefficients
=
np
.
squeeze
(
np
.
asarray
(
coefficients
))
np_coefficients
=
np
.
atleast_1d
(
np
.
squeeze
(
np
.
asarray
(
coefficients
))
)
taps
=
len
(
np_coefficients
)
taps
=
len
(
np_coefficients
)
if
not
taps
:
if
not
taps
:
raise
ValueError
(
"
Coefficients cannot be empty
"
)
raise
ValueError
(
"
Coefficients cannot be empty
"
)
...
...
This diff is collapsed.
Click to expand it.
test/test_sfg_generators.py
+
102
−
0
View file @
3f9dd294
import
numpy
as
np
import
numpy
as
np
import
pytest
from
b_asic.core_operations
import
(
from
b_asic.core_operations
import
(
Addition
,
Addition
,
...
@@ -16,6 +17,7 @@ from b_asic.special_operations import Delay
...
@@ -16,6 +17,7 @@ from b_asic.special_operations import Delay
def
test_wdf_allpass
():
def
test_wdf_allpass
():
# Third-order
sfg
=
wdf_allpass
([
0.3
,
0.5
,
0.7
])
sfg
=
wdf_allpass
([
0.3
,
0.5
,
0.7
])
assert
(
assert
(
len
(
len
(
...
@@ -28,6 +30,9 @@ def test_wdf_allpass():
...
@@ -28,6 +30,9 @@ def test_wdf_allpass():
==
3
==
3
)
)
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Delay
)])
==
3
# Fourth-order
sfg
=
wdf_allpass
([
0.3
,
0.5
,
0.7
,
0.9
])
sfg
=
wdf_allpass
([
0.3
,
0.5
,
0.7
,
0.9
])
assert
(
assert
(
len
(
len
(
...
@@ -40,6 +45,34 @@ def test_wdf_allpass():
...
@@ -40,6 +45,34 @@ def test_wdf_allpass():
==
4
==
4
)
)
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Delay
)])
==
4
# First-order
sfg
=
wdf_allpass
([
0.3
])
assert
(
len
(
[
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
SymmetricTwoportAdaptor
)
]
)
==
1
)
# First-order with scalar input (happens to work)
sfg
=
wdf_allpass
(
0.3
)
assert
(
len
(
[
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
SymmetricTwoportAdaptor
)
]
)
==
1
)
def
test_direct_form_fir
():
def
test_direct_form_fir
():
impulse_response
=
[
0.3
,
0.5
,
0.7
]
impulse_response
=
[
0.3
,
0.5
,
0.7
]
...
@@ -75,6 +108,36 @@ def test_direct_form_fir():
...
@@ -75,6 +108,36 @@ def test_direct_form_fir():
impulse_response
.
append
(
0.0
)
impulse_response
.
append
(
0.0
)
assert
np
.
allclose
(
sim
.
results
[
'
0
'
],
impulse_response
)
assert
np
.
allclose
(
sim
.
results
[
'
0
'
],
impulse_response
)
impulse_response
=
[
0.3
]
sfg
=
direct_form_fir
(
impulse_response
)
assert
(
len
(
[
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
ConstantMultiplication
)
]
)
==
1
)
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Addition
)])
==
0
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Delay
)])
==
0
impulse_response
=
0.3
sfg
=
direct_form_fir
(
impulse_response
)
assert
(
len
(
[
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
ConstantMultiplication
)
]
)
==
1
)
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Addition
)])
==
0
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Delay
)])
==
0
def
test_transposed_direct_form_fir
():
def
test_transposed_direct_form_fir
():
impulse_response
=
[
0.3
,
0.5
,
0.7
]
impulse_response
=
[
0.3
,
0.5
,
0.7
]
...
@@ -109,3 +172,42 @@ def test_transposed_direct_form_fir():
...
@@ -109,3 +172,42 @@ def test_transposed_direct_form_fir():
sim
.
run_for
(
6
)
sim
.
run_for
(
6
)
impulse_response
.
append
(
0.0
)
impulse_response
.
append
(
0.0
)
assert
np
.
allclose
(
sim
.
results
[
'
0
'
],
impulse_response
)
assert
np
.
allclose
(
sim
.
results
[
'
0
'
],
impulse_response
)
impulse_response
=
[
0.3
]
sfg
=
transposed_direct_form_fir
(
impulse_response
)
assert
(
len
(
[
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
ConstantMultiplication
)
]
)
==
1
)
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Addition
)])
==
0
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Delay
)])
==
0
impulse_response
=
0.3
sfg
=
transposed_direct_form_fir
(
impulse_response
)
assert
(
len
(
[
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
ConstantMultiplication
)
]
)
==
1
)
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Addition
)])
==
0
assert
len
([
comp
for
comp
in
sfg
.
components
if
isinstance
(
comp
,
Delay
)])
==
0
def
test_sfg_generator_errors
():
sfg_gens
=
[
wdf_allpass
,
transposed_direct_form_fir
,
direct_form_fir
]
for
gen
in
sfg_gens
:
with
pytest
.
raises
(
ValueError
,
match
=
"
Coefficients cannot be empty
"
):
gen
([])
with
pytest
.
raises
(
TypeError
,
match
=
"
coefficients must be a 1D-array
"
):
gen
([[
1
,
2
],
[
1
,
3
]])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment