How to find coordinates of intersecting line?
2 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!