# Finding the differences(using features, not subtraction) in order to find differences in signals

I have a question. Let’s say I have two signals (discretely represented as arrays), $$S_1$$ and $$S_2$$ as shown below. $$S_1$$ has a similar form to $$S_2$$. If the signals are subtracted, $$S_2-S_1$$, they will not give the output on the right as their voltages don’t necessarily line up in the parts where their features don’t. Is there a way I can filter $$S_1$$ Using $$S_2$$ to give me the output on the right. Thanks

• I'm not quite sure what you mean with lining up, but maybe you just want to first cross-correlate the two arrays, then from that just find the maximum, which shows you how you'd need to shift one of the arrays for them to be "maximally similar". Then you do that shift and your point-wise subtraction. I'm almost certain there's a coll application behind this and there'd be an even more elegant way, but we'd need more info on about what these signals are and why you need to subtract them to help. For example, just from your plots, I'd completely ignore $S_2$ and just high-pass filter $S_1$. – Marcus Müller Jun 20 '19 at 8:20
• there is a technique known as dynamic time warping that tries to align pairs of signals. – user28715 Jun 20 '19 at 13:44
• @MarcusMüller I have tried lining up the signals using a cross correlation methods however the features of the signals, e.g above we have two square pulses, are not always the same length between $S_1$ and $S_2$, thus thus will produce a bunch of spikes, which we could get rid of with a low pass filter, however, for robustness, there are cases where the differing features have high freq. – frozenbooger Jun 21 '19 at 23:18
• @StanleyPawlukiewicz, I started looking at a paper which discusses method, it looks promising. I will update this question soon. – frozenbooger Jun 21 '19 at 23:18
• but: if they are not always of the same length, and not in the same distances, why should you line them up at all? How are they related? That relationship will define how you do it. – Marcus Müller Jun 22 '19 at 12:47