【发布时间】:2017-01-28 12:23:11
【问题描述】:
我会添加列,这些列是到最近过零的时间距离。如果该点在过零之后,则时间距离可以为负。
这里是零交叉的计算和绘图
# Data generation
t=seq(0,10,0.05)
h = sin(t)+3*cos(3*t)
dh = cos(t)-9*sin(3*t)
plot(t,h,type='b')
# Find indices of zero crossings
df <- data.frame(h,dh)
zero_cross_down <- df[-1,] < 0 & df[-nrow(df),] >= 0
zero_cross_up <- df[-1,] >= 0 & df[-nrow(df),] < 0
indx_h_cross_down = which(zero_cross_down[,1])
indx_h_cross_up = which(zero_cross_up[,1])
# Find times of zero crossings and plot
hb<-df[,"h"][indx_h_cross_down]
ha<-df[,"h"][indx_h_cross_down+1]
tb<-indx_h_cross_down*0.05
ta<-(indx_h_cross_down+1)*0.05
tzcd_h <- tb + (ta-tb)/(ha-hb)*(0-hb)
points(tb,0*tzcd_h,col="red",pch='v')
hb<-df[,"h"][indx_h_cross_up]
ha<-df[,"h"][indx_h_cross_up+1]
tb<-indx_h_cross_up*0.05
ta<-(indx_h_cross_up+1)*0.05
tzcu_h <- tb + (ta-tb)/(ha-hb)*(0-hb)
points(tb,0*tzcu_h,col="green",pch='^')
但是,现在,我不知道如何计算,并且 dh 的一列是到最近的十字路口的时间。
【问题讨论】:
-
您是否正在寻找
t中的元素与您计算的交叉点(向上或向下)之间的时间差的最小绝对值? -
我需要到最近的十字路口的未来时间距离。所以,我想要一个向量或另一列相同长度的时间值到最近的交叉点(上/下)。
-
OP 表示穿越后距离可能为负数。
-
@John:请查看更新是否回答了您的问题和/或 OP。
标签: r