Finding baseline (reference) of nosiy data and lag/lead between 2 signals 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
You can try the function 'ccf' in R.
The way I would setup your data is:
df=
time | red | black | red diff | black diff |

** make sure your time interval's are constant. i.e every 5 seconds/10 seconds etc

red diff and black diff being the difference between the adjacent values in the red and black data columns, respectively. 
i.e. diff(df$red) = red diff

Then do a ccf on the 2 difference columns and adjust 'lag.max' as necessary to view the plot that is generated. There should be a peak in the graph which is the lag (that occurs the most) between red and black.