-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New xcorr
convenience features
#293
Comments
Specifying the lags is a little more complicated when you have signals of unequal size - for |
I think there is also merit in leaving the functions themselves straightforward and letting the user manage any pre and post processing they want to do. Unless these are best applied to the fourier transformed data, I think it might be cleaner to leave them out of the xcorr function itself (separation of concerns and all that). It might be a good idea to add these features to DSP more genrally though, e.g. under a 'preprocessing' submodule, then they could be used for any signal processing, not just the functions into which the kwargs are built. |
I don't know, having implemented all of these things for my own version of
xcorr I think it would be nice to have the library handle some of them.
Without accounting for the changing number of zeros, the result of xcorr is
seldom useful for my research. However I am also sympathetic to having a
simple function that's fast. Maybe we could use a different function, like
"cross_correlation" that provides all the gloss, which but at the end of
the day calls out to a fairly simple xcorr?
…On Wed, May 1, 2019, 3:16 AM HDictus ***@***.***> wrote:
I think there is also merit in leaving the functions themselves
straightforward and letting the user manage any pre and post processing
they want to do. Unless these are best applied to the fourier transformed
data, I think it might be cleaner to leave them out of the xcorr function
itself (separation of concerns and all that).
It might be a good idea to add these features to DSP more genrally though,
e.g. under a 'preprocessing' submodule, then they could be used for any
signal processing, not just the functions into which the kwargs are built.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#293 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUDZT23DVDBEQOZQS7FKBDPTE7VNANCNFSM4HJGJGOA>
.
|
I don't think this would affect the performance of As for whether it makes sense to separate them, I think that might make sense in some cases but not others:
|
I call demean "centre" in my own code. How would maxlags work? I only use it when doing direct (time-domain) cross correlation, especially with point processes. I can't think of how to do it with fft based convolution. edit: I can't think of how to do it with FFT convolution in a way that's not just post processing, i.e. returning a smaller portion of the convolution. |
Also normalize should probably imply demean and unbiased, because you'll be returning pearson correlation coefficients right? |
Yeah, maybe The index twiddling to get I've got a 1D implementation of using BenchmarkTools
u = rand(48000*5)
su = length(u)
v = rand(48000*5)
sv = length(v)
minlag = -48000
maxlag=48000
@assert xcorr(u,v; padmode=:none)[sv+minlag:sv+maxlag] ≈ xcorr_lin_fft(u,v; lagbounds=(minlag,maxlag))
display(@benchmark xcorr($u,$v; padmode=:none)[$(sv+minlag:sv+maxlag)])
display(@benchmark xcorr_lin_fft($u,$v; lagbounds=$(minlag,maxlag))) I was thinking that normalization was orthogonal to centering and unbiasing. In general I'd think most people would want all three to be |
Another enhancement would be to make (Also wondering, maybe it would make sense to unify |
+1 for extending the |
Hello @cbrnr 😉 It seems this issue had stagnated and the initial author has less time for packages at the moment. Would you be able to open a PR for this? |
So we meet in Julia land 😄 ! I'm not sure I have the time to tackle all enhancements mentioned in the top post, but I could at least try to implement |
There are some commonly-used features that are useful when doing cross-correlations that we might want to add (maybe as keyword arguments to
xcorr
):demean::Bool
- subtract the mean from each before cross-correlating, which would otherwise add an offset biasnormalize::Bool
- normalize bysqrt(sum(x->x^2, u)*sum(x->x^2, v))
to compensate for varying energies in signalsmaxlag::Int
- specifying a maximum lag (often we care about lags shorter than our signals, and this allows less padding before the FFT, or fewer dot-products if doing it in the time-domain)unbiased::Bool
- compensate for the varying numbers of zeros during the cross-correlation, which otherwise adds a scale biasThe text was updated successfully, but these errors were encountered: