How to find coordinates of intersecting line?

조회 수: 1 (최근 30일)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2022년 11월 20일
편집: Torsten 2022년 11월 20일
Hi, I have plot which is shown below and there is black (dashed) vertical line in x axis at 3. I need to find the coordinates of intersection between black line and red curve.
clear all; close all;
fs= 8192*2; % sampling frequency
dt = 1/fs; % sample time
T=5; % duration of the signal
Nt = T*fs; % total number of samples
t = 0:dt:T-dt; % time vector
% Source definition
f0 = 1; % frequency at time t = 0s
f1 = 5; % freqeuncy at time t = T
%-------------------------------------------------------
beta = (f1-f0)/T; % beta
finst = f0+beta*t.'; % instantaneous frequency
phi = 2*pi*cumsum(finst)*dt;
figure()
plot(wrapTo2Pi(phi),t,'r');
hold on
xline(3,'--k')
xlabel('phase')
ylabel('s')

채택된 답변

Matt J
Matt J 2022년 11월 20일
편집: Matt J 2022년 11월 20일
fs= 8192*2; % sampling frequency
dt = 1/fs; % sample time
T=5; % duration of the signal
Nt = T*fs; % total number of samples
t = 0:dt:T-dt; % time vector
% Source definition
f0 = 1; % frequency at time t = 0s
f1 = 5; % freqeuncy at time t = T
%-------------------------------------------------------
beta = (f1-f0)/T; % beta
finst = f0+beta*t.'; % instantaneous frequency
phi = 2*pi*cumsum(finst)*dt;
figure()
plot(wrapTo2Pi(phi),t,'r');
hold on
xline(3,'--k')
xlabel('phase')
ylabel('s')
hold off
z=wrapTo2Pi(phi(:)).';
n=nnz(diff(z)<-pi);
tc=interp1(phi,t,3+2*pi*(0:n) );
pc=0*tc+3;
hold on; plot(pc,tc,'xb'); hold off

추가 답변 (1개)

Torsten
Torsten 2022년 11월 20일
fs= 8192*2; % sampling frequency
dt = 1/fs; % sample time
T=5; % duration of the signal
Nt = T*fs; % total number of samples
t = 0:dt:T-dt; % time vector
% Source definition
f0 = 1; % frequency at time t = 0s
f1 = 5; % freqeuncy at time t = T
%-------------------------------------------------------
beta = (f1-f0)/T; % beta
finst = f0+beta*t.'; % instantaneous frequency
phi = 2*pi*cumsum(finst)*dt;
phase = wrapTo2Pi(phi);
n = numel(phase);
v = (phase(1:n-1)-3).*(phase(2:n)-3);
idx = v <= 0;
coordinates = t(idx);
figure()
plot(phase,t,'r');
hold on
xline(3,'--k')
xlabel('phase')
ylabel('s')
plot(3*ones(size(coordinates)),coordinates,'o')
hold off
  댓글 수: 2
Matt J
Matt J 2022년 11월 20일
I wonder if the jump discontinuity lines are to be considered part of the curve.
Torsten
Torsten 2022년 11월 20일
편집: Torsten 2022년 11월 20일
Most probably not. But then take every second value from the "coordinates" array :-)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by