texlive[63946] Master/texmf-dist: bodeplot (20jul22)

commits+karl at tug.org commits+karl at tug.org
Wed Jul 20 22:20:21 CEST 2022


Revision: 63946
          http://tug.org/svn/texlive?view=revision&revision=63946
Author:   karl
Date:     2022-07-20 22:20:21 +0200 (Wed, 20 Jul 2022)
Log Message:
-----------
bodeplot (20jul22)

Modified Paths:
--------------
    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/bodeplot.dtx
    trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty

Modified: trunk/Master/texmf-dist/doc/latex/bodeplot/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/bodeplot/README.md	2022-07-20 20:19:40 UTC (rev 63945)
+++ trunk/Master/texmf-dist/doc/latex/bodeplot/README.md	2022-07-20 20:20:21 UTC (rev 63946)
@@ -5,6 +5,16 @@
 
 *Version 1.0.8 and newer store `gnuplot` temporary files in the working directory. Use class option `declutter` to restore pre-v1.0.8 behavior. Option `declutter` can cause errors if used with a `tikzexternalize` prefix.*
 
+Compilation instructions:
+1) `latex bodeplot.ins` to generate `bodeplot.sty`
+2) To compile documentation (needs `gnuplot` on system PATH):
+```
+pdflatex bodeplot.dtx --shell-escape
+makeindex -s gind.ist bodeplot.idx
+makeindex -s gglo.ist -o bodeplot.gls bodeplot.glo
+pdflatex bodeplot.dtx --shell-escape
+pdflatex bodeplot.dtx --shell-escape
+```
 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.
@@ -42,4 +52,4 @@
     - `\addNyquistZPKPlot[plot-options]{z/{zeros},p/{poles},k/gain,d/delay}`
     - `\addNyquistTFPlot[plot-options]{num/{coeff},den/{coeff},d/delay}`
 
-Limitation: Phase plots from TF commands are wrapped between 0 and 360 degrees.
\ No newline at end of file
+Limitation: Nichols charts from TF commands are wrapped between 0 and 360 degrees.

Modified: trunk/Master/texmf-dist/doc/latex/bodeplot/bodeplot.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.dtx	2022-07-20 20:19:40 UTC (rev 63945)
+++ trunk/Master/texmf-dist/source/latex/bodeplot/bodeplot.dtx	2022-07-20 20:20:21 UTC (rev 63946)
@@ -18,7 +18,6 @@
 % \iffalse
 %<package>\NeedsTeXFormat{LaTeX2e}[2006/05/20]
 %<package>\ProvidesPackage{bodeplot}
-%<package>\RequirePackage{tikz}
 %<package>\RequirePackage{pdftexcmds}
 %<package>\RequirePackage{ifplatform}
 %<package>\RequirePackage{pgfplots}
@@ -55,6 +54,7 @@
   \geometry{lmargin=2in,rmargin=1in,tmargin=1in,bmargin=1in}
 \usetikzlibrary{decorations.markings,arrows.meta,spy,backgrounds}
 \usepackage[nottoc]{tocbibind}
+\sloppy
 \EnableCrossrefs
 \CodelineIndex
 \RecordChanges
@@ -66,7 +66,7 @@
 %</driver>
 % \fi
 %
-% \CheckSum{1375}
+% \CheckSum{1404}
 %
 % \changes{v1.0}{2021/10/25}{Initial release}
 % \changes{v1.0.4}{2021/11/05}{Fixed unintended optional argument macro expansion}
