Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用r中的双小波从相位箭头计算滞后_R_Wavelet_Biwavelet - Fatal编程技术网

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

用r中的双小波从相位箭头计算滞后,r,wavelet,biwavelet,R,Wavelet,Biwavelet,我试图理解R中的交叉小波函数,但不知道如何用双小波包将相位滞后箭头转换为时间滞后。例如: 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(

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

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)
require(gamair)
数据(开罗)

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

我不知道有什么软件包可以让这成为一个一步的过程,但因为我们基本上是在处理正弦波,一个选择是“调零”波,然后找到零交叉点。然后可以计算波1和波2的过零点之间的平均距离。如果知道测量之间的时间步长,可以轻松计算滞后时间(在这种情况下,测量步骤之间的时间为一天)

以下是我用来完成此任务的代码:

#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
#平滑数据以消除会引入过多过零的噪声)
从温度减去70,在波的中间大约引入一个“零”。

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

我不知道有什么软件包可以让这成为一个一步的过程,但因为我们基本上是在处理正弦波,一个选择是“调零”波,然后找到零交叉点。然后可以计算波1和波2的过零点之间的平均距离。如果知道测量之间的时间步长,可以轻松计算滞后时间(在这种情况下,测量步骤之间的时间为一天)

以下是我用来完成此任务的代码:

#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
#平滑数据以消除会引入过多过零的噪声)
从温度减去70,在波的中间大约引入一个“零”。

spline1在我的例子中,对于半日潮波,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小时。

在我的例子中,对于半日潮,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小时