Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LISA Instrument
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LISA Simulation
LISA Instrument
Commits
20d1eb1d
Commit
20d1eb1d
authored
4 years ago
by
Jean-Baptiste Bayle
Browse files
Options
Downloads
Patches
Plain Diff
Remove unnecessary function in dsp.py
parent
866e666f
No related branches found
No related tags found
1 merge request
!2
Add instrument simulation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lisainstrument/dsp.py
+3
-82
3 additions, 82 deletions
lisainstrument/dsp.py
with
3 additions
and
82 deletions
lisainstrument/dsp.py
+
3
−
82
View file @
20d1eb1d
...
@@ -95,85 +95,6 @@ def lagrange_coeffs(eps, num_tabs, p): # pylint: disable=invalid-name
...
@@ -95,85 +95,6 @@ def lagrange_coeffs(eps, num_tabs, p): # pylint: disable=invalid-name
return
coeffs
.
T
return
coeffs
.
T
def
time_shift
(
data
,
shift
,
order
=
31
):
def
identity
(
x
):
"""
Shift data in time by tau
"""
Identity function, no operations.
"""
return
x
Args:
data (numpy.ndarray): data to be shited
tau (numpy.ndarray): amount of time each data point is to be shifted
(must be of same dimension as data)
fs (double): sampling frequency in (Hz)
order (int): interpolation order
"""
logging
.
debug
(
"
Time shifting data
'
%s
'
by
'
%s
'
(order=%d)
"
,
data
,
shift
,
order
)
if
numpy
.
isscalar
(
data
):
logging
.
debug
(
"
Data is a constant scalar and cannot be time shifted
"
)
return
data
if
numpy
.
all
(
shift
==
0
):
logging
.
debug
(
"
Time shift is vanishing and cannot be applied
"
)
return
data
data
=
numpy
.
asarray
(
data
)
mode
=
"
timeseries
"
if
isinstance
(
shift
,
numpy
.
ndarray
)
else
"
constant
"
logging
.
debug
(
"
Using mode
'
%s
'"
,
mode
)
if
mode
==
"
timeseries
"
and
data
.
size
!=
shift
.
size
:
raise
ValueError
(
f
"
`data` and `tau` must be of the same size (got
{
data
.
size
}
,
{
shift
.
size
}
)
"
)
num_tabs
=
order
+
1
p
=
num_tabs
//
2
# pylint: disable=invalid-name
size
=
data
.
size
def
lagrange_coeffs
(
eps
):
"""
Calculate coefficients for lagrange interpolation
"""
coeffs
=
numpy
.
zeros
([
num_tabs
,
eps
.
size
])
if
p
>
1
:
factor
=
numpy
.
ones
(
eps
.
size
,
dtype
=
numpy
.
float64
)
factor
*=
eps
*
(
1
-
eps
)
for
j
in
range
(
1
,
p
):
factor
*=
(
-
1
)
*
(
1
-
j
/
p
)
/
(
1
+
j
/
p
)
coeffs
[
p
-
1
-
j
]
=
factor
/
(
j
+
eps
)
coeffs
[
p
+
j
]
=
factor
/
(
j
+
1
-
eps
)
coeffs
[
p
-
1
]
=
1
-
eps
coeffs
[
p
]
=
eps
for
j
in
range
(
2
,
p
):
coeffs
*=
1
-
(
eps
/
j
)
**
2
coeffs
*=
(
1
+
eps
)
*
(
1
-
eps
/
p
)
else
:
coeffs
[
p
-
1
]
=
1
-
eps
coeffs
[
p
]
=
eps
return
coeffs
.
T
k
=
numpy
.
floor
(
shift
).
astype
(
int
)
eps
=
shift
-
k
coeffs
=
lagrange_coeffs
(
eps
)
logging
.
debug
(
"
Using Lagrange coefficiens
'
%s
'"
,
coeffs
)
if
mode
==
"
timeseries
"
:
logging
.
debug
(
"
Computing Lagrange matrix
"
)
indices
=
numpy
.
arange
(
size
)
i_min
=
numpy
.
min
(
k
-
(
p
-
1
)
+
indices
)
i_max
=
numpy
.
max
(
k
+
p
+
indices
+
1
)
csr_ind
=
numpy
.
tile
(
numpy
.
arange
(
num_tabs
),
size
)
+
numpy
.
repeat
(
k
+
indices
,
num_tabs
)
-
(
p
-
1
)
csr_ptr
=
num_tabs
*
numpy
.
arange
(
size
+
1
)
mat
=
scipy
.
sparse
.
csr_matrix
((
numpy
.
ravel
(
coeffs
),
csr_ind
-
i_min
,
csr_ptr
),
shape
=
(
size
,
i_max
-
i_min
))
logging
.
debug
(
"
Padding data (left=%d, right=%d)
"
,
max
(
0
,
-
i_min
),
max
(
0
,
i_max
-
size
))
data_padded
=
numpy
.
pad
(
data
[
max
(
0
,
i_min
):
min
(
size
,
i_max
)],
(
max
(
0
,
-
i_min
),
max
(
0
,
i_max
-
size
)))
logging
.
debug
(
"
Computing matrix-vector product
"
)
shifted
=
mat
.
dot
(
data_padded
)
elif
mode
==
"
constant
"
:
i_min
=
k
-
(
p
-
1
)
i_max
=
k
+
p
+
size
logging
.
debug
(
"
Padding data (left=%d, right=%d)
"
,
max
(
0
,
-
i_min
),
max
(
0
,
i_max
-
size
))
data_padded
=
numpy
.
pad
(
data
[
max
(
0
,
i_min
):
min
(
size
,
i_max
)],
(
max
(
0
,
-
i_min
),
max
(
0
,
i_max
-
size
)))
logging
.
debug
(
"
Computing correlation product
"
)
shifted
=
numpy
.
correlate
(
data_padded
,
coeffs
[
0
],
mode
=
"
valid
"
)
return
shifted
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