blob: 350f4bd1616da0863481f36ad24736e4f3575ac4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#' S3 class for transfer functions
#'
#' \code{tf} is an S3 class for defining transfer functions.
#'
#' @param num coefficients of the numerator plynomial in q^{-1}
#' @param den coefficients of the denominator plynomial in q^{-1}
#' @param Ts sampling time
#'
#' @return an object of class tf
#' @export
tf <- function(num=c(1),den=c(1),Ts=1){
out <- list(num=num,den=den,Ts=Ts)
class(out) <- "tf"
return(out)
}
#' Display the Transfer Function
#'
#' Printing method for objects inheriting from class \code{tf}
#'
#' @param G an object of class \code{tf}
#' @export
print.tf <- function(G){
cat("Transfer Function \nG(q^{-1}) = B(q^{-1})/A(q^{-1}) \n\n")
cat("A(q^{-1}) = ")
for(i in seq_along(G$den)){
if(i-1==0){
cat(G$den[i])
} else{
if(G$den[i]>0)
cat("+")
cat(G$den[i],"q^{-",i-1,"}",sep="")
}
cat("\t")
}
cat("\n")
cat("B(q^{-1}) = ")
for(i in seq_along(G$num)){
if(i-1==0){
cat(G$num[i])
} else{
if(G$num[i]>0)
cat("+")
cat(G$num[i],"q^{-",i-1,"}",sep="")
}
cat("\t")
}
}
|