@@ -74,13 +74,12 @@
 % \changes{v1.0.7}{2021/12/02}{Removed unnecessary semicolons}
 % \changes{v1.0.7}{2022/01/18}{Updated documentation}
 % \changes{v1.0.8}{2022/07/06}{Added a new class option `declutter'}
+% \changes{v1.1.0}{2022/07/06}{Fixed phase wrapping in gnuplot mode}
 %
 % \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}~v1.0.8,
-% dated July 06, 2022.}}
+% \title{The \textsf{bodeplot} package\thanks{This document corresponds to \textsf{bodeplot}~v1.1.0, dated July 20, 2022.}}
 % \author{Rushikesh Kamalapurkar \\ \texttt{rlkamalapurkar at gmail.com}}
 %
 % \maketitle
@@ -88,14 +87,14 @@
 % \clearpage
 % \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}) \emph{with zero delay}, this package also supports linear and asymptotic approximation of Bode plots.
+% 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}) \emph{with zero delay}, this package also supports linear and asymptotic approximation of Bode plots. By default, all phase plots use degrees as units. Use the |rad| package option to generate plots in radians.
 % \subsection{External Dependencies}
-% By default, the package uses |gnuplot| to do all the computations. If |gnuplot| is not available, the |pgf| package option can be used to do the calculations using the native |pgf| math engine. Compilation using the |pgf| math engine is typically slower, but the end result should be the identical.
+% By default, the package uses |gnuplot| to do all the computations. If |gnuplot| is not available, the |pgf| package option can be used to do the calculations using the native |pgf| math engine. Compilation using the |pgf| math engine is typically slower, but the end result should be the identical (other than phase wrapping in the TF format, see limitations below).
 %\subsection{Directory Structure}
 % Since version 1.0.8, the |bodeplot| package places all |gnuplot| temporary files in the working directory. The package option |declutter| restores the original behavior where the temporary files are placed in a folder called |gnuplot|.
 % \subsection{Limitations} 
 % \begin{itemize}
-%   \item In TF form, the phase angles are always between 0 and 360$^\circ$. As such, the Bode phase plots and the Nyquist and Nichols plots will have phase wrapping discontinuities. I do not know how this can be rectified, pull requests are welcome!
+%   \item When plotting Nichols charts in TF form, the phase angles are wrapped between 0 and 360$^\circ$. As such, the Nichols charts will have phase wrapping discontinuities. Phase wrapping in Bode plots was fixed in v1.1.0 using |gnuplot|. In |pgf| mode, Bode phase plots, plotted using the TF form, will also show phase wrapping discontinuities.
 %   \item Use of the |declutter| option with other directory management tools such as a |tikzexternalize| prefix is not recommended.
 % \end{itemize}
 % \clearpage
@@ -123,7 +122,7 @@
 
 \hrulefill
 
-Bode plot in TF format with arrow decoration, transport delay, and color customization (note the phase wrapping)
+Bode plot in TF format with arrow decoration, transport delay, and color customization (the phase plot will show wrapping if the |pgf| package option is used)
 \begin{LTXexample}[pos=r,width=0.5\textwidth]
 \BodeTF[%
   samples=1000,
@@ -188,10 +187,8 @@
 
 \begin{minipage}[t]{0.45\textwidth}
 \begin{LTXexample}[pos=t,width=\columnwidth]
-\begin{BodePlot}[%
-  axes/{ylabel={Gain (dB)},
-  ytick distance=40,
-  height=2cm,
+\begin{BodeMagPlot}[%
+  axes/{height=2cm,
   width=4cm}
 ]
 {0.01}
@@ -207,13 +204,12 @@
     p/{{-0.5,-10},{-0.5,10}},
     k/10
   }
-\end{BodePlot}
+\end{BodeMagPlot}
 \end{LTXexample}
 \end{minipage}\hfill
 \begin{minipage}[t]{0.45\textwidth}
 \begin{LTXexample}[pos=t,width=\columnwidth]
-\begin{BodePlot}[%
-  ylabel={Phase ($^{\circ}$)},
+\begin{BodePhPlot}[%
   height=2cm,
   width=4cm,
   ytick distance=90
@@ -231,7 +227,7 @@
     p/{{-0.5,-10},{-0.5,10}},
     k/10
   }
-\end{BodePlot}
+\end{BodePhPlot}
 \end{LTXexample}
 \end{minipage}
 
@@ -243,20 +239,21 @@
 {%
   z/{0,{-0.1,-0.5},{-0.1,0.5}},
   p/{{-0.5,-10},{-0.5,10}},
-  k/10
+  k/10,
+  d/0.01
 }
 {0.001}
-{100}
+{500}
 \end{LTXexample}
 
 \hrulefill
 
-Nichols chart in TF format
+Same Nichols chart in TF format (shows phase wrapping discontinuity)
 \begin{LTXexample}[pos=r,hsep=20pt,width=0.5\textwidth]
 \NicholsTF[samples=1000]
-{num/{10,2,2.6,0},den/{1,1,100.25}}
+{num/{10,2,2.6,0},den/{1,1,100.25},d/0.01}
 {0.001}
-{100}
+{500}
 \end{LTXexample}
 
 \hrulefill
@@ -486,12 +483,12 @@
 % \end{center}
 % \end{figure}
 %
-% \DescribeEnv{BodePlot}
-% |\begin{BodePlot}|\oarg{obj1/\marg{opt1},obj2/\marg{opt2},...}\\
+% \DescribeEnv{BodeMagPlot}
+% |\begin{BodeMagPlot}|\oarg{obj1/\marg{opt1},obj2/\marg{opt2},...}\\
 % \hspace*{3em}\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 |\addBodeComponentPlot|. The optional argument is comprised of a comma separated list of tuples, either |obj/{opt}| or just |{opt}|. Each tuple passes options to different |pgfplots| macros that generate the axes and the plots according to:
+% \hspace*{1.5em}|\end{BodeMagPlot}|\\
+% The |BodeMagPlot| environment works in conjunction with the parametric function generator macros |\addBodeZPKPlots|, |\addBodeTFPlot|, and |\addBodeComponentPlot|, intended to be used for magnitude plots. The optional argument is comprised of a comma separated list of tuples, either |obj/{opt}| or just |{opt}|. Each tuple passes options to different |pgfplots| macros that generate the axes and the plots according to:
 % \begin{itemize}
 %  \item Tuples of the form |obj/{opt}|:
 %   \begin{itemize}
@@ -503,6 +500,13 @@
 % \end{itemize}
 % 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 |\addBodeComponentPlot|.
 %
+%\DescribeEnv{BodePhPlot}
+% |\begin{BodePhPlot}|\oarg{obj1/\marg{opt1},obj2/\marg{opt2},...}\\
+	% \hspace*{3em}\marg{min-frequency}\marg{max-frequency}\\
+	% \hspace*{2em}|\addBode...|\\
+	% \hspace*{1.5em}|\end{BodePhPlot}|\\
+% Intended to be used for phase plots, otherwise same as the |BodeMagPlot| environment
+%
 % \DescribeMacro{\addBodeZPKPlots}
 % |\addBodeZPKPlots| \oarg{approx1/\marg{opt1},approx2/\marg{opt2},...}\\
 % \hspace*{2em}\marg{plot-type}\\
@@ -512,8 +516,7 @@
 %
 % 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}
+%\begin{BodeMagPlot}[height=2cm,width=4cm] {0.01} {100}
 %  \addBodeZPKPlots[
 %    true/{black,thick},
 %    linear/{red,dashed,thick},
@@ -520,10 +523,9 @@
 %    asymptotic/{blue,dotted,thick}]
 %    {magnitude}
 %    {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}
-%\end{BodePlot}
+%\end{BodeMagPlot}
 %
-%\begin{BodePlot}[ylabel={Phase ($^{\circ}$)},
-%  height=2cm, width=4cm, ytick distance=90] {0.01} {100}
+%\begin{BodePhPlot}[height=2cm, width=4cm, ytick distance=90] {0.01} {100}
 %  \addBodeZPKPlots[
 %    true/{black,thick},
 %    linear/{red,dashed,thick},
@@ -530,13 +532,11 @@
 %    asymptotic/{blue,dotted,thick}]
 %    {phase}
 %    {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}
-%\end{BodePlot}
+%\end{BodePhPlot}
 %\end{verbatim}
 % \begin{figure}
 %  \begin{center}
-%    \begin{BodePlot}[ ylabel={Gain (dB)}, ytick distance=40,
-%      height=2cm, width=4cm] {0.01} {100}
-%
+%    \begin{BodeMagPlot}[height=2cm,width=4cm]{0.01}{100}
 %      \addBodeZPKPlots[
 %        true/{black,thick},
 %        linear/{red,dashed,thick},
@@ -543,10 +543,8 @@
 %        asymptotic/{blue,dotted,thick}]
 %      {magnitude}
 %      {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}
-%    \end{BodePlot}
-%    \begin{BodePlot}[ylabel={Phase ($^{\circ}$)},
-%      height=2cm, width=4cm, ytick distance=90] {0.01} {100}
-%
+%    \end{BodeMagPlot}
+%    \begin{BodePhPlot}[height=2cm,width=4cm,ytick distance=90]{0.01}{100}
 %      \addBodeZPKPlots[
 %        true/{black,thick},
 %        linear/{red,dashed,thick},
@@ -553,9 +551,9 @@
 %        asymptotic/{blue,dotted,thick}]
 %      {phase}
 %      {z/{0,{-0.1,-0.5},{-0.1,0.5}},p/{{-0.5,-10},{-0.5,10}},k/10}
-%    \end{BodePlot}
+%    \end{BodePhPlot}
 %  \end{center}
-%  \caption{\label{multiBodeZPK}Superimposed approximate and true Bode plots using the \texttt{BodePlot} environment and the \texttt{\textbackslash addBodeZPKPlots} macro.}
+%  \caption{\label{multiBodeZPK}Superimposed approximate and true Bode plots using the \texttt{BodeMagPlot} and \texttt{BodePhPlot} environments and the \texttt{\textbackslash addBodeZPKPlots} macro.}
 % \end{figure}
 % which generates the plot in Figure \ref{multiBodeZPK}.
 %
@@ -584,7 +582,7 @@
 % \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}
+%\begin{BodePhPlot}[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}}
@@ -594,17 +592,17 @@
 %  \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{BodePhPlot}
 %\end{verbatim}
 %\begin{figure}
 %  \begin{center}
-%    \begin{BodePlot}[ylabel={Phase (degree)},ytick distance=90]{0.01}{100}
+%    \begin{BodePhPlot}[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{BodePhPlot}
 %  \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.}
+%  \caption{\label{multiBodeComponents}Superimposed approximate and true Bode Phase plot using the \texttt{BodePhPlot} 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}.
 %
@@ -620,21 +618,21 @@
 %
 % \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}
+%\begin{BodeMagPlot}[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{BodeMagPlot}
 %\end{verbatim}
 % generates the plot in Figure \ref{BodePeak}.
 %
 % \begin{figure}
 % \begin{center}
-%  \begin{BodePlot}[xlabel={}]{0.1}{10}
+%  \begin{BodeMagPlot}[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{BodeMagPlot}
 % \end{center}
 % \cprotect\caption{\label{BodePeak} Resonant peak in asymptotic Bode plot using |\MagSOPolesPeak|.}
 % \end{figure}
@@ -727,7 +725,7 @@
 % |\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.
+% \noindent Similar to |\addNyquistZPKPlot|, with a transfer function input in the TF form.
 %
 % \subsection{Nichols charts}
 % \DescribeMacro{\NicholsZPK}
@@ -804,8 +802,7 @@
 % \begin{macro}{gnuplot at prefix}
 % \changes{v1.0.3}{2021/11/03}{Added jobname to gnuplot prefix}
 % \changes{v1.0.8}{2022/07/06}{Fixed issue \#6}
-% \begin{macro}{gnuplot at degrees}
-% 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| and |declutter| class options. 
+% 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 class options. 
 %    \begin{macrocode}
 \newif\if at pgfarg\@pgfargfalse
 \DeclareOption{pgf}{%
@@ -815,21 +812,27 @@
 \DeclareOption{declutter}{%
   \@declutterargtrue
 }
+\newif\if at radarg\@radargfalse
+\DeclareOption{rad}{%
+  \@radargtrue
+}
 \ProcessOptions\relax
 %    \end{macrocode}
 % Then, we define two new macros to unify |pgfplots| and |gnuplot|.
 %    \begin{macrocode}
+\newcommand{\n at mod}[2]{(#1)-(floor((#1)/(#2))*(#2))}
 \if at pgfarg
-  \newcommand{\n at pow}[2]{(#1)^(#2)}%
-  \newcommand{\n at mod}[2]{mod((#1),(#2))}%
+  \newcommand{\n at pow}[2]{(#1)^(#2)}
+  \pgfplotsset{%
+    trig format plots=rad%
+  }
 \else
-  \newcommand{\n at pow}[2]{(#1)**(#2)}%
-  \newcommand{\n at mod}[2]{(#1)-(floor((#1)/(#2))*(#2))}%
+  \newcommand{\n at pow}[2]{(#1)**(#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. The |declutter| option is used to enable the |gnuplot| directory to declutter the working directory.
 %    \begin{macrocode}
-  \newcounter{gnuplot at id}%
-  \setcounter{gnuplot at id}{0}%
+  \newcounter{gnuplot at id}
+  \setcounter{gnuplot at id}{0}
   \if at declutterarg
     \tikzset{%
       gnuplot at prefix/.style={%
@@ -846,21 +849,11 @@
     }
   \fi
 %    \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 at degrees/.code={%
-      \ifnum\value{gnuplot at id}=1
-        \xdef\pgfplots at gnuplot@format{\pgfplots at gnuplot@format set angles degrees;}%
-      \fi
-    }%
-  }
-%    \end{macrocode}
 % If the operating system is not Windows, and if the |declutter| option is not passed, we create the |gnuplot| folder if it does not already exist. \changes{v1.0.2}{2021/11/01}{Fixed issue \#1}
 %    \begin{macrocode}
   \ifwindows\else
     \if at declutterarg
-      \immediate\write18{mkdir -p gnuplot}%
+      \immediate\write18{mkdir -p gnuplot}
     \fi
   \fi
 \fi
@@ -869,7 +862,6 @@
 % \end{macro}
 % \end{macro}
 % \end{macro}
-% \end{macro}
 % \begin{macro}{bode at style}
 % Default axis properties for all plot macros are collected in this |pgf| style.
 %    \begin{macrocode}
@@ -889,6 +881,20 @@
 }
 %    \end{macrocode}
 % \end{macro}
+% \begin{macro}{ph at filter}
+% \begin{macro}{ph at x@filter}
+% These macros create |pgf| filters to convert plots from radians to degrees.
+%    \begin{macrocode}
+\if at radarg
+  \pgfplotsset{ph at filter/.style = {ytick distance=pi/4, ylabel={Phase (rad)}}}%
+  \pgfplotsset{ph at x@filter/.style = {xlabel={Phase (rad)}}}%
+\else
+  \pgfplotsset{ph at filter/.style = {y filter/.expression={y*180/pi}, ytick distance=45, ylabel={Phase (deg)}}}%
+  \pgfplotsset{ph at x@filter/.style = {x filter/.expression={x*180/pi}, xlabel={Phase (deg)}}}%
+\fi
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
 % \subsection{Parametric function generators for poles, zeros, gains, and delays.}
 % \begin{macro}{\MagK}
 % \begin{macro}{\MagKAsymp}
@@ -901,7 +907,7 @@
 \newcommand*{\MagK}[2]{(20*log10(abs(#1)))}
 \newcommand*{\MagKAsymp}{\MagK}
 \newcommand*{\MagKLin}{\MagK}
-\newcommand*{\PhK}[2]{(#1<0?-180:0)}
+\newcommand*{\PhK}[2]{(#1<0?-pi:0)}
 \newcommand*{\PhKAsymp}{\PhK}
 \newcommand*{\PhKLin}{\PhK}
 %    \end{macrocode}
@@ -916,7 +922,7 @@
 % 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}
+\newcommand*{\PhDel}[2]{-#1*t}
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -945,7 +951,7 @@
 % 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}) : 
+  (\n at mod{-atan2((t - (#2)),-(#1))}{2*pi}) : 
   (-atan2((t - (#2)),-(#1)))) : 
   (-atan2((t - (#2)),-(#1))))}
 %    \end{macrocode}
@@ -952,16 +958,16 @@
 % 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}))})) ? 
+  (abs(#1)+abs(#2) == 0 ? -pi/2 :
+  (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)))/
+  (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?3*pi/2:-pi/2):-pi/2) :
+  (-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?3*pi/2:-pi/2):-pi/2) + 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}
@@ -969,7 +975,7 @@
 %    \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))}
+  (#2>0?(#1>0?3*pi/2:-pi/2):-pi/2))}
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -1026,10 +1032,10 @@
 \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))}
+  (#1>0 ? -pi : pi) :
+  (#1>0 ? (-pi*(log10(t*(\n at pow{10}{#1})/#2))/(2*#1)) : 
+    (pi*(log10(t*(\n at pow{10}{abs(#1)})/#2))/(2*abs(#1))))))}
+\newcommand*{\PhCSPolesAsymp}[2]{(#1>0?(t<#2?0:-pi):(t<#2?0:pi))}
 %    \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}
@@ -1092,10 +1098,10 @@
 \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))}
+  (#1>0 ? -pi : pi))}
 \newcommand*{\PhSOPolesAsymp}[2]{(#2>0 ?
   \PhCSPolesAsymp{(#1/(2*sqrt(#2)))}{(sqrt(#2))} :
-  (#1>0 ? -180 : 180))}
+  (#1>0 ? -pi : pi))}
 %    \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}
@@ -1151,7 +1157,7 @@
 %    \end{macrocode}
 % The |\noexpand| macros below are needed to so that only the macro |\opt at group| is expanded. \changes{v1.0.3}{2021/11/03}{Added Tikz option}
 %    \begin{macrocode}
-  \edef\temp at cmd{\noexpand\begin{tikzpicture}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{groupplot}[%
       bode at style,
       xmin={#3},
@@ -1167,34 +1173,21 @@
 %    \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[variable=t,thick,\optmag at plot]}%
-        \temp at cmd {\func at mag};
-        \optmag at commands
-        \expandafter\nextgroupplot\expandafter[ytick distance=45,
-          ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optph at plot]}%
-        \temp at cmd {\func at ph};
-        \optph at commands
-      \else
+      \edef\temp at mag@cmd{\noexpand\nextgroupplot[ytick distance=20, ylabel={Gain (dB)}, xmajorticks=false, \optmag at axes]
+      \noexpand\addplot[variable=t, thick, \optmag at plot]}
+      \edef\temp at ph@cmd{\noexpand\nextgroupplot[ph at filter, xlabel={Frequency (rad/s)}, \optph at axes]
+      \noexpand\addplot[variable=t, thick, \optph at plot]}
 %    \end{macrocode}
 % In |gnuplot| mode, we increment the |gnuplot at id| counter before every plot to make sure that new and reusable |.gnuplot| and |.table| files are generated for every plot.
 %    \begin{macrocode}
-      \stepcounter{gnuplot at id}
-      \expandafter\nextgroupplot\expandafter[ytick distance=20,
-        ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
-      \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optmag at plot]}%
-      \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\func at mag};
+      \if at pgfarg\else
+        \edef\temp at mag@cmd{\noexpand\stepcounter{gnuplot at id} \unexpanded\expandafter{\temp at mag@cmd} gnuplot[gnuplot at prefix]}
+        \edef\temp at ph@cmd{\noexpand\stepcounter{gnuplot at id} \unexpanded\expandafter{\temp at ph@cmd} gnuplot[gnuplot at prefix]}
+      \fi
+      \temp at mag@cmd {\func at mag};
       \optmag at commands
-      \stepcounter{gnuplot at id}
-      \expandafter\nextgroupplot\expandafter[ytick distance=45,
-        ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
-      \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optph at plot]}%
-      \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\func at ph};
+      \temp at ph@cmd {\func at ph};
       \optph at commands
-    \fi
     \end{groupplot}
   \end{tikzpicture}
 }
@@ -1201,7 +1194,7 @@
 %    \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. \changes{v1.0.3}{2021/11/03}{Added Tikz option}
+% 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. \changes{v1.0.3}{2021/11/03}{Added Tikz option} \changes{v1.1.0}{2022/07/06}{Fixed phase wrapping in gnuplot mode}
 %    \begin{macrocode}
 \newcommand{\BodeTF}[4][]{%
   \parse at opt{#1}%
@@ -1208,7 +1201,7 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{groupplot}[%
       bode at style,
       xmin={#3},
@@ -1221,31 +1214,22 @@
     ]%
   }%
   \temp at cmd
+      \edef\temp at mag@cmd{\noexpand\nextgroupplot[ytick distance=20, ylabel={Gain (dB)}, xmajorticks=false, \optmag at axes]
+      \noexpand\addplot[variable=t, thick, \optmag at plot]}
+      \edef\temp at ph@cmd{\noexpand\nextgroupplot[ph at filter, xlabel={Frequency (rad/s)}, \optph at axes]
+      \noexpand\addplot[variable=t, thick, \optph at plot]}
+      \if at pgfarg\else
+        \edef\temp at mag@cmd{\noexpand\stepcounter{gnuplot at id} \unexpanded\expandafter{\temp at mag@cmd} gnuplot[gnuplot at prefix]}
+        \edef\temp at ph@cmd{\noexpand\stepcounter{gnuplot at id} \unexpanded\expandafter{\temp at ph@cmd} gnuplot[gnuplot at prefix]}
+      \fi
+      \temp at mag@cmd {\func at mag};
+      \optmag at commands
       \if at pgfarg
-        \expandafter\nextgroupplot\expandafter[ytick distance=20,
-          ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optmag at plot]}%
-        \temp at cmd {\func at mag};
-        \optmag at commands
-        \expandafter\nextgroupplot\expandafter[ytick distance=45,
-          ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optph at plot]}%
-        \temp at cmd {\func at ph};
-        \optph at commands
+        \temp at ph@cmd {\n at mod{\func at ph}{2*pi}};
       \else
-        \stepcounter{gnuplot at id}%
-        \expandafter\nextgroupplot\expandafter[ytick distance=20,
-          ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optmag at plot]}%
-        \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\func at mag};
-        \optmag at commands
-        \stepcounter{gnuplot at id}%
-        \expandafter\nextgroupplot\expandafter[ytick distance=45,
-          ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optph at plot]}%
-        \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\func at ph};
-        \optph at commands
+        \temp at ph@cmd {'+' using (t):\func at ph smooth unwrap};
       \fi
+      \optph at commands
     \end{groupplot}
   \end{tikzpicture}
 }
@@ -1269,7 +1253,7 @@
     \else
       \stepcounter{gnuplot at id}%
       \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\opt]}
-      \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\plot at macro};
+      \temp at cmd gnuplot[gnuplot at prefix] {\plot at macro};
     \fi
   }%
 }
@@ -1276,7 +1260,7 @@
 %    \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.
+% 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.  \changes{v1.1.0}{2022/07/06}{Fixed phase wrapping in gnuplot mode}
 %    \begin{macrocode}
 \newcommand{\addBodeTFPlot}[3][thick]{%
   \gdef\plot at macro{}%
@@ -1287,10 +1271,18 @@
     \build at TF@plot{\plot at macro}{\temp at macro}{#3}%
   \fi
   \if at pgfarg
-    \addplot[variable=t,#1]{\plot at macro};
+    \ifnum\pdfstrcmp{#2}{phase}=0
+      \addplot[variable=t,#1]{\n at mod{\plot at macro}{2*pi}};
+    \else
+      \addplot[variable=t,#1]{\plot at macro};
+    \fi
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[gnuplot at degrees, gnuplot at prefix] {\plot at macro};
+    \ifnum\pdfstrcmp{#2}{phase}=0
+      \addplot[variable=t,#1] gnuplot[gnuplot at prefix] {'+' using (t):\plot at macro smooth unwrap}
+    \else
+      \addplot[variable=t,#1] gnuplot[gnuplot at prefix] {\plot at macro};
+    \fi
   \fi
 }
 %    \end{macrocode}
@@ -1303,17 +1295,67 @@
     \addplot[variable=t,#1]{#2};
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[gnuplot at degrees,gnuplot at prefix] {#2};
+    \addplot[variable=t,#1] gnuplot[gnuplot at prefix] {#2};
   \fi
 }
 %    \end{macrocode}
 %\end{macro}
+% \begin{environment}{BodePhPlot}
+% An environment to host phase plot macros that pass parametric functions to |\addplot| macros. Uses the defaults specified in |bode at style| to create a shortcut that includes the |tikzpicture| and |semilogaxis| environments.\changes{v1.1.0}{2022/07/20}{Added separate environments for phase and magnitude plots}
+%    \begin{macrocode}
+\newenvironment{BodePhPlot}[3][]{%
+  \parse at env@opt{#1}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]
+    \noexpand\begin{semilogxaxis}[%
+      ph at filter,
+      bode at style,
+      xmin={#2},
+      xmax={#3},
+      domain=#2:#3,
+      height=2.5cm,
+      xlabel={Frequency (rad/s)},
+      \unexpanded\expandafter{\opt at axes}
+    ]%
+  }
+  \temp at cmd
+}{
+    \end{semilogxaxis}
+  \end{tikzpicture}
+}
+%    \end{macrocode}
+% \end{environment}
+% \begin{environment}{BodeMagPlot}
+% An environment to host magnitude plot macros that pass parametric functions to |\addplot| macros. Uses the defaults specified in |bode at style| to create a shortcut that includes the |tikzpicture| and |semilogaxis| environments.\changes{v1.1.0}{2022/07/20}{Added separate environments for phase and magnitude plots}
+%    \begin{macrocode}
+\newenvironment{BodeMagPlot}[3][]{%
+  \parse at env@opt{#1}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]
+    \noexpand\begin{semilogxaxis}[%
+      bode at style,
+      xmin={#2},
+      xmax={#3},
+      domain=#2:#3,
+      height=2.5cm,
+      xlabel={Frequency (rad/s)},
+      ylabel={Gain (dB)},
+      ytick distance=40,
+      \unexpanded\expandafter{\opt at axes}
+    ]%
+  }
+  \temp at cmd
+}{
+    \end{semilogxaxis}
+  \end{tikzpicture}
+}
+%    \end{macrocode}
+% \end{environment}
 % \begin{environment}{BodePlot}
-% An environment to host macros that pass parametric functions to |\addplot| macros. Uses the defaults specified in |bode at style| to create a shortcut that includes the |tikzpicture| and |semilogaxis| environments. \changes{v1.0.3}{2021/11/03}{Added tikz option to environments}
+% Same as |BodeMagPlot|. The |BodePlot| environment is deprecated as of v1.1.0, please use the |BodePhPlot| and |BodeMagPlot| environments instead.\changes{v1.0.3}{2021/11/03}{Added tikz option to environments}\changes{v1.1.0}{2022/02/20}{Deprecated BodePlot environment}
 %    \begin{macrocode}
 \newenvironment{BodePlot}[3][]{%
+  \PackageWarning{bodeplot}{Since v1.1.0, the BodePlot environment returns phase plots in radian units only. Please use the BodePhPlot environment if degree units are needed.}%
   \parse at env@opt{#1}%
-  \edef\temp at cmd{\noexpand\begin{tikzpicture}[\unexpanded\expandafter{\opt at tikz}]
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]
     \noexpand\begin{semilogxaxis}[%
       bode at style,
       xmin={#2},
@@ -1323,7 +1365,7 @@
       xlabel={Frequency (rad/s)},
       \unexpanded\expandafter{\opt at axes}
     ]%
-  }%
+  }
   \temp at cmd
 }{
     \end{semilogxaxis}
@@ -1475,8 +1517,8 @@
       \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))-\loop at delay*180*t/pi+360}{360})}%
+  \xdef#2{(atan2((\num at im),(\num at real))-atan2((\den at im),%
+    (\den at real))-\loop at delay*t)}%
   \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}))))}%
 }
@@ -1581,7 +1623,7 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
       bode at style,
       domain=#3:#4,
@@ -1594,7 +1636,7 @@
   }%
   \temp at cmd
       \addplot [only marks,mark=+,thick,red] (-1 , 0);
-      \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\unexpanded\expandafter{\opt at plot}]}%
+      \edef\temp at cmd{\noexpand\addplot[variable=t, 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)} );
@@ -1601,7 +1643,7 @@
         \opt at commands
       \else
         \stepcounter{gnuplot at id}%
-        \temp at cmd gnuplot[parametric,gnuplot at degrees,gnuplot at prefix] {%
+        \temp at cmd gnuplot[parametric,gnuplot at prefix] {%
           \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
           \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
         \opt at commands
@@ -1619,7 +1661,7 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
       bode at style,
       domain=#3:#4,
@@ -1632,7 +1674,7 @@
   }%
   \temp at cmd
       \addplot [only marks,mark=+,thick,red] (-1 , 0);
-      \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\unexpanded\expandafter{\opt at plot}]}%
+      \edef\temp at cmd{\noexpand\addplot[variable=t, 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)} );
@@ -1639,7 +1681,7 @@
         \opt at commands
       \else
         \stepcounter{gnuplot at id}%
-        \temp at cmd gnuplot[parametric,gnuplot at degrees,gnuplot at prefix]{%
+        \temp at cmd gnuplot[parametric,gnuplot at prefix]{%
           \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
           \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
         \opt at commands
@@ -1661,7 +1703,7 @@
       {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at degrees,gnuplot at prefix]{%
+    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at prefix]{%
       \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
@@ -1680,7 +1722,7 @@
       {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at degrees,gnuplot at prefix]{%
+    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at prefix]{%
       \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
@@ -1692,7 +1734,7 @@
 %    \begin{macrocode}
 \newenvironment{NyquistPlot}[3][]{%
   \parse at env@opt{#1}%
-  \edef\temp at cmd{\noexpand\begin{tikzpicture}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
       bode at style,
       height=5cm,
@@ -1758,12 +1800,12 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
+      ph at x@filter,
       bode at style,
       domain=#3:#4,
       height=5cm,
-      xlabel={Phase (degrees)},
       ylabel={Gain (dB)},
       samples=500,
       \unexpanded\expandafter{\opt at axes}
@@ -1776,7 +1818,7 @@
         \opt at commands
       \else
         \stepcounter{gnuplot at id}%
-        \temp at cmd gnuplot[parametric, gnuplot at degrees, gnuplot at prefix]
+        \temp at cmd gnuplot[parametric,gnuplot at prefix]
           { \func at ph , \func at mag };
         \opt at commands
       \fi
@@ -1788,12 +1830,12 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
+      ph at x@filter,
       bode at style,
       domain=#3:#4,
       height=5cm,
-      xlabel={Phase (degrees)},
       ylabel={Gain (dB)},
       samples=500,
       \unexpanded\expandafter{\opt at axes}
@@ -1802,12 +1844,12 @@
   \temp at cmd
       \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\opt at plot]}%
       \if at pgfarg
-        \temp at cmd ( {\func at ph} , {\func at mag} );
+        \temp at cmd ( {\n at mod{\func at ph}{2*pi}} , {\func at mag} );
         \opt at commands
       \else
         \stepcounter{gnuplot at id}%
-        \temp at cmd gnuplot[parametric, gnuplot at degrees, gnuplot at prefix]
-          { \func at ph , \func at mag };
+        \temp at cmd gnuplot[parametric,gnuplot at prefix]
+          { \n at mod{\func at ph}{2*pi} , \func at mag };
         \opt at commands
       \fi
     \end{axis}
@@ -1815,12 +1857,12 @@
 }
 \newenvironment{NicholsChart}[3][]{%
   \parse at env@opt{#1}%
-  \edef\temp at cmd{\noexpand\begin{tikzpicture}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
+      ph at x@filter,
       bode at style,
       domain=#2:#3,
       height=5cm,
-      xlabel={Phase (degrees)},
       ylabel={Gain (dB)},
       \unexpanded\expandafter{\opt at axes}
     ]%
@@ -1838,7 +1880,7 @@
     \addplot[variable=t,#1] ( {\func at ph} , {\func at mag} );
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at degrees,gnuplot at prefix]
+    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at prefix]
       {\func at ph , \func at mag};
   \fi
 }
@@ -1847,11 +1889,11 @@
   \gdef\func at ph{}%
   \build at TF@plot{\func at mag}{\func at ph}{#2}%
   \if at pgfarg
-    \addplot[variable=t,#1] ( {\func at ph} , {\func at mag} );
+    \addplot[variable=t,#1] ( {\n at mod{\func at ph}{2*pi}} , {\func at mag} );
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[gnuplot at degrees,gnuplot at prefix]
-      {\func at ph , \func at mag};
+    \addplot[variable=t,#1] gnuplot[gnuplot at prefix]
+      {\n at mod{\func at ph}{2*pi} , \func at mag};
   \fi
 }
 %    \end{macrocode}

Modified: trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty	2022-07-20 20:19:40 UTC (rev 63945)
+++ trunk/Master/texmf-dist/tex/latex/bodeplot/bodeplot.sty	2022-07-20 20:20:21 UTC (rev 63946)
@@ -16,7 +16,6 @@
 %% LaTeX version 2006/05/20 or later.
 \NeedsTeXFormat{LaTeX2e}[2006/05/20]
 \ProvidesPackage{bodeplot}
-\RequirePackage{tikz}
 \RequirePackage{pdftexcmds}
 \RequirePackage{ifplatform}
 \RequirePackage{pgfplots}
@@ -35,15 +34,21 @@
 \DeclareOption{declutter}{%
   \@declutterargtrue
 }
+\newif\if at radarg\@radargfalse
+\DeclareOption{rad}{%
+  \@radargtrue
+}
 \ProcessOptions\relax
+\newcommand{\n at mod}[2]{(#1)-(floor((#1)/(#2))*(#2))}
 \if at pgfarg
-  \newcommand{\n at pow}[2]{(#1)^(#2)}%
-  \newcommand{\n at mod}[2]{mod((#1),(#2))}%
+  \newcommand{\n at pow}[2]{(#1)^(#2)}
+  \pgfplotsset{%
+    trig format plots=rad%
+  }
 \else
-  \newcommand{\n at pow}[2]{(#1)**(#2)}%
-  \newcommand{\n at mod}[2]{(#1)-(floor((#1)/(#2))*(#2))}%
-  \newcounter{gnuplot at id}%
-  \setcounter{gnuplot at id}{0}%
+  \newcommand{\n at pow}[2]{(#1)**(#2)}
+  \newcounter{gnuplot at id}
+  \setcounter{gnuplot at id}{0}
   \if at declutterarg
     \tikzset{%
       gnuplot at prefix/.style={%
@@ -59,16 +64,9 @@
       }%
     }
   \fi
-  \pgfplotsset{%
-    gnuplot at degrees/.code={%
-      \ifnum\value{gnuplot at id}=1
-        \xdef\pgfplots at gnuplot@format{\pgfplots at gnuplot@format set angles degrees;}%
-      \fi
-    }%
-  }
   \ifwindows\else
     \if at declutterarg
-      \immediate\write18{mkdir -p gnuplot}%
+      \immediate\write18{mkdir -p gnuplot}
     \fi
   \fi
 \fi
@@ -86,14 +84,21 @@
     width=5cm,
   }%
 }
+\if at radarg
+  \pgfplotsset{ph at filter/.style = {ytick distance=pi/4, ylabel={Phase (rad)}}}%
+  \pgfplotsset{ph at x@filter/.style = {xlabel={Phase (rad)}}}%
+\else
+  \pgfplotsset{ph at filter/.style = {y filter/.expression={y*180/pi}, ytick distance=45, ylabel={Phase (deg)}}}%
+  \pgfplotsset{ph at x@filter/.style = {x filter/.expression={x*180/pi}, xlabel={Phase (deg)}}}%
+\fi
 \newcommand*{\MagK}[2]{(20*log10(abs(#1)))}
 \newcommand*{\MagKAsymp}{\MagK}
 \newcommand*{\MagKLin}{\MagK}
-\newcommand*{\PhK}[2]{(#1<0?-180:0)}
+\newcommand*{\PhK}[2]{(#1<0?-pi:0)}
 \newcommand*{\PhKAsymp}{\PhK}
 \newcommand*{\PhKLin}{\PhK}
 \newcommand*{\MagDel}[2]{0}
-\newcommand*{\PhDel}[2]{-#1*180*t/pi}
+\newcommand*{\PhDel}[2]{-#1*t}
 \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}) ?
@@ -102,25 +107,25 @@
   )}
 \newcommand*{\MagPoleAsymp}{\MagPoleLin}
 \newcommand*{\PhPole}[2]{(#1 > 0 ? (#2 > 0 ?
-  (\n at mod{-atan2((t - (#2)),-(#1))+360}{360}) :
+  (\n at mod{-atan2((t - (#2)),-(#1))}{2*pi}) :
   (-atan2((t - (#2)),-(#1)))) :
   (-atan2((t - (#2)),-(#1))))}
 \newcommand*{\PhPoleLin}[2]{%
-  (abs(#1)+abs(#2) == 0 ? -90 :
+  (abs(#1)+abs(#2) == 0 ? -pi/2 :
   (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) :
+  (#2>0?(#1>0?3*pi/2:-pi/2):-pi/2) :
   (-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)))/
+    \n at pow{#2}{2}))}))))*((#2>0?(#1>0?3*pi/2:-pi/2):-pi/2) + 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))}
+  (#2>0?(#1>0?3*pi/2:-pi/2):-pi/2))}
 \newcommand*{\MagZero}{0-\MagPole}
 \newcommand*{\MagZeroLin}{0-\MagPoleLin}
 \newcommand*{\MagZeroAsymp}{0-\MagPoleAsymp}
@@ -136,10 +141,10 @@
 \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))}
+  (#1>0 ? -pi : pi) :
+  (#1>0 ? (-pi*(log10(t*(\n at pow{10}{#1})/#2))/(2*#1)) :
+    (pi*(log10(t*(\n at pow{10}{abs(#1)})/#2))/(2*abs(#1))))))}
+\newcommand*{\PhCSPolesAsymp}[2]{(#1>0?(t<#2?0:-pi):(t<#2?0:pi))}
 \newcommand*{\MagCSZeros}{0-\MagCSPoles}
 \newcommand*{\MagCSZerosLin}{0-\MagCSPolesLin}
 \newcommand*{\MagCSZerosAsymp}{0-\MagCSPolesAsymp}
@@ -162,10 +167,10 @@
 \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))}
+  (#1>0 ? -pi : pi))}
 \newcommand*{\PhSOPolesAsymp}[2]{(#2>0 ?
   \PhCSPolesAsymp{(#1/(2*sqrt(#2)))}{(sqrt(#2))} :
-  (#1>0 ? -180 : 180))}
+  (#1>0 ? -pi : pi))}
 \newcommand*{\MagSOZeros}{0-\MagSOPoles}
 \newcommand*{\MagSOZerosLin}{0-\MagSOPolesLin}
 \newcommand*{\MagSOZerosAsymp}{0-\MagSOPolesAsymp}
@@ -187,7 +192,7 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{groupplot}[%
       bode at style,
       xmin={#3},
@@ -200,31 +205,18 @@
     ]%
   }%
   \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[variable=t,thick,\optmag at plot]}%
-        \temp at cmd {\func at mag};
-        \optmag at commands
-        \expandafter\nextgroupplot\expandafter[ytick distance=45,
-          ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optph at plot]}%
-        \temp at cmd {\func at ph};
-        \optph at commands
-      \else
-      \stepcounter{gnuplot at id}
-      \expandafter\nextgroupplot\expandafter[ytick distance=20,
-        ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
-      \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optmag at plot]}%
-      \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\func at mag};
+      \edef\temp at mag@cmd{\noexpand\nextgroupplot[ytick distance=20, ylabel={Gain (dB)}, xmajorticks=false, \optmag at axes]
+      \noexpand\addplot[variable=t, thick, \optmag at plot]}
+      \edef\temp at ph@cmd{\noexpand\nextgroupplot[ph at filter, xlabel={Frequency (rad/s)}, \optph at axes]
+      \noexpand\addplot[variable=t, thick, \optph at plot]}
+      \if at pgfarg\else
+        \edef\temp at mag@cmd{\noexpand\stepcounter{gnuplot at id} \unexpanded\expandafter{\temp at mag@cmd} gnuplot[gnuplot at prefix]}
+        \edef\temp at ph@cmd{\noexpand\stepcounter{gnuplot at id} \unexpanded\expandafter{\temp at ph@cmd} gnuplot[gnuplot at prefix]}
+      \fi
+      \temp at mag@cmd {\func at mag};
       \optmag at commands
-      \stepcounter{gnuplot at id}
-      \expandafter\nextgroupplot\expandafter[ytick distance=45,
-        ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
-      \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optph at plot]}%
-      \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\func at ph};
+      \temp at ph@cmd {\func at ph};
       \optph at commands
-    \fi
     \end{groupplot}
   \end{tikzpicture}
 }
@@ -233,7 +225,7 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{groupplot}[%
       bode at style,
       xmin={#3},
@@ -246,31 +238,22 @@
     ]%
   }%
   \temp at cmd
+      \edef\temp at mag@cmd{\noexpand\nextgroupplot[ytick distance=20, ylabel={Gain (dB)}, xmajorticks=false, \optmag at axes]
+      \noexpand\addplot[variable=t, thick, \optmag at plot]}
+      \edef\temp at ph@cmd{\noexpand\nextgroupplot[ph at filter, xlabel={Frequency (rad/s)}, \optph at axes]
+      \noexpand\addplot[variable=t, thick, \optph at plot]}
+      \if at pgfarg\else
+        \edef\temp at mag@cmd{\noexpand\stepcounter{gnuplot at id} \unexpanded\expandafter{\temp at mag@cmd} gnuplot[gnuplot at prefix]}
+        \edef\temp at ph@cmd{\noexpand\stepcounter{gnuplot at id} \unexpanded\expandafter{\temp at ph@cmd} gnuplot[gnuplot at prefix]}
+      \fi
+      \temp at mag@cmd {\func at mag};
+      \optmag at commands
       \if at pgfarg
-        \expandafter\nextgroupplot\expandafter[ytick distance=20,
-          ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optmag at plot]}%
-        \temp at cmd {\func at mag};
-        \optmag at commands
-        \expandafter\nextgroupplot\expandafter[ytick distance=45,
-          ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optph at plot]}%
-        \temp at cmd {\func at ph};
-        \optph at commands
+        \temp at ph@cmd {\n at mod{\func at ph}{2*pi}};
       \else
-        \stepcounter{gnuplot at id}%
-        \expandafter\nextgroupplot\expandafter[ytick distance=20,
-          ylabel={Gain (dB)},xmajorticks=false,\optmag at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optmag at plot]}%
-        \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\func at mag};
-        \optmag at commands
-        \stepcounter{gnuplot at id}%
-        \expandafter\nextgroupplot\expandafter[ytick distance=45,
-          ylabel={Phase ($^{\circ}$)},xlabel={Frequency (rad/s)},\optph at axes]
-        \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\optph at plot]}%
-        \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\func at ph};
-        \optph at commands
+        \temp at ph@cmd {'+' using (t):\func at ph smooth unwrap};
       \fi
+      \optph at commands
     \end{groupplot}
   \end{tikzpicture}
 }
@@ -289,7 +272,7 @@
     \else
       \stepcounter{gnuplot at id}%
       \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\opt]}
-      \temp at cmd gnuplot[gnuplot at degrees,gnuplot at prefix] {\plot at macro};
+      \temp at cmd gnuplot[gnuplot at prefix] {\plot at macro};
     \fi
   }%
 }
@@ -302,10 +285,18 @@
     \build at TF@plot{\plot at macro}{\temp at macro}{#3}%
   \fi
   \if at pgfarg
-    \addplot[variable=t,#1]{\plot at macro};
+    \ifnum\pdfstrcmp{#2}{phase}=0
+      \addplot[variable=t,#1]{\n at mod{\plot at macro}{2*pi}};
+    \else
+      \addplot[variable=t,#1]{\plot at macro};
+    \fi
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[gnuplot at degrees, gnuplot at prefix] {\plot at macro};
+    \ifnum\pdfstrcmp{#2}{phase}=0
+      \addplot[variable=t,#1] gnuplot[gnuplot at prefix] {'+' using (t):\plot at macro smooth unwrap}
+    \else
+      \addplot[variable=t,#1] gnuplot[gnuplot at prefix] {\plot at macro};
+    \fi
   \fi
 }
 \newcommand{\addBodeComponentPlot}[2][thick]{%
@@ -313,12 +304,52 @@
     \addplot[variable=t,#1]{#2};
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[gnuplot at degrees,gnuplot at prefix] {#2};
+    \addplot[variable=t,#1] gnuplot[gnuplot at prefix] {#2};
   \fi
 }
+\newenvironment{BodePhPlot}[3][]{%
+  \parse at env@opt{#1}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]
+    \noexpand\begin{semilogxaxis}[%
+      ph at filter,
+      bode at style,
+      xmin={#2},
+      xmax={#3},
+      domain=#2:#3,
+      height=2.5cm,
+      xlabel={Frequency (rad/s)},
+      \unexpanded\expandafter{\opt at axes}
+    ]%
+  }
+  \temp at cmd
+}{
+    \end{semilogxaxis}
+  \end{tikzpicture}
+}
+\newenvironment{BodeMagPlot}[3][]{%
+  \parse at env@opt{#1}%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]
+    \noexpand\begin{semilogxaxis}[%
+      bode at style,
+      xmin={#2},
+      xmax={#3},
+      domain=#2:#3,
+      height=2.5cm,
+      xlabel={Frequency (rad/s)},
+      ylabel={Gain (dB)},
+      ytick distance=40,
+      \unexpanded\expandafter{\opt at axes}
+    ]%
+  }
+  \temp at cmd
+}{
+    \end{semilogxaxis}
+  \end{tikzpicture}
+}
 \newenvironment{BodePlot}[3][]{%
+  \PackageWarning{bodeplot}{Since v1.1.0, the BodePlot environment returns phase plots in radian units only. Please use the BodePhPlot environment if degree units are needed.}%
   \parse at env@opt{#1}%
-  \edef\temp at cmd{\noexpand\begin{tikzpicture}[\unexpanded\expandafter{\opt at tikz}]
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]
     \noexpand\begin{semilogxaxis}[%
       bode at style,
       xmin={#2},
@@ -328,7 +359,7 @@
       xlabel={Frequency (rad/s)},
       \unexpanded\expandafter{\opt at axes}
     ]%
-  }%
+  }
   \temp at cmd
 }{
     \end{semilogxaxis}
@@ -464,8 +495,8 @@
       \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))-\loop at delay*180*t/pi+360}{360})}%
+  \xdef#2{(atan2((\num at im),(\num at real))-atan2((\den at im),%
+    (\den at real))-\loop at delay*t)}%
   \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}))))}%
 }
@@ -553,7 +584,7 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
       bode at style,
       domain=#3:#4,
@@ -566,7 +597,7 @@
   }%
   \temp at cmd
       \addplot [only marks,mark=+,thick,red] (-1 , 0);
-      \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\unexpanded\expandafter{\opt at plot}]}%
+      \edef\temp at cmd{\noexpand\addplot[variable=t, 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)} );
@@ -573,7 +604,7 @@
         \opt at commands
       \else
         \stepcounter{gnuplot at id}%
-        \temp at cmd gnuplot[parametric,gnuplot at degrees,gnuplot at prefix] {%
+        \temp at cmd gnuplot[parametric,gnuplot at prefix] {%
           \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
           \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
         \opt at commands
@@ -586,7 +617,7 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
       bode at style,
       domain=#3:#4,
@@ -599,7 +630,7 @@
   }%
   \temp at cmd
       \addplot [only marks,mark=+,thick,red] (-1 , 0);
-      \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\unexpanded\expandafter{\opt at plot}]}%
+      \edef\temp at cmd{\noexpand\addplot[variable=t, 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)} );
@@ -606,7 +637,7 @@
         \opt at commands
       \else
         \stepcounter{gnuplot at id}%
-        \temp at cmd gnuplot[parametric,gnuplot at degrees,gnuplot at prefix]{%
+        \temp at cmd gnuplot[parametric,gnuplot at prefix]{%
           \n at pow{10}{((\func at mag)/20)}*cos(\func at ph),
           \n at pow{10}{((\func at mag)/20)}*sin(\func at ph)};
         \opt at commands
@@ -623,7 +654,7 @@
       {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at degrees,gnuplot at prefix]{%
+    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at prefix]{%
       \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
@@ -637,7 +668,7 @@
       {\n at pow{10}{((\func at mag)/20)}*sin(\func at ph)} );
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at degrees,gnuplot at prefix]{%
+    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at prefix]{%
       \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
@@ -644,7 +675,7 @@
 }
 \newenvironment{NyquistPlot}[3][]{%
   \parse at env@opt{#1}%
-  \edef\temp at cmd{\noexpand\begin{tikzpicture}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
       bode at style,
       height=5cm,
@@ -691,12 +722,12 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
+      ph at x@filter,
       bode at style,
       domain=#3:#4,
       height=5cm,
-      xlabel={Phase (degrees)},
       ylabel={Gain (dB)},
       samples=500,
       \unexpanded\expandafter{\opt at axes}
@@ -709,7 +740,7 @@
         \opt at commands
       \else
         \stepcounter{gnuplot at id}%
-        \temp at cmd gnuplot[parametric, gnuplot at degrees, gnuplot at prefix]
+        \temp at cmd gnuplot[parametric,gnuplot at prefix]
           { \func at ph , \func at mag };
         \opt at commands
       \fi
@@ -721,12 +752,12 @@
   \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}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
+      ph at x@filter,
       bode at style,
       domain=#3:#4,
       height=5cm,
-      xlabel={Phase (degrees)},
       ylabel={Gain (dB)},
       samples=500,
       \unexpanded\expandafter{\opt at axes}
@@ -735,12 +766,12 @@
   \temp at cmd
       \edef\temp at cmd{\noexpand\addplot[variable=t,thick,\opt at plot]}%
       \if at pgfarg
-        \temp at cmd ( {\func at ph} , {\func at mag} );
+        \temp at cmd ( {\n at mod{\func at ph}{2*pi}} , {\func at mag} );
         \opt at commands
       \else
         \stepcounter{gnuplot at id}%
-        \temp at cmd gnuplot[parametric, gnuplot at degrees, gnuplot at prefix]
-          { \func at ph , \func at mag };
+        \temp at cmd gnuplot[parametric,gnuplot at prefix]
+          { \n at mod{\func at ph}{2*pi} , \func at mag };
         \opt at commands
       \fi
     \end{axis}
@@ -748,12 +779,12 @@
 }
 \newenvironment{NicholsChart}[3][]{%
   \parse at env@opt{#1}%
-  \edef\temp at cmd{\noexpand\begin{tikzpicture}[\unexpanded\expandafter{\opt at tikz}]%
+  \edef\temp at cmd{\noexpand\begin{tikzpicture} [\unexpanded\expandafter{\opt at tikz}]%
     \noexpand\begin{axis}[%
+      ph at x@filter,
       bode at style,
       domain=#2:#3,
       height=5cm,
-      xlabel={Phase (degrees)},
       ylabel={Gain (dB)},
       \unexpanded\expandafter{\opt at axes}
     ]%
@@ -771,7 +802,7 @@
     \addplot[variable=t,#1] ( {\func at ph} , {\func at mag} );
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at degrees,gnuplot at prefix]
+    \addplot[variable=t,#1] gnuplot[parametric,gnuplot at prefix]
       {\func at ph , \func at mag};
   \fi
 }
@@ -780,11 +811,11 @@
   \gdef\func at ph{}%
   \build at TF@plot{\func at mag}{\func at ph}{#2}%
   \if at pgfarg
-    \addplot[variable=t,#1] ( {\func at ph} , {\func at mag} );
+    \addplot[variable=t,#1] ( {\n at mod{\func at ph}{2*pi}} , {\func at mag} );
   \else
     \stepcounter{gnuplot at id}%
-    \addplot[variable=t,#1] gnuplot[gnuplot at degrees,gnuplot at prefix]
-      {\func at ph , \func at mag};
+    \addplot[variable=t,#1] gnuplot[gnuplot at prefix]
+      {\n at mod{\func at ph}{2*pi} , \func at mag};
   \fi
 }
 \endinput



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