# Compare two signals, find times when they are affected by the same processes

I have two (noisy) signals $$S_1(t)$$ and $$S_2(t)$$. They contain information on three distinct events occurring in a physical system. Event $$A$$ affects only $$S_1(t)$$, event $$B$$ affects both $$S_1(t)$$ and $$S_2(t)$$, and event $$C$$ affects only $$S_2(t)$$. I want to identify the sequence of events in the system by analyzing the signals.

Is there some generic way to identify if two strings of data contain correlated events and find the timing of said events?

More specifically, my signals take the form $$$$\textrm{d}S_i (t + \textrm{d}t) = S_i^{\textrm{true}}(t)\textrm{d}t + \textrm{d}W(t),$$$$ where $$S_i^{\textrm{true}}$$ is the noiseless value of the signal calculated from the state of the system at time $$t$$, $$\textrm{d}W(t)$$ is a Wiener element (uncorrelated Gaussian noise), and the statement is to be read as an update formula. The l.h.s. is what is available to me. In case of an event the true values change sign in the following manner: \begin{align*} A &\Rightarrow\ S_1^{\textrm{true}} \to -S_1^{\textrm{true}}, \\ B &\Rightarrow\ S_1^{\textrm{true}} \to -S_1^{\textrm{true}} \textrm{ and } S_2^{\textrm{true}} \to -S_2^{\textrm{true}},\\ C &\Rightarrow\ S_2^{\textrm{true}} \to -S_2^{\textrm{true}}. \end{align*} The way I am trying to do things right now: I am using a running average to get rid off some of the noise, then I find the second derivatives of the smoothed signals. If the true value changes, there will be a peak in the second derivative. I then determine whether there is a peak in both signals or just one at the given time. However, this does not work very well, as the derivatives pick up the noise, too.

Here is a plot of my raw and running window averaged signals: I have no experience with signal processing. Is there a canonical procedure? If the question is too broad, where can I find recipes to deal with issues as such?

You can model your system as a hypothesis testing problem. For example, let $$M_1$$ and $$M_2$$ denote the two systems which are correlated. Let the observed signal in $$M_1$$ and $$M_2$$ be given as \begin{align} y_1(t) = s_1(t) + n_1(t) \\ y_2(t) = s_2(t) + n_2(t), \end{align} respectively, where $$n_i(t) \sim \mathcal{N}(0, \sigma_i^2)$$, for $$i = \{1,2\}$$, and $$s_i(t)$$, for $$i = \{1,2\}$$, is the original signal. Since the two systems are correlated, you can model them as \begin{align} \begin{bmatrix} y_1(t) \\ y_2(t) \end{bmatrix} = \begin{bmatrix} 1 & \rho \\ \rho & 1 \end{bmatrix} \begin{bmatrix} s_1(t) \\ s_2(t) \end{bmatrix} + \begin{bmatrix} n_1(t) \\ n_2(t) \end{bmatrix}, \end{align} where $$-1 < \rho < 1$$ denotes the correlation constant between the two systems. Now, we can model the system as a hypothesis testing problem as follows: \begin{align} \mathcal{H}_0: \rho = 0, &\quad \mbox{uncorrelated model} \\ \mathcal{H}_1: \rho \ne 0, &\quad \mbox{correlated model}. \end{align} If you assume that $$s_1(t)$$ and $$s_2(t)$$ are known, then find the maximum likelihood estimate (MLE) of $$\rho$$ under $$\mathcal{H}_1$$. If you assume $$s_1(t)$$ and $$s_2(t)$$ are unknown, then use generalized likelihood ratio test, i.e., find the MLE of $$s_i(t)$$ under each hypothesis and replace $$s_i(t)$$ with its MLE.