How to measure the time dependent correlation of two signals I have two signals (time series) shown in the plot below. Just by looking at the figure, we can see that the two main peaks of both signals are very closely aligned (correlated), however the red signal has additional features elsewhere which don't match the blue curve.

I am looking for some function which can tell me how correlated these two signals are at a given time. IE: at t = -18 and t = +10 where the peaks are located, the correlation should be very close to -1, while at t = -40, the correlation is probably close to 0.

Specifically, I want a robust way to tell that if I see a peak in the blue curve, then there is a corresponding (negative) peak in the red curve.

I've looked into Cross correlation, however this seems suitable for time series which simply have a constant time lag with respect to each other. In my problem the correlation between my two signals is changing with time. I've thought about dividing up the signal into small bins and computing the correlation of each bin, but I was hoping there is a better way.
Your signals look like they have about the same ordinal scale, and little lag. Hence, you can perform local correlations: take a segment of both signals centered at a time location, you can normalize them in amplitude  and dispersion (divise by mean and standard deviation, or median and median absolute deviation). Apply a smoothing window: if you do not do that, remember you are already applying a rectangular window. Then do a cross-correlation, and repeat over time. 

Such a process creates a 2D image from two 1D signals. It  could be called windowed cross-correlation (see also Windowed cross correlation in Matlab), or local cross-correlation. From the latter:


  We address the problem of capturing and tracking local correlations
  among time evolving time series. Our approach is based on comparing
  the local auto-covariance matrices (via their spectral decompositions)
  of each series and generalizes the notion of linear cross-correlation


If you are unsure about scales, or want of more generic setting, some perform cross-correlation in a multiscale wavelet domain. You can check the concept of wavelet coherence (Matlab), illustrated by Torrence et al. Interdecadal Changes in the ENSO–Monsoon System
, with Matlab software