Reputation: 897
I am wondering what the mode arguments in signal.correlate (or numpy.correlate) mean?
def crossCorrelator(sig1, sig2):
correlate = signal.correlate(sig1,sig2,mode='same')
return(correlate)
flux0 = [ 0.02006948 0.01358697 -0.06196026 -0.03842506 -0.09023056 -0.05464169 -0.02530553 -0.01937054 -0.01237411 0.03472263 0.17865012 0.27441767 0.23532932 0.16358341 0.08743969 0.12166425 0.10287468 0.13430794 0.08262321 0.0515434 0.04657624 0.09017276 0.09131331 0.04696824 -0.03901519 -0.01413654 0.05448175 0.1236946 0.09968044 -0.001584 -0.06094561 -0.02998289 -0.00113092 0.04336605 0.01105071 0.0527657 0.03825847 0.02309524]
flux1 = [-0.02946104 -0.02590192 -0.02274955 0.00485888 -0.0149776 0.01757462 0.02820086 0.0379213 0.03580811 0.06507382 0.09995243 0.12814133 0.16109725 0.12371425 0.08273643 0.09433014 0.05137761 0.04057405 -0.08171598 -0.06541216 0.00126869 0.09223577 0.06811737 0.0795967 0.08689563 0.0928949 0.09971169 0.05413958 0.05410236 0.00120439 0.02454734 0.06450544 0.01508899 -0.06100537 -0.10038889 -0.00651572 0.01095773 0.05517478]
correlation = crossCorrelator(flux0,flux1)
f, axarr = plt.subplots(2)
axarr[0].plot(np.arange(len(flux0)),flux0)
axarr[0].plot(np.arange(len(flux1)),flux1)
axarr[1].plot(np.arange(len(correlation)),correlation)
plt.show()
When I use mode 'same' the correlation array has same dimension as the fluxes for full it has double? If the len(flux0/1) is of dimension time what dimension would len(correlation) be ?
I am really more looking for a mathematical explanation, the answers I have found so far were more of technical nature...
Upvotes: 2
Views: 2312
Reputation: 4095
Given two sequences (a[0], .., a[A-1]) and (b[0], .., b[B-1]) of lengths A and B, respectively, the convolution is calculated as
c[n] = sum_m a[m] * b[n-m]
If mode=="full"
then the convolution is calculated for n ranging from 0 to A+B-2, so the return array has A+B-1 elements.
If mode=="same"
then scipy.signal.correlate
computes the convolution for n ranging from (B-1)/2 to A-1+(B-1)/2, where integer division is assumed. The return array has A elements. numpy.correlate
behaves the same way only if A>=B; if A is less than B it switches the two arrays (and the returned array has B elements).
If mode=="valid"
then the convolution is calculated for n ranging from min(A,B)-1 to max(A,B)-1, and therefore has max(A,B)-min(A,B)+1 elements.
Upvotes: 2