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
Merge requests
!174
Add random signal generators
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add random signal generators
randomsignalgenerators
into
master
Overview
0
Commits
1
Pipelines
2
Changes
2
Merged
Oscar Gustafsson
requested to merge
randomsignalgenerators
into
master
2 years ago
Overview
0
Commits
1
Pipelines
2
Changes
2
Expand
Related to
#168 (closed)
0
0
Merge request reports
Compare
master
version 1
aff24574
2 years ago
master (base)
and
latest version
latest version
9996e607
1 commit,
2 years ago
version 1
aff24574
1 commit,
2 years ago
2 files
+
118
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
b_asic/signal_generator.py
+
82
−
1
Options
@@ -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
:
@@ -187,6 +189,85 @@ class Sinusoid(SignalGenerator):
)
class
Gaussian
(
SignalGenerator
):
"""
Signal generator with Gaussian noise.
See :class:`numpy.random.Generator.normal` for further details.
Parameters
----------
seed : int, optional
The seed of the random number generator.
scale : float, default: 1
The standard deviation of the noise.
loc : float, default: 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 :class:`numpy.random.Generator.normal` for further details.
Parameters
----------
seed : int, optional
The seed of the random number generator.
low : float, default: -1
The lower value of the uniform range.
high : float, default: 1
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.
Loading