texlive[60899] Master: bodeplot (30oct21)

commits+karl at tug.org commits+karl at tug.org
Sat Oct 30 21:39:33 CEST 2021


Revision: 60899
          http://tug.org/svn/texlive?view=revision&revision=60899
Author:   karl
Date:     2021-10-30 21:39:33 +0200 (Sat, 30 Oct 2021)
Log Message:
-----------
bodeplot (30oct21)

Modified Paths:
--------------
    trunk/Master/tlpkg/bin/tlpkg-ctan-check
    trunk/Master/tlpkg/tlpsrc/collection-mathscience.tlpsrc

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/bodeplot/
    trunk/Master/texmf-dist/doc/latex/bodeplot/README.md
    trunk/Master/texmf-dist/doc/latex/bodeplot/bodeplot.pdf
    trunk/Master/texmf-dist/source/latex/bodeplot/
    trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.dtx
    trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.ins
    trunk/Master/texmf-dist/tex/latex/bodeplot/
    trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty
    trunk/Master/tlpkg/tlpsrc/bodeplot.tlpsrc

Added: trunk/Master/texmf-dist/doc/latex/bodeplot/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/bodeplot/README.md	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/bodeplot/README.md	2021-10-30 19:39:33 UTC (rev 60899)
@@ -0,0 +1,43 @@
+# bodeplot
+LaTeX package to plot Bode, Nichols, and Nyquist diagrams.
+
+Inspired by the `bodegraph` package.
+
+Limitation: Phase plots from TF commands are wrapped between 0 and 360 degrees.
+
+Added functionality:
+ - New `\BodeZPK` and `\BodeTF` commands to generate Bode plots of any transfer function given either poles, zeros, gain, and delay, or numerator and denominator coefficients and delay
+ - Support for unstable poles and zeros.
+ - Support for complex poles and zeros.
+ - Support for general stable and unstable second order transfer functions.
+ - Support for both `gnuplot` (default) and `pgfplots` (package option `pgf`).
+ - Support for linear and asymptotic approximation of magnitude and phase plots of any transfer function given poles, zeros, and gain.
+
+Main Bode/Nyquist/Nichols commands:
+Given Zeros, Poles, Gain, and Delay (Bode plots support asymptotic and linear approximation for systems without delays):
+ - `\BodeZPK[object1/type1/{options1},object2/type2/{options2},...]{z/{zeros},p/{poles},k/gain,d/delay}{min-frequency}{max-frequency}`
+ - `\NicholsZPK[plot/{options},axes/{options}]{z/{zeros},p/{poles},k/gain,d/delay}{min-frequency}{max-frequency}`
+ - `\NyquistZPK[plot/{options},axes/{options}]{z/{zeros},p/{poles},k/gain,d/delay}{min-frequency}{max-frequency}`
+
+Given Numerator and denominator coefficients and delay (does not support approximation yet):
+ - `\BodeTF[object1/type1/{options1},object2/type2/{options2},...]{num/{coeff},den/{coeff},d/delay}{min-frequency}{max-frequency}`
+ - `\NicholsTF[plot/{options},axes/{options}]{num/{coeff},den/{coeff},d/delay}`
+ - `\NyquistTF[plot/{options},axes/{options}]{num/{coeff},den/{coeff},d/delay}`
+ 
+Other new environments and associated commands:
+ - `BodePlot` environment
+    - `\addBodeZPKPlots[{approximation1/{plot-options1}},{approximation2/{plot-options2}},...]{plot-type (phase or magnitude)}{z/{zeros},p/{poles},k/gain,d/delay}`
+    - `\addBodeTFPlot[plot-options]{plot-type (phase or magnitude)}{num/{coeff},den/{coeff},d/delay}`
+    - `\addBodeComponentPlot[plot-options]{basic_component_plot_command}`
+      - Basic component plot commands: ***(append `Lin` to get linear approximation and `Asymp` to get asymptotic approximation)*** ***(change `Pole` to `Zero` to get inverse plots)*** ***(change `Mag` to `Ph` to get phase plots)***
+      - `\MagK{a}` - Pure gain, G(s) = a.
+      - `\MagPole{a}{b}` - Single pole at s = a+bi, G(s) = 1/(s - a-bi).
+      - `\MagCSPoles{z}{w}` - Cannonical Second order system, G(s) = 1/(s^2 + 2zws + w^2).
+      - `\MagSOPoles{a}{b}` - Second Order system, G(s) = 1/(s^2 + as + b).
+      - `\MagDel{T}` - Pure delay, G(s) = exp(-Ts) (does not admit asymptotic approximation).
+ - `NicholsChart` environment
+    - `\addNicholsZPKChart[plot-options]{z/{zeros},p/{poles},k/gain,d/delay}`
+    - `\addNicholsTFChart[plot-options]{num/{coeff},den/{coeff},d/delay}`
+ - `NyquistPlot` environment
+    - `\addNyquistZPKPlot[plot-options]{z/{zeros},p/{poles},k/gain,d/delay}`
+    - `\addNyquistTFPlot[plot-options]{num/{coeff},den/{coeff},d/delay}`


Property changes on: trunk/Master/texmf-dist/doc/latex/bodeplot/README.md
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/bodeplot/bodeplot.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/latex/bodeplot/bodeplot.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/bodeplot/bodeplot.pdf	2021-10-30 19:38:46 UTC (rev 60898)
+++ trunk/Master/texmf-dist/doc/latex/bodeplot/bodeplot.pdf	2021-10-30 19:39:33 UTC (rev 60899)

