summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorashwinrcs2015-10-12 16:00:12 +0530
committerashwinrcs2015-10-12 16:00:12 +0530
commitb7bda69b96ebb0273fa5514121880959ae926366 (patch)
treeb3dabbeab55dda22bb3c017a6290889fc8b9dae2
parent69813446dfe77003c88773da6bc397a1658229e1 (diff)
downloadSysID-R-code-b7bda69b96ebb0273fa5514121880959ae926366.tar.gz
SysID-R-code-b7bda69b96ebb0273fa5514121880959ae926366.tar.bz2
SysID-R-code-b7bda69b96ebb0273fa5514121880959ae926366.zip
Function idinput including rgs and rbs codes
-rw-r--r--R/idinput.R33
1 files changed, 33 insertions, 0 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