[Tex/LaTex] Draw Bode diagram

drawtikz-pgf

I want to recreate the following Bode diagram :

enter image description here

My problem is the curved line, I don't know the formula so I've to draw it manually but regretfully I'm not able to recreate it perfectly, here's my try :

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=1in]{geometry}
\usepackage{xcolor}
\usepackage{graphicx,setspace}
\renewcommand{\baselinestretch}{1.5}
\usepackage{tikz}
\usetikzlibrary{angles, arrows.meta,
                quotes}
\usetikzlibrary{fit,calc,positioning,decorations.pathreplacing,matrix}                
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}

\begin{document}
\begin{tikzpicture}[scale=.8]
\begin{axis}[xmode=log,
            tick style={draw=none},
            xmin=1e-2,
            xmax=1e3,
            ymin=-100,
            ymax=100,
            grid=both]
\draw [blue] (axis cs:1e-2,-90) .. controls (axis cs:0.08,-75) .. (axis cs:0.3,-45);
\draw [blue] (axis cs:0.3,-45) .. controls (axis cs:1,-15) .. (axis cs:2,3);
\draw [blue] (axis cs:2,3) .. controls (axis cs:30,65) .. (axis cs:1e3,5);
\draw [red,dashed] (axis cs:1e-2,-90) -- (axis cs:1e-1,-90) -- (axis cs:1e-1,0) -- (axis cs:1e1,0) -- (axis cs:1e1,90) -- (axis cs:1e2,90) -- (axis cs:1e2,0) -- (axis cs:1e3,0);
\end{axis}
\end{tikzpicture}

\end{document}

Best Answer

From the phase plot, your transfer function has:

  • 1 integrator,
  • 1 pole (at w=100),
  • and 2 zeros (at w=0.1 and w=10).

It can be written as follows:

enter image description here

Here is my attempt using bodegraph package. You can also check this tutorial: The Easiest Way to Draw a BODE Plot in LaTeX!).

\documentclass{standalone}

\usepackage{bodegraph}

\begin{document}

\begin{tikzpicture}[
    gnuplot def/.append style={prefix={}},
]

 \tikzset{
 semilog lines/.style={black},
 semilog lines 2/.style={gray!50},
 semilog half lines/.style={gray!50, dotted},
 semilog label x/.style={below,font=\small},
 semilog label y/.style={above,font=\small} }


\begin{scope}[xscale=10/5,yscale=5/200]

% y axis step
\OrdBode{50}

% Semilog grid
\semilog*{-2}{3}{-100}{100}

% Plot asymptotic lines
\draw[blue!80,dashed,line width=1.2] (-2,-90 ) -| (-1,0 ) -| (1,90) -|(2,0) -- (3,0);

% Phase plot of the transfer function
\BodeGraph[red!80]{-2:3}{\IntArg{1}+\POArg{1}{0.01}-\POArg{1}{10}-\POArg{1}{0.1}}

% Text node
\node[fill=white] at (-1,50){Phase ($^{\circ}$)};
\end{scope}

\end{tikzpicture}

\end{document}

which yields:

enter image description here

For a touch of style, suggested by @Sebastiano, you can modify opacity of the phase label as follows:

\node[fill=white,opacity=0.9] at (-1,50){Phase ($^{\circ}$)};

which yields: enter image description here

Related Question