From looking at your data, it appears that the root cause for the large td value is due to the presence of “NaN” values in the “s2” data vector. Consider filling in the missing data in this data vector, for example, using the “fillmissing” function, prior to calling the “align_signal” function you provided.
I was able to confirm that the “td” value as the output of the “align_signal” function is 4 instead of 24482 when I used linear interpolation to fill the missing data in “s2”.