Property changes on: trunk/Master/texmf-dist/doc/latex/bodeplot/bodeplot.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.dtx	                        (rev 0)
+++ trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.dtx	2021-10-30 19:39:33 UTC (rev 60899)
@@ -0,0 +1,1358 @@
+% \iffalse meta-comment
+%
+% Copyright (C) 2021 by Rushikesh Kamalapurkar <rlkamalapurkar at gmail.com>
+% -----------------------------------------------------------
+%
+% This file may be distributed and/or modified under the conditions of
+% the LaTeX Project Public License, either version 1.3c of this license
+% or (at your option) any later version. The latest version of this
+% license is in:
+%
+% http://www.latex-project.org/lppl.txt
+%
+% and version 1.3c or later is part of all distributions of LaTeX
+% version 2006/05/20 or later.
+%
+% \fi
+%
+% \iffalse
+%<package> \NeedsTeXFormat{LaTeX2e}[2006/05/20]
+%<package> \ProvidesPackage{bodeplot}
+%<package> \RequirePackage{tikz}
+%<package> \RequirePackage{pgfplots}
+%<package> \pgfplotsset{compat=1.18,variable=t}
+%<package> \usepgfplotslibrary{groupplots}
+%
+%<*driver>
+\documentclass{ltxdoc}
+\usepackage{bodeplot,cprotect,hyperref}
+\usetikzlibrary{decorations.markings,arrows.meta}
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+\begin{document}
+  \DocInput{bodeplot.dtx}
+  \PrintChanges
+  \PrintIndex
+\end{document}
+%</driver>
+% \fi
+%
+% \CheckSum{0}
+%
+% \changes{v1.0}{2021/10/25}{Initial release}
+%
+% \GetFileInfo{bodeplot.sty}
+%
+% \DoNotIndex{\newcommand,\xdef,\gdef,\def,\edef,\addplot,\approx,\arabic,\opt,\typ,\obj,\else,\if at pgfarg,\fi,\begin,\end,\feature,\footnotesize,\draw,\detokenize,\DeclareOption,\foreach,\ifdim,\ifodd,\Im,\Re,\let,\newif,\nextgroupplot,\noexpand,\expandafter,\unexpanded,\PackageError,\PackageWarning,\relax,\RequirePackage,\tikzset,\pgfmathsetmacro,\pgfmathtruncatemacro,\ProcessOptions}
+%
+% \title{The \textsf{bodeplot} package\thanks{This document
+% corresponds to \textsf{bodeplot}~\fileversion,
+% dated \filedate.}}
+% \author{Rushikesh Kamalapurkar \\ \texttt{rlkamalapurkar at gmail.com}}
+%
+% \maketitle
+%
+% \section{Introduction}
+%
+% Generate Bode, Nyquist, and Nichols plots for transfer functions in the canonical (TF) form \begin{equation}G(s) = e^{-Ts}\frac{b_ms^m+\cdots+b_1s+b_0}{a_ns^n+\cdots+a_1s+a_0}\label{eq:TF}\end{equation} and the zero-pole-gain (ZPK) form \begin{equation}G(s) = Ke^{-Ts}\frac{(s-z_1)(s-z_2)\cdots(s-z_m)}{(s-p_1)(s-p_2)\cdots(s-p_n)}.\label{eq:ZPK}\end{equation} In the equations above, $b_m,\cdots,b_0$ and $a_n,\cdots,a_0$ are real coefficients, $T\geq 0$ is the loop delay, $z_1,\cdots,z_m$ and $p_1,\cdots,p_n$ are complex zeros and poles of the transfer function, respectively, and $K\in \Re$ is the loop gain. For transfer functions in the ZPK format in (\ref{eq:ZPK}) with zero delay, this package also supports linear and asymptotic approximation of Bode plots.
+%
+% \section{Usage}
+% \subsection{Bode plots}
+% \DescribeMacro{\BodeZPK}
+% |\BodeZPK| \oarg{obj1/typ1/\marg{opt1},obj2/typ2/\marg{opt2},...}\\
+% \hspace*{2em}\marg{z/\marg{zeros},p/\marg{poles},k/\marg{gain},d/\marg{delay}}\\
+% \hspace*{2em}\marg{min-freq}\marg{max-freq}
+%
+% \noindent Plots the Bode plot of a transfer function given in ZPK format using the |groupplot| environment. The three mandatory arguments include: (1) a list of tuples, comprised of the zeros, the poles, the gain, and the transport delay of the transfer function, (2) the lower end of the frequency range for the $x-$ axis, and (3) the higher end of the frequency range for the $x-$axis. The zeros and the poles are complex numbers, entered as a comma-separated list of comma-separated lists, of the form |{{real part 1,imaginary part 1},| |{real part 2,imaginary part 2},...}|. If the imaginary part is not provided, it is assumed to be zero.
+%
+% The optional argument is comprised of a comma separated list of tuples, either |obj/typ/{opt}|, or |obj/{opt}|, or just |{opt}|. Each tuple passes options to different |pgfplots| macros that generate the group, the axes, and the plots according to:
+% \begin{itemize}
+% \item Tuples of the form |obj/typ/{opt}|:
+% \begin{itemize}
+%  \item |plot/typ/{opt}|: modify plot properties by adding options |{opt}| to the |\addplot| macro for the magnitude plot if |typ| is |mag| and the phase plot if |typ| is |ph|.
+%  \item |axes/typ/{opt}|: modify axis properties by adding options |{opt}| to the |\nextgroupplot| macro for the magnitude plot if |typ| is |mag| and the phase plot if |typ| is |ph|.
+% \end{itemize}
+% \item Tuples of the form |obj/{opt}|:
+% \begin{itemize}
+%  \item |plot/{opt}|: adds options |{opt}| to |\addplot| macros for both the magnitude and the phase plots.
+%  \item |axes/{opt}|: adds options |{opt}| to |\nextgroupplot| macros for both the magnitude and the phase plots.
+%  \item |group/{opt}|: adds options |{opt}| to the |groupplot| environment.
+%  \item |approx/linear|: plots linear approximation.
+%  \item |approx/asymptotic|: plots asymptotic approximation.
+% \end{itemize}
+% \item Tuples of the form |{opts}| add all of the supplied options to |\addplot| macros for both the magnitude and the phase plots.
+% \end{itemize}
+% The options |{opt}| can be any |key=value| options that are supported by the |pgfplots| macros they are added to. \textit{Linear or asymptotic approximation of transfer functions that include a transport delay is not supported.}
+
+% For example, given a transfer function \begin{equation}G(s) = 10\frac{s(s+0.1+0.5\mathrm{i})(s+0.1-0.5\mathrm{i})}{(s+0.5+10\mathrm{i})(s+0.5-10\mathrm{i})},\label{eq:ZPKExample}\end{equation} its Bode plot over the frequency range $[0.01,100]$ can be generated using\\
+% |\BodeZPK|\\
+% |  {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}|\\
+% |  {0.01}{100}|\\
+% which generates the plot in Figure \ref{simpleBode}. If a delay is not specified, it is assumed to be zero. If a gain is not specified, it is assumed to be 1. By default, each of the axes, excluding ticks and labels, are 5cm wide and 2.5cm high. The width and the height, along with other properties of the plots, the axes, and the group can be customized using native |pgf| keys as shown in the example below.
+%
+% \begin{figure}
+% \begin{center}
+% \BodeZPK{z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}{0.01}{100}
+% \cprotect\caption{\label{simpleBode}Output of the default |\BodeZPK| macro.}
+% \end{center}
+% \end{figure}
+%
+% A linear approximation of the Bode plot with customization of the plots, the axes, and the group can be generated using\\
+% |\BodeZPK[plot/mag/{red,thick},plot/ph/{blue,thick},|\\
+% |  axes/mag/{ytick distance=40,xmajorticks=true,|\\
+% |  xlabel={Frequency (rad/s)}},axes/ph/{ytick distance=90},|\\
+% |  group/{group style={group size=2 by 1,horizontal sep=2cm,|\\
+% |  width=4cm,height=2cm}},approx/linear]|\\
+% |  {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}|\\
+% |  {0.01}{100}|\\
+% which generates the plot in Figure \ref{customBode}.
+%
+% \begin{figure}
+% \begin{center}
+% \BodeZPK[plot/mag/{red,thick},plot/ph/{blue,thick},axes/mag/{ytick distance=40,xmajorticks=true,xlabel={Frequency (rad/s)}},axes/ph/{ytick distance=90},approx/linear,group/{group style={group size = 2 by 1,horizontal sep=2cm},width=4cm,height=2cm},] {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},g/10} {0.01} {100}
+% \cprotect\caption{\label{customBode}Customization of the default |\BodeZPK| macro.}
+% \end{center}
+% \end{figure}
+%
+% \DescribeMacro{\BodeTF}
+% |\BodeTF| \oarg{obj1/typ1/\marg{opt1},obj2/typ2/\marg{opt2},...}\\
+% \hspace*{2em}\marg{num/\marg{coeffs},den/\marg{coeffs},d/\marg{delay}}\\
+% \hspace*{2em}\marg{min-freq}\marg{max-freq} \rmfamily
+%
+% \noindent Plots the Bode plot of a transfer function given in TF format. The three mandatory arguments include: (1) a list of tuples comprised of the coefficients in the numerator and the denominator of the transfer function and the transport delay, (2) the lower end of the frequency range for the $x-$ axis, and (3) the higher end of the frequency range for the $x-$axis. The coefficients are entered as a comma-separated list, in order from the highest degree of $s$ to the lowest, with zeros for missing degrees. The optional arguments are the same as |\BodeZPK|, except that linear/asymptotic approximation is not supported, so |approx/...| is ignored.
+%
+% For example, given the same transfer function as (\ref{eq:ZPKExample}) in TF form and with a small transport delay, \begin{equation}G(s) = e^{-0.01s}\frac{s(10s^2+2s+2.6)}{(s^2+s+100.25)},\label{eq:TFExample}\end{equation} its Bode plot over the frequency range $[0.01,100]$ can be generated using\\
+% |\BodeTF[blue,thick]|\\
+% |  {num/{10,2,2.6,0},den/{1,0.2,100},d/0.01}|\\
+% |  {0.01}{100}|\\
+% which generates the plot in Figure \ref{simpleBodeTF}. Note the $0$ added to the numerator coefficients to account for the fact that the numerator does not have a constant term in it. As demonstrated in this example, if a single comma-separated list of options is passed, it applies to both the magnitude and the phase plots.
+%
+% \begin{figure}
+% \begin{center}
+% \BodeTF[blue,thick]{num/{10,2,2.6,0},den/{1,1,100.25},d/0.01}{0.01}{100}
+% \cprotect\caption{\label{simpleBodeTF}Output of the |\BodeTF| macro.}
+% \end{center}
+% \end{figure}
+%
+% \DescribeEnv{BodePlot}
+% |\begin{BodePlot}|\oarg{axis-options}\marg{min-frequency}\marg{max-frequency}\\
+% \hspace*{2em}|\addBode...|\\
+% \hspace*{1.5em}|\end{BodePlot}|\\
+% The |BodePlot| environment works in conjunction with the parametric function generator macros |\addBodeZPKPlots|, |\addBodeTFPlot|, and |\addBodeComponentPlots|. If supplied, |axis-options| are passed directly to the |semilogaxis| environment and the frequency limits are translated to the x-axis limits and the domain of the |semilogaxis| environment. Example usage in the description of |\addBodeZPKPlots|, |\addBodeTFPlot|, and |\addBodeComponentPlots|.
+%
+% \DescribeMacro{\addBodeZPKPlots}
+% |\addBodeZPKPlots| \oarg{approx1/\marg{opt1},approx2/\marg{opt2},...}\\
+% \hspace*{2em}\marg{plot-type}\\
+% \hspace*{2em}\marg{z/\marg{zeros},p/\marg{poles},k/\marg{gain},d/\marg{delay}}
+%
+% \noindent Generates the appropriate parametric functions and supplies them to multiple |\addplot| macros, one for each |approx/{opt}| pair in the optional argument. If no optional argument is supplied, then a single |\addplot| command corresponding to the true Bode plot is generated. This macro can be used inside any |semilogaxis| environment as long as a domain for the x-axis is supplied through either the |approx/{opt}| interface or directly in the optional argument of the |semilogaxis| environment. Use with the |BodePlot| environment supplied with this package is recommended. The second mandatory argument, |plot-type| is either magnitude or |phase|. If it is not equal to |phase|, it is assumed to be |magnitude|. The last mandatory argument is the same as |\BodeZPK|.
+%
+% For example, given the transfer function in (\ref{eq:ZPKExample}), its linear, asymptotic, and true Bode plots can be superimposed using
+%\begin{verbatim}
+%\begin{BodePlot}[ ylabel={Gain (dB)}, ytick distance=40,
+%  height=2cm, width=4cm] {0.01} {100}
+%  \addBodeZPKPlots[
+%    true/{black,thick},
+%    linear/{red,dashed,thick},
+%    asymptotic/{blue,dotted,thick}]
+%    {magnitude}
+%    {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.1,-10},{-0.1,10}},k/10}
+%\end{BodePlot}
+%
+%\begin{BodePlot}[ylabel={Phase ($^{\circ}$)},
+%  height=2cm, width=4cm, ytick distance=90,] {0.01} {100}
+%  \addBodeZPKPlots[
+%    true/{black,thick},
+%    linear/{red,dashed,thick},
+%    asymptotic/{blue,dotted,thick}]
+%    {phase}
+%    {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.1,-10},{-0.1,10}},k/10}
+%\end{BodePlot}
+%\end{verbatim}
+% \begin{figure}
+%  \begin{center}
+%    \begin{BodePlot}[ ylabel={Gain (dB)}, ytick distance=40,
+%      height=2cm, width=4cm] {0.01} {100}
+%
+%      \addBodeZPKPlots[
+%        true/{black,thick},
+%        linear/{red,dashed,thick},
+%        asymptotic/{blue,dotted,thick}]
+%      {magnitude}
+%      {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.1,-10},{-0.1,10}},k/10}
+%    \end{BodePlot}
+%    \begin{BodePlot}[ylabel={Phase ($^{\circ}$)},
+%      height=2cm, width=4cm, ytick distance=90,] {0.01} {100}
+%
+%      \addBodeZPKPlots[
+%        true/{black,thick},
+%        linear/{red,dashed,thick},
+%        asymptotic/{blue,dotted,thick}]
+%      {phase}
+%      {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.1,-10},{-0.1,10}},k/10}
+%    \end{BodePlot}
+%  \end{center}
+%  \caption{\label{multiBodeZPK}Superimposed approximate and true Bode plots using the \texttt{BodePlot} environment and the \texttt{\textbackslash addBodeZPKPlots} macro.}
+% \end{figure}
+% which generates the plot in Figure \ref{multiBodeZPK}.
+%
+% \DescribeMacro{\addBodeTFPlot}
+% |\addBodeTFPlot|\oarg{plot-options}\\
+% \hspace*{2em}\marg{plot-type}\\
+% \hspace*{2em}\marg{num/\marg{coeffs},den/\marg{coeffs},d/\marg{delay}}
+%
+% \noindent Generates a single parametric function for either Bode magnitude or phase plot of a transfer function in TF form. The generated parametric function is passed to the |\addplot| macro. This macro can be used inside any |semilogaxis| environment as long as a domain for the x-axis is supplied through either the |plot-options| interface or directly in the optional argument of the container |semilogaxis| environment. Use with the |BodePlot| environment supplied with this package is recommended. The second mandatory argument, |plot-type| is either magnitude or |phase|. If it is not equal to |phase|, it is assumed to be |magnitude|. The last mandatory argument is the same as |\BodeTF|.
+%
+% \DescribeMacro{\addBodeComponentPlot}
+% |\addBodeComponentPlot|\oarg{plot-options}\marg{plot-command}
+%
+% \noindent Generates a single parametric function corresponding to the mandatory argument |plot-command| and passes it to the |\addplot| macro. The plot command can be any parametric function that uses |t| as the independent variable. The parametric function must be |gnuplot| compatible (or |pgfplots| compatible if the package is loaded using the |pgf| option). The intended use of this macro is to plot the parametric functions generated using the basic component macros described in Section \ref{sec:BasicComponents} below.
+%
+% \subsubsection{Basic components up to first order\label{sec:BasicComponents}}
+%
+% \DescribeMacro{\TypeFeatureApprox}
+% |\TypeFeatureApprox|\marg{real-part}\marg{imaginary-part}
+%
+% \noindent This entry describes 20 different macros of the form |\TypeFeatureApprox| that take the real part and the imaginary part of a complex number as arguments. The |Type| in the macro name should be replaced by either |Mag| or |Ph| to generate a parametric function corresponding to the magnitude or the phase plot, respectively. The |Feature| in the macro name should be replaced by one of |K|, |Pole|, |Zero|, or |Del|, to generate the Bode plot of a gain, a complex pole, a complex zero, or a transport delay, respectively. If the |Feature| is set to either |K| or |Del|, the |imaginary-part| mandatory argument is ignored. The |Approx| in the macro name should either be removed, or it should be replaced by |Lin| or |Asymp| to generate the true Bode plot, the linear approximation, or the asymptotic approximation, respectively. If the |Feature| is set to |Del|, then |Approx| has to be removed. For example, 
+% \begin{itemize}
+% \item |\MagK{k}{0}| or |\MagK{k}{400}| generates a parametric function for the true Bode magnitude of $ G(s) = k $
+% \item |\PhPoleLin{a}{b}| generates a parametric function for the linear approximation of the Bode phase of $ G(s) = \frac{1}{s-a-\mathrm{i}b} $.
+% \item |\PhDel{T}{200}| or |\PhDel{T}{0}| generates a parametric function for the Bode phase of $ G(s) = e^{-Ts} $.
+% \end{itemize}
+% All 20 of the macros defined by combinations of |Type|, |Feature|, and |Approx|, and any |gnuplot| (or |pgfplot| if the |pgf| class option is loaded) compatible function of the 20 macros can be used as |plot-command| in the |addBodeComponentPlot| macro. This is sufficient to generate the Bode plot of any rational transfer function with delay. For example, the Bode phase plot in Figure \ref{multiBodeZPK} can also be generated using:
+%\begin{verbatim}
+%\begin{BodePlot}[ylabel={Phase (degree)},ytick distance=90]{0.01}{100}
+%  \addBodeComponentPlot[black,thick]{\PhZero{0}{0} + \PhZero{-0.1}{-0.5} +
+%    \PhZero{-0.1}{0.5} + \PhPole{-0.5}{-10} + \PhPole{-0.5}{10} +
+%    \PhK{10}{0}}
+%  \addBodeComponentPlot[red,dashed,thick] {\PhZeroLin{0}{0} + 
+%    \PhZeroLin{-0.1}{-0.5} + \PhZeroLin{-0.1}{0.5} +
+%    \PhPoleLin{-0.5}{-10} + \PhPoleLin{-0.5}{10} + \PhKLin{10}{20}}
+%  \addBodeComponentPlot[blue,dotted,thick] {\PhZeroAsymp{0}{0} + 
+%    \PhZeroAsymp{-0.1}{-0.5} + \PhZeroAsymp{-0.1}{0.5} + 
+%    \PhPoleAsymp{-0.5}{-10} + \PhPoleAsymp{-0.5}{10} + \PhKAsymp{10}{40}}
+%\end{BodePlot}
+%\end{verbatim}
+%\begin{figure}
+%  \begin{center}
+%    \begin{BodePlot}[ylabel={Phase (degree)},ytick distance=90]{0.01}{100}
+%      \addBodeComponentPlot[black,thick] {\PhZero{0}{0} + \PhZero{-0.1}{-0.5} + \PhZero{-0.1}{0.5} + \PhPole{-0.5}{-10} + \PhPole{-0.5}{10} + \PhK{10}{0}}
+%      \addBodeComponentPlot[red,dashed,thick] {\PhZeroLin{0}{0} + \PhZeroLin{-0.1}{-0.5} + \PhZeroLin{-0.1}{0.5} + \PhPoleLin{-0.5}{-10} + \PhPoleLin{-0.5}{10} + \PhKLin{10}{20}}
+%      \addBodeComponentPlot[blue,dotted,thick] {\PhZeroAsymp{0}{0} + \PhZeroAsymp{-0.1}{-0.5} + \PhZeroAsymp{-0.1}{0.5} + \PhPoleAsymp{-0.5}{-10} + \PhPoleAsymp{-0.5}{10} + \PhKAsymp{10}{40}}
+%    \end{BodePlot}
+%  \end{center}
+%  \caption{\label{multiBodeComponents}Superimposed approximate and true Bode Phase plot using the \texttt{BodePlot} environment, the \texttt{\textbackslash addBodeComponentPlot} macro, and several macros of the \texttt{\textbackslash TypeFeatureApprox} form.}
+%\end{figure}
+% which gives us the plot in Figure \ref{multiBodeComponents}.
+%
+% \subsubsection{Basic components of the second order}
+%
+% \DescribeMacro{\TypeSOFeatureApprox}
+% |\TypeSOFeatureApprox|\marg{a1}\marg{a0}
+%
+% \noindent This entry describes 12 different macros of the form |\TypeSOFeatureApprox| that take the coefficients $ a_1 $ and $ a_0 $ of a general second order system as inputs. The |Feature| in the macro name should be replaced by either |Poles| or |Zeros| to generate the Bode plot of $G(s)=\frac{1}{s^2+a_1 s+a_0}$ or $G(s)=s^2+a_1 s+a_0$, respectively. The |Type| in the macro name should be replaced by either |Mag| or |Ph| to generate a parametric function corresponding to the magnitude or the phase plot, respectively. The |Approx| in the macro name should either be removed, or it should be replaced by |Lin| or |Asymp| to generate the true Bode plot, the linear approximation, or the asymptotic approximation, respectively.
+% 
+% \DescribeMacro{\MagSOFeaturePeak}
+% |\MagSOFeaturePeak|\oarg{draw-options}\marg{a1}\marg{a0}
+%
+% \noindent This entry describes 2 different macros of the form |\MagSOFeaturePeak| that take the the coefficients $ a_1 $ and $ a_0 $ of a general second order system as inputs, and draw a resonant peak using the |\draw| TikZ macro. The |Feature| in the macro name should be replaced by either |Poles| or |Zeros| to generate a peak for poles and a valley for zeros, respectively.  For example, the command
+%\begin{verbatim}
+%\begin{BodePlot}[xlabel={}]{0.1}{10}
+%  \addBodeComponentPlot[red,dashed,thick]{\MagSOPoles{0.2}{1}}
+%  \addBodeComponentPlot[black,thick]{\MagSOPolesLin{0.2}{1}}
+%  \MagSOPolesPeak[thick]{0.2}{1}
+%\end{BodePlot}
+%\end{verbatim}
+% generates the plot in Figure \ref{BodePeak}.
+%
+% \begin{figure}
+% \begin{center}
+%  \begin{BodePlot}[xlabel={}]{0.1}{10}
+%    \addBodeComponentPlot[red,dashed,thick]{\MagSOPoles{0.2}{1}}
+%    \addBodeComponentPlot[black,thick]{\MagSOPolesLin{0.2}{1}}
+%    \MagSOPolesPeak[very thick]{0.2}{1}
+%  \end{BodePlot}
+% \end{center}
+% \cprotect\caption{\label{BodePeak} Resonant peak in asymptotic Bode plot using |\MagSOPolesPeak|.}
+% \end{figure}
+%
+% \DescribeMacro{\TypeCSFeatureApprox}
+% |\TypeCSFeatureApprox|\marg{zeta}\marg{omega-n}
+%
+% \noindent This entry describes 12 different macros of the form |\TypeCSFeatureApprox| that take the damping ratio, $ \zeta $, and the natural frequency, $ \omega_n $ of a canonical second order system as inputs. The |Type| in the macro name should be replaced by either |Mag| or |Ph| to generate a parametric function corresponding to the magnitude or the phase plot, respectively. The |Feature| in the macro name should be replaced by either |Poles| or |Zeros| to generate the Bode plot of $G(s)=\frac{1}{s^2+2\zeta\omega_n s+\omega_n^2}$ or $G(s)=s^2+2\zeta\omega_n s+\omega_n^2$, respectively. The |Approx| in the macro name should either be removed, or it should be replaced by |Lin| or |Asymp| to generate the true Bode plot, the linear approximation, or the asymptotic approximation, respectively.
+%
+% \DescribeMacro{\MagCSFeaturePeak}
+% |\MagCSFeaturePeak|\oarg{draw-options}\marg{zeta}\marg{omega-n}
+%
+% \noindent This entry describes 2 different macros of the form |\MagCSFeaturePeak| that take the damping ratio, $ \zeta $, and the natural frequency, $ \omega_n $ of a canonical second order system as inputs, and draw a resonant peak using the |\draw| TikZ macro. The |Feature| in the macro name should be replaced by either |Poles| or |Zeros| to generate a peak for poles and a valley for zeros, respectively.
+%
+% \DescribeMacro{\MagCCFeaturePeak}
+% |\MagCCFeaturePeak|\oarg{draw-options}\marg{real-part}\marg{imaginary-part}
+%
+% \noindent This entry describes 2 different macros of the form |\MagCCFeaturePeak| that take the real and imaginary parts of a pair of complex conjugate poles or zeros as inputs, and draw a resonant peak using the |\draw| TikZ macro. The |Feature| in the macro name should be replaced by either |Poles| or |Zeros| to generate a peak for poles and a valley for zeros, respectively.
+%
+% \subsection{Nyquist plots}
+% \DescribeMacro{\NyquistZPK}
+% |\NyquistZPK| \oarg{plot/\marg{opt},axes/\marg{opt}}\\
+% \hspace*{2em}\marg{z/\marg{zeros},p/\marg{poles},k/\marg{gain},d/\marg{delay}}\\
+% \hspace*{2em}\marg{min-freq}\marg{max-freq}
+%
+% \noindent Plots the Nyquist plot of a transfer function given in ZPK format with a thick red $+$ marking the critical point (-1,0). The mandatory arguments are the same as |\BodeZPK|. Since there is only one plot in a Nyquist diagram, the |\typ| specifier in the optional argument tuples is not needed. As such, the supported optional argument tuples are |plot/{opt}|, which passes |{opt}| to |\addplot| and |axes/{opt}|, which passes |{\opt}| to the |axis| environment. Asymptotic/linear approximations are not supported in Nyquist plots. If just |{opt}| is provided as the optional argument, it is interpreted as |plot/{opt}|. Arrows to indicate the direction of increasing $\omega$ can be added by adding |\usetikzlibrary{decorations.markings}| and |\usetikzlibrary{arrows.meta}| to the preamble and then passing a tuple of the form\\
+%|plot/{postaction=decorate,decoration={markings,|\\
+%|  mark=between positions 0.1 and 0.9 step 5em with|\\
+%|  {\arrow{Stealth| |[length=2mm, blue]}}}}|\\
+%\textbf{Caution:} with a high number of samples, adding arrows in this way may cause the error message |! Dimension too big|.
+%
+% For example, the command\\
+% |\NyquistZPK[plot/{red,thick,samples=2000},axes/{blue,thick}]|\\
+% |  {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}|\\
+% |  {-30}{30}|\\
+% generates the Nyquist plot in Figure \ref{simpleNyquistZPK}.
+%
+% \begin{figure}
+% \begin{center}
+% \NyquistZPK[plot/{red,thick,samples=2000},axes/{blue,thick}] {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10} {-30} {30}
+% \cprotect\caption{\label{simpleNyquistZPK}Output of the |\NyquistZPK| macro.}
+% \end{center}
+% \end{figure}
+%
+% % \DescribeMacro{\NyquistTF}
+% |\NyquistTF| \oarg{plot/\marg{opt},axes/\marg{opt}}\\
+% \hspace*{2em}\marg{num/\marg{coeffs},den/\marg{coeffs},d/\marg{delay}}\\
+% \hspace*{2em}\marg{min-freq}\marg{max-freq}
+%
+% \noindent Nyquist plot of a transfer function given in TF format. Same mandatory arguments as |\BodeTF| and same optional arguments as |\NyquistZPK|. For example, the command\\
+% |\NyquistTF[plot/{green,thick,samples=500,postaction=decorate,|\\
+% |  decoration={markings,|\\
+% |  mark=between positions 0.1 and 0.9 step 5em|\\
+% |  with{\arrow{Stealth[length=2mm, blue]}}}}]|\\
+% |  {num/{10,2,2.6,0},den/{1,1,100.25}}|\\
+% |  {-30}{30}|\\
+% generates the Nyquist plot in Figure \ref{simpleNyquistTF}.
+%
+% \begin{figure}
+% \begin{center}
+% \NyquistTF[plot/{green,thick,samples=500,postaction=decorate,decoration={markings,mark=between positions 0.1 and 0.9 step 5em with {\arrow{Stealth[length=2mm, blue]}}}}] {num/{10,2,2.6,0},den/{1,1,100.25},d/0.01} {-30} {30}
+% \cprotect\caption{\label{simpleNyquistTF}Output of the |\NyquistTF| macro with direction arrows. Increasing the number of samples can cause |decorations.markings| to throw errors.}
+% \end{center}
+% \end{figure}
+%
+% \DescribeEnv{NyquistPlot}
+% |\begin{NyquistPlot}|\oarg{axis-options}\marg{min-frequency}\marg{max-frequency}\\
+% \hspace*{2em}|\addNyquist...|\\
+% \hspace*{1.5em}|\end{NyquistPlot}|\\
+% The |NyquistPlot| environment works in conjunction with the parametric function generator macros |\addNyquistZPKPlot| and |\addNyquistTFPlot|. If supplied, |axis-options| are passed directly to the |axis| environment and the frequency limits are translated to the x-axis limits and the domain of the |axis| environment.
+%
+% \DescribeMacro{\addNyquistZPKPlot}
+% |\addNyquistZPKPlot|\oarg{plot-options}\\
+% \hspace*{2em}\marg{z/\marg{zeros},p/\marg{poles},k/\marg{gain},d/\marg{delay}}
+%
+% \noindent Generates a twp parametric functions for the magnitude and the phase a transfer function in ZPK form. The generated magnitude and phase parametric functions are converted to real and imaginary part parametric functions and passed to the |\addplot| macro. This macro can be used inside any |axis| environment as long as a domain for the x-axis is supplied through either the |plot-options| interface or directly in the optional argument of the container |axis| environment. Use with the |NyquistPlot| environment supplied with this package is recommended. The mandatory argument is the same as |\BodeZPK|.
+%
+% \DescribeMacro{\addNyquistTFPlot}
+% |\addNyquistTFPlot|\oarg{plot-options}\\
+% \hspace*{2em}\marg{num/\marg{coeffs},den/\marg{coeffs},d/\marg{delay}}
+%
+% \noindent Similar to |\addNyquistZPKPlot|,  with a transfer function input in the TF form.
+%
+% \subsection{Nichols charts}
+% \DescribeMacro{\NicholsZPK}
+% |\NicholsZPK| \oarg{plot/\marg{opt},axes/\marg{opt}}\\
+% \hspace*{2em}\marg{z/\marg{zeros},p/\marg{poles},k/\marg{gain},d/\marg{delay}}\\
+% \hspace*{2em}\marg{min-freq}\marg{max-freq}
+%
+% \noindent Nichols chart of a transfer function given in ZPK format. Same arguments as |\NyquistZPK|.
+%
+% \DescribeMacro{\NicholsTF}
+% |\NicholsTF| \oarg{plot/\marg{opt},axes/\marg{opt}}\\
+% \hspace*{2em}\marg{num/\marg{coeffs},den/\marg{coeffs},d/\marg{delay}}\\
+% \hspace*{2em}\marg{min-freq}\marg{max-freq}
+%
+% \noindent Nichols chart of a transfer function given in TF format. Same arguments as |\NyquistTF|. For example, the command\\
+% |\NicholsTF[plot/{green,thick,samples=2000}]|\\
+% |  {num/{10,2,2.6,0},den/{1,1,100.25},d/0.01}|\\
+% |  {0.001}{100}|\\
+% generates the Nichols chart in Figure \ref{simpleNicholsTF}.
+%
+% \begin{figure}
+% \begin{center}
+% \NicholsTF[plot/{green,thick,samples=2000}] {num/{10,2,2.6,0},den/{1,1,100.25},d/0.01} {0.001} {100}
+% \cprotect\caption{\label{simpleNicholsTF}Output of the |\NyquistZPK| macro.}
+% \end{center}
+% \end{figure}
+%
+%
+% \DescribeEnv{NicholsChart}
+% |\begin{NicholsChart}|\oarg{axis-options}\marg{min-frequency}\marg{max-frequency}\\
+% \hspace*{2em}|\addNichols...|\\
+% \hspace*{1.5em}|\end{NicholsChart}|\\
+% The |NicholsChart| environment works in conjunction with the parametric function generator macros |\addNicholsZPKChart| and |\addNicholsTFChart|. If supplied, |axis-options| are passed directly to the |axis| environment and the frequency limits are translated to the x-axis limits and the domain of the |axis| environment.
+%
+% \DescribeMacro{\addNicholsZPKChart}
+% |\addNicholsZPKChart|\oarg{plot-options}\\
+% \hspace*{2em}\marg{z/\marg{zeros},p/\marg{poles},k/\marg{gain},d/\marg{delay}}
+%
+% \noindent Generates a twp parametric functions for the magnitude and the phase a transfer function in ZPK form. The generated magnitude and phase parametric functions are passed to the |\addplot| macro. This macro can be used inside any |axis| environment as long as a domain for the x-axis is supplied through either the |plot-options| interface or directly in the optional argument of the container |axis| environment. Use with the |NicholsChart| environment supplied with this package is recommended. The mandatory argument is the same as |\BodeZPK|.
+%
+% \DescribeMacro{\addNicholsTFChart}
+% |\addNicholsTFChart|\oarg{plot-options}\\
+% \hspace*{2em}\marg{num/\marg{coeffs},den/\marg{coeffs},d/\marg{delay}}
+%
+% \noindent Similar to |\addNicholsZPKChart|, with a transfer function input in the TF form.
+%
+% \StopEventually{\PrintIndex}
+%
+% \section{Implementation}
+% \subsection{Initialization}
+% \begin{macro}{\pdfstrcmp}
+% The package makes extensive use of the |\pdfstrcmp| macro to parse options. Since that macro is not available in |lualatex|, this code is needed.
+%    \begin{macrocode}
+\RequirePackage{ifluatex}%
+\ifluatex
+  \RequirePackage{pdftexcmds}%
+  \let\pdfstrcmp\pdf at strcmp
+\fi
+%    \end{macrocode}
+% \end{macro}
+% \begin{macro}{\n at mod}
+% \begin{macro}{\n at pow}
+% \begin{macro}{idGnuplot}
+% \begin{macro}{gnuplot def}
+% \begin{macro}{gnuplot degrees}
+% \begin{macro}{bodeStyle}
+% This code is needed to support both |pgfplots| and |gnuplot| simultaneously. New macros are defined for the |pow| and |mod| functions to address differences between the two math engines. We start by processing the |pgf| class option.
+%    \begin{macrocode}
+\newif\if at pgfarg\@pgfargfalse
+\DeclareOption{pgf}{%
+  \@pgfargtrue
+}
+\ProcessOptions\relax
+%    \end{macrocode}
+% Then, we define two new macros to unify |pgfplots| and |gnuplot|.
+%    \begin{macrocode}
+\if at pgfarg
+  \newcommand{\n at pow}[2]{(#1)^(#2)}%
+  \newcommand{\n at mod}[2]{mod((#1),(#2))}%
+\else
+  \newcommand{\n at pow}[2]{(#1)**(#2)}%
+  \newcommand{\n at mod}[2]{(#1)-(floor((#1)/(#2))*(#2))}%
+%    \end{macrocode}
+% Then, we create a counter so that a new data table is generated and for each new plot. If the plot macros have not changed, the tables, once generated, can be reused by |gnuplot|, which reduces compilation time.
+%    \begin{macrocode}
+  \newcounter{idGnuplot}%
+  \setcounter{idGnuplot}{0}%
+  \tikzset{%
+    gnuplot def/.style={%
+      id=\arabic{idGnuplot},
+      prefix=gnuplot/
+    }%
+  }
+%    \end{macrocode}
+% Then, we add |set angles degrees| to all |gnuplot| macros to avoid having to convert from degrees to radians everywhere.
+%    \begin{macrocode}
+  \pgfplotsset{%
+    gnuplot degrees/.code={%
+      \ifnum\value{idGnuplot}=1
+        \xdef\pgfplots at gnuplot@format{\pgfplots at gnuplot@format set angles degrees;}%
+      \fi
+    }%
+  }
+\fi
+%    \end{macrocode}
+% Default axis properties for all plot macros are collected in the following |pgf| style.
+%    \begin{macrocode}
+\pgfplotsset{%
+  bodeStyle/.style = {%
+    label style={font=\footnotesize},
+    tick label style={font=\footnotesize},
+    grid=both,
+    major grid style={color=gray!80},
+    minor grid style={color=gray!20},
+    x label style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
+    y label style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
+    scale only axis,
+    samples=200,
+    width=5cm,
+  }%
+}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \subsection{Parametric function generators for poles, zeros, gains, and delays.}
+% \begin{macro}{\MagK}
+% \begin{macro}{\MagKAsymp}
+% \begin{macro}{\MagKLin}
+% \begin{macro}{\PhK}
+% \begin{macro}{\PhKAsymp}
+% \begin{macro}{\PhKLin}
+% True, linear, and asymptotic magnitude and phase parametric functions for a pure gain $G(s)=k+0\mathrm{i}$. The macros take two arguments corresponding to real and imaginary part of the gain to facilitate code reuse between delays, gains, poles, and zeros, but only real gains are supported. The second argument, if supplied, is ignored.
+%    \begin{macrocode}
+\newcommand*{\MagK}[2]{(20*log10(abs(#1)))}
+\newcommand*{\MagKAsymp}{\MagK}
+\newcommand*{\MagKLin}{\MagK}
+\newcommand*{\PhK}[2]{(#1<0?-180:0)}
+\newcommand*{\PhKAsymp}{\PhK}
+\newcommand*{\PhKLin}{\PhK}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \begin{macro}{\PhKAsymp}
+% \begin{macro}{\PhKLin}
+% True magnitude and phase parametric functions for a pure delay $G(s)=e^{-Ts}$. The macros take two arguments corresponding to real and imaginary part of the gain to facilitate code reuse between delays, gains, poles, and zeros, but only real gains are supported. The second argument, if supplied, is ignored.
+%    \begin{macrocode}
+\newcommand*{\MagDel}[2]{0}
+\newcommand*{\PhDel}[2]{-#1*180*t/pi}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \begin{macro}{\MagPole}
+% \begin{macro}{\MagPoleAsymp}
+% \begin{macro}{\MagPoleLin}
+% \begin{macro}{\PhPole}
+% \begin{macro}{\PhPoleAsymp}
+% \begin{macro}{\PhPoleLin}
+% These macros are the building blocks for most of the plotting functions provided by this package. We start with Parametric function for the true magnitude of a complex pole.
+%    \begin{macrocode}
+\newcommand*{\MagPole}[2]
+  {(-20*log10(sqrt(\n at pow{#1}{2} + \n at pow{t - (#2)}{2})))}
+%    \end{macrocode}
+% Parametric function for linear approximation of the magnitude of a complex pole.
+%    \begin{macrocode}
+\newcommand*{\MagPoleLin}[2]{(t < sqrt(\n at pow{#1}{2} + \n at pow{#2}{2}) ?
+  -20*log10(sqrt(\n at pow{#1}{2} + \n at pow{#2}{2})) :
+  -20*log10(t)
+  )}
+%    \end{macrocode}
+% Parametric function for asymptotic approximation of the magnitude of a complex pole, same as linear approximation.
+%    \begin{macrocode}
+\newcommand*{\MagPoleAsymp}{\MagPoleLin}
+%    \end{macrocode}
+% Parametric function for the true phase of a complex pole.
+%    \begin{macrocode}
+\newcommand*{\PhPole}[2]{(#1 > 0 ? (#2 > 0 ? 
+  (\n at mod{-atan2((t - (#2)),-(#1))+360}{360}) : 
+  (-atan2((t - (#2)),-(#1)))) : 
+  (-atan2((t - (#2)),-(#1))))}
+%    \end{macrocode}
+% Parametric function for linear approximation of the phase of a complex pole.
+%    \begin{macrocode}
+\newcommand*{\PhPoleLin}[2]{%
+  (abs(#1)+abs(#2) == 0 ? -90 :
+  (t < (sqrt(\n at pow{#1}{2} + \n at pow{#2}{2}) / 
+    (\n at pow{10}{sqrt(\n at pow{#1}{2}/(\n at pow{#1}{2} + \n at pow{#2}{2}))})) ? 
+  (-atan2(-(#2),-(#1))) :
+  (t >= (sqrt(\n at pow{#1}{2} + \n at pow{#2}{2}) * 
+    (\n at pow{10}{sqrt(\n at pow{#1}{2}/(\n at pow{#1}{2} + \n at pow{#2}{2}))})) ? 
+  (#2>0?(#1>0?270:-90):-90) :
+  (-atan2(-(#2),-(#1)) + (log10(t/(sqrt(\n at pow{#1}{2} + \n at pow{#2}{2}) / 
+    (\n at pow{10}{sqrt(\n at pow{#1}{2}/(\n at pow{#1}{2} + 
+    \n at pow{#2}{2}))}))))*((#2>0?(#1>0?270:-90):-90) + atan2(-(#2),-(#1)))/
+    (log10(\n at pow{10}{sqrt((4*\n at pow{#1}{2})/
+    (\n at pow{#1}{2} + \n at pow{#2}{2}))}))))))}
+%    \end{macrocode}
+% Parametric function for asymptotic approximation of the phase of a complex pole.
+%    \begin{macrocode}
+\newcommand*{\PhPoleAsymp}[2]{(t < (sqrt(\n at pow{#1}{2} + \n at pow{#2}{2})) ? 
+  (-atan2(-(#2),-(#1))) :
+  (#2>0?(#1>0?270:-90):-90))}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \begin{macro}{\MagZero}
+% \begin{macro}{\MagZeroAsymp}
+% \begin{macro}{\MagZeroLin}
+% \begin{macro}{\PhZero}
+% \begin{macro}{\PhZeroAsymp}
+% \begin{macro}{\PhZeroLin}
+% Plots of zeros are defined to be negative of plots of poles. The |0-| is necessary due to a bug in |gnuplot| (fixed in version 5.4, patchlevel 3).
+%    \begin{macrocode}
+\newcommand*{\MagZero}{0-\MagPole}
+\newcommand*{\MagZeroLin}{0-\MagPoleLin}
+\newcommand*{\MagZeroAsymp}{0-\MagPoleAsymp}
+\newcommand*{\PhZero}{0-\PhPole}
+\newcommand*{\PhZeroLin}{0-\PhPoleLin}
+\newcommand*{\PhZeroAsymp}{0-\PhPoleAsymp}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \subsection{Second order systems.}
+% Although second order systems can be dealt with using the macros defined so far, the following dedicated macros for second order systems involve less computation. 
+% \begin{macro}{\MagCSPoles}
+% \begin{macro}{\MagCSPolesAsymp}
+% \begin{macro}{\MagCSPolesLin}
+% \begin{macro}{\PhCSPoles}
+% \begin{macro}{\PhCSPolesAsymp}
+% \begin{macro}{\PhCSPolesLin}
+% \begin{macro}{\MagCSZeros}
+% \begin{macro}{\MagCSZerosAsymp}
+% \begin{macro}{\MagCSZerosLin}
+% \begin{macro}{\PhCSZeros}
+% \begin{macro}{\PhCSZerosAsymp}
+% \begin{macro}{\PhCSZerosLin}
+% Consider the canonical second order transfer function $G(s) = \frac{1}{s^2 + 2 \zeta w_n s + w_n^2}$. We start with true, linear, and asymptotic magnitude plots for this transfer function.
+%    \begin{macrocode}
+\newcommand*{\MagCSPoles}[2]{(-20*log10(sqrt(\n at pow{\n at pow{#2}{2} 
+    - \n at pow{t}{2}}{2} + \n at pow{2*#1*#2*t}{2})))}
+\newcommand*{\MagCSPolesLin}[2]{(t < #2 ? -40*log10(#2) : - 40*log10(t))}
+\newcommand*{\MagCSPolesAsymp}{\MagCSPolesLin}
+%    \end{macrocode}
+% Then, we have true, linear, and asymptotic phase plots for the canonical second order transfer function.
+%    \begin{macrocode}
+\newcommand*{\PhCSPoles}[2]{(-atan2((2*(#1)*(#2)*t),(\n at pow{#2}{2} 
+  - \n at pow{t}{2})))}
+\newcommand*{\PhCSPolesLin}[2]{(t < (#2 / (\n at pow{10}{abs(#1)})) ? 
+  0 :
+  (t >= (#2 * (\n at pow{10}{abs(#1)})) ? 
+  (#1>0 ? -180 : 180) :
+  (#1>0 ? (-180*(log10(t*(\n at pow{10}{#1})/#2))/(2*#1)) : 
+    (180*(log10(t*(\n at pow{10}{abs(#1)})/#2))/(2*abs(#1))))))}
+\newcommand*{\PhCSPolesAsymp}[2]{(#1>0?(t<#2?0:-180):(t<#2?0:180))}
+%    \end{macrocode}
+% Plots of the inverse function $G(s)=s^2+2\zeta\omega_n s+\omega_n^2$ are defined to be negative of plots of poles. The |0-| is necessary due to a bug in |gnuplot| (fixed in version 5.4, patchlevel 3).
+%    \begin{macrocode}
+\newcommand*{\MagCSZeros}{0-\MagCSPoles}
+\newcommand*{\MagCSZerosLin}{0-\MagCSPolesLin}
+\newcommand*{\MagCSZerosAsymp}{0-\MagCSPolesAsymp}
+\newcommand*{\PhCSZeros}{0-\PhCSPoles}
+\newcommand*{\PhCSZerosLin}{0-\PhCSPolesLin}
+\newcommand*{\PhCSZerosAsymp}{0-\PhCSPolesAsymp}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \begin{macro}{\MagCSPolesPeak}
+% \begin{macro}{\MagCSZerosPeak}
+% These macros are used to add a resonant peak to linear and asymptotic plots of canonical second order poles and zeros. Since the plots are parametric, a separate |\draw| command is needed to add a vertical arrow.
+%    \begin{macrocode}
+\newcommand*{\MagCSPolesPeak}[3][]{%
+  \draw[#1,->] (axis cs:{#3},{-40*log10(#3)}) -- 
+  (axis cs:{#3},{-40*log10(#3)-20*log10(2*abs(#2))})
+}
+\newcommand*{\MagCSZerosPeak}[3][]{%
+  \draw[#1,->] (axis cs:{#3},{40*log10(#3)}) -- 
+  (axis cs:{#3},{40*log10(#3)+20*log10(2*abs(#2))})
+}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \begin{macro}{\MagSOPoles}
+% \begin{macro}{\MagSOPolesAsymp}
+% \begin{macro}{\MagSOPolesLin}
+% \begin{macro}{\PhSOPoles}
+% \begin{macro}{\PhSOPolesAsymp}
+% \begin{macro}{\PhSOPolesLin}
+% \begin{macro}{\MagSOZeros}
+% \begin{macro}{\MagSOZerosAsymp}
+% \begin{macro}{\MagSOZerosLin}
+% \begin{macro}{\PhSOZeros}
+% \begin{macro}{\PhSOZerosAsymp}
+% \begin{macro}{\PhSOZerosLin}
+% Consider a general second order transfer function $G(s) = \frac{1}{s^2 + a s + b}$. We start with true, linear, and asymptotic magnitude plots for this transfer function.
+%    \begin{macrocode}
+\newcommand*{\MagSOPoles}[2]{%
+  (-20*log10(sqrt(\n at pow{#2 - \n at pow{t}{2}}{2} + \n at pow{#1*t}{2})))}
+\newcommand*{\MagSOPolesLin}[2]{%
+  (t < sqrt(abs(#2)) ? -20*log10(abs(#2)) : - 40*log10(t))}
+\newcommand*{\MagSOPolesAsymp}{\MagSOPolesLin}
+%    \end{macrocode}
+% Then, we have true, linear, and asymptotic phase plots for the general second order transfer function.
+%    \begin{macrocode}
+\newcommand*{\PhSOPoles}[2]{(-atan2((#1)*t,((#2) - \n at pow{t}{2})))}
+\newcommand*{\PhSOPolesLin}[2]{(#2>0 ?
+  \PhCSPolesLin{(#1/(2*sqrt(#2)))}{(sqrt(#2))} :
+  (#1>0 ? -180 : 180))}
+\newcommand*{\PhSOPolesAsymp}[2]{(#2>0 ?
+  \PhCSPolesAsymp{(#1/(2*sqrt(#2)))}{(sqrt(#2))} :
+  (#1>0 ? -180 : 180))}
+%    \end{macrocode}
+% Plots of the inverse function $G(s)=s^2+as+b$ are defined to be negative of plots of poles. The |0-| is necessary due to a bug in |gnuplot| (fixed in version 5.4, patchlevel 3).
+%    \begin{macrocode}
+\newcommand*{\MagSOZeros}{0-\MagSOPoles}
+\newcommand*{\MagSOZerosLin}{0-\MagSOPolesLin}
+\newcommand*{\MagSOZerosAsymp}{0-\MagSOPolesAsymp}
+\newcommand*{\PhSOZeros}{0-\PhSOPoles}
+\newcommand*{\PhSOZerosLin}{0-\PhSOPolesLin}
+\newcommand*{\PhSOZerosAsymp}{0-\PhSOPolesAsymp}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \begin{macro}{\MagSOPolesPeak}
+% \begin{macro}{\MagSOZerosPeak}
+% These macros are used to add a resonant peak to linear and asymptotic plots of general second order poles and zeros. Since the plots are parametric, a separate |\draw| command is needed to add a vertical arrow.
+%    \begin{macrocode}
+\newcommand*{\MagSOPolesPeak}[3][]{%
+  \draw[#1,->] (axis cs:{sqrt(abs(#3))},{-20*log10(abs(#3))}) -- 
+  (axis cs:{sqrt(abs(#3))},{-20*log10(abs(#3)) - 
+    20*log10(abs(#2/sqrt(abs(#3))))});
+}
+\newcommand*{\MagSOZerosPeak}[3][]{%
+  \draw[#1,->] (axis cs:{sqrt(abs(#3))},{20*log10(abs(#3))}) -- 
+  (axis cs:{sqrt(abs(#3))},{20*log10(abs(#3)) + 
+    20*log10(abs(#2/sqrt(abs(#3))))});
+}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \subsection{Commands for Bode plots}
+% \subsubsection{User macros}
+% \begin{macro}{\BodeZPK}
+% This macro takes lists of complex poles and zeros of the form |{re,im}|, and values of gain and delay as inputs and constructs parametric functions for the Bode magnitude and phase plots. This is done by adding together the parametric functions generated by the macros for individual zeros, poles, gain, and delay, described above. The parametric functions are then plotted in a |tikzpicture| environment using the |\addplot| macro. Unless the package is loaded with the option |pgf|, the parametric functions are evaluated using |gnuplot|.
+%    \begin{macrocode}
+\newcommand{\BodeZPK}[4][]{%
+%    \end{macrocode}
+% Most of the work is done by the |\parse at opt| and the |\build at ZPK@plot| macros, described in the 'Internal macros' section. The former is used to parse the optional arguments and the latter to extract poles, zeros, gain, and delay from the first mandatory argument and to generate macros |\func at mag| and |\func at ph| that hold the magnitude and phase parametric functions.
+%    \begin{macrocode}
+  \parse at opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{\opt at approx}{#2}%
+%    \end{macrocode}
+% The |\noexpand| macros below are needed to so that only the macro |\opt at group| is expanded.
+%    \begin{macrocode}
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{groupplot}[%
+    bodeStyle,
+    xmin={#3},
+    xmax={#4},
+    domain=#3:#4,
+    height=2.5cm,
+    xmode=log,
+    group style = {group size = 1 by 2,vertical sep=0.25cm,},
+    \opt at group,]}
+  \temp at cmd
+%    \end{macrocode}
+% To ensure frequency tick marks on magnitude and the phase plots are always aligned, we use the |groupplot| library. The |\expandafter| chain below is used to expand macros in the plot and group optional arguments.
+%    \begin{macrocode}
+  \if at pgfarg
+    \expandafter\nextgroupplot\expandafter[ytick distance=20,
+      ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optmag at plot]}%
+    \temp at cmd {\func at mag};
+    \expandafter\nextgroupplot\expandafter[ytick distance=45,
+      ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optph at plot]}%
+    \temp at cmd {\func at ph};
+  \else
+%    \end{macrocode}
+% In |gnuplot| mode, we increment the |idGnuplot| counter before every plot to make sure that new and reusable |.gnuplot| and |.table| files are generated for every plot.
+%    \begin{macrocode}
+    \stepcounter{idGnuplot}
+    \expandafter\nextgroupplot\expandafter[ytick distance=20,
+      ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optmag at plot]}%
+    \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\func at mag};
+    \stepcounter{idGnuplot}
+    \expandafter\nextgroupplot\expandafter[ytick distance=45,
+      ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optph at plot]}%
+    \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\func at ph};
+  \fi
+  \end{groupplot}\end{tikzpicture}}
+%    \end{macrocode}
+% \end{macro}
+% \begin{macro}{\BodeTF}
+% Implementation of this macro is very similar to the |\BodeZPK| macro above. The only difference is the lack of linear and asymptotic plots and slightly different parsing of the mandatory arguments.
+%    \begin{macrocode}
+\newcommand{\BodeTF}[4][]{%
+  \parse at opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{groupplot}[%
+    bodeStyle,
+    xmin={#3},
+    xmax={#4},
+    domain=#3:#4,
+    height=2.5cm,
+    xmode=log,
+    group style = {group size = 1 by 2,vertical sep=0.25cm,},
+    \opt at group,]}
+  \temp at cmd
+  \if at pgfarg
+    \expandafter\nextgroupplot\expandafter[ytick distance=20,
+      ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optmag at plot]}%
+    \temp at cmd {\func at mag};
+    \expandafter\nextgroupplot\expandafter[ytick distance=45,
+      ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optph at plot]}%
+    \temp at cmd {\func at ph};
+  \else
+    \stepcounter{idGnuplot}%
+    \expandafter\nextgroupplot\expandafter[ytick distance=20,
+      ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optmag at plot]}%
+    \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\func at mag};
+    \stepcounter{idGnuplot}%
+    \expandafter\nextgroupplot\expandafter[ytick distance=45,
+      ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optph at plot]}%
+    \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\func at ph};
+  \fi
+  \end{groupplot}\end{tikzpicture}}
+%    \end{macrocode} 
+% \end{macro}
+% \begin{macro}{\addBodeZPKPlots}
+% This macro is designed to issues multiple |\addplot| macros for the same set of poles, zeros, gain, and delay. All of the work is done by the |\build at ZPK@plot| macro.
+%    \begin{macrocode}
+\newcommand{\addBodeZPKPlots}[3][{}]{%
+  \foreach \approx/\opt in {#1} {%
+    \gdef\plot at macro{}%
+    \gdef\temp at macro{}%
+    \ifnum\pdfstrcmp{#2}{phase}=0
+      \build at ZPK@plot{\temp at macro}{\plot at macro}{\approx}{#3}%
+    \else
+      \build at ZPK@plot{\plot at macro}{\temp at macro}{\approx}{#3}%
+    \fi
+    \if at pgfarg
+      \edef\temp at cmd{\noexpand\addplot[red,thick,\opt]}%
+      \temp at cmd {\plot at macro};
+    \else
+      \stepcounter{idGnuplot}%
+      \edef\temp at cmd{\noexpand\addplot[red,thick,\opt]}
+      \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\plot at macro};
+    \fi
+  }%
+}
+%    \end{macrocode}
+%\end{macro}
+% \begin{macro}{\addBodeTFPlot}
+% This macro is designed to issues a single |\addplot| macros for the set of coefficients and delay. All of the work is done by the |\build at TF@plot| macro.
+%    \begin{macrocode}
+\newcommand{\addBodeTFPlot}[3][red,thick]{%
+  \gdef\plot at macro{}%
+  \gdef\temp at macro{}%
+  \ifnum\pdfstrcmp{#2}{phase}=0
+    \build at TF@plot{\temp at macro}{\plot at macro}{#3}%
+  \else
+    \build at TF@plot{\plot at macro}{\temp at macro}{#3}%
+  \fi
+  \if at pgfarg
+    \addplot[#1]{\plot at macro};
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot[#1] gnuplot[gnuplot degrees, gnuplot def] {\plot at macro};
+  \fi
+}
+%    \end{macrocode}
+%\end{macro}
+% \begin{macro}{\addBodeComponentPlot}
+% This macro is designed to issue a single |\addplot| macro capable of plotting linear combinations of the basic components described in Section \ref{sec:BasicComponents}. The only work to do here is to handle the |pgf| package option.
+%    \begin{macrocode}
+\newcommand{\addBodeComponentPlot}[2][red,thick]{%
+  \if at pgfarg
+    \addplot[#1]{#2};
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot[#1] gnuplot[gnuplot degrees,gnuplot def] {#2};
+  \fi
+}
+%    \end{macrocode}
+%\end{macro}
+% \begin{environment}{BodePlot}
+% An environment to host macros that pass parametric functions to |\addplot| macros. Uses the defaults specified in |bodeStyle| to create a shortcut that includes the |tikzpicture| and |semilogaxis| environments.
+%    \begin{macrocode}
+\newenvironment{BodePlot}[3][]{%
+  \begin{tikzpicture}
+    \begin{semilogxaxis}[%
+      bodeStyle,
+      xmin={#2},
+      xmax={#3},
+      domain=#2:#3,
+      height=2.5cm,
+      xlabel={Frequency (rad/s)},
+      #1]
+}{
+  \end{semilogxaxis}
+  \end{tikzpicture}
+}
+%    \end{macrocode}
+% \end{environment}
+% \subsubsection{Internal macros}
+% \begin{macro}{\add at feature}
+% This is an internal macro to add a basic component (pole, zero, gain, or delay), described using one of the macros in Section \ref{sec:BasicComponents} (input |#2|), to a parametric function stored in a global macro (input |#1|). The basic component value (input |#3|) is a complex number of the form |{re,im}|. If the imaginary part is missing, it is assumed to be zero. Implementation made possible by \href{https://tex.stackexchange.com/a/619637/110602}{this StackExchange answer}.
+%    \begin{macrocode}
+\newcommand*{\add at feature}[3]{%
+  \ifcat$\detokenize\expandafter{#1}$%
+    \xdef#1{\unexpanded\expandafter{#1 0+#2}}%
+  \else
+    \xdef#1{\unexpanded\expandafter{#1+#2}}%
+  \fi
+  \foreach \y [count=\n] in #3 {%
+    \xdef#1{\unexpanded\expandafter{#1}{\y}}%
+    \xdef\Last at LoopValue{\n}%
+  }%
+  \ifnum\Last at LoopValue=1%
+    \xdef#1{\unexpanded\expandafter{#1}{0}}%
+  \fi
+}
+%    \end{macrocode}
+%\end{macro}
+% \begin{macro}{\build at ZPK@plot}
+% This is an internal macro to build parametric Bode magnitude and phase plots by concatenating basic component (pole, zero, gain, or delay) macros (Section \ref{sec:BasicComponents}) to global magnitude and phase macros (inputs |#1| and |#2|). The |\add at feature| macro is used to do the concatenation. The basic component macros are inferred from a |feature/{values}| list, where |feature| is one of |z|,|p|,|k|, and |d|, for zeros, poles, gain, and delay, respectively, and |{values}| is a comma separated list of comma separated lists (complex numbers of the form |{re,im}|). If the imaginary part is missing, it is assumed to be zero.
+%    \begin{macrocode}
+\newcommand{\build at ZPK@plot}[4]{%
+  \foreach \feature/\values in {#4} {%
+    \ifnum\pdfstrcmp{\feature}{z}=0
+      \foreach \z in \values {%
+        \ifnum\pdfstrcmp{#3}{linear}=0
+          \add at feature{#2}{\PhZeroLin}{\z}%
+          \add at feature{#1}{\MagZeroLin}{\z}%
+        \else
+          \ifnum\pdfstrcmp{#3}{asymptotic}=0
+            \add at feature{#2}{\PhZeroAsymp}{\z}%
+            \add at feature{#1}{\MagZeroAsymp}{\z}%
+          \else
+            \add at feature{#2}{\PhZero}{\z}%
+            \add at feature{#1}{\MagZero}{\z}%
+          \fi
+        \fi
+      }%
+    \fi
+    \ifnum\pdfstrcmp{\feature}{p}=0
+      \foreach \p in \values {%
+        \ifnum\pdfstrcmp{#3}{linear}=0
+          \add at feature{#2}{\PhPoleLin}{\p}%
+          \add at feature{#1}{\MagPoleLin}{\p}%
+        \else
+          \ifnum\pdfstrcmp{#3}{asymptotic}=0
+            \add at feature{#2}{\PhPoleAsymp}{\p}%
+            \add at feature{#1}{\MagPoleAsymp}{\p}%
+          \else
+            \add at feature{#2}{\PhPole}{\p}%
+            \add at feature{#1}{\MagPole}{\p}%
+          \fi
+        \fi
+      }%
+    \fi
+    \ifnum\pdfstrcmp{\feature}{k}=0
+      \ifnum\pdfstrcmp{#3}{linear}=0
+        \add at feature{#2}{\PhKLin}{\values}%
+        \add at feature{#1}{\MagKLin}{\values}%
+      \else
+        \ifnum\pdfstrcmp{#3}{asymptotic}=0
+          \add at feature{#2}{\PhKAsymp}{\values}%
+          \add at feature{#1}{\MagKAsymp}{\values}%
+        \else
+          \add at feature{#2}{\PhK}{\values}%
+          \add at feature{#1}{\MagK}{\values}%
+        \fi
+      \fi
+    \fi
+    \ifnum\pdfstrcmp{\feature}{d}=0
+      \ifnum\pdfstrcmp{#3}{linear}=0
+        \PackageError {bodeplot} {Linear approximation for pure delays is not 
+        supported.} {Plot the true Bode plot using 'true' instead of 'linear'.}
+      \else
+        \ifnum\pdfstrcmp{#3}{asymptotic}=0
+          \PackageError {bodeplot} {Asymptotic approximation for pure delays is not 
+          supported.} {Plot the true Bode plot using 'true' instead of 'asymptotic'.}
+        \else
+          \ifdim\values pt < 0pt
+            \PackageError {bodeplot} {Delay needs to be a positive number.}
+          \fi
+          \add at feature{#2}{\PhDel}{\values}%
+          \add at feature{#1}{\MagDel}{\values}%
+        \fi
+      \fi
+    \fi
+  }%
+}
+%    \end{macrocode}
+%\end{macro}
+% \begin{macro}{\build at TF@plot}
+% This is an internal macro to build parametric Bode magnitude and phase functions by computing the magnitude and the phase given numerator and denominator coefficients and delay (input |#3|). The functions are assigned to user-supplied global magnitude and phase macros (inputs |#1| and |#2|).
+%    \begin{macrocode}
+\newcommand{\build at TF@plot}[3]{%
+  \gdef\num at real{0}%
+  \gdef\num at im{0}%
+  \gdef\den at real{0}%
+  \gdef\den at im{0}%
+  \gdef\loop at delay{0}%
+  \foreach \feature/\values in {#3} {%
+    \ifnum\pdfstrcmp{\feature}{num}=0
+      \foreach \numcoeff [count=\numpow] in \values {%
+        \xdef\num at degree{\numpow}%
+      }%
+      \foreach \numcoeff [count=\numpow] in \values {%
+        \pgfmathtruncatemacro{\currentdegree}{\num at degree-\numpow}%
+        \ifnum\currentdegree = 0
+          \xdef\num at real{\num at real+\numcoeff}%
+        \else
+          \ifodd\currentdegree
+            \xdef\num at im{\num at im+(\numcoeff*(\n at pow{-1}{(\currentdegree-1)/2})*%
+              (\n at pow{t}{\currentdegree}))}%
+          \else
+            \xdef\num at real{\num at real+(\numcoeff*(\n at pow{-1}{(\currentdegree)/2})*%
+              (\n at pow{t}{\currentdegree}))}%
+          \fi
+        \fi
+      }%
+    \fi
+    \ifnum\pdfstrcmp{\feature}{den}=0
+      \foreach \dencoeff [count=\denpow] in \values {%
+        \xdef\den at degree{\denpow}%
+      }%
+      \foreach \dencoeff [count=\denpow] in \values {%
+        \pgfmathtruncatemacro{\currentdegree}{\den at degree-\denpow}%
+        \ifnum\currentdegree = 0
+          \xdef\den at real{\den at real+\dencoeff}%
+        \else
+          \ifodd\currentdegree
+            \xdef\den at im{\den at im+(\dencoeff*(\n at pow{-1}{(\currentdegree-1)/2})*%
+              (\n at pow{t}{\currentdegree}))}%
+          \else
+            \xdef\den at real{\den at real+(\dencoeff*(\n at pow{-1}{(\currentdegree)/2})*%
+              (\n at pow{t}{\currentdegree}))}%
+          \fi
+        \fi
+      }%
+    \fi
+    \ifnum\pdfstrcmp{\feature}{d}=0
+      \xdef\loop at delay{\values}%
+    \fi
+  }%
+  \xdef#2{(\n at mod{atan2((\num at im),(\num at real))-atan2((\den at im),%
+    (\den at real))+360}{360}-\loop at delay*180*t/pi)}%
+  \xdef#1{(20*log10(sqrt((\n at pow{\num at real}{2})+(\n at pow{\num at im}{2})))-%
+    20*log10(sqrt((\n at pow{\den at real}{2})+(\n at pow{\den at im}{2}))))}%
+}
+%    \end{macrocode}
+%\end{macro}
+% \begin{macro}{\parse at opt}
+% Parses options supplied to the main Bode macros. A |for| loop over tuples of the form |\obj/\typ/\opt| with a long list of nested if-else statements does the job. The input |\obj| is either |plot|, |axes|, |group| or |approx|, and the corresponding |\opt| are passed to the |\addplot| macro, the |\nextgroupplot| macro, the |groupplot| environment, and the |\build at ZPK@plot| macros, respectively. The input tuples should not contain any macros that need to be passed to respective |pgf| macros unexpanded. If an input tuple needs to contain such a macro, the |\xdef| macros below need to be defined using |\unexpanded\expandafter{\opt}| instead of just |\opt|. For example, the |\parse at N@opt| macro in Section \ref{sec:NInternal} can pass macros in its arguments, unexpanded, to |pgf| plot macros and environments, which is useful, for example, when the user wishes to add direction arrows to Nyquist plots. I did not think such a use case would be encountered when plotting Bode plots.
+%    \begin{macrocode}
+\newcommand{\parse at opt}[1]{%
+  \gdef\optmag at axes{}%
+  \gdef\optph at axes{}%
+  \gdef\optph at plot{}%
+  \gdef\optmag at plot{}%
+  \gdef\opt at group{}%
+  \gdef\opt at approx{}%
+  \foreach \obj/\typ/\opt in {#1} {%
+    \ifnum\pdfstrcmp{\obj}{plot}=0
+      \ifnum\pdfstrcmp{\typ}{mag}=0
+        \xdef\optmag at plot{\optmag at plot,\opt}%
+      \else
+        \ifnum\pdfstrcmp{\typ}{ph}=0
+          \xdef\optph at plot{\optph at plot,\opt}%
+        \else
+          \xdef\optmag at plot{\optmag at plot,\opt}%
+          \xdef\optph at plot{\optph at plot,\opt}%
+        \fi
+      \fi
+    \else
+      \ifnum\pdfstrcmp{\obj}{axes}=0
+        \ifnum\pdfstrcmp{\typ}{mag}=0
+          \xdef\optmag at axes{\optmag at axes,\opt}%
+        \else
+          \ifnum\pdfstrcmp{\typ}{ph}=0
+            \xdef\optph at axes{\optph at axes,\opt}%
+          \else
+            \xdef\optmag at axes{\optmag at axes,\opt}%
+            \xdef\optph at axes{\optph at axes,\opt}%
+          \fi
+        \fi
+      \else
+        \ifnum\pdfstrcmp{\obj}{group}=0
+          \xdef\opt at group{\opt at group,\opt}%
+        \else
+          \ifnum\pdfstrcmp{\obj}{approx}=0
+            \xdef\opt at approx{\typ}%
+          \else
+            \xdef\optmag at plot{\optmag at plot,\obj}%
+            \xdef\optph at plot{\optph at plot,\obj}%
+          \fi
+        \fi
+      \fi
+    \fi
+  }%
+}
+%    \end{macrocode}
+%\end{macro}
+% \subsection{Nyquist plots}
+% \subsubsection{User macros}
+% \begin{macro}{\NyquistZPK}
+% Converts magnitude and phase parametric functions built using |\build at ZPK@plot| into real part and imaginary part parametric functions. A plot of these is the Nyquist plot. The parametric functions are then plotted in a |tikzpicture| environment using the |\addplot| macro. Unless the package is loaded with the option |pgf|, the parametric functions are evaluated using |gnuplot|. A large number of samples is typically needed to get a smooth plot because frequencies near 0 result in plot points that are very close to each other. Linear frequency sampling is unnecessarily fine near zero and very coarse for large $\omega$. Logarithmic sampling makes it worse, perhaps inverse logarithmic sampling will help, merge requests are welcome!
+%    \begin{macrocode}
+\newcommand{\NyquistZPK}[4][]{%
+  \parse at N@opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{axis}[%
+        bodeStyle,
+        domain=#3:#4,
+        height=5cm,
+        xlabel={$\Re$},
+        ylabel={$\Im$},
+        samples=500,
+        \opt at axes,]}%
+  \temp at cmd
+      \addplot [only marks,mark=+,thick,red] (-1 , 0);
+      \edef\temp at cmd{\noexpand\addplot[thick,\unexpanded\expandafter{\opt at plot}]}%
+      \if at pgfarg
+        \temp at cmd ( {\n at pow{10}{((\func at mag)/20)}*cos(\func at ph)},
+          {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
+      \else
+        \stepcounter{idGnuplot}%
+        \temp at cmd gnuplot[parametric,gnuplot degrees,gnuplot def] {%
+          \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
+          \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
+      \fi
+    \end{axis}
+  \end{tikzpicture}
+}
+%    \end{macrocode}
+% \end{macro}
+% \begin{macro}{\NyquistTF}
+% Implementation of this macro is very similar to the |\NyquistZPK| macro above. The only difference is a slightly different parsing of the mandatory arguments via |\build at TF@plot|.
+%    \begin{macrocode}
+\newcommand{\NyquistTF}[4][]{%
+  \parse at N@opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{axis}[%
+        bodeStyle,
+        domain=#3:#4,
+        height=5cm,
+        xlabel={$\Re$},
+        ylabel={$\Im$},
+        samples=500,
+        \opt at axes,]}
+  \temp at cmd
+      \addplot [only marks,mark=+,thick,red] (-1 , 0);
+      \edef\temp at cmd{\noexpand\addplot[thick,\unexpanded\expandafter{\opt at plot}]}%
+      \if at pgfarg
+        \temp at cmd ( {\n at pow{10}{((\func at mag)/20)}*cos(\func at ph)},
+          {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
+      \else
+        \stepcounter{idGnuplot}%
+        \temp at cmd gnuplot[parametric,gnuplot degrees,gnuplot def]{%
+          \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
+          \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
+      \fi
+    \end{axis}
+  \end{tikzpicture}
+}
+%    \end{macrocode}
+% \end{macro}
+% \begin{macro}{\addNyquistZPKPlot}
+% Adds Nyquist plot of a transfer function in ZPK form. This macro is designed to pass two parametric function to an |\addplot| macro. The parametric functions for phase (|\func at ph|) and magnitude (|\func at mag|) are built using the |\build at ZPK@plot| macro, converted to real and imaginary parts and passed to |\addplot| commands.
+%    \begin{macrocode}
+\newcommand{\addNyquistZPKPlot}[2][]{%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{}{#2}%
+  \if at pgfarg
+    \addplot [#1] ( {\n at pow{10}{((\func at mag)/20)}*cos(\func at ph)},
+      {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot [#1] gnuplot[parametric,gnuplot degrees,gnuplot def]{%
+      \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
+      \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
+  \fi
+}
+%    \end{macrocode}
+%\end{macro}
+% \begin{macro}{\addNyquistTFPlot}
+% Adds Nyquist plot of a transfer function in TF form. This macro is designed to pass two parametric function to an |\addplot| macro. The parametric functions for phase (|\func at ph|) and magnitude (|\func at mag|) are built using the |\build at TF@plot| macro, converted to real and imaginary parts and passed to |\addplot| commands.
+%    \begin{macrocode}
+\newcommand{\addNyquistTFPlot}[2][]{%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \if at pgfarg
+    \addplot [#1] ( {\n at pow{10}{((\func at mag)/20)}*cos(\func at ph)},
+      {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot [#1] gnuplot[parametric,gnuplot degrees,gnuplot def]{%
+      \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
+      \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
+  \fi
+}
+%    \end{macrocode}
+%\end{macro}
+%\begin{macro}{NyquistPlot}
+% An environment to host |\addNyquist...| macros that pass parametric functions to |\addplot|. Uses the defaults specified in |bodeStyle| to create a shortcut that includes the |tikzpicture| and |axis| environments.
+%    \begin{macrocode}
+\newenvironment{NyquistPlot}[3][]{%
+  \begin{tikzpicture}
+    \begin{axis}[%
+      bodeStyle,
+      height=5cm,
+      domain=#2:#3,
+      xlabel={$\Re$},
+      ylabel={$\Im$},
+      #1]
+    \addplot [only marks,mark=+,thick,red] (-1 , 0);
+}{%
+    \end{axis}
+  \end{tikzpicture}
+}
+%    \end{macrocode}
+%\end{macro}
+% \subsubsection{Internal commands\label{sec:NInternal}}
+% \begin{macro}{\parse at opt}
+% Parses options supplied to the main Nyquist and Nichols macros. A |for| loop over tuples of the form |\obj/\opt|, processed using nested if-else statements does the job. The input |\obj| is either |plot| or |axes|, and the corresponding |\opt| are passed to the |\addplot| macro and the |axis| environment, respectively. If the input tuples contain macros, they are to be passed to respective |pgf| macros unexpanded.
+%    \begin{macrocode}
+\newcommand{\parse at N@opt}[1]{%
+  \gdef\opt at axes{}%
+  \gdef\opt at plot{}%
+  \foreach \obj/\opt in {#1} {%
+    \ifnum\pdfstrcmp{\obj}{axes}=0
+      \xdef\opt at axes{\unexpanded\expandafter{\opt}}%
+    \else
+      \ifnum\pdfstrcmp{\obj}{plot}=0
+        \xdef\opt at plot{\unexpanded\expandafter{\opt}}%
+      \else
+        \xdef\opt at plot{\unexpanded\expandafter{\obj}}%
+      \fi
+    \fi
+  }%
+}
+%    \end{macrocode}
+% \end{macro}
+% \subsection{Nichols charts}
+% \begin{macro}{\NicholsZPK}
+% \begin{macro}{\NicholsTF}
+% \begin{macro}{NicholsChart}
+% \begin{macro}{\addNicholsZPKChart}
+% \begin{macro}{\addNicholsTFChart}
+% These macros and the |NicholsChart| environment generate Nichols charts, and they are implemented similar to their Nyquist counterparts.
+%    \begin{macrocode}
+\newcommand{\NicholsZPK}[4][]{%
+  \parse at N@opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{axis}[%
+        bodeStyle,
+        domain=#3:#4,
+        height=5cm,
+        xlabel={Phase (degrees)},
+        ylabel={Gain (dB)},
+        samples=500,
+        \opt at axes]}
+  \temp at cmd
+      \edef\temp at cmd{\noexpand\addplot[red,thick,\opt at plot]}%
+      \if at pgfarg
+        \temp at cmd ( {\func at ph} , {\func at mag} );
+      \else
+        \stepcounter{idGnuplot}%
+        \temp at cmd gnuplot[parametric, gnuplot degrees, gnuplot def]
+          { \func at ph , \func at mag };
+      \fi
+    \end{axis}
+  \end{tikzpicture}
+}
+\newcommand{\NicholsTF}[4][]{%
+  \parse at N@opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{axis}[%
+        bodeStyle,
+        domain=#3:#4,
+        height=5cm,
+        xlabel={Phase (degrees)},
+        ylabel={Gain (dB)},
+        samples=500,
+        \opt at axes]}
+  \temp at cmd
+      \edef\temp at cmd{\noexpand\addplot[red,thick,\opt at plot]}%
+      \if at pgfarg
+        \temp at cmd ( {\func at ph} , {\func at mag} );
+      \else
+        \stepcounter{idGnuplot}%
+        \temp at cmd gnuplot[parametric, gnuplot degrees, gnuplot def]
+          { \func at ph , \func at mag };
+      \fi
+    \end{axis}
+  \end{tikzpicture}
+}
+\newenvironment{NicholsChart}[3][]{%
+  \begin{tikzpicture}
+    \begin{axis}[%
+      bodeStyle,
+      domain=#2:#3,
+      height=5cm,
+      ytick distance=20,
+      xtick distance=15,
+      xlabel={Phase (degrees)},
+      ylabel={Gain (dB)},
+      #1]
+}{
+    \end{axis}
+  \end{tikzpicture}
+}
+\newcommand{\addNicholsZPKChart}[2][]{%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{}{#2}%
+  \if at pgfarg
+    \addplot [#1] ( {\func at ph} , {\func at mag} );
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot [#1] gnuplot[parametric,gnuplot degrees,gnuplot def]
+      {\func at ph , \func at mag};
+  \fi
+}
+\newcommand{\addNicholsTFChart}[2][]{%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \if at pgfarg
+    \addplot [#1] ( {\func at ph} , {\func at mag} );
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot [#1] gnuplot[gnuplot degrees,gnuplot def]
+      {\func at ph , \func at mag};
+  \fi
+}
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \Finale
+\endinput
\ No newline at end of file


Property changes on: trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.dtx
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.ins	                        (rev 0)
+++ trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.ins	2021-10-30 19:39:33 UTC (rev 60899)
@@ -0,0 +1,41 @@
+%%
+%% Copyright (C) 2021 by Rushikesh Kamalapurkar
+%%
+%% This file may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.3c of this license or (at your option) any later
+%% version. The latest version of this license is in:
+%%
+%% http://www.latex-project.org/lppl.txt
+%%
+%% and version 1.3c or later is part of all distributions of
+%% LaTeX version 2006/05/20 or later.
+%%
+\input docstrip.tex
+\keepsilent
+\usedir{tex/latex/bodeplot}
+\preamble
+This is a generated file.
+Copyright (C) 2021 by Rushikesh Kamalapurkar
+This file may be distributed and/or modified under the
+conditions of the LaTeX Project Public License, either
+version 1.3c of this license or (at your option) any later
+version. The latest version of this license is in:
+http://www.latex-project.org/lppl.txt
+and version 1.3c or later is part of all distributions of
+LaTeX version 2006/05/20 or later.
+\endpreamble
+\generate{\file{bodeplot.sty}{\from{bodeplot.dtx}{package}}}
+\Msg{*********************************************************}
+\Msg{*}
+\Msg{* To finish the installation you have to move the}
+\Msg{* following file into a directory searched by TeX:}
+\Msg{*}
+\Msg{* bodeplot.sty}
+\Msg{*}
+\Msg{* To produce the documentation run the file bodeplot.dtx}
+\Msg{* through LaTeX.}
+\Msg{*}
+\Msg{* Happy TeXing!}
+\Msg{*********************************************************}
+\endbatchfile
\ No newline at end of file

Added: trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty	2021-10-30 19:39:33 UTC (rev 60899)
@@ -0,0 +1,681 @@
+%%
+%% This is file `bodeplot.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% bodeplot.dtx  (with options: `package')
+%% This is a generated file.
+%% Copyright (C) 2021 by Rushikesh Kamalapurkar
+%% This file may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.3c of this license or (at your option) any later
+%% version. The latest version of this license is in:
+%% http://www.latex-project.org/lppl.txt
+%% and version 1.3c or later is part of all distributions of
+%% LaTeX version 2006/05/20 or later.
+ \NeedsTeXFormat{LaTeX2e}[2006/05/20]
+ \ProvidesPackage{bodeplot}
+ \RequirePackage{tikz}
+ \RequirePackage{pgfplots}
+ \pgfplotsset{compat=1.18,variable=t}
+ \usepgfplotslibrary{groupplots}
+
+\RequirePackage{ifluatex}%
+\ifluatex
+  \RequirePackage{pdftexcmds}%
+  \let\pdfstrcmp\pdf at strcmp
+\fi
+\newif\if at pgfarg\@pgfargfalse
+\DeclareOption{pgf}{%
+  \@pgfargtrue
+}
+\ProcessOptions\relax
+\if at pgfarg
+  \newcommand{\n at pow}[2]{(#1)^(#2)}%
+  \newcommand{\n at mod}[2]{mod((#1),(#2))}%
+\else
+  \newcommand{\n at pow}[2]{(#1)**(#2)}%
+  \newcommand{\n at mod}[2]{(#1)-(floor((#1)/(#2))*(#2))}%
+  \newcounter{idGnuplot}%
+  \setcounter{idGnuplot}{0}%
+  \tikzset{%
+    gnuplot def/.style={%
+      id=\arabic{idGnuplot},
+      prefix=gnuplot/
+    }%
+  }
+  \pgfplotsset{%
+    gnuplot degrees/.code={%
+      \ifnum\value{idGnuplot}=1
+        \xdef\pgfplots at gnuplot@format{\pgfplots at gnuplot@format set angles degrees;}%
+      \fi
+    }%
+  }
+\fi
+\pgfplotsset{%
+  bodeStyle/.style = {%
+    label style={font=\footnotesize},
+    tick label style={font=\footnotesize},
+    grid=both,
+    major grid style={color=gray!80},
+    minor grid style={color=gray!20},
+    x label style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
+    y label style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
+    scale only axis,
+    samples=200,
+    width=5cm,
+  }%
+}
+\newcommand*{\MagK}[2]{(20*log10(abs(#1)))}
+\newcommand*{\MagKAsymp}{\MagK}
+\newcommand*{\MagKLin}{\MagK}
+\newcommand*{\PhK}[2]{(#1<0?-180:0)}
+\newcommand*{\PhKAsymp}{\PhK}
+\newcommand*{\PhKLin}{\PhK}
+\newcommand*{\MagDel}[2]{0}
+\newcommand*{\PhDel}[2]{-#1*180*t/pi}
+\newcommand*{\MagPole}[2]
+  {(-20*log10(sqrt(\n at pow{#1}{2} + \n at pow{t - (#2)}{2})))}
+\newcommand*{\MagPoleLin}[2]{(t < sqrt(\n at pow{#1}{2} + \n at pow{#2}{2}) ?
+  -20*log10(sqrt(\n at pow{#1}{2} + \n at pow{#2}{2})) :
+  -20*log10(t)
+  )}
+\newcommand*{\MagPoleAsymp}{\MagPoleLin}
+\newcommand*{\PhPole}[2]{(#1 > 0 ? (#2 > 0 ?
+  (\n at mod{-atan2((t - (#2)),-(#1))+360}{360}) :
+  (-atan2((t - (#2)),-(#1)))) :
+  (-atan2((t - (#2)),-(#1))))}
+\newcommand*{\PhPoleLin}[2]{%
+  (abs(#1)+abs(#2) == 0 ? -90 :
+  (t < (sqrt(\n at pow{#1}{2} + \n at pow{#2}{2}) /
+    (\n at pow{10}{sqrt(\n at pow{#1}{2}/(\n at pow{#1}{2} + \n at pow{#2}{2}))})) ?
+  (-atan2(-(#2),-(#1))) :
+  (t >= (sqrt(\n at pow{#1}{2} + \n at pow{#2}{2}) *
+    (\n at pow{10}{sqrt(\n at pow{#1}{2}/(\n at pow{#1}{2} + \n at pow{#2}{2}))})) ?
+  (#2>0?(#1>0?270:-90):-90) :
+  (-atan2(-(#2),-(#1)) + (log10(t/(sqrt(\n at pow{#1}{2} + \n at pow{#2}{2}) /
+    (\n at pow{10}{sqrt(\n at pow{#1}{2}/(\n at pow{#1}{2} +
+    \n at pow{#2}{2}))}))))*((#2>0?(#1>0?270:-90):-90) + atan2(-(#2),-(#1)))/
+    (log10(\n at pow{10}{sqrt((4*\n at pow{#1}{2})/
+    (\n at pow{#1}{2} + \n at pow{#2}{2}))}))))))}
+\newcommand*{\PhPoleAsymp}[2]{(t < (sqrt(\n at pow{#1}{2} + \n at pow{#2}{2})) ?
+  (-atan2(-(#2),-(#1))) :
+  (#2>0?(#1>0?270:-90):-90))}
+\newcommand*{\MagZero}{0-\MagPole}
+\newcommand*{\MagZeroLin}{0-\MagPoleLin}
+\newcommand*{\MagZeroAsymp}{0-\MagPoleAsymp}
+\newcommand*{\PhZero}{0-\PhPole}
+\newcommand*{\PhZeroLin}{0-\PhPoleLin}
+\newcommand*{\PhZeroAsymp}{0-\PhPoleAsymp}
+\newcommand*{\MagCSPoles}[2]{(-20*log10(sqrt(\n at pow{\n at pow{#2}{2}
+    - \n at pow{t}{2}}{2} + \n at pow{2*#1*#2*t}{2})))}
+\newcommand*{\MagCSPolesLin}[2]{(t < #2 ? -40*log10(#2) : - 40*log10(t))}
+\newcommand*{\MagCSPolesAsymp}{\MagCSPolesLin}
+\newcommand*{\PhCSPoles}[2]{(-atan2((2*(#1)*(#2)*t),(\n at pow{#2}{2}
+  - \n at pow{t}{2})))}
+\newcommand*{\PhCSPolesLin}[2]{(t < (#2 / (\n at pow{10}{abs(#1)})) ?
+  0 :
+  (t >= (#2 * (\n at pow{10}{abs(#1)})) ?
+  (#1>0 ? -180 : 180) :
+  (#1>0 ? (-180*(log10(t*(\n at pow{10}{#1})/#2))/(2*#1)) :
+    (180*(log10(t*(\n at pow{10}{abs(#1)})/#2))/(2*abs(#1))))))}
+\newcommand*{\PhCSPolesAsymp}[2]{(#1>0?(t<#2?0:-180):(t<#2?0:180))}
+\newcommand*{\MagCSZeros}{0-\MagCSPoles}
+\newcommand*{\MagCSZerosLin}{0-\MagCSPolesLin}
+\newcommand*{\MagCSZerosAsymp}{0-\MagCSPolesAsymp}
+\newcommand*{\PhCSZeros}{0-\PhCSPoles}
+\newcommand*{\PhCSZerosLin}{0-\PhCSPolesLin}
+\newcommand*{\PhCSZerosAsymp}{0-\PhCSPolesAsymp}
+\newcommand*{\MagCSPolesPeak}[3][]{%
+  \draw[#1,->] (axis cs:{#3},{-40*log10(#3)}) --
+  (axis cs:{#3},{-40*log10(#3)-20*log10(2*abs(#2))})
+}
+\newcommand*{\MagCSZerosPeak}[3][]{%
+  \draw[#1,->] (axis cs:{#3},{40*log10(#3)}) --
+  (axis cs:{#3},{40*log10(#3)+20*log10(2*abs(#2))})
+}
+\newcommand*{\MagSOPoles}[2]{%
+  (-20*log10(sqrt(\n at pow{#2 - \n at pow{t}{2}}{2} + \n at pow{#1*t}{2})))}
+\newcommand*{\MagSOPolesLin}[2]{%
+  (t < sqrt(abs(#2)) ? -20*log10(abs(#2)) : - 40*log10(t))}
+\newcommand*{\MagSOPolesAsymp}{\MagSOPolesLin}
+\newcommand*{\PhSOPoles}[2]{(-atan2((#1)*t,((#2) - \n at pow{t}{2})))}
+\newcommand*{\PhSOPolesLin}[2]{(#2>0 ?
+  \PhCSPolesLin{(#1/(2*sqrt(#2)))}{(sqrt(#2))} :
+  (#1>0 ? -180 : 180))}
+\newcommand*{\PhSOPolesAsymp}[2]{(#2>0 ?
+  \PhCSPolesAsymp{(#1/(2*sqrt(#2)))}{(sqrt(#2))} :
+  (#1>0 ? -180 : 180))}
+\newcommand*{\MagSOZeros}{0-\MagSOPoles}
+\newcommand*{\MagSOZerosLin}{0-\MagSOPolesLin}
+\newcommand*{\MagSOZerosAsymp}{0-\MagSOPolesAsymp}
+\newcommand*{\PhSOZeros}{0-\PhSOPoles}
+\newcommand*{\PhSOZerosLin}{0-\PhSOPolesLin}
+\newcommand*{\PhSOZerosAsymp}{0-\PhSOPolesAsymp}
+\newcommand*{\MagSOPolesPeak}[3][]{%
+  \draw[#1,->] (axis cs:{sqrt(abs(#3))},{-20*log10(abs(#3))}) --
+  (axis cs:{sqrt(abs(#3))},{-20*log10(abs(#3)) -
+    20*log10(abs(#2/sqrt(abs(#3))))});
+}
+\newcommand*{\MagSOZerosPeak}[3][]{%
+  \draw[#1,->] (axis cs:{sqrt(abs(#3))},{20*log10(abs(#3))}) --
+  (axis cs:{sqrt(abs(#3))},{20*log10(abs(#3)) +
+    20*log10(abs(#2/sqrt(abs(#3))))});
+}
+\newcommand{\BodeZPK}[4][]{%
+  \parse at opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{\opt at approx}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{groupplot}[%
+    bodeStyle,
+    xmin={#3},
+    xmax={#4},
+    domain=#3:#4,
+    height=2.5cm,
+    xmode=log,
+    group style = {group size = 1 by 2,vertical sep=0.25cm,},
+    \opt at group,]}
+  \temp at cmd
+  \if at pgfarg
+    \expandafter\nextgroupplot\expandafter[ytick distance=20,
+      ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optmag at plot]}%
+    \temp at cmd {\func at mag};
+    \expandafter\nextgroupplot\expandafter[ytick distance=45,
+      ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optph at plot]}%
+    \temp at cmd {\func at ph};
+  \else
+    \stepcounter{idGnuplot}
+    \expandafter\nextgroupplot\expandafter[ytick distance=20,
+      ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optmag at plot]}%
+    \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\func at mag};
+    \stepcounter{idGnuplot}
+    \expandafter\nextgroupplot\expandafter[ytick distance=45,
+      ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optph at plot]}%
+    \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\func at ph};
+  \fi
+  \end{groupplot}\end{tikzpicture}}
+\newcommand{\BodeTF}[4][]{%
+  \parse at opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{groupplot}[%
+    bodeStyle,
+    xmin={#3},
+    xmax={#4},
+    domain=#3:#4,
+    height=2.5cm,
+    xmode=log,
+    group style = {group size = 1 by 2,vertical sep=0.25cm,},
+    \opt at group,]}
+  \temp at cmd
+  \if at pgfarg
+    \expandafter\nextgroupplot\expandafter[ytick distance=20,
+      ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optmag at plot]}%
+    \temp at cmd {\func at mag};
+    \expandafter\nextgroupplot\expandafter[ytick distance=45,
+      ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optph at plot]}%
+    \temp at cmd {\func at ph};
+  \else
+    \stepcounter{idGnuplot}%
+    \expandafter\nextgroupplot\expandafter[ytick distance=20,
+      ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optmag at plot]}%
+    \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\func at mag};
+    \stepcounter{idGnuplot}%
+    \expandafter\nextgroupplot\expandafter[ytick distance=45,
+      ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
+    \edef\temp at cmd{\noexpand\addplot[red,thick,\optph at plot]}%
+    \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\func at ph};
+  \fi
+  \end{groupplot}\end{tikzpicture}}
+\newcommand{\addBodeZPKPlots}[3][{}]{%
+  \foreach \approx/\opt in {#1} {%
+    \gdef\plot at macro{}%
+    \gdef\temp at macro{}%
+    \ifnum\pdfstrcmp{#2}{phase}=0
+      \build at ZPK@plot{\temp at macro}{\plot at macro}{\approx}{#3}%
+    \else
+      \build at ZPK@plot{\plot at macro}{\temp at macro}{\approx}{#3}%
+    \fi
+    \if at pgfarg
+      \edef\temp at cmd{\noexpand\addplot[red,thick,\opt]}%
+      \temp at cmd {\plot at macro};
+    \else
+      \stepcounter{idGnuplot}%
+      \edef\temp at cmd{\noexpand\addplot[red,thick,\opt]}
+      \temp at cmd gnuplot[gnuplot degrees,gnuplot def] {\plot at macro};
+    \fi
+  }%
+}
+\newcommand{\addBodeTFPlot}[3][red,thick]{%
+  \gdef\plot at macro{}%
+  \gdef\temp at macro{}%
+  \ifnum\pdfstrcmp{#2}{phase}=0
+    \build at TF@plot{\temp at macro}{\plot at macro}{#3}%
+  \else
+    \build at TF@plot{\plot at macro}{\temp at macro}{#3}%
+  \fi
+  \if at pgfarg
+    \addplot[#1]{\plot at macro};
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot[#1] gnuplot[gnuplot degrees, gnuplot def] {\plot at macro};
+  \fi
+}
+\newcommand{\addBodeComponentPlot}[2][red,thick]{%
+  \if at pgfarg
+    \addplot[#1]{#2};
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot[#1] gnuplot[gnuplot degrees,gnuplot def] {#2};
+  \fi
+}
+\newenvironment{BodePlot}[3][]{%
+  \begin{tikzpicture}
+    \begin{semilogxaxis}[%
+      bodeStyle,
+      xmin={#2},
+      xmax={#3},
+      domain=#2:#3,
+      height=2.5cm,
+      xlabel={Frequency (rad/s)},
+      #1]
+}{
+  \end{semilogxaxis}
+  \end{tikzpicture}
+}
+\newcommand*{\add at feature}[3]{%
+  \ifcat$\detokenize\expandafter{#1}$%
+    \xdef#1{\unexpanded\expandafter{#1 0+#2}}%
+  \else
+    \xdef#1{\unexpanded\expandafter{#1+#2}}%
+  \fi
+  \foreach \y [count=\n] in #3 {%
+    \xdef#1{\unexpanded\expandafter{#1}{\y}}%
+    \xdef\Last at LoopValue{\n}%
+  }%
+  \ifnum\Last at LoopValue=1%
+    \xdef#1{\unexpanded\expandafter{#1}{0}}%
+  \fi
+}
+\newcommand{\build at ZPK@plot}[4]{%
+  \foreach \feature/\values in {#4} {%
+    \ifnum\pdfstrcmp{\feature}{z}=0
+      \foreach \z in \values {%
+        \ifnum\pdfstrcmp{#3}{linear}=0
+          \add at feature{#2}{\PhZeroLin}{\z}%
+          \add at feature{#1}{\MagZeroLin}{\z}%
+        \else
+          \ifnum\pdfstrcmp{#3}{asymptotic}=0
+            \add at feature{#2}{\PhZeroAsymp}{\z}%
+            \add at feature{#1}{\MagZeroAsymp}{\z}%
+          \else
+            \add at feature{#2}{\PhZero}{\z}%
+            \add at feature{#1}{\MagZero}{\z}%
+          \fi
+        \fi
+      }%
+    \fi
+    \ifnum\pdfstrcmp{\feature}{p}=0
+      \foreach \p in \values {%
+        \ifnum\pdfstrcmp{#3}{linear}=0
+          \add at feature{#2}{\PhPoleLin}{\p}%
+          \add at feature{#1}{\MagPoleLin}{\p}%
+        \else
+          \ifnum\pdfstrcmp{#3}{asymptotic}=0
+            \add at feature{#2}{\PhPoleAsymp}{\p}%
+            \add at feature{#1}{\MagPoleAsymp}{\p}%
+          \else
+            \add at feature{#2}{\PhPole}{\p}%
+            \add at feature{#1}{\MagPole}{\p}%
+          \fi
+        \fi
+      }%
+    \fi
+    \ifnum\pdfstrcmp{\feature}{k}=0
+      \ifnum\pdfstrcmp{#3}{linear}=0
+        \add at feature{#2}{\PhKLin}{\values}%
+        \add at feature{#1}{\MagKLin}{\values}%
+      \else
+        \ifnum\pdfstrcmp{#3}{asymptotic}=0
+          \add at feature{#2}{\PhKAsymp}{\values}%
+          \add at feature{#1}{\MagKAsymp}{\values}%
+        \else
+          \add at feature{#2}{\PhK}{\values}%
+          \add at feature{#1}{\MagK}{\values}%
+        \fi
+      \fi
+    \fi
+    \ifnum\pdfstrcmp{\feature}{d}=0
+      \ifnum\pdfstrcmp{#3}{linear}=0
+        \PackageError {bodeplot} {Linear approximation for pure delays is not
+        supported.} {Plot the true Bode plot using 'true' instead of 'linear'.}
+      \else
+        \ifnum\pdfstrcmp{#3}{asymptotic}=0
+          \PackageError {bodeplot} {Asymptotic approximation for pure delays is not
+          supported.} {Plot the true Bode plot using 'true' instead of 'asymptotic'.}
+        \else
+          \ifdim\values pt < 0pt
+            \PackageError {bodeplot} {Delay needs to be a positive number.}
+          \fi
+          \add at feature{#2}{\PhDel}{\values}%
+          \add at feature{#1}{\MagDel}{\values}%
+        \fi
+      \fi
+    \fi
+  }%
+}
+\newcommand{\build at TF@plot}[3]{%
+  \gdef\num at real{0}%
+  \gdef\num at im{0}%
+  \gdef\den at real{0}%
+  \gdef\den at im{0}%
+  \gdef\loop at delay{0}%
+  \foreach \feature/\values in {#3} {%
+    \ifnum\pdfstrcmp{\feature}{num}=0
+      \foreach \numcoeff [count=\numpow] in \values {%
+        \xdef\num at degree{\numpow}%
+      }%
+      \foreach \numcoeff [count=\numpow] in \values {%
+        \pgfmathtruncatemacro{\currentdegree}{\num at degree-\numpow}%
+        \ifnum\currentdegree = 0
+          \xdef\num at real{\num at real+\numcoeff}%
+        \else
+          \ifodd\currentdegree
+            \xdef\num at im{\num at im+(\numcoeff*(\n at pow{-1}{(\currentdegree-1)/2})*%
+              (\n at pow{t}{\currentdegree}))}%
+          \else
+            \xdef\num at real{\num at real+(\numcoeff*(\n at pow{-1}{(\currentdegree)/2})*%
+              (\n at pow{t}{\currentdegree}))}%
+          \fi
+        \fi
+      }%
+    \fi
+    \ifnum\pdfstrcmp{\feature}{den}=0
+      \foreach \dencoeff [count=\denpow] in \values {%
+        \xdef\den at degree{\denpow}%
+      }%
+      \foreach \dencoeff [count=\denpow] in \values {%
+        \pgfmathtruncatemacro{\currentdegree}{\den at degree-\denpow}%
+        \ifnum\currentdegree = 0
+          \xdef\den at real{\den at real+\dencoeff}%
+        \else
+          \ifodd\currentdegree
+            \xdef\den at im{\den at im+(\dencoeff*(\n at pow{-1}{(\currentdegree-1)/2})*%
+              (\n at pow{t}{\currentdegree}))}%
+          \else
+            \xdef\den at real{\den at real+(\dencoeff*(\n at pow{-1}{(\currentdegree)/2})*%
+              (\n at pow{t}{\currentdegree}))}%
+          \fi
+        \fi
+      }%
+    \fi
+    \ifnum\pdfstrcmp{\feature}{d}=0
+      \xdef\loop at delay{\values}%
+    \fi
+  }%
+  \xdef#2{(\n at mod{atan2((\num at im),(\num at real))-atan2((\den at im),%
+    (\den at real))+360}{360}-\loop at delay*180*t/pi)}%
+  \xdef#1{(20*log10(sqrt((\n at pow{\num at real}{2})+(\n at pow{\num at im}{2})))-%
+    20*log10(sqrt((\n at pow{\den at real}{2})+(\n at pow{\den at im}{2}))))}%
+}
+\newcommand{\parse at opt}[1]{%
+  \gdef\optmag at axes{}%
+  \gdef\optph at axes{}%
+  \gdef\optph at plot{}%
+  \gdef\optmag at plot{}%
+  \gdef\opt at group{}%
+  \gdef\opt at approx{}%
+  \foreach \obj/\typ/\opt in {#1} {%
+    \ifnum\pdfstrcmp{\obj}{plot}=0
+      \ifnum\pdfstrcmp{\typ}{mag}=0
+        \xdef\optmag at plot{\optmag at plot,\opt}%
+      \else
+        \ifnum\pdfstrcmp{\typ}{ph}=0
+          \xdef\optph at plot{\optph at plot,\opt}%
+        \else
+          \xdef\optmag at plot{\optmag at plot,\opt}%
+          \xdef\optph at plot{\optph at plot,\opt}%
+        \fi
+      \fi
+    \else
+      \ifnum\pdfstrcmp{\obj}{axes}=0
+        \ifnum\pdfstrcmp{\typ}{mag}=0
+          \xdef\optmag at axes{\optmag at axes,\opt}%
+        \else
+          \ifnum\pdfstrcmp{\typ}{ph}=0
+            \xdef\optph at axes{\optph at axes,\opt}%
+          \else
+            \xdef\optmag at axes{\optmag at axes,\opt}%
+            \xdef\optph at axes{\optph at axes,\opt}%
+          \fi
+        \fi
+      \else
+        \ifnum\pdfstrcmp{\obj}{group}=0
+          \xdef\opt at group{\opt at group,\opt}%
+        \else
+          \ifnum\pdfstrcmp{\obj}{approx}=0
+            \xdef\opt at approx{\typ}%
+          \else
+            \xdef\optmag at plot{\optmag at plot,\obj}%
+            \xdef\optph at plot{\optph at plot,\obj}%
+          \fi
+        \fi
+      \fi
+    \fi
+  }%
+}
+\newcommand{\NyquistZPK}[4][]{%
+  \parse at N@opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{axis}[%
+        bodeStyle,
+        domain=#3:#4,
+        height=5cm,
+        xlabel={$\Re$},
+        ylabel={$\Im$},
+        samples=500,
+        \opt at axes,]}%
+  \temp at cmd
+      \addplot [only marks,mark=+,thick,red] (-1 , 0);
+      \edef\temp at cmd{\noexpand\addplot[thick,\unexpanded\expandafter{\opt at plot}]}%
+      \if at pgfarg
+        \temp at cmd ( {\n at pow{10}{((\func at mag)/20)}*cos(\func at ph)},
+          {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
+      \else
+        \stepcounter{idGnuplot}%
+        \temp at cmd gnuplot[parametric,gnuplot degrees,gnuplot def] {%
+          \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
+          \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
+      \fi
+    \end{axis}
+  \end{tikzpicture}
+}
+\newcommand{\NyquistTF}[4][]{%
+  \parse at N@opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{axis}[%
+        bodeStyle,
+        domain=#3:#4,
+        height=5cm,
+        xlabel={$\Re$},
+        ylabel={$\Im$},
+        samples=500,
+        \opt at axes,]}
+  \temp at cmd
+      \addplot [only marks,mark=+,thick,red] (-1 , 0);
+      \edef\temp at cmd{\noexpand\addplot[thick,\unexpanded\expandafter{\opt at plot}]}%
+      \if at pgfarg
+        \temp at cmd ( {\n at pow{10}{((\func at mag)/20)}*cos(\func at ph)},
+          {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
+      \else
+        \stepcounter{idGnuplot}%
+        \temp at cmd gnuplot[parametric,gnuplot degrees,gnuplot def]{%
+          \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
+          \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
+      \fi
+    \end{axis}
+  \end{tikzpicture}
+}
+\newcommand{\addNyquistZPKPlot}[2][]{%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{}{#2}%
+  \if at pgfarg
+    \addplot [#1] ( {\n at pow{10}{((\func at mag)/20)}*cos(\func at ph)},
+      {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot [#1] gnuplot[parametric,gnuplot degrees,gnuplot def]{%
+      \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
+      \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
+  \fi
+}
+\newcommand{\addNyquistTFPlot}[2][]{%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \if at pgfarg
+    \addplot [#1] ( {\n at pow{10}{((\func at mag)/20)}*cos(\func at ph)},
+      {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot [#1] gnuplot[parametric,gnuplot degrees,gnuplot def]{%
+      \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
+      \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
+  \fi
+}
+\newenvironment{NyquistPlot}[3][]{%
+  \begin{tikzpicture}
+    \begin{axis}[%
+      bodeStyle,
+      height=5cm,
+      domain=#2:#3,
+      xlabel={$\Re$},
+      ylabel={$\Im$},
+      #1]
+    \addplot [only marks,mark=+,thick,red] (-1 , 0);
+}{%
+    \end{axis}
+  \end{tikzpicture}
+}
+\newcommand{\parse at N@opt}[1]{%
+  \gdef\opt at axes{}%
+  \gdef\opt at plot{}%
+  \foreach \obj/\opt in {#1} {%
+    \ifnum\pdfstrcmp{\obj}{axes}=0
+      \xdef\opt at axes{\unexpanded\expandafter{\opt}}%
+    \else
+      \ifnum\pdfstrcmp{\obj}{plot}=0
+        \xdef\opt at plot{\unexpanded\expandafter{\opt}}%
+      \else
+        \xdef\opt at plot{\unexpanded\expandafter{\obj}}%
+      \fi
+    \fi
+  }%
+}
+\newcommand{\NicholsZPK}[4][]{%
+  \parse at N@opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{axis}[%
+        bodeStyle,
+        domain=#3:#4,
+        height=5cm,
+        xlabel={Phase (degrees)},
+        ylabel={Gain (dB)},
+        samples=500,
+        \opt at axes]}
+  \temp at cmd
+      \edef\temp at cmd{\noexpand\addplot[red,thick,\opt at plot]}%
+      \if at pgfarg
+        \temp at cmd ( {\func at ph} , {\func at mag} );
+      \else
+        \stepcounter{idGnuplot}%
+        \temp at cmd gnuplot[parametric, gnuplot degrees, gnuplot def]
+          { \func at ph , \func at mag };
+      \fi
+    \end{axis}
+  \end{tikzpicture}
+}
+\newcommand{\NicholsTF}[4][]{%
+  \parse at N@opt{#1}%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture}\noexpand\begin{axis}[%
+        bodeStyle,
+        domain=#3:#4,
+        height=5cm,
+        xlabel={Phase (degrees)},
+        ylabel={Gain (dB)},
+        samples=500,
+        \opt at axes]}
+  \temp at cmd
+      \edef\temp at cmd{\noexpand\addplot[red,thick,\opt at plot]}%
+      \if at pgfarg
+        \temp at cmd ( {\func at ph} , {\func at mag} );
+      \else
+        \stepcounter{idGnuplot}%
+        \temp at cmd gnuplot[parametric, gnuplot degrees, gnuplot def]
+          { \func at ph , \func at mag };
+      \fi
+    \end{axis}
+  \end{tikzpicture}
+}
+\newenvironment{NicholsChart}[3][]{%
+  \begin{tikzpicture}
+    \begin{axis}[%
+      bodeStyle,
+      domain=#2:#3,
+      height=5cm,
+      ytick distance=20,
+      xtick distance=15,
+      xlabel={Phase (degrees)},
+      ylabel={Gain (dB)},
+      #1]
+}{
+    \end{axis}
+  \end{tikzpicture}
+}
+\newcommand{\addNicholsZPKChart}[2][]{%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at ZPK@plot{\func at mag}{\func at ph}{}{#2}%
+  \if at pgfarg
+    \addplot [#1] ( {\func at ph} , {\func at mag} );
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot [#1] gnuplot[parametric,gnuplot degrees,gnuplot def]
+      {\func at ph , \func at mag};
+  \fi
+}
+\newcommand{\addNicholsTFChart}[2][]{%
+  \gdef\func at mag{}%
+  \gdef\func at ph{}%
+  \build at TF@plot{\func at mag}{\func at ph}{#2}%
+  \if at pgfarg
+    \addplot [#1] ( {\func at ph} , {\func at mag} );
+  \else
+    \stepcounter{idGnuplot}%
+    \addplot [#1] gnuplot[gnuplot degrees,gnuplot def]
+      {\func at ph , \func at mag};
+  \fi
+}
+\endinput
+%%
+%% End of file `bodeplot.sty'.


Property changes on: trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/tlpkg/bin/tlpkg-ctan-check
===================================================================
--- trunk/Master/tlpkg/bin/tlpkg-ctan-check	2021-10-30 19:38:46 UTC (rev 60898)
+++ trunk/Master/tlpkg/bin/tlpkg-ctan-check	2021-10-30 19:39:33 UTC (rev 60899)
@@ -137,7 +137,7 @@
     bitelist bithesis bitpattern bitset bitter bizcard
     bjfuthesis blacklettert1 blindtext blkarray
     blochsphere block blockdraw_mp bloques blowup blox
-    bmstu-iu8 bnumexpr bodegraph bohr boisik bold-extra
+    bmstu-iu8 bnumexpr bodegraph bodeplot bohr boisik bold-extra
     boites boldtensors bondgraph bondgraphs book-of-common-prayer
     bookcover bookdb bookest bookhands booklet bookman bookmark
     bookshelf booktabs booktabs-de booktabs-fr boolexpr boondox bophook

Added: trunk/Master/tlpkg/tlpsrc/bodeplot.tlpsrc
===================================================================
Modified: trunk/Master/tlpkg/tlpsrc/collection-mathscience.tlpsrc
===================================================================
--- trunk/Master/tlpkg/tlpsrc/collection-mathscience.tlpsrc	2021-10-30 19:38:46 UTC (rev 60898)
+++ trunk/Master/tlpkg/tlpsrc/collection-mathscience.tlpsrc	2021-10-30 19:39:33 UTC (rev 60899)
@@ -24,6 +24,7 @@
 depend binomexp
 depend biocon
 depend bitpattern
+depend bodeplot
 depend bohr
 depend boldtensors
 depend bosisio



More information about the tex-live-commits mailing list.