summaryrefslogtreecommitdiff
path: root/R/rgs.R
blob: 117717735749208375021c0b56de6c0567067dbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
idin.rgs <- function(n,band,var){
  # Function to generate a random Gaussian 
  # signal of given frequency band and variance
  require(signal)
  uk1 <- rnorm(n,mean = 0,sd = 1)
 
  for(i in 1:n){
    #Checking for zeros
    
    if(uk1[i] == 0){
      uk1[i] <- rnorm(1,mean = 0,sd = 1)
    }
  }
  # Getting the filter coefficients
  bfilt <- butter(8,c(band[1],band[2]),type = "pass",plane = "z")
 
  # Filtering the signal
  ukf <- filter(bfilt,uk1)
  
  # Adjusting for required variance
  uk <- sqrt(var)*ukf
  return(uk)
}