finddelay no significant correlation and nan values

9 views (last 30 days)
Hello,
I'm having trouble using the finddelay function and was wondering if any could provideo insights. I have two curves, that are very similar, though not identical (two methods or recording same data). They are offset and I'm trying to align them. This seems like a perfect job for finddelay(). But, no matter what I do, finddelay results in:
Warning: The returned delay was set to zero because no significant correlation was found between inputs.
> In finddelay (line 261)
The only hiccup I can think is that each curve has some nans in it, but even restricting the curve to exclude the nan portions results in the error. Does anyone have a good sense of why finddelay isnt working on this dataset? Or what another good alternative would be? As a bandaid, I'm just using the max value, but that is unsatisfying. Is the data set not long enough?
Code is:
D = finddelay(v1,v2)

Answers (1)

Star Strider
Star Strider on 7 Apr 2021
The NaN values in the data (note the gaps in the posted plot) are causing problems. Filling them resolves the problems.
Try this:
D = load('finddelayq.mat');
v1 = D.v1;
v2 = D.v2;
v1nans = nnz(isnan(v1))
v2nans = nnz(isnan(v2))
v1i = fillmissing(v1, 'makima');
v2i = fillmissing(v2, 'makima');
figure
plot(v1i)
hold on
plot(v2i)
hold off
grid
Dly1 = finddelay(v1i,v2i);
[v1ia,v2ia,Dly2] = alignsignals(v1i, v2i);
figure
plot(v1ia)
hold on
plot(v2ia)
hold off
grid
v1id = detrend(v1i, 3);
v2id = detrend(v2i, 3);
[v1ida,v2ida,Dly3] = alignsignals(v1id, v2id);
figure
subplot(2,1,1)
plot(v1id)
hold on
plot(v2id)
hold off
grid
title('Detrended')
subplot(2,1,2)
plot(v1ida)
hold on
plot(v2ida)
hold off
grid
title(sprintf('Detrended & Aligned (Delay = %d)',Dly3))
producing:
v1nans =
40
v2nans =
25
And signals that appear to be more closely aligned than they were originally, as demonstrated in this plot —
.

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!