Trouble with time-syncing two radio signals using cross-correlation I posted a similar question a while ago here (I'm posting this follow-up since I'd like to focus more on cross-correlation now). I have a setup where I have two software-defined radios connected to different antennas, and a circuit switches the antennas on and off at the same time. I am trying to time-sync the two signals as precisely as possible. The radios are sampling at 2.4 MS/s and I'm sampling about 0.2 seconds of data. Even though I've synced the two clocks of the radios, due to slight hardware differences there will always be a slight delay in one of the signals which is why I need to sync them in software. I have a system that is able to sync the signals most of the time just by getting the signal's envelopes and identifying where the antenna switching happens, but this doesn't work so well when the "silence" part is too noisy / too high amplitude, so I would like to use cross correlation.

Here are two of the signals I'm trying to align: s0, s1. I believe the correct delay of s0 should be approximately 1069.

I'm normalizing both signals to have a max amplitude of 1, and I've also tried downsampling to make it lower detail. I'm just doing signal.correlate(s0, s1) and plotting the result, but I don't even see any local maximum at the correct delay (I know the correct delay from the other method).

Here's the plotted correlation:



And here it is zoomed in to where I'd expect the actual delay to be:



There doesn't seem to be any local max around 1069.

Is anyone able to successfully sync these two signals using cross correlation, or is it just not possible for this kind of data? Everyone doing similar project to me uses cross correlation to do the time synchronization, so I'm not sure why it's not working at all for me (even when I use their code). Any help would be greatly appreciated!
It will work when you take the 2nd gradient of the signals:

import numpy as np
from scipy import signal

s0 = np.gradient(np.gradient(s0))
s1 = np.gradient(np.gradient(s1))
np.argmax(signal.correlate(s0, s1)) -&gt; 525358


That corresponds to a shift of 1071 which is close to your expected 1069
Interestingly the minimum (most negative correlation) is close by at 1069

Plotting the cross-correlation of 2nd gradient gives a reasonably sharp peak:


Zomming in to the accordingly shifted data shows that this worked:



Using the most negative correlation results in the almost same picture:


What might be surprising is that the min and max are just two samples apart and also that the signal seems to be significantly phase shifted. On the other hand the start is matched perfectly. My interpretation of this is that the sync is not so much done by what we see as signal but by some high frequency parts of noise received in both channels. Since this 2 sample shift between min and max is the typical result when matching two channels that received the same random noise.

I can not explain easily why the correlation of the original data works in some cases. But here is an simple example that gives an idea:

a = np.array([0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 0, 0, 0, 0], dtype=float)
b = np.array([0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 0, 0, 0, 0], dtype=float)
np.argmax(signal.correlate(a, b)) -&gt; 16


which is correct

but when adding an offset it fails

a += 5
b += 5
np.argmax(signal.correlate(a, b)) -&gt; 20


the correlation of the first gradient still gives the right result but it will fail also if a significant ramp is added. Though for the 2nd gradient the correct result is achieved

a += np.array(range(0,len(a)))*5
b += np.array(range(0,len(b)))*5
np.argmax(signal.correlate(a, b)) -&gt; 20
a = np.gradient(a)
b = np.gradient(b)
np.argmax(signal.correlate(a, b)) -&gt; 20
a = np.gradient(a)
b = np.gradient(b)
np.argmax(signal.correlate(a, b)) -&gt; 16