顺利更改日长

用户名

我想对日长度随时间平滑变化(但保持正弦曲线)进行建模。https://en.wikipedia.org/wiki/Chirp给出了用于更改瞬时频率的“线性调频”公式,但是在经过5天的24小时编码后,过渡到再过5天12小时:

period = list(  c(24,24,5), c(24,12,5) )
alpha = list(   c(0,5),     c(0,5)  )
s_samples = 100
A=50
O=50
simulatedData = data.frame(t=numeric(), v=numeric()) #initialise the output
daySteps = c(0, cumsum(unlist(period)[seq(3,length(unlist(period)), by=3)])) #set up the period starts and ends to set over, starting at 0
##Cycle over each of the items in the list
for(set in seq(period) ){
  t_points = s_samples*period[[set]][3]
  t = seq(daySteps[set], daySteps[set+1], length.out=t_points) #make the time
  slope = (24/period[[set]][2]-24/period[[set]][1])/(max(t)-min(t)) # get the slope
  f0 = 24/period[[set]][1] - slope*(min(t)) # find the freq when t0
  c = (24/period[[set]][2]-f0)/(max(t)) #calculate the chirp see https://en.wikipedia.org/wiki/Chirp and https://dsp.stackexchange.com/questions/57904/chirp-after-t-seconds
  wt = ((c*(t^2))/2) + f0*(t) # calc the freq 
  a = alpha[[set]][1]
  v = A * cos(2*pi*wt - a) + O
  simulatedData = rbind(simulatedData, data.frame(t, v) )
}
plot(simulatedData, type="l", lwd=2)
t = seq(0,sum(unlist(period)[seq(3,length(unlist(period)), by=3)]), by=1/24)
points(t, A*cos(2*pi*t)+O, col=3, type="l", lty=2)
points(t, A*cos(2*(24/12)*pi*t)+O, col=4, type="l", lty=2)

黑色=模拟  蓝色= 12小时周期; 绿色= 24小时

正如预期的那样,前24天是完美的,而后5天的最后一部分与周期为12小时的周期匹配,但是该时段的前半部分看起来相差180度。怎么了?

艾伦·卡梅伦

I think you're making this a lot more complex than it needs to be. Remember that many R functions are already vectorized. The following function will produce a linear chirp between frequencies f0 and f1 between t0 and t1, with an optional phi parameter to specify at what point on the cycle you want your sequence to begin:

chirp <- function(f0, f1, t0, t1, phi = 0, n_steps = 1000)
{
  C <- (f1 - f0)/(t1 - t0)
  x <- seq(t0, t1, length.out = n_steps)
  y <- sin(2 * pi * (C / 2 * (x - t0)^2 + f0 * (x - t0)) + phi) # Ref Wikipedia
  data.frame(x, y)
}

Of course, it can also produce the static first half of your plot by "chirping" between two identical frequencies, so we can get a data frame of x, y points on the plot by doing

df <- rbind(chirp(1, 1, 0, 5), chirp(1, 2, 5, 10))

Which results in:

plot(df$x, df$y, type = "l")

在此处输入图片说明

Note that between 5 and 10 days there are 7.5 cycles, so if you wanted to smoothly continue frequency 2, you would need to set the phi parameter to a half cycle (i.e. to pi):

df <- rbind(df, chirp(2, 2, 10, 15, phi = pi))

plot(df$x, df$y, type = "l")

在此处输入图片说明

请注意,如果线性调频脉冲发生在原始信号的偶数周期内,则线性调频脉冲信号和2 Hz信号的相位仅在n秒后匹配。对于奇数,相位将相差180度。这是线性chi的数学结果。要看到这一点,让我们使用函数在6秒内鸣叫,以便相位在10秒时匹配:

plot(df$x, df$y, type = "l")
lines(df2$x, df2$y, lty = 2, col = "green")
lines(df3$x, df3$y, lty = 2, col = "blue")
lines(df$x, df$y)

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章