diff options
Diffstat (limited to 'R')
-rw-r--r-- | R/idinput.R | 33 | ||||
-rw-r--r-- | R/myCode/idinput.R | 9 | ||||
-rw-r--r-- | R/rbs1.R | 22 | ||||
-rw-r--r-- | R/test/test.R | 7 |
4 files changed, 62 insertions, 9 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/myCode/idinput.R b/R/myCode/idinput.R deleted file mode 100644 index 05472e1..0000000 --- a/R/myCode/idinput.R +++ /dev/null @@ -1,9 +0,0 @@ -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) -}
\ No newline at end of file diff --git a/R/rbs1.R b/R/rbs1.R new file mode 100644 index 0000000..033f6a3 --- /dev/null +++ b/R/rbs1.R @@ -0,0 +1,22 @@ +gen.rbs<-function(n,band,type){ + require(signal) + v<-rnorm(n) + for(i in 1:n){ + if (v[i]==0){ + + v[i]=rnorm(1) + } + } + a<-butter(8,band,type = type,plane = 'z') + v1=filter(a,v) + for(i in 1:n){ + + if(v1[i]>0){ + v1[i]=1 + } + if(v1[i]<0){ + v1[i]=-1 + } + } + return(v1) +}
\ No newline at end of file diff --git a/R/test/test.R b/R/test/test.R new file mode 100644 index 0000000..8a710dd --- /dev/null +++ b/R/test/test.R @@ -0,0 +1,7 @@ +m<-idpoly(A=c(1,-1.5,0.7),B=c(1,0.5),ioDelay=1) +u<-rnorm(1000) +y<-sim(m,u,sigma=0.1) +z<-idframe(y,u) +outputNames(z)<-"y" +inputNames(z)<-"u" +plot(z)
\ No newline at end of file |