How to find coordinates of intersecting line?

2 Ansichten (letzte 30 Tage)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota am 20 Nov. 2022
Bearbeitet: Torsten am 20 Nov. 2022
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')

Akzeptierte Antwort

Matt J
Matt J am 20 Nov. 2022
Bearbeitet: Matt J am 20 Nov. 2022
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

Weitere Antworten (1)

Torsten
Torsten am 20 Nov. 2022
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 Kommentare
Matt J
Matt J am 20 Nov. 2022
I wonder if the jump discontinuity lines are to be considered part of the curve.
Torsten
Torsten am 20 Nov. 2022
Bearbeitet: Torsten am 20 Nov. 2022
Most probably not. But then take every second value from the "coordinates" array :-)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Modeling finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by