# Need a similarity metric that describes these two curve as highly similar

I have a large number of time series data and I need to be able to compare the similarity of the curves to a reference curve. The reference curve in question is shown in red in the figure, and I'd like to compute a similarity metric for the blue curve that tells me that these things are highly similar.

The reason that I want these things to be similar is that they are both characterized by a largely monotonic rise, followed by a near plateau at some upper value, and then followed by a largely monotonic drop back down to the initial level. I have computed some similarity measures such as the Frechet distance and DTW distances, using the following snippets of code

sim_score = similaritymeasures.frechet_dist(Z, Zref)
sim_score2, _ = fastdtw(Z, Zref, dist=euclidean)


The problem is is that the scores computed using these techniques do not tell me that these curves are similar. For example, the fastdtw score is shown in the title of the figure, and this score is actually quite large when compared to other comparison scores for curves which I would judge by eye to be much more dissimilar. For example, the following curve has roughly half the fastdtw distance, despite it not having as similar of a shape.

The issue seems to be that the temporal overlap is still being weighted much more heavily then more shape-related attributes. Now it's perhaps possible that a more nuanced understanding of what's possible with DTW would give me the outcome I need, perhaps using a more fully-featured DTW package like https://pypi.org/project/dtw-python/, but I'm unfamiliar with many of the options available in that package. Or maybe there's another method that would be better suited. Of course, I could brute force this by creating a piecewise continuous curve with a bunch of variable parameters describing a step-like shape, optimize them against the target curve, and take the best error match as the distance metric. If the optimization doesn't get trapped in a local minima, then this should work, but it's more involved and messier than I'd like to do if I can avoid it.

Would appreciate any other ideas you all might be able to suggest. Thanks in advance!

• Have you tried plain old crosscorrelation? It looks like it should work well with your examples. – MBaz Apr 11 at 17:27
• Good point. I actually hadn't looked at that yet. The lags between my two signals are not known in advance, and the duration of each individual plateau region in the signals are not necessarily equal, but playing with that would be a good thing to consider. Thanks! – gammapoint Apr 11 at 17:37
• Cross correlation would give you a peak at a time equal to the delay between the signals, and the strength of the cross correlation relative to the strengths of each signals' autocorrelation should give you a measure of how good the fit is. – TimWescott Apr 11 at 18:49
• do you happen to have a mathematical model for what causes these signals, or what they'll be used for? A winning strategy is often finding the parameters of the model that most likely led to these signals, and then comparing the parameter sets. – Marcus Müller Apr 11 at 20:01

While I still don't yet understand all the options in the dtw-python package, it seems as though the relative ordering of my two examples is now as expected using the code snippet
alignment = dtw.dtw(y, yref, keep_internals=True)