# intersection of lines and curves

24 views (last 30 days)
SHANTANU KSHIRSAGAR on 12 May 2020
Commented: Star Strider on 22 May 2020
i have data in which line is plotted on a signal having pulses. I want to find out all points of intersections between the line and the curve. Right now i am able to get single point of intersection on only one side of pulse. I also need point of intersection on the other side.

#### 1 Comment

SHANTANU KSHIRSAGAR on 12 May 2020
also in some cases getting wrong intersection, in remaining getting error of not having unique points(intersect1).

Star Strider on 12 May 2020
Try this:
x_curve = D.x_curve;
y_curve = D.y_curve;
x_line = D.x_line;
y_line = D.y_line;
x_curve(x_curve == 0) = []; % Eliminate Spurious Points
y_curve(y_curve == 0) = []; % Eliminate Spurious Points
zci = @(v) find(v(:).*circshift(v(:), -1, 1) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector (>= R2016b)
icix = zci(y_curve - y_line(1:end-2));
figure
plot(x_curve, y_curve, x_line, y_line)
hold on
plot(x_curve(icix), y_curve(icix), 'dr')
hold off
grid
producing: The x-values of the intersections are about 0.135 and 0.149. (They are: x_curve(icix).)
The points are dense enough that it is not necessary to interpolate them to get reasonably precise values for the intersections.
.

Star Strider on 13 May 2020
As always, my pleasure!
O.K. In that event, see if this does what you want.
Try this:
x_curve = D.x_curve;
y_curve = D.y_curve;
x_line = D.x_line;
y_line = D.y_line;
stlvls = [0.75 3.1];
[ymin,mnix] = min(y_curve);
[ymax,mxix] = max(y_curve);
tlvl = interp1(y_curve(mnix:mxix), x_curve(mnix:mxix), stlvls, 'linear');
fprintf('risetime = %.6f\n', diff(tlvl))
figure
plot(x_curve, y_curve)
hold on
plot(tlvl, stlvls, 'dr')
hold off
grid
producing: The rise time between the two levels is the difference between the ‘tlvl’ elements, and the times are those elements. This is subject to the constraints of interp1, that are explained in its documentation. The code works here, although it may not be robust for all waveforms.
For instances such as the earlier waveform, it would be necessary to sort the indices of the ‘icix’ vector for each intersecting line (assuming two different levels and four elements, so concatenate the elements in one vector, then sort), and then use interp1 if necessary to get the associated times. If the lines and curve have a large number of points, it may not be necessary to interpolate them to get accurate time estimates. Just use the indices, and do the appropriate arithmetic on the times derived from the indices to get the risetime and falltime.
SHANTANU KSHIRSAGAR on 22 May 2020
Star Strider on 22 May 2020
As always, my pleasure!

KALYAN ACHARJYA on 12 May 2020
Edited: KALYAN ACHARJYA on 12 May 2020
Have you tried this way?
data1
data2
diff=data1-data2;
small_value=?? % Define small value to deal with samll differenece also
% Make the lower as possible, though ensure that it donot missed the interconnection
idx=find(diff<small_value);
If the data1 and data2 are non floating numbers, you can do the following
idx=find(data1==data2)

SHANTANU KSHIRSAGAR on 12 May 2020
i am not able to use the fuctions which are mentioned in the links. If we need to do it without these external functions is it possible .
Walter Roberson on 12 May 2020
Do you mean that you are not permitted to use the functions there, or that you have technical problems when you try to use those functions?
If you are not permitted to use the functions there, then I would be concerned that if I were to give you code for this purpose, that you would not be permitted to use it.
SHANTANU KSHIRSAGAR on 12 May 2020