Python: Interpretation in XCORR

I have a question about xcorr in Python. Let's say that I do the following:

output=plt.xcorr(x,y, maxlags=4)

What time series are lagging behind? The result will be a cross-correlation between x and y at time t = -4 to +4. So, the conclusion relates to cross-correlation between x and y as follows:

enter image description here or vice versa between x and y? I tried to delve into the xcorr code to get a better idea (see here ), but I lost a little ... np.correlate (x, y, mode = 2). What does mode = 2 mean? I see only here mode = valid, fullor same.

+4
source share
1 answer

mode , . x y (x > y):

  • valid/0: , (x-y + 1 )
  • same/1: ( )
  • full/2: , (x + y-1 )

, numpy. xcorr full. ( , convolve correlate.)

, . numpy.correlate numpy. multiarray.correlate () multiarray.correlate2 (). numpy.convolve multiarray.correlate (.. , ).

, , , . - , . , .

a <= [1,2,3,4,5]
b <= [10,20]

convolve:

numpy.convolve(a,b,mode='full') => [ 10, 40, 70, 100, 230, 100]

, :

    1  2  3  4  5  => 1 x 10 = 10
20 10

    1  2  3  4  5  => 1 x 20 + 2 x 10 = 40
   20 10

...

    1  2  3  4  5     => 5 x 20 = 100
               20 10

, .

:

numpy.correlate(a,b,mode='full') => [ 20, 50, 80, 110, 140, 50]

    1  2  3  4  5  => 1 x 20 = 20
10 20

    1  2  3  4  5  => 1 x 10 + 2 x 20 = 50
   10 20

...

    1  2  3  4  5     => 5 x 10 = 100
               10 20

, , . , , , a b , . correlate .


matplotlib xcorr. x y .

numpy.correlate x y, . -maxlags.. maxlags. , . y (.. x).

:

xcorr([1.,2.,3.,4.,5.], [0,0,0,0,1.], normed=False, maxlags=4)
+7

Source: https://habr.com/ru/post/1545904/


All Articles