summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuraj Yerramilli2016-02-09 17:37:13 +0530
committerSuraj Yerramilli2016-02-09 17:37:13 +0530
commite44e1cb2c9059813a0dcc9d8708b43b2f25a62e6 (patch)
treea42fe657205e003213fbbf7fadc63a808952c235
parent265e592671ca87f59daa6e98299dcdf508508f7c (diff)
downloadSysID-R-code-e44e1cb2c9059813a0dcc9d8708b43b2f25a62e6.tar.gz
SysID-R-code-e44e1cb2c9059813a0dcc9d8708b43b2f25a62e6.tar.bz2
SysID-R-code-e44e1cb2c9059813a0dcc9d8708b43b2f25a62e6.zip
added multisine
-rw-r--r--R/idinput.R31
1 files changed, 29 insertions, 2 deletions
diff --git a/R/idinput.R b/R/idinput.R
index 0f279c0..c9831b0 100644
--- a/R/idinput.R
+++ b/R/idinput.R
@@ -26,9 +26,10 @@
idinput<-function(n,type='rgs',band=c(0,1),levels=c(-1,1)){
if(type=="rbs"){
rbs(n,band,levels)
- }
- else if(type=="rgs"){
+ } else if(type=="rgs"){
rgs(n,band,levels)
+ } else if(type=="sine"){
+ multisine(n,1,band,levels)
}
}
@@ -44,6 +45,32 @@ rbs <- function(n,band,levels){
sapply(u,function(x) if(x>0) levels[2] else levels[1])
}
+multisine <- function(N,nin=1,band,levels){
+ sinedata <- list(nSin=10,nTrial=10,gridSkip=1)
+ freq <- 2*pi*seq(1,floor(N/2),by=sinedata$gridSkip)/N
+ band <- band*pi
+ freq <- freq[freq>=band[1] & freq<=band[2]]
+ nl <- length(freq)
+ freqInd <- seq(from=1,to=nl,length.out = nin*sinedata$nSin)
+
+ # Begin Trials
+ trials <- function(x){
+ freqs <- freq[freqInd[seq(from=x,to=nin*sinedata$nSin,by=nin)]]
+ for(k in 1:sinedata$nTrial){
+ utrial <- rowSums(cos(sapply(freqs,
+ function(x) (1:N-1)*x+2*pi*rnorm(1))))
+ if(k==1) u <- utrial; temp <- diff(range(utrial))
+ if(diff(range(utrial))< temp) {
+ u <- utrial; temp <- diff(range(utrial))
+ }
+ }
+ clevel <- max(abs(u))
+ diff(levels)/2/clevel*(u+clevel)+levels[1]
+ }
+ u <- sapply(1:nin,trials)
+ return(u)
+}
+
butter_filt <- function(x,band){
filt <- T; type <- "pass"
if(band[1]<=2e-3){