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
!153
Add initial support for signal generators
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add initial support for signal generators
signalgenerator
into
master
Overview
0
Commits
1
Pipelines
2
Changes
4
Merged
Oscar Gustafsson
requested to merge
signalgenerator
into
master
2 years ago
Overview
0
Commits
1
Pipelines
2
Changes
4
Expand
0
0
Merge request reports
Compare
master
version 1
9031f60f
2 years ago
master (base)
and
latest version
latest version
c2a9e42b
1 commit,
2 years ago
version 1
9031f60f
1 commit,
2 years ago
4 files
+
230
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
b_asic/signal_generator.py
0 → 100644
+
139
−
0
Options
"""
B-ASIC signal generators
These can be used as input to Simulation to algorithmically provide signal values.
"""
from
numbers
import
Number
from
typing
import
Callable
class
SignalGenerator
:
def
__call__
(
self
,
time
:
int
)
->
complex
:
raise
NotImplementedError
def
__add__
(
self
,
other
)
->
"
AddGenerator
"
:
if
isinstance
(
other
,
Number
):
return
AddGenerator
(
self
,
Constant
(
other
))
return
AddGenerator
(
self
,
other
)
def
__radd__
(
self
,
other
)
->
"
AddGenerator
"
:
if
isinstance
(
other
,
Number
):
return
AddGenerator
(
self
,
Constant
(
other
))
return
AddGenerator
(
self
,
other
)
def
__sub__
(
self
,
other
)
->
"
SubGenerator
"
:
if
isinstance
(
other
,
Number
):
return
SubGenerator
(
self
,
Constant
(
other
))
return
SubGenerator
(
self
,
other
)
def
__rsub__
(
self
,
other
)
->
"
SubGenerator
"
:
if
isinstance
(
other
,
Number
):
return
SubGenerator
(
Constant
(
other
),
self
)
return
SubGenerator
(
other
,
self
)
def
__mul__
(
self
,
other
)
->
"
MulGenerator
"
:
if
isinstance
(
other
,
Number
):
return
MultGenerator
(
self
,
Constant
(
other
))
return
MultGenerator
(
self
,
other
)
def
__rmul__
(
self
,
other
)
->
"
MulGenerator
"
:
if
isinstance
(
other
,
Number
):
return
MultGenerator
(
self
,
Constant
(
other
))
return
MultGenerator
(
self
,
other
)
class
Impulse
(
SignalGenerator
):
"""
Signal generator that creates an impulse at a given delay.
Parameters
----------
delay : int, default: 0
The delay before the signal goes to 1 for one sample.
"""
def
__init__
(
self
,
delay
:
int
=
0
)
->
Callable
[[
int
],
complex
]:
self
.
_delay
=
delay
def
__call__
(
self
,
time
:
int
)
->
complex
:
return
1
if
time
==
self
.
_delay
else
0
class
Step
(
SignalGenerator
):
"""
Signal generator that creates a step at a given delay.
Parameters
----------
delay : int, default: 0
The delay before the signal goes to 1.
"""
def
__init__
(
self
,
delay
:
int
=
0
)
->
Callable
[[
int
],
complex
]:
self
.
_delay
=
delay
def
__call__
(
self
,
time
:
int
)
->
complex
:
return
1
if
time
>=
self
.
_delay
else
0
class
Constant
(
SignalGenerator
):
"""
Signal generator that outputs a constant value.
Parameters
----------
constant : complex, default: 1.0
The constant.
"""
def
__init__
(
self
,
constant
:
complex
=
1.0
)
->
Callable
[[
int
],
complex
]:
self
.
_constant
=
constant
def
__call__
(
self
,
time
:
int
)
->
complex
:
return
self
.
_constant
class
AddGenerator
:
"""
Signal generator that adds two signals.
"""
def
__init__
(
self
,
a
:
SignalGenerator
,
b
:
SignalGenerator
)
->
Callable
[[
int
],
complex
]:
self
.
_a
=
a
self
.
_b
=
b
def
__call__
(
self
,
time
:
int
)
->
complex
:
return
self
.
_a
(
time
)
+
self
.
_b
(
time
)
class
SubGenerator
:
"""
Signal generator that subtracts two signals.
"""
def
__init__
(
self
,
a
:
SignalGenerator
,
b
:
SignalGenerator
)
->
Callable
[[
int
],
complex
]:
self
.
_a
=
a
self
.
_b
=
b
def
__call__
(
self
,
time
:
int
)
->
complex
:
return
self
.
_a
(
time
)
-
self
.
_b
(
time
)
class
MultGenerator
:
"""
Signal generator that multiplies two signals.
"""
def
__init__
(
self
,
a
:
SignalGenerator
,
b
:
SignalGenerator
)
->
Callable
[[
int
],
complex
]:
self
.
_a
=
a
self
.
_b
=
b
def
__call__
(
self
,
time
:
int
)
->
complex
:
return
self
.
_a
(
time
)
*
self
.
_b
(
time
)
Loading