10

我知道可以通过将输出rnorm()视为时间序列来实现白噪声。关于如何模拟粉红噪声的任何建议?

4

2 回答 2

11

tuneR具有noise可以生成白噪声或粉红噪声的波形对象的功能:

require(tuneR)
w <- noise(kind = c("white"))
p <- noise(kind = c("pink"))
par(mfrow=c(2,1))
plot(w,main="white noise")
plot(p,main="pink noise")

编辑:我意识到上面的方法不会生成向量(doh)。将其转换为向量的残酷方法是添加以下代码:

writeWave(p,"p.wav")#writes pink noise on your hard drive
require(audio)#loads `audio` package to use `load.wave` function
p.vec <- load.wave("path/to/p.wav")#this will load pink noise as a vector

在此处输入图像描述

于 2012-01-02T10:20:05.203 回答
1

正如@mbq 所说,您可以只使用 p@left 来获取向量,而不是保存和读取 wav 文件。另一方面,您可以直接使用在 tuneR 中生成时间序列的函数:

TK95 <- function(N, alpha = 1){ 
    f <- seq(from=0, to=pi, length.out=(N/2+1))[-c(1,(N/2+1))] # Fourier frequencies
    f_ <- 1 / f^alpha # Power law
    RW <- sqrt(0.5*f_) * rnorm(N/2-1) # for the real part
    IW <- sqrt(0.5*f_) * rnorm(N/2-1) # for the imaginary part
    fR <- complex(real = c(rnorm(1), RW, rnorm(1), RW[(N/2-1):1]), 
                  imaginary = c(0, IW, 0, -IW[(N/2-1):1]), length.out=N)
     # Those complex numbers that are to be back transformed for Fourier Frequencies 0, 2pi/N, 2*2pi/N, ..., pi, ..., 2pi-1/N 
     # Choose in a way that frequencies are complex-conjugated and symmetric around pi 
     # 0 and pi do not need an imaginary part
    reihe <- fft(fR, inverse=TRUE) # go back into time domain
    return(Re(reihe)) # imaginary part is 0
}

这完美地工作:

par(mfrow=c(3,1))
replicate(3,plot(TK95(1000,1),type="l",ylab="",xlab="time"))

在此处输入图像描述

于 2019-12-19T15:02:49.903 回答