# Find a portion of a signal using dtw ?

51 Ansichten (letzte 30 Tage)
David Santos am 19 Jul. 2024 um 16:43
Kommentiert: Umar am 23 Jul. 2024 um 14:24
I have the two attached signals and I want to know if "ref" is included somehow (time warping could happen) inside "det" signal.
Figure 1 show ref and det signals:
As you can see ref "can fit" inside det (ref is similar to det(1:100) aprox ) so I try to adjust them normalizing signals and using dtw:
refn=ref/max(ref);
detn=det/max(det);
[~, ix ,iy]= dtw(detn,refn);
figure;plot(refn(iy));hold on;plot(detn(ix));
max(normxcorr2(refn(iy),detn(ix)))
Obtaining:
with a normalized correlation of 0.86
I would love to be able to dtw adjust ref signal over det with the nedd of both signal be the same size so the adjust could be better. For example in this case I could have the signals between x=57:204 and get a better correlation (0.99) of both signals:
x=detn(ix);
y=refn(iy);
max(normxcorr2(x(57:204),y(57:204)))
But I'm missing the first part of ref signal (which could fit quita well) and also some samples at the end because dtw always thinks that both signals have to be the same size but I'm looking also for the possibility of being just a fragment of the other.
Any clue on how to get this adjustment of signals when one can be a portion of the other?
All the best
##### 7 Kommentare5 ältere Kommentare anzeigen5 ältere Kommentare ausblenden
David Santos am 23 Jul. 2024 um 9:39
So if I want that signal1 stay unmodified (no warping at all) should I put that constraint to 0?
% Fill the warpPath matrix with constraints
for i = 1:n+m
warpPath(i, 1) = max(1, i-0);
warpPath(i, 2) = min(n, i+constraint);
end
And for the indexes (ix, iy in the matlab dtw function) i Guess It must be obtained from the D matrix but do you know how?
All the best
Umar am 23 Jul. 2024 um 14:24
Hi David,
To keep signal1 unmodified (no warping), you should set the constraint to 0 in the warpPath matrix. By setting warpPath(i, 1) = max(1, i-0) and warpPath(i, 2) = min(n, i+constraint), it will make sure no warping for signal1.
Now, to obtain indexes (ix, iy) from the D matrix in DTW function, you can find the optimal warping path by backtracking through the accumulated cost matrix D. The indexes can be extracted by following the path with the lowest accumulated cost. It sounds like you are making progress.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Multirate Signal Processing finden Sie in Help Center und File Exchange

R2024a

### Community Treasure Hunt

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

Start Hunting!

Translated by