# Comparing two time domain signals in a scale and shift-invariant way

I have two signals in the time domain, call them $S_1(t)$ and $S_2$(t). Because of calibration issues relating to the underlying devices that these signals are obtained from, they will not necessarily have the same scale or mean. What is the appropriate way to compute a measure of similarity such that, if $S_2(t)$=$C_1 * S_1(t) + C_2$, where $C_1$ and $C_2$ are constants, my measure of similarity will say that these signals are identical? Or at least indicates that they are very similar?

Edit: The solution provided by Digiproc is indeed a good solution to the problem as I originally stated it. However, it seems that I simplified my original problem too much for this question and that their solution would not work in my case. In particular, one of my signals has noisy spiky behavior in addition (i.e., very sharp and large localized peaks due to sensor technical issues). Therefore the dividing of one of the samples by the sample magnitude is not going to lead to a good alignment of the two signals. Is the MSE difference approach mentioned by robert-bristow-johnson in the comment the best approach then?

• there is a pretty straight-forward way of finding $C_1$ and $C_2$ to minimize the mean square difference between $S_2(t)$ and $C_1 S_1(t)+C_2$. Sep 18, 2017 at 6:44
• Thank you, @robert-bristow-johnson. I accidentally undid my upvote of your comment, so am unable to upvote it again. But so far your solution is the best for my actual problem (which wasn't stated well in my original question). If this answer remains the best, feel free to add it as an answer. Sep 18, 2017 at 14:51
• Or maybe using a Pearson correlation coefficient would make more sense? It's invariant to transformations of the type Ax+B. Sep 18, 2017 at 17:23

• I agree on the method, although the average of the samples of $S_1$ is not necessarily equal to $C_2$. Furthermore, the last step, i.e., the computation of a similarity measure, is missing. A straightforward approach would be to compute the mean squared error after offset removal and level matching: $e=\frac{1}{N}\sum_{i=0}^{N-1}(S_1^\prime[i]-S_2^\prime[i])^2$ with $S_1^\prime$ and $S_2^\prime$ the normalized signals. Sep 18, 2017 at 4:17