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
!304
Add Upsample and Downsample signal generators
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add Upsample and Downsample signal generators
updownsamplesignal
into
master
Overview
0
Commits
1
Pipelines
1
Changes
2
Merged
Oscar Gustafsson
requested to merge
updownsamplesignal
into
master
1 year ago
Overview
0
Commits
1
Pipelines
1
Changes
2
Expand
Closes
#213 (closed)
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
c050576b
1 commit,
1 year ago
2 files
+
137
−
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
+
77
−
1
Options
@@ -13,7 +13,7 @@ if you want more information.
from
math
import
pi
,
sin
from
numbers
import
Number
from
typing
import
Optional
,
Sequence
from
typing
import
Optional
,
Sequence
,
Union
import
numpy
as
np
@@ -408,3 +408,79 @@ class _DivGenerator(SignalGenerator):
else
f
"
{
self
.
_b
}
"
)
return
f
"
{
a
}
/
{
b
}
"
class
Upsample
(
SignalGenerator
):
"""
Signal generator that upsamples the value of a signal generator or a sequence.
*factor* - 1 zeros are inserted between every value. If a sequence, it will
automatically be zero-padded.
Parameters
----------
data : SignalGenerator or 1-D array
The signal generator or array to upsample.
factor : int
Upsampling factor.
phase : int, default 0
The phase of the upsampling.
"""
def
__init__
(
self
,
data
:
Union
[
SignalGenerator
,
Sequence
[
complex
]],
factor
:
int
,
phase
:
int
=
0
,
)
->
None
:
if
not
isinstance
(
data
,
SignalGenerator
):
data
=
ZeroPad
(
data
)
self
.
_generator
=
data
self
.
_factor
=
factor
self
.
_phase
=
phase
def
__call__
(
self
,
time
:
int
)
->
complex
:
index
=
(
time
-
self
.
_phase
)
/
self
.
_factor
if
int
(
index
)
==
index
:
return
self
.
_generator
(
int
(
index
))
else
:
return
0.0
def
__repr__
(
self
)
->
str
:
return
f
"
Upsample(
{
self
.
_generator
!r}
,
{
self
.
_factor
}
,
{
self
.
_phase
}
)
"
class
Downsample
(
SignalGenerator
):
"""
Signal generator that downsamples the value of a signal generator or a sequence.
Return every *factor*:th value. If a sequence, it will automatically be zero-padded.
Parameters
----------
data : SignalGenerator or 1-D array
The signal generator or array to downsample.
factor : int
Downsampling factor.
phase : int, default 0
The phase of the downsampling.
"""
def
__init__
(
self
,
data
:
Union
[
SignalGenerator
,
Sequence
[
complex
]],
factor
:
int
,
phase
:
int
=
0
,
)
->
None
:
if
not
isinstance
(
data
,
SignalGenerator
):
data
=
ZeroPad
(
data
)
self
.
_generator
=
data
self
.
_factor
=
factor
self
.
_phase
=
phase
def
__call__
(
self
,
time
:
int
)
->
complex
:
index
=
time
*
self
.
_factor
+
self
.
_phase
return
self
.
_generator
(
index
)
def
__repr__
(
self
)
->
str
:
return
f
"
Downsample(
{
self
.
_generator
!r}
,
{
self
.
_factor
}
,
{
self
.
_phase
}
)
"
Loading