Newer
Older
## randomize the phases of a real signal, for non-linear time series analysis
phase_randomize <- function (x)
{
N <- length(x)
X <- fft(x)
k <- seq(2,floor(N/2)+1)
X[k] <- Mod(X[k])*exp(2*pi*1i*runif(length(k)))
X[N-k+2] <- Conj(X[k])
if (N == 2*floor(N/2)) {k <- N/2+1
X[k] <- Mod(X[k])}
y <- fft(X,inverse=TRUE)
Re(y)/N
}