summaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/idinput.R33
-rw-r--r--R/rbs.R34
-rw-r--r--R/rgs.R24
3 files changed, 33 insertions, 58 deletions
diff --git a/R/idinput.R b/R/idinput.R
new file mode 100644
index 0000000..5251163
--- /dev/null
+++ b/R/idinput.R
@@ -0,0 +1,33 @@
+#' @export
+idinput<-function(n,type='rgs',band=c(0,1),levels=c(-1,1)){
+ if(type=="rbs"){
+ v1<-gen.rbs(n,band,levels)
+ }
+ else if(type=="rgs"){
+ v1<-gen.rgs(n,band,levels)
+ }
+ return(v1)
+}
+
+gen.rgs<-function(n,band,levels){
+ require(signal)
+ mu<-(levels[1]+levels[2])/2
+ sigma<-(levels[2]-levels[1])/2
+ v<-rnorm(n,mu,sigma)
+ v<-sapply(v, function(x) {if(x==0) rnorm(1) else x})
+ gfilt<-butter(8,band,type ='pass',plane ='z')
+ v1<-filter(gfilt,v)
+ return(v1)
+}
+
+gen.rbs<-function(n,band,levels){
+ require(signal)
+ v<-rnorm(n)
+
+ v<-sapply(v, function(x) {if(x==0) rnorm(1) else x}, simplify = 'vector')
+ #if we do not specify else case, it assigns it as NULL
+ bfilt<-butter(8,band,type = 'pass',plane = 'z')
+ v1<-filter(bfilt,v)
+ v1<-sapply(v1, function(x) {if(x>0) levels[2] else levels[1]})
+ return(v1)
+} \ No newline at end of file
diff --git a/R/rbs.R b/R/rbs.R
deleted file mode 100644
index 98fa785..0000000
--- a/R/rbs.R
+++ /dev/null
@@ -1,34 +0,0 @@
-#' @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)
-}
-
diff --git a/R/rgs.R b/R/rgs.R
deleted file mode 100644
index ee1eca3..0000000
--- a/R/rgs.R
+++ /dev/null
@@ -1,24 +0,0 @@
-#' @export
-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)
-} \ No newline at end of file