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
Compare revisions
54e587c1e37790817c46fe0764340f020fc11939 to 7c45e4c3a1c395bcc404e736cecb57d1597c93c8
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
da/B-ASIC
Select target project
No results found
7c45e4c3a1c395bcc404e736cecb57d1597c93c8
Select Git revision
Swap
Target
da/B-ASIC
Select target project
da/B-ASIC
lukja239/B-ASIC
robal695/B-ASIC
3 results
54e587c1e37790817c46fe0764340f020fc11939
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Add random signal generators
· 9996e607
Oscar Gustafsson
authored
2 years ago
9996e607
Fix NumPy crosslinks
· 7c45e4c3
Oscar Gustafsson
authored
2 years ago
7c45e4c3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
b_asic/signal_generator.py
+83
-2
83 additions, 2 deletions
b_asic/signal_generator.py
docs_sphinx/conf.py
+2
-1
2 additions, 1 deletion
docs_sphinx/conf.py
test/test_signal_generator.py
+36
-0
36 additions, 0 deletions
test/test_signal_generator.py
with
121 additions
and
3 deletions
b_asic/signal_generator.py
View file @
7c45e4c3
...
...
@@ -13,7 +13,9 @@ if you want more information.
from
math
import
pi
,
sin
from
numbers
import
Number
from
typing
import
Sequence
from
typing
import
Optional
,
Sequence
import
numpy
as
np
class
SignalGenerator
:
...
...
@@ -168,7 +170,7 @@ class Sinusoid(SignalGenerator):
frequency : float
The normalized frequency of the sinusoid. Should normally be in the
interval [0, 1], where 1 corresponds to half the sample rate.
phase : float, default: 0
phase : float, default: 0
.0
The normalized phase offset.
"""
...
...
@@ -187,6 +189,85 @@ class Sinusoid(SignalGenerator):
)
class
Gaussian
(
SignalGenerator
):
"""
Signal generator with Gaussian noise.
See :py:meth:`numpy.random.Generator.normal` for further details.
Parameters
----------
seed : int, optional
The seed of the random number generator.
scale : float, default: 1.0
The standard deviation of the noise.
loc : float, default: 0.0
The average value of the noise.
"""
def
__init__
(
self
,
seed
:
Optional
[
int
]
=
None
,
loc
:
float
=
0.0
,
scale
:
float
=
1.0
)
->
None
:
self
.
_rng
=
np
.
random
.
default_rng
(
seed
)
self
.
_seed
=
seed
self
.
_loc
=
loc
self
.
_scale
=
scale
def
__call__
(
self
,
time
:
int
)
->
complex
:
return
self
.
_rng
.
normal
(
self
.
_loc
,
self
.
_scale
)
def
__repr__
(
self
):
ret_list
=
[]
if
self
.
_seed
is
not
None
:
ret_list
.
append
(
f
"
seed=
{
self
.
_seed
}
"
)
if
self
.
_loc
:
ret_list
.
append
(
f
"
loc=
{
self
.
_loc
}
"
)
if
self
.
_scale
!=
1.0
:
ret_list
.
append
(
f
"
scale=
{
self
.
_scale
}
"
)
args
=
"
,
"
.
join
(
ret_list
)
return
f
"
Gaussian(
{
args
}
)
"
class
Uniform
(
SignalGenerator
):
"""
Signal generator with uniform noise.
See :py:meth:`numpy.random.Generator.normal` for further details.
Parameters
----------
seed : int, optional
The seed of the random number generator.
low : float, default: -1.0
The lower value of the uniform range.
high : float, default: 1.0
The upper value of the uniform range.
"""
def
__init__
(
self
,
seed
:
Optional
[
int
]
=
None
,
low
:
float
=
-
1.0
,
high
:
float
=
1.0
)
->
None
:
self
.
_rng
=
np
.
random
.
default_rng
(
seed
)
self
.
_seed
=
seed
self
.
_low
=
low
self
.
_high
=
high
def
__call__
(
self
,
time
:
int
)
->
complex
:
return
self
.
_rng
.
uniform
(
self
.
_low
,
self
.
_high
)
def
__repr__
(
self
):
ret_list
=
[]
if
self
.
_seed
is
not
None
:
ret_list
.
append
(
f
"
seed=
{
self
.
_seed
}
"
)
if
self
.
_low
!=
-
1.0
:
ret_list
.
append
(
f
"
low=
{
self
.
_low
}
"
)
if
self
.
_high
!=
1.0
:
ret_list
.
append
(
f
"
high=
{
self
.
_high
}
"
)
args
=
"
,
"
.
join
(
ret_list
)
return
f
"
Uniform(
{
args
}
)
"
class
_AddGenerator
(
SignalGenerator
):
"""
Signal generator that adds two signals.
...
...
This diff is collapsed.
Click to expand it.
docs_sphinx/conf.py
View file @
7c45e4c3
...
...
@@ -8,7 +8,7 @@
import
shutil
project
=
'
B-ASIC
'
copyright
=
'
2020-202
2
, Oscar Gustafsson et al
'
copyright
=
'
2020-202
3
, Oscar Gustafsson et al
'
author
=
'
Oscar Gustafsson et al
'
html_logo
=
"
../logo_tiny.png
"
...
...
@@ -37,6 +37,7 @@ intersphinx_mapping = {
'
python
'
:
(
'
https://docs.python.org/3/
'
,
None
),
'
graphviz
'
:
(
'
https://graphviz.readthedocs.io/en/stable/
'
,
None
),
'
matplotlib
'
:
(
'
https://matplotlib.org/stable/
'
,
None
),
'
numpy
'
:
(
'
https://numpy.org/doc/stable/
'
,
None
),
'
PyQt5
'
:
(
"
https://www.riverbankcomputing.com/static/Docs/PyQt5
"
,
None
),
}
...
...
This diff is collapsed.
Click to expand it.
test/test_signal_generator.py
View file @
7c45e4c3
...
...
@@ -4,9 +4,11 @@ import pytest
from
b_asic.signal_generator
import
(
Constant
,
Gaussian
,
Impulse
,
Sinusoid
,
Step
,
Uniform
,
ZeroPad
,
_AddGenerator
,
_DivGenerator
,
...
...
@@ -97,6 +99,40 @@ def test_sinusoid():
assert
str
(
g
)
==
"
Sinusoid(0.5, 0.25)
"
def
test_gaussian
():
g
=
Gaussian
(
1234
)
assert
g
(
0
)
==
pytest
.
approx
(
-
1.6038368053963015
)
assert
g
(
1
)
==
pytest
.
approx
(
0.06409991400376411
)
assert
str
(
g
)
==
"
Gaussian(seed=1234)
"
# Check same seed gives same sequence
g1
=
Gaussian
(
12345
)
g2
=
Gaussian
(
12345
)
for
n
in
range
(
100
):
assert
g1
(
n
)
==
g2
(
n
)
assert
str
(
Gaussian
(
1234
,
1
,
2
))
==
"
Gaussian(seed=1234, loc=1, scale=2)
"
def
test_uniform
():
g
=
Uniform
(
1234
)
assert
g
(
0
)
==
pytest
.
approx
(
0.9533995333962844
)
assert
g
(
1
)
==
pytest
.
approx
(
-
0.23960852996076443
)
assert
str
(
g
)
==
"
Uniform(seed=1234)
"
# Check same seed gives same sequence
g1
=
Uniform
(
12345
)
g2
=
Uniform
(
12345
)
for
n
in
range
(
100
):
assert
g1
(
n
)
==
g2
(
n
)
assert
str
(
Uniform
(
1234
,
1
,
2
))
==
"
Uniform(seed=1234, low=1, high=2)
"
def
test_addition
():
g
=
Impulse
()
+
Impulse
(
2
)
assert
g
(
-
1
)
==
0
...
...
This diff is collapsed.
Click to expand it.