diff options
author | Suraj Yerramilli | 2015-06-08 15:56:42 +0530 |
---|---|---|
committer | Suraj Yerramilli | 2015-06-08 15:56:42 +0530 |
commit | b10ba6f6009c0cc289e24c7844b47cc7de61e0ec (patch) | |
tree | 96f3a43303e3c8d9b2498092528fd1afbf361cfa | |
parent | 1b5bae90702713531ffe70f5837a74a7471881eb (diff) | |
download | SysID-R-code-b10ba6f6009c0cc289e24c7844b47cc7de61e0ec.tar.gz SysID-R-code-b10ba6f6009c0cc289e24c7844b47cc7de61e0ec.tar.bz2 SysID-R-code-b10ba6f6009c0cc289e24c7844b47cc7de61e0ec.zip |
Added the seed parameter
-rw-r--r-- | R/sim.R | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -1,8 +1,8 @@ #' @export -sim <- function(model,input,sigma=0) UseMethod("sim") +sim <- function(model,input,sigma=0,seed=NULL) UseMethod("sim") #' @export -sim.default <- function(model,input,sigma=0){ +sim.default <- function(model,input,sigma=0,seed=NULL){ print("The sim method is not developed for the current class of the object") } @@ -30,14 +30,17 @@ sim.default <- function(model,input,sigma=0){ #' y <- sim(model,u,sigma=0.1) #' #' @export -sim.arx <- function(model,input,sigma=0){ +sim.arx <- function(model,input,sigma=0,seed=NULL){ na <- length(model$A) - 1; nk <- model$ioDelay; nb <- length(model$B) - nk; nb1 <- nb+nk n <- max(na,nb1) coef <- matrix(c(model$A[-1],model$B),nrow=na+nb1) y <- rep(0,length(input)+n) - u <- c(rep(0,n),input) + u <- c(rep(0,n),input$input[,1]) + + if(!is.null(seed)) set.seed(seed) + ek <- rnorm(length(input),sd=sigma) # padLeftZeros <- function(x) c(rep(0,n),x) # u <- apply(input,2,padLeftZeros) @@ -75,10 +78,11 @@ sim.arx <- function(model,input,sigma=0){ #' y <- sim(model,u,sigma=0.1) #' #' @export -sim.idpoly <- function(model,input,sigma=1){ +sim.idpoly <- function(model,input,sigma=0,seed=NULL){ require(signal);require(polynom) n <- length(input)[1] + if(!is.null(seed)) set.seed(seed) ek <- rnorm(n,sd=sigma) den1 <- as.numeric(polynomial(model$A)*polynomial(model$D)) filt1 <- Arma(b=model$C,a=den1) |