hi,i propose two ways :
1)as you have to series P1, P2 of length N both:
2)Or logically, you can compute the quadratic error, as
( P1(i,j)-P2(i,j) )² for 1<=i,j <=N :
figure, plot(f), xlabel(' Measurments'), ylabel(' E^2'),
The "time_index" is when there is high correlation between p1 and p2 .