Time difference between two curves

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2011-4-11
Are you looking for the first possible match, or all the possible matches, or ??
Sébastien Malengé
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.

请先登录,再进行评论。

采纳的回答

Arnaud Miege
Arnaud Miege 2011-4-11
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

更多回答(4 个)

Sébastien Malengé
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 个评论
Arnaud Miege
Arnaud Miege 2011-4-11
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.

请先登录,再进行评论。


Sébastien Malengé
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 个评论
Arnaud Miege
Arnaud Miege 2011-4-11
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.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2011-4-11
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 2011-4-11
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 个评论
Walter Roberson
Walter Roberson 2011-4-11
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....)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by