What you are describing is called (/ has been solved via) "Dynamic Time Warping".
In DTW, you calculate a series of simple operations between two sequences that if applied on one sequence they would "bring it" directly "over" the other. Of course, there might be more than one ways to do this in which case you are selecting the one with the least cost. This "cost of distortion" is now your similarity.
For more information on DTW, please see this, this and this. More relevant to your application might be this publication. For a practical example, please see this link.
With regards to some of the rest of your questions:
- May cropping the longer signal corrupt the result of the cross-correlation?
Yes, it would...
- What is the best approach for resampling x and y?
...because both cropping and re-sampling assume a linear speed up. This might not be the case across the entire length of your signal.
- As I mentioned, x and y are only looking very similar after filtering. Is filtering signals prior cross-correlation advisable?
It depends a lot on the application. However, filtering two signals $x,y$ with the same impulse response $h$ is expected to increase their cross correlation because after convolution, both $x,y$ time instances would now have the same $h$ imprint on them.
EDIT: Following a brief review of the data provided with the question, it seems that these are some sort of counts (?) or other digital / impulsive data. Therefore, the question "...is filtering signals prior to cross-correlation advisable?" is ill posed. The fact remains that if you filter two signals through the same filter, their cross-correlation will increase. But here, it seems that the signals do not exist in their final form yet. To clarify: We have to agree on which one is the signal. If you were dealing (for example) with a pulse width modulation (PWM) derived sound signal, we would not try to correlate the two PWM pulse trains that produce it but their integrated versions because THAT is what we consider as our signal. Consequently, in this particular case we are dealing with here, we have to understand what is considered as "signal". The only thing we know about it is that it comes out of some process. That's fine but, at the same time, if you have to integrate the data to PRODUCE the signal of interest then the process itself or its context would tell you what sort of integration you have to apply. It might not even be called "low pass filtering". In conclusion: If your signal has to be integrated first, then don't try to compare the "pulse sequences". To get back to the PWM-Audio case, it is like asking "Should I integrate the PWM pulses before cross correlation or would this spoil my signal?". Of course you have to apply the integration because otherwise, you don't have the signal to work with. Decide on the parameters of integration, apply them to your original signal and then, if you still have drifts and compressions and dilations of features in the signal, see if you can use DWT to establish the time delay.
- Is it a must to detrend data prior cross-correlation or might it be enough to remove the mean?
Again, depends on the application and the amount of drift expected in the data but in general, it is a good idea to remove any long term drifts to avoid the cross-correlation being thrown off by the fact that the trends seem to match despite those little "details" on top of them. Where "details", of course, might be your desired signal. This is illustrative but a hypothetical scenario, your data might not even include such a case, it simply shows how detrending might help.
Hope this helps.
EDIT (2):
In the light of more information, I have to say that this does not look like a task for DTW neither cross-correlation the way it is described.
What is attempted here is an estimation of the delay between two waveforms by aligning "landmark" points. NOT the waveforms themselves. Personally, I am struggling to see why the marked points in the signal should align at all. Therefore, what I would suggest is this:
- Pick the higher frequency waveform
- Mark the peak you are after
- Extract $\pm m$ points (or ms) around it. For example, if the peak is at sample 4500, extract
x[4500-200:4500+200]
. Call this your template $q$.
- Subtract the mean of $q$ from $q$
- Downsample $q$ so that it matches the sampling rate of the lower frequency signal. Call this $q_d$.
This is now your template. It is shorter than the signal you are looking for and you can "slide" it over the lower rate signal and estimate the cross correlation. At the point that the cross correlation peaks is where this second waveform is, in the lower rate signal. Prior to applying cross correlation, you might want to be subtracting the mean of the signal portion you are about to compare with your template or instead of removing the mean, you might want to be applying detrending. Because the duration of the signal is small, simple linear detrending might work good enough.
This is an attempt to align specific points of interest in the signal. Not the waveform as a whole
Hope this helps.
EDIT (3):
Ideally, a large amount of the information provided in the comments here, should appear in the original question and then perhaps we can delete all of these comments.
If you can control the load of the inverter, maybe you can insert a "sync event". Apply a known load on and off after the inverter has reached its nominal operation to create a "click" with a predictable response. You can use that "click" later to sync the two signals. If you have this capability, then you can average the responses from a number of "clicks" so that you have a good idea of what you are looking for, via cross correlation, as the "sync pulse".
Of course, this covers what happens when the two signals are supposed to have a constant time invariant delay.
subplot
type of graph marking on the graph of one waveform how it corresponds with the other? ">this< should match with >this<" kind of thing, not parallel lines. $\endgroup$