summaryrefslogtreecommitdiff
path: root/R/rbs.R
blob: 98fa7856689f6c8427a24084e1671912ea302f6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#' @export
idin.rbs <- function(n,band,levels){
  # Function to generate a random binary 
  # signal of given frequency band and levels
  require(signal)
  uk1 = rnorm(n,mean = 0,sd = 1)
  uk = rep(0,n)
  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)
  
  # Getting the binary signal
  for(i in 1:n){
  if(ukf[i] < 0){
    uk[i] = levels[1]
  }
  }
  for(i in 1:n){
    if(ukf[i] > 0){
      uk[i] = levels[2]
    }
  }
  return(uk)
}