The first thing that comes on my mind is to use cross-correlation (CCF).
Essentially you compare one trace with variously shifted version of the other to see if there is a correlation between them.
For example (I am using R but you should be able to adapt this to your software of choice, I have added comments), say A and B are very similar, but shifted of a certain amount in the x axis (10 units in the example) and C is extremely different
# Set the random seed to get a reproducible example
set.seed(12345)
# Number of points per trace
n <- 1000
# All of the possible sensor values
values <- seq(0, 330, 30)
# Sample with replacement to get 100 random values
A <- sample(values, n, replace=TRUE)
# Let B = A shifted by 10 positions and then change one value every 5
B <- c(A[-1:-10], A[1:10])
B[seq(0, n, 5)] <- sample(values, n/5, replace=TRUE)
# C is a completely different trace
C <- sample(values, n, replace=TRUE)
# Plot the traces (I'm offsetting B and C just for visual clarity)
plot(A, t="l", col="red", lwd=2, ylim=c(0, 1200))
points(B + 360, t="l", col="green", lwd=2)
points(C + 720, t="l", col="blue", lwd=2)
# Now calculate the CCF
c.AB <- ccf(A,B, 100)
c.BC <- ccf(B,C, 100)
c.AC <- ccf(A,C, 100)
# Superimpose the CCF plots
plot(c.AB$lag, c.AB$acf, t="o", col="green", ylim=c(-0.5,1), ylab="CCF", xlab="Lag")
points(c.BC$lag, c.BC$acf, t="o", col="red")
points(c.AC$lag, c.AC$acf, t="o", col="blue")
abline(v=10, col="grey", lty=3)
legend("topleft", c("A-B", "B-C", "A-C"), col=c("green", "red", "blue"), lty=1, lwd=2, pch=20)
The CCF graphs look like this:
This graphs means that there is a strong positive correlation (max correlation = 1, here you have 0.8) between A and B and that they are shifted of 10 units. You can see this because the peak is at lag=10, corresponding to the gray dashed line, so the maximum correlation is when you shift trace B by 10 units.
B and C and A and C are instead uncorrelated.
No comments:
Post a Comment