| 1 |
# bodeplot |
| 2 |
LaTeX package to plot Bode, Nichols, and Nyquist diagrams. |
| 3 |
Inspired by the `bodegraph` package. |
| 4 |
|
| 5 |
Author: Rushikesh Kamalapurkar ([[email protected]](mailto:[email protected])) |
| 6 |
|
| 7 |
License: [LPPL-1.3c](https://github.com/rlkamalapurkar/bodeplot/blob/main/LICENSE) |
| 8 |
|
| 9 |
## New features: |
| 10 |
1. (v3.0) - All plotting commands use a simplified PGF-style key/value syntax |
| 11 |
2. (v3.1) - If `Python` with `scipy` and `numpy` is available with `--shell-escape` then pole zero maps can be plotted for systems in `TF` format using `\PoleZeroMapTF` and the `\BodeTF` and `\addBodeTFPlots` commands support linear and asymptotic approximations. |
| 12 |
3. (v3.1) - If `Python` with `scipy` and `numpy` is available with `--shell-escape` then the phase plots in `pgf` mode are no longer wrapped. |
| 13 |
|
| 14 |
## Limitations |
| 15 |
1. TF commands are wrapped between -180 and 180 degrees in `pgf` mode unless `Python` with `scipy` and `numpy` is available with `--shell-escape`. |
| 16 |
2. 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. |
| 17 |
3. Before version 1.2, in `pgf` mode, the package set `trig format plots` to `rad` globally. Version 1.2 onwards, this option is passed to each `addplot` command individually so it does not affect non-`bodeplot` plots. To roll back to pre-v1.2 behavior, load the package with `\usepackage[pgf]{bodeplot}[=2024-02-06]`. |
| 18 |
|
| 19 |
## Compilation instructions |
| 20 |
1) `latex bodeplot.ins` to generate `bodeplot.sty` |
| 21 |
2) To compile documentation (needs `gnuplot` on system PATH): |
| 22 |
``` |
| 23 |
lualatex --shell-escape bodeplot.dtx |
| 24 |
makeindex -s gind.ist bodeplot.idx |
| 25 |
makeindex -s gglo.ist -o bodeplot.gls bodeplot.glo |
| 26 |
lualatex --shell-escape bodeplot.dtx |
| 27 |
lualatex --shell-escape bodeplot.dtx |
| 28 |
``` |
| 29 |
## Added functionality over `bodegraph` |
| 30 |
- 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. |
| 31 |
- Support for linear and asymptotic approximation of magnitude and phase plots of any transfer function. |
| 32 |
- Support for pole-zero maps. |
| 33 |
- All plots are fully customizable using `pgf` options (see package documentation for a full list of commands, environments, and options). |
| 34 |
- Support for unstable poles and zeros. |
| 35 |
- Support for complex poles and zeros. |
| 36 |
- Support for general stable and unstable second order transfer functions. |
| 37 |
- Support for both `gnuplot` (default) and `pgfplots` (package option `pgf`). |
| 38 |
- Support for `rad/s` (default) and `Hz` (package option `Hz` or `pgf` key `frequency unit=Hz` for per-plot change) frequency units. |
| 39 |
- Support for `deg` (default) and `rad` (package option `rad` or `pgf` key `phase unit=rad` for per-plot change) phase units. |
| 40 |
|
| 41 |
## Basic Bode/Nyquist/Nichols commands |
| 42 |
*See package documentation for the complete key reference, command list, and environment options.* |
| 43 |
|
| 44 |
Starting v3.0, all plotting commands use a simplified PGF-style key/value syntax. |
| 45 |
|
| 46 |
- Zeros–poles–gain (ZPK) form with optional delay: |
| 47 |
```latex |
| 48 |
\BodeZPK[% |
| 49 |
domain=0.001:100, |
| 50 |
samples=1000, |
| 51 |
mag plot={blue, thick}, |
| 52 |
ph plot={green, thick}, |
| 53 |
phase unit=rad% |
| 54 |
]{% |
| 55 |
zeros={0,-0.1-0.5i,-0.1+0.5i}, |
| 56 |
poles={-0.5-10i,-0.5+10i}, |
| 57 |
gain=10, |
| 58 |
delay=0.01% |
| 59 |
} |
| 60 |
``` |
| 61 |
Use the same interface with `\NicholsZPK[...]` or `\NyquistZPK[...]` to generate Nichols and Nyquist plots. Approximation options ( `linear`, `asymptotic`) are available for systems without delays through the `approx=...` key. |
| 62 |
|
| 63 |
- Transfer-function (TF) form: |
| 64 |
```latex |
| 65 |
\BodeTF[% |
| 66 |
domain=0.001:100, |
| 67 |
samples=1000, |
| 68 |
frequency unit=Hz% |
| 69 |
]{% |
| 70 |
numerator={10,2,2.6,0}, |
| 71 |
denominator={1,1,100.25}, |
| 72 |
delay=0.01% |
| 73 |
} |
| 74 |
``` |
| 75 |
The TF syntax is shared by `\NicholsTF[...]` and `\NyquistTF[...]`. Approximation options ( `linear`, `asymptotic`) are available for systems without delays through the `approx=...` key if `Python` with `scipy` and `numpy` is available via `--shell-escape`. |
| 76 |
|
| 77 |
## Basic pole-zero map commands |
| 78 |
*See package documentation for the full list of keys.* |
| 79 |
|
| 80 |
- Given zeros and poles (gain and delay are ignored by the plot): |
| 81 |
```latex |
| 82 |
\PoleZeroMapZPK[% |
| 83 |
axes={width=6cm, height=6cm}, |
| 84 |
plot={blue, thick}% |
| 85 |
]{% |
| 86 |
zeros={0,-0.1-0.5i,-0.1+0.5i}, |
| 87 |
poles={-0.5-10i,-0.5+10i}, |
| 88 |
gain=10, |
| 89 |
delay=0.01% |
| 90 |
} |
| 91 |
``` |
| 92 |
- Given numerator and denominator (requires `Python` with `scipy` and `numpy` is available via `--shell-escape`) (delay is ignored by the plot) |
| 93 |
```latex |
| 94 |
\PoleZeroMapTF[% |
| 95 |
axes={width=6cm, height=6cm}, |
| 96 |
plot={blue, thick}% |
| 97 |
]{% |
| 98 |
numerator={10,2,2.6,0}, |
| 99 |
denominator={1,1,100.25}, |
| 100 |
delay=0.01% |
| 101 |
} |
| 102 |
``` |