首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用r中的双小波从相位箭头计算滞后

使用r中的双小波从相位箭头计算滞后
EN

Stack Overflow用户
提问于 2015-08-04 22:30:56
回答 2查看 683关注 0票数 1

我正在尝试理解R中的交叉小波函数,但不知道如何使用双小波包将相位滞后箭头转换为时间滞后。例如:

代码语言:javascript
复制
require(gamair)
data(cairo)
data_1 <- within(cairo, Date <- as.Date(paste(year, month, day.of.month, sep = "-")))
data_1 <- data_1[,c('Date','temp')]
data_2 <- data_1

# add a lag
n <- nrow(data_1)
nn <- n - 49
data_1 <- data_1[1:nn,]
data_2 <- data_2[50:nrow(data_2),]
data_2[,1] <- data_1[,1]

require(biwavelet)
d1 <- data_1[,c('Date','temp')]
d2 <- data_2[,c('Date','temp')]
xt1 <- xwt(d1,d2)
plot(xt1, plot.phase = TRUE)

这是我的两个时间序列。两者都是相同的,但其中一个落后于另一个。箭头显示的相位角为45度--显然,向上或向下指的是90度(同相或异相),所以我的解释是我看到的是45度的滞后。

现在如何将其转换为时间延迟,即如何计算这些信号之间的时间延迟?

我在网上读到,这只能在特定的波长下完成(我假设这意味着在特定的时间段?)。那么,假设我们对365个周期感兴趣,并且信号之间的时间步长是一天,那么如何计算时间延迟呢?

EN

回答 2

Stack Overflow用户

发布于 2015-08-06 05:10:04

所以我相信你在问如何确定给定两个时间序列的滞后时间(在这种情况下,你人为地添加了49天的滞后时间)。

我不知道有什么包可以一步完成这一过程,但由于我们基本上是在处理sin波,一种选择是将波“清零”,然后找到零交叉点。然后,您可以计算波1和波2的零交叉点之间的平均距离。如果您知道测量之间的时间步长,则可以轻松计算滞后时间(在这种情况下,测量步长之间的时间是一天)。

下面是我用来实现这一点的代码:

代码语言:javascript
复制
#smooth the data to get rid of the noise that would introduce excess zero crossings)
#subtracted 70 from the temp to introduce a "zero" approximately in the middle of the wave
spline1 <- smooth.spline(data_1$Date, y = (data_1$temp - 70), df = 30)
plot(spline1)
#add the smoothed y back into the original data just in case you need it
data_1$temp_smoothed <- spline1$y

#do the same for wave 2
spline2 <- smooth.spline(data_2$Date, y = (data_2$temp - 70), df = 30)
plot(spline2)
data_2$temp_smoothed <- spline2$y

#function for finding zero crossing points, borrowed from the msProcess package
zeroCross <- function(x, slope="positive")
{
  checkVectorType(x,"numeric")
  checkScalarType(slope,"character")
  slope <- match.arg(slope,c("positive","negative"))
  slope <- match.arg(lowerCase(slope), c("positive","negative"))

  ipost  <- ifelse1(slope == "negative", sort(which(c(x, 0) < 0 & c(0, x) > 0)),
  sort(which(c(x, 0) > 0 & c(0, x) < 0)))
  offset <- apply(matrix(abs(x[c(ipost-1, ipost)]), nrow=2, byrow=TRUE), MARGIN=2, order)[1,] - 2
  ipost + offset
}

#find zero crossing points for the two waves
zcross1 <- zeroCross(data_1$temp_smoothed, slope = 'positive')
length(zcross1)
[1] 10

zcross2 <- zeroCross(data_2$temp_smoothed, slope = 'positive')
length(zcross2)
[1] 11

#join the two vectors as a data.frame (using only the first 10 crossing points for wave2 to avoid any issues of mismatched lengths)
zcrossings <- as.data.frame(cbind(zcross1, zcross2[1:10]))

#calculate the mean of the crossing point differences
mean(zcrossings$zcross1 - zcrossings$V2)
[1] 49

我相信有更多雄辩的方法可以做到这一点,但它应该能让您获得所需的信息。

票数 0
EN

Stack Overflow用户

发布于 2018-12-07 15:39:32

在我的例子中,对于半日潮,90度等于3小时(90*12.5小时/360= 3.125小时)。12.5小时为半日周期。因此,对于45度等于-> 45*12.5/360 = 1.56小时。

因此,在您的案例中: 90度-> 90*365/360 = 91.25小时。45度-> 45*365/360= 45.625小时。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31812094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档