归一化互相关(转自https://anomaly.io/understand-auto-cross-correlation-normalized-shift/index.html)
Normalized Cross-Correlation
There are three problems with cross-correlation:
It is difficult to understand the scoring value.
Both metrics must have the same amplitude. If Graph B has the same shape as Graph A but values two times smaller, the correlation will not be detected.
corr(a, a/2) = 19.5
Due to the formula, a zero value will not be taken into account, since 00=0 and 0200=0.
To solve these problems we use normalized cross-correlation:
n o r m _ c o r r ( x , y ) = ∑ n = 0 n − 1 x [ n ] ∗ y [ n ] ∑ n = 0 n − 1 x [ n ] 2 ∗ ∑ n = 0 n − 1 y [ n ] 2 norm\_corr(x,y)=\dfrac{\sum_{n=0}^{n-1} x[n]*y[n]}{\sqrt{\sum_{n=0}^{n-1} x[n]^2 * \sum_{n=0}^{n-1} y[n]^2}} norm_corr(x,y)=∑n=0n−1x[n]2∗∑n=0n−1y[n]2∑n=0n−1x[n]∗y[n]
Using this formula let’s compute the normalized cross-correlation of AB and AC.
n o r m _ c o r r ( a , b ) = 1 ∗ 2 + 2 ∗ 3 + − 2 ∗ − 2 + 4 ∗ 3 + 2 ∗ 2 + 3 ∗ 4 + 1 ∗ 1 + 0 ∗ − 1 ( 1 + 4 + 4 + 16 + 4 + 9 + 1 + 0 ) ∗ ( 4 + 9 + 4 + 9 + 4 + 16 + 1 + 1 ) = 41 ( 39 ) ∗ ( 48 ) = 0.947 norm\_corr(a,b) = \dfrac{1*2+2*3+-2*-2+4*3+2*2+3*4+1*1+0*-1}{\sqrt{(1+4+4+16+4+9+1+0)*(4+9+4+9+4+16+1+1)}} \\ = \dfrac{41}{\sqrt{(39)*(48)}} \\ = 0.947 norm_corr(a,b)=(1+4+4+16+4+9+1+0)∗(4+9+4+9+4+16+1+1)1∗2+2∗3+−2∗−2+4∗3+2∗2+3∗4+1∗1+0∗−1=(39)∗(48)41=0.947
n o r m _ c o r r ( a , c ) = 1 ∗ − 2 + 2 ∗ 0 + − 2 ∗ 4 + 4 ∗ 0 + 2 ∗ 1 + 3 ∗ 1 + 1 ∗ 0 + 0 ∗ − 2 ( 1 + 4 + 4 + 16 + 4 + 9 + 1 + 0 ) ∗ ( 4 + 0 + 16 + 0 + 1 + 1 + 0 + 4 ) = − 5 ( 39 ) ∗ ( 26 ) = − 0.157 norm\_corr(a,c) =\dfrac{1*-2+2*0+-2*4+4*0+2*1+3*1+1*0+0*-2}{\sqrt{(1+4+4+16+4+9+1+0)*(4+0+16+0+1+1+0+4)}} \\ =\dfrac{-5}{\sqrt{(39)*(26)}} \\ =-0.157 norm_corr(a,c)=(1+4+4+16+4+9+1+0)∗(4+0+16+0+1+1+0+4)1∗−2+2∗0+−2∗4+4∗0+2∗1+3∗1+1∗0+0∗−2=(39)∗(26)−5=−0.157
Graphs A and B correlate, with a high value of 0.947.
Graphs A and C don’t correlate, showing a low value of -0.157.
Normalized cross-correlation scoring is easy to understand:
– The higher the value, the higher the correlation is.
– The maximum value is 1 when two signals are exactly the same:
norm_corr(a,a)=1
– The minimum value is -1 when two signals are exactly opposite:
norm_corr(a, -a) = -1
Normalized cross-correlation can detect the correlation of two signals with different amplitudes: norma_corr(a, a/2) = 1.
Notice we have perfect correlation between signal A and the same signal with half the amplitude!