Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bedartha Goswami
uncertise
Commits
a142cf7e
Commit
a142cf7e
authored
Aug 04, 2020
by
Andyara Callegare
Browse files
Cross correlation function
parent
2a4b1f7d
Changes
1
Hide whitespace changes
Inline
Side-by-side
uncertise/distributions.py
View file @
a142cf7e
...
...
@@ -120,27 +120,19 @@ def basic_stats(cdfmat, var_span, verbose=False):
return
median
,
max
,
mean
,
min
def
cross_correlation
(
x
,
y
,
normed
=
True
,
detrend
=
False
,
maxlags
=
10
):
''' Cross correlation of two signals of equal length
def
cross_correlation
(
x
,
y
,
maxlags
=
10
):
''' Cross correlation of two signals of equal length
Returns the coefficients when normed=True
Returns inner products when normed=False
Usage: lags, c = xcorr(x,y,maxlags=len(x)-1)
Optional detrending e.g. mlab.detrend_mean
'''
c_{av}[k] = sum_n a[n+k] * conj(v[n])
'''
Nx
=
len
(
x
)
if
Nx
!=
len
(
y
):
raise
ValueError
(
'x and y must be equal length'
)
if
detrend
:
import
matplotlib.mlab
as
mlab
x
=
mlab
.
detrend_mean
(
np
.
asarray
(
x
))
# can set your preferences here
y
=
mlab
.
detrend_mean
(
np
.
asarray
(
y
))
c
=
np
.
correlate
(
x
,
y
,
mode
=
'full'
)
if
normed
:
n
=
np
.
sqrt
(
np
.
dot
(
x
,
x
)
*
np
.
dot
(
y
,
y
))
# this is the transformation function
c
=
np
.
true_divide
(
c
,
n
)
if
maxlags
is
None
:
maxlags
=
Nx
-
1
...
...
@@ -151,4 +143,4 @@ def cross_correlation(x, y, normed=True, detrend=False, maxlags=10):
lags
=
np
.
arange
(
-
maxlags
,
maxlags
+
1
)
c
=
c
[
Nx
-
1
-
maxlags
:
Nx
+
maxlags
]
return
lags
,
c
return
lags
,
c
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment