# Bodegraph - Plotting higher order transfer function

I need help plotting a higher order transfer function using the package bodegraph. The transfer function is mind is the following: Seing as bodegraph has no way of inputting a higher order than 2 transfer function, i tried decomposing the transfer function by partial fraction expansion and came out with the following residuals: By having a series of 1st order functions i should be able to use the following bodegraph function to achieve the desired bodeplot: After normalizing my functions i get the following residuals By utilizing these i have the following input to BodeAmp function: \POAmp{K}{tau}

\BodeAmp[bode lines, red, name path=Gomagnitude]{-4:4}
{\POAmp{0.0000002562225476}{0.0003660322108}
+\POAmp{0.001246189024}{0.007621951220}
-\POAmp{0.07907822923}{0.06064281383}
+\POAmp{0.04071061644}{0.08561643836}
+ \POAmp{0.1185515519}{0.1783803068}
}


This however should produce the following output from matlab, but i dosent. Im quite certain it either has to do with the pole in the right hand plane being input incorrectly to the POAmp function, (it didnt work setting both the gain and time constant negative to keep the input format), or the fact that i cant cascade the first order transfer functions like that using the residuals.

The full code is as following, which is a MWE that only plots the magnitude spectrum of the transfer function:

\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations, positioning, intersections, calc}%
\usepackage{amsmath,amssymb}
\usepackage{bodegraph}

\begin{document}

% Define the layers to draw the diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{tikzpicture}[>=latex',
ref lines/.style={thin, black!60},
ref points/.style={circle, black, opacity=0.7, fill, minimum size= 3pt, inner sep=0},
every node/.style={font=\small},
bode lines/.style={very thick, blue},
Gclabel/.style={text=blue},
xscale=12/12,
gnuplot def/.style={samples=100,id=\arabic{idGnuplot},prefix=gnuplot/\jobname },
semilog lines/.style={thin, black!60},
semilog lines 2/.style={thin, black!20, dashed},
semilog half lines/.style={semilog lines 2, dashed },
Black lines/.style={very thick, blue},
Black grid/.style={ultra thin,brown},
Black abaque mag/.style={gray,ultra thin,dashed,smooth},
Black abaque phase/.style={gray,ultra thin,smooth},
Black label points/.style={font=\tiny},
Black label axes/.style={Black grid, font=\tiny},
Nyquist lines/.style={very thick, blue},
Nyquist grid/.style={ultra thin,brown},
Nyquist label axes/.style={Nyquist grid,font=\tiny},
Nyquist label points/.style={font=\tiny},
Temp lines/.style={very thick, blue},
Temp grid/.style={ultra thin,brown},
Temp label axes/.style={Temp grid, font=\tiny},
Temp label points/.style={font=\tiny},
Abaque grid/.style={ultra thin,brown!80},
Abaque lines/.style={thick, blue,smooth}
]

\begin{scope}[yscale=4/110]
\UnitedB
\semilog{-5}{5}{-150}{-50}

% Bode plot (magnitude) for the original system, 4/(s/(1+2s)).
% Asymptotic line
%\BodeAmp[ref lines, red!60]{-5:5}{\SOAmpAsymp{59.37351685}{1.538057009}{45.90206967}}
% Bode plot
\BodeAmp[bode lines, red, name path=Gomagnitude]{-4:4}{
+\POAmp{0.0000002562225476}{0.0003660322108}
+\POAmp{0.001246189024}{0.007621951220}
-\POAmp{0.07907822923}{0.06064281383}
+\POAmp{0.04071061644}{0.08561643836}
+ \POAmp{0.1185515519}{0.1783803068}
}

\end{scope}

\end{tikzpicture}

\end{document}


And produces the following output: • I've come to the conclusion that the way the command is written the + sign for adding another \POAmp will infact multiply the two rather than adding and thus i need another way of parsing the transfer function. Perhaps the author @rpapa would know a way? Apr 7, 2016 at 16:57
• anyone? :) Help would be appriciated Apr 10, 2016 at 11:45

you must not make a single factor decomposition (parfrac) but a factorization of the numerator and denominator then normalize all functions of the first order denominator are programmed with \ POamp {K} {tau} those of the denominator - \ POAmp {K} {tau} If root is specified \ POAMP {K} {-} tau

and with bodegraph and the code

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations, positioning, intersections, calc}%
\usepackage{amsmath,amssymb}
\usepackage{bodegraph}

%\usepackage{align}

\begin{document}

\begin{enumerate}
\item factor the transfert function
\begin{align*}
H\left(s\right)&=\dfrac{7682 s^2+7.682 10^6 s+5364}
{s^5+2874 s^4+3.882 10^5 s^3+3.257 10^6 s^2- 6.249 10^7 s-3.871 10^8}\\
H\left(s\right)&= \dfrac{ 7682. \left(s + 999.9993017\right) \left(s + 0.0006982561501\right)}{\left(s + 2732.364566\right) \left(s
+ 131.2257472\right) \left(s + 16.48597565\right) \left(s + 5.605736444\right) \left(s - 11.68202532\right)}
\end{align*}
\item Normalize
\begin{align*}
H\left(s\right)&=\dfrac{7682\cdot 5364}{-3.871 10^8} \dfrac{ \left(1+\dfrac{s}{1000} \right) \left(1+\dfrac{s}{0.000698} \right)}
{ \left(1+\dfrac{s}{2732.36} \right) \left(1+\dfrac{s}{131.225} \right) \left(1+\dfrac{s}{16.485}\right) \left(1+\dfrac{s}{ 5.60}\right) \left(1-\dfrac{s}{11.68}\right)}\\
H\left(s\right)&=-0.106 \dfrac{ \left(1+0.001\cdot s \right) \left(1+1432.2\cdot s \right)}
{ \left(1+0.000365\cdot s \right) \left(1+0.0076\cdot s \right) \left(1+0.060\cdot s\right) \left(1+0.178\cdot s\right) \left(1-0.0856\cdot s\right)}
\end{align*}
\end{enumerate}

% Define the layers to draw the diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{tikzpicture}[>=latex',
ref lines/.style={thin, black!60},
ref points/.style={circle, black, opacity=0.7, fill, minimum size= 3pt, inner sep=0},
every node/.style={font=\small},
bode lines/.style={very thick, blue},
Gclabel/.style={text=blue},
xscale=12/12,
gnuplot def/.style={samples=100,id=\arabic{idGnuplot},prefix=gnuplot/\jobname },
semilog lines/.style={thin, black!60},
semilog lines 2/.style={thin, black!20, dashed},
semilog half lines/.style={semilog lines 2, dashed },
Black lines/.style={very thick, blue},
Black grid/.style={ultra thin,brown},
Black abaque mag/.style={gray,ultra thin,dashed,smooth},
Black abaque phase/.style={gray,ultra thin,smooth},
Black label points/.style={font=\tiny},
Black label axes/.style={Black grid, font=\tiny},
Nyquist lines/.style={very thick, blue},
Nyquist grid/.style={ultra thin,brown},
Nyquist label axes/.style={Nyquist grid,font=\tiny},
Nyquist label points/.style={font=\tiny},
Temp lines/.style={very thick, blue},
Temp grid/.style={ultra thin,brown},
Temp label axes/.style={Temp grid, font=\tiny},
Temp label points/.style={font=\tiny},
Abaque grid/.style={ultra thin,brown!80},
Abaque lines/.style={thick, blue,smooth}
]

\begin{scope}[yscale=4/110]
\UnitedB
\semilog{-5}{6}{-150}{50}

% Bode plot (magnitude) for the original system, 4/(s/(1+2s)).
% Asymptotic line
%\BodeAmp[ref lines, red!60]{-5:5}{\SOAmpAsymp{59.37351685}{1.538057009}{45.90206967}}
% Bode plot
\BodeAmp[bode lines, red, name path=Gomagnitude]{-5:5}{
-\POAmp{1}{0.001}
-\POAmp{1}{1432.2}
+\POAmp{-0.106}{0.000365}
+\POAmp{1}{0.0076}
+ \POAmp{1}{0.06}
+ \POAmp{1}{0.178}
+ \POAmp{1}{-0.0856}
}

\end{scope}
\begin{scope}[yshift=-10cm,yscale=4/110]

\semilog{-5}{6}{-90}{90}

% Bode plot (magnitude) for the original system, 4/(s/(1+2s)).
% Asymptotic line
%\BodeAmp[ref lines, red!60]{-5:5}{\SOAmpAsymp{59.37351685}{1.538057009}{45.90206967}}
% Bode plot
\BodeArg[bode lines, red, name path=Gomagnitude]{-5:6}{
-\POArg{1}{0.001}
-\POArg{1}{1432.2}
+\POArg{-0.106}{0.000365}
+\POArg{1}{0.0076}
+ \POArg{1}{0.06}
+ \POArg{1}{0.178}
+ \POArg{1}{-0.0856}
}

\end{scope}

\end{tikzpicture}

\end{document}


The plot is not the same as matlab for phase because matlab must reply in the field modulo 180)

• Really good answer! Thanks alot, that's what i needed! however i still have some concerns: I need to resemblance that of the matlab plot, your magnitude spectrum is not corresponding entirely to the matlab one in terms of dampening. Is there a way to offset the phase to match the matlab response? Apr 10, 2016 at 15:46
• add -180° in phase plot Apr 10, 2016 at 19:39
• Adding the phase works. The magnitude plot however is wrong, quite certain it has to do with the gain, any ideas? Apr 10, 2016 at 22:05
• I may have made mistakes in typing the transfer function checks the values and try with another software Apr 11, 2016 at 6:59
• I tried but i get the same factorisation as you, however the gain is the issue. Are you sure that (7682*5364)/(-3.871E8) is the correct gain? Apr 11, 2016 at 10:09