How to find a delay between two similar vectors

4 vues (au cours des 30 derniers jours)
Jórdan Venâncio Leite
Jórdan Venâncio Leite le 30 Oct 2021
Modifié(e) : Star Strider le 30 Oct 2021
Hi,
I need to calculate the delay between the two vectors from the attached J.mat file. The first vector is J(:,1),J(:,2) and the second J(:,1),J(:,3). If you watch carefully there is a lag between the blue and the green vector, which are identical, except at the beginning, where there is a little difference between both. I need to know what are the values of the areas marked in red, considering that they repeat.
Thanks in advance

Réponses (2)

Star Strider
Star Strider le 30 Oct 2021
Use the finddelay function. (The introduction release isn’t stated in the documentation, however I believe it’s been available for about five years.)
It is difficult to work with .mat files with the online Run application, so I did this offlline.
LD = load('Jórdan Venâncio Leite J.mat');
J2 = LD.J2; % First Column Is 'Time', Last Two Columns Are The Signals
dly = finddelay(J2(:,2),J2(:,3)) % Delay Indices
Time = J2(dly,1) % Delay Time
figure
plot(J2(:,1), J2(:,[2 3]))
grid
producing —
dly =
1920
Time =
0.191900000000000
See that line for related functions as well.
.
  2 commentaires
Jórdan Venâncio Leite
Jórdan Venâncio Leite le 30 Oct 2021
Hi star! Thanks for your answer!
There is a way to do it automatically? Considering that i have a similar vector but much bigger. What i'm saying is that this vector has more than a single delay. Each part has a unique delay.
Star Strider
Star Strider le 30 Oct 2021
Modifié(e) : Star Strider le 30 Oct 2021
That could be a challenge, because the data are much noisier that I originally realised.
That aside, the best option is likely the midcross function that will give the rise and fall times of the bilevel waveform. Filter the data first, then continue with the processing —
Ts = mean(diff(J2(:,1)));
Fs = 1/Ts;
[J22,df] = lowpass(J2(:,2), 252, Fs, 'ImpulseResponse','iir');
J23 = filtfilt(df, J2(:,3));
J22x = midcross(J22,J2(:,1));
J22x = J22x(2:end);
J23x = midcross(J23,J2(:,1));
Difference = J23x - J22x;
RiseTimeDifferences = Difference(2:2:end)
FallTimeDifferences = Difference(1:2:end)
figure
plot(J2(:,1), J2(:,[2 3]))
hold on
plot(J22x, ones(size(J22x))*0.5,'xb')
plot(J23x, ones(size(J23x))*0.5,'xr')
hold off
grid
The ‘J22x’ vector contiinnues to have 7 elements, while the ‘J23x’ vector has 6. I leave it to you to resolve that, since it will likely require some sort of thresholding. The cutoff frequency selection is appropriate, however does not completely resolve this.
Then, choose the alternate values (rise times, fall times, or both) to calculate the delays.
EDIT — (30 Oct 2021 at 20:50)
Changed the midcross calls section to include the ‘Difference’ calculation and its related calculations, code otherwise unchanged.
.

Connectez-vous pour commenter.


Sulaymon Eshkabilov
Sulaymon Eshkabilov le 30 Oct 2021
Here is one of the possible solution routines:
load('J.mat')
plot(J2(:,1), J2(:,2:3))
D2=diff(J2(:,2));
D3=diff(J2(:,3));
hold on;
Idx2 = D2<0;
Idx3 = D3<0;
Values2 =J2(Idx2,1);
Values3 =J2(Idx3,1);
y2 = zeros(size(Values2));
y3 = zeros(size(Values3));
plot(Values2, y2, 'ro', Values3, y3, 'bo'), shg

Community Treasure Hunt

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

Start Hunting!

Translated by