필터 지우기
필터 지우기

Time difference between two curves

조회 수: 3 (최근 30일)
Sébastien Malengé
Sébastien Malengé 2011년 4월 11일
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é
Sébastien Malengé 2011년 4월 11일
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é
Sébastien Malengé 2011년 4월 11일
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é
Sébastien Malengé 2011년 4월 11일
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
Teja Muppirala
Teja Muppirala 2011년 4월 11일
Oops, I think I meant -2.7
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