Você está na página 1de 4

Block diagram generation in LATEX

Xu Chen (ucbmaxchen AT gmail AT com)


2011-10-11
Background knowledge: basic LATEX commands and some LYX knowledge.
There are multiple ways to generate block diagrams in LATEX. Here are three that I found most suitable for me:

xyplot using \xymatrix

This supports LYX (www.lyx.org), the editor I use for LATEX.


Basic commands:
\xymatrix: generate a matrix where you can position each element with items you want (in my case, blocked
transfer functions)
\ar[pos]: arrow placing to [pos], where pos can take the values of: l(eft), r(ight), d(own), u(pp)
[F]{stuff}: put contents into frames, e.g., [F]{C} gives you a boxed C.

Example 1:
Code: \xymatrix{*-=[o]{\circ}\ar[r] & *+[F]{P}\ar@{-}[r] & *+[.][F]{}\ar[d]\\*+[.][F]{}\ar[u] & *+[F]{C}\ar[l]
& *+[.][F]{}\ar[l]\ar@(dl,dr)[ll]}
Result:
/

O
_o

Example 2:
Code: \xymatrix{*-=[o]{\circ}\ar[r] & *+[F]{P}\ar[r] & *+[.][F]{}\ar[d]\\*+[.][F]{}\ar[u]^{-} & *+[F]{C}\ar[l]
& *+[.][F]{}\ar[l]}
Result:
O

Troubles in LYX: The label is troublsome when I want to customize its locations. E.g., I want to get
O

o
1

which, when put in the what-you-see-is-what-you-get LYX environment (with the command ctrl+m), gives you
the following:
O

o
However, in the ctrl+l environment in LYX there is no such error.

PSTricks and pst-sigsys

pst-sigsys stands for (my personal interpretation) additional PSTricks for signal processing.
Pros:
commands are more meaningful and easier to remember
the figures are prettier
much easier in node connections
Cons: it does not support pdflatex. I need to compile to dvi first, and then use ps2pdf.
Useful commands:
Nodes:
\pnode(x,y){name}: put a zero dimentional node at (x,y)
\rnode[refpoint]{name}{stuff}: put stuff in a box, centered at refpoint
\cnode(x,y){radius}{name}: draw a circle node
Node connections (nc):
\ncline{arrows}{starting name}{ending name}, where arrows can take the values: ->, <-, -, ...
\begin{pspicture}(6,2): the frame of the pic is a 6 by 2 rectangle
Node labeling:
\ncput[npos = 0.9]{-}: node connection, put label on the line, at 90% of the length, the stuff to put
is -
\baput[]{}: put above the line
\bbput[]{}: put below the line
Example 1:
Codes:
\begin{pspicture}(6,2)
\rput(0,1){\rnode{x}{$x[n]$}}
%\psfblock[framesize =0.75 0.5](2,1){a}{$H_1$}
%\psfblock[framesize =1.5 1](4,1){b}{$H_2$}
\psblock(1.5,1){a}{$H_1$}
\psblock(3,1){b}{$H_2$}
\rput(6,1){\rnode{y}{$y[n]$}}
%
\psset{style = Arrow }
\ncline[nodesepA =.15]{x}{a}
\ncline{a}{b}
\ncline[nodesepB =.15]{b}{y}
\end{pspicture}
2

Result:

[]

[]

Some more examples

1 []
1 ()
[]

2 ()

1 []
[]

2 []
2 ()

( 1 )

1 ()

( 1 )

++ ( 1 ) ()
(1 ) ( 1 )

( 1 )

tikz

Compared to pst-sigsys, this one is more convenient for me since it supports pdflatex directly.
Example codes from http://www.texample.net/tikz/examples/control-system-principles/
\tikzstyle{block} = [draw, rectangle, minimum height=2em, minimum width=4em] %fill=blue!20
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate] \tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{tikzpicture}[auto, node distance=2cm,>=latex]
\node [input, name=input] {};
3

\node [sum, right of=input] (sum) {};


\node [block, right of=sum, node distance=3.5cm] (controller) {$C(z^{-1})$};
\node [block, right of=controller, pin={[pinstyle]above:$d(k)$}, node distance=4cm] (system) {$P(z^{-1})$};
\draw [->] (controller) node[name=u] {$u(k)$} (system);
\node [output, right of=system] (output) {};
\node [block, below of=u] (measurements) {$F(z^{-1})$};
\draw [draw,->] (input) node {$r(k)$} (sum);
\draw [->] (sum) node {$e(k)$} (controller);
\draw [->] (system) node [name=y] {$y(k)$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (measurements) -| node[pos=0.99] {$-$} node [near end] {$y_m(k)$} (sum);
\end{tikzpicture}
()
()

()

( 1 )

()

( 1 )

()
( 1 )

()

Você também pode gostar