summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuraj Yerramilli2016-02-22 23:44:44 +0530
committerSuraj Yerramilli2016-02-22 23:44:44 +0530
commit51308947043af27965a369736bd65d673451a9b3 (patch)
treecdba2928ed3fd801d62b2eafd89505079e201768
parent31ac65cd1d832bb5e56a3e5acf530c5c9e6ec9cb (diff)
downloadSysID-R-code-51308947043af27965a369736bd65d673451a9b3.tar.gz
SysID-R-code-51308947043af27965a369736bd65d673451a9b3.tar.bz2
SysID-R-code-51308947043af27965a369736bd65d673451a9b3.zip
added support for multivariate frequency response objects
-rw-r--r--NAMESPACE2
-rw-r--r--R/idframe.R39
-rw-r--r--man/plot.idfrd.Rd2
3 files changed, 24 insertions, 19 deletions
diff --git a/NAMESPACE b/NAMESPACE
index 2e8d793..2171461 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -29,6 +29,7 @@ S3method(summary,idframe)
S3method(time,idframe)
export("inputNames<-")
export("outputNames<-")
+export()
export(armax)
export(arx)
export(bj)
@@ -66,5 +67,6 @@ export(step)
import(ggplot2)
import(polynom)
import(reshape2)
+import(signal)
import(tframe)
importFrom(zoo,na.approx)
diff --git a/R/idframe.R b/R/idframe.R
index 2313bff..cd48958 100644
--- a/R/idframe.R
+++ b/R/idframe.R
@@ -135,11 +135,6 @@ deltat.idframe <- function(data){
#'
#' @export
idfrd <- function(response,freq,Ts){
- response <- ifelse(is.vector(response),
- array(response,c(0,0,length(response))),
- ifelse(nrow(response)==1,
- array(response,c(0,0,nrow(response))),
- response))
out <- list(response=response,freq=freq,Ts=Ts)
class(out) <- "idfrd"
return(out)
@@ -159,23 +154,31 @@ idfrd <- function(response,freq,Ts){
#' frf <- spa(data) # Estimates the frequency response from data
#' plot(frf)
#'
-#' @import ggplot2 reshape2
+#' @import ggplot2 reshape2 signal
#'
#' @export
-plot.idfrd <- function(x){
-
- mag <- 20*log10(Mod(x$resp[1,1,]))
- phase <- 180/pi*signal::unwrap(Arg(x$resp[1,1,]))
- sys_df <- data.frame(Frequency = x$freq,Gain = mag,Phase = phase)
- melted_sys_df <- reshape2::melt(sys_df, id.var = c("Frequency"))
+plot.idfrd <- function(x,col="steelblue",lwd=1){
+ nfreq <- dim(x$freq)[1]
+ mag <- 20*log10(Mod(x$resp))
+ nout <- dim(mag)[1]; nin <- dim(mag)[2]
+ dim(mag) <- c(nin*nout,nfreq)
+ phase <-180/pi*apply((Arg(x$resp)),3,signal::unwrap)
- bode <- ggplot(sys_df, aes(x = Frequency)) +
- geom_line(colour="steelblue") + scale_x_log10() + theme_bw() +
- geom_vline(xintercept=max(x$freq),size=1.2)
- bode_gain <- bode + aes(y = Gain)
- bode_phase <- bode + aes(y = Phase)
+ g <- vector("list",nin*nout)
+
+ for(i in 1:length(g)){
+ df <- data.frame(Frequency=x$freq[,],Magnitude=mag[i,],
+ Phase = phase[i,])
+ melt_df <- reshape2::melt(df,id.var="Frequency")
+ g[[i]] <- ggplot(melt_df, aes(Frequency, value)) +
+ geom_line(size=lwd,color=col) + scale_x_log10() +
+ facet_grid(variable ~ .,scale="free") +
+ theme_bw(14,"sans") + ylab("") +
+ theme(axis.title.x=element_text(size=11)) +
+ geom_vline(xintercept=max(x$freq),size=1.2)
+ }
- multiplot(bode_gain,bode_phase)
+ multiplot(plotlist=g,cols=nin)
}
# Multiple plot function
diff --git a/man/plot.idfrd.Rd b/man/plot.idfrd.Rd
index b2459f4..541c2eb 100644
--- a/man/plot.idfrd.Rd
+++ b/man/plot.idfrd.Rd
@@ -4,7 +4,7 @@
\alias{plot.idfrd}
\title{Plotting idfrd objects}
\usage{
-\method{plot}{idfrd}(x)
+\method{plot}{idfrd}(x, col = "steelblue", lwd = 1)
}
\arguments{
\item{x}{An object of class \code{idframe}}