Effacer les filtres
Effacer les filtres

Time difference between two curves

3 vues (au cours des 30 derniers jours)
Sébastien Malengé
Sébastien Malengé le 11 Avr 2011
Hi !
I have two curves, one is a ramp, the second is more like many steps. The two curves don't start at the same time, but finish at the same time. What I'm asking is how can I have the time difference when curveA.value = curveB.value (the two curves are exporting with a From Workspace block). I don't know how to do because the curves don't have the same value at the same time.
Thanks !
  2 commentaires
Walter Roberson
Walter Roberson le 11 Avr 2011
Are you looking for the first possible match, or all the possible matches, or ??
Sébastien Malengé
Sébastien Malengé le 11 Avr 2011
All, I want all the possible match, because I want to know the time difference between my curve A and B when the value is the same.

Connectez-vous pour commenter.

Réponse acceptée

Arnaud Miege
Arnaud Miege le 11 Avr 2011
If you are using Simulink, which it sounds as if you are, then you can feed both signals to a Relational Operator block, and feed the output of that block to a Stop Simulation block. The stop time will then tell you when one signal becomes greater than (or smaller than) the other one.
HTH,
Arnaud

Plus de réponses (4)

Sébastien Malengé
Sébastien Malengé le 11 Avr 2011
Actually, what I want is a vector, because I need to find the max, the min, etc. I don't know if my question is clear or not, if not I can give you a figure of my two curves.
  1 commentaire
Arnaud Miege
Arnaud Miege le 11 Avr 2011
No, it's not clear at all... Are you using Simulink? If so, both curves will have the same timestamp, you should therefore be able to compute the time difference between the two.

Connectez-vous pour commenter.


Sébastien Malengé
Sébastien Malengé le 11 Avr 2011
I try to explain it better (sorry for my English by the way), my two curves look like that :
So, as you can see, I have one ramp and one "steps". They don't start at the same time, but sometime, they are the same values (at a different time). What I need is to know the difference between curve A and B when the values for the both is the same.
It's more understandable now...?
  1 commentaire
Arnaud Miege
Arnaud Miege le 11 Avr 2011
I think in Simulink, you can only compare two signals at the same point in time. What you can do is compare each curve independently to the same constant value using the relational operator block as I suggested. You can then look at these two signals and when they change from 0 to 1 is when the curve in question is greater than/smaller than the constant value. The time difference between these two trigger signals is what you're after. If you want to do this in Simulink, you'll probably need to use either an Embedded MATLAB Function block (now simply called a "MATLAB Function" block in R2011a) or a Stateflow chart to work out the logic to extract the time difference from the two trigger signals, it's not straightforward.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 11 Avr 2011
If you are asking for all possible matches, then potentially each sample of curveA could match against each sample of curveB at all time instances in curveB. You would then need an output matrix which was length(curveA) by length(curveB), unless you use the very new Simulink dynamic array sizes. If you are going to use the array of maximum size, you might as well make it a boolean array with a 1 for each location in which the values match. You can do that in a fairly simple matlab statement,
bsxfun(@eq, curveA.', curveB)
If these are floating point values, don't be surprised if you get no matches: you may wish to match to a tolerance rather than matching exactly.

Teja Muppirala
Teja Muppirala le 11 Avr 2011
If all you really want to know is what the difference between the curves is, then one way would be to use kind of a reverse look-up table.
t = linspace(0,10,1001);
y1 = 1+t;
y2 = (t-1.7) .* (t >= 1.7);
y2 = round(2*y2)/2;
plot(t,y1,t,y2); %My two curves
gap = interp1(y1,t,y2) - t;
figure
plot(y2,gap);
title('The gap between the two curves as a function of y2');
Clearly the gap is about -1.7.
  2 commentaires
Teja Muppirala
Teja Muppirala le 11 Avr 2011
Oops, I think I meant -2.7
Walter Roberson
Walter Roberson le 11 Avr 2011
If that kind of number is what was being sought, then xcorr or equivalent should give you the "best" time match. However, the original poster wants _all_ of the time matches. (Not sure what the original poster wants to do about the list of times corresponding to the horizontal part of the steps....)

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by