I have 2 datasets which vary with time as shown in the figure - Sa – Red , Sb – BLACK . I am doing the analysis in R. The entire dataset and a segment of data from 30 - 31 s are shown below - -
As you can see from the figures, the datasets appear similar but one dataset leads (or lags) the other dataset in time. The downward peaks appear to be slightly shifted in time for one of the signals wrt the other. I would like to determine the following –
The baseline value (reference) for the two signals – Is there a statistical method to find out this? Is there some signal processing techniques that need to applied before determining the baseline? For Sa, the baseline is more noisy and shifts up and down – so it seems difficult to assume a constant reference line
The time lag / lead between these two signals – I tried to make the reference line constant by removing data points above an approximate baseline and replacing it with the approx baseline value. Then I found out values sa1, sa2, sa3, sa4, ..etc. Similarly, I found sb1 ,sb2, sb3, sb4,… etc.
2a. Is there a way I can map sa1 to sb1, sa2 to sb2..and so on? The idea is to calculate (sa1-sb1), (sa2-sb2),… and find out the average time lag/ lead for the two signals over the entire dataset. I understand that this method is very approximate, since the resolution is lost while assuming a baseline based on just eyeballing.
2b. Is there another method for calculating the time lag/ lead? Or the exact times sa1,sa2.. etc at which the signal drops below the reference line and comes back to its reference line? Will a cross correlation work? How do I use it for noisy signals?
3.The frequency of the downward peaks