This appendix shows examples of the use of TeXdraw.
The block diagram of a lattice filter uses a library of extended commands built from the basic TeXdraw commands.
The block diagram uses a "delay" block. This is defined as a segment
which leaves the current position at the end of this block. A second
macro, \bdot
, draws a "big" dot which is used to mark junctions
of lines. The \Ttext
command centers text above a given point.
The offset to position the text is local to a segment, resulting in no
change to the current point. Similar macros to position text below a
point (\Btext
), to the left of a point (\Ltext
) and to the
right of a point (\Rtext
) are used in the final drawing.
\def\delay {\bsegment \setsegscale 0.3 \lvec (0 +0.5) \lvec (1 +0.5) \lvec (1 -0.5) \lvec (0 -0.5) \lvec (0 0) \textref h:C v:C \htext (0.5 0){$z^{-1}$} \savepos (1 0)(*ex *ey) \esegment \move (*ex *ey)} \def\bdot {\fcir f:0 r:0.02 } \def\Ttext #1{\bsegment \textref h:C v:B \htext (0 +0.06){#1} \esegment}
Several of the block diagram elements scale with the size of the summing
nodes. The radius of the circles for the summing nodes is defined as
the macro \cradius
. The summing nodes will have enclosed plus
signs, appropriately scaled. The plus sign is drawn by the macro
\pluss
. The macro \pcir
draws both the circle and the
plus sign. The incoming lines to a summing node will be labelled with
plus or minus signs (characters this time), placed at the appropriate
position with respect to the center of the summing node. These
positions are given in terms of compass directions. The macro
\putwnw
places text west by north-west relative to the center of
the summing node.
\def\cradius {0.08} \def\pluss {\bsegment \setsegscale {\cradius} \move (-0.5 0) \lvec (+0.5 0) \move (0 -0.5) \lvec (0 +0.5) \esegment} \def\pcir {\lcir r:{\cradius} \pluss} \def\puttext (#1 #2)#3{\bsegment \setsegscale {\cradius} \textref h:C v:C \htext (#1 #2){#3} \esegment} \def\putwnw #1{\puttext (-1.7 +1.2){#1}}
The block diagram has vectors arriving and departing from the summing
nodes (circles). One could calculate the points of intersection of the
lines with the circles, and then enter the values into the TeXdraw
code. However, in this example, we implement an automated procedure.
Two macros are needed, an arrow vector to a circle (\avectoc
) and
an arrow vector leaving from a circle (\avecfrc
). The macros
will calculate the point of intersection with the circle and start or
end the vector at the intersection point.
The arrow macros use scaling and relative positioning inside of a
drawing segment. In the case of the macro \avectoc
, a move is
made to the final point (center of the circle), then within a drawing
segment, a scaled move is made back towards the initial point to
determine the intersection point with the circle.
\def\avectoc (#1 #2){\currentpos \xa\ya \cossin ({\xa} \ya)(#1 #2)\cosa\sina \savepos (#1 #2)(*tx *ty) \bsegment \move (*tx *ty) \setsegscale {\cradius} \rmove ({-\cosa} -\sina) \savecurrpos (*ex *ey) \esegment \avec (*ex *ey) \move (#1 #2)} \def\avecfrc (#1 #2){\currentpos \xa\ya \cossin ({\xa} \ya)(#1 #2)\cosa\sina \bsegment \setsegscale {\cradius} \move ({\cosa} \sina) \savecurrpos (*ex *ey) \esegment \move (*ex *ey) \avec (#1 #2)}
Having defined these macros, we are ready to draw the block diagram. The first and last sections of the lattice filter are very similar, differing mainly in the text labels. With more effort, code could be shared between the commands used to draw these blocks.
\centertexdraw{ \drawdim in \arrowheadtype t:F \arrowheadsize l:0.08 w:0.04 \def\pl {$\scriptscriptstyle +$} \def\mn {$\scriptscriptstyle -$} \move (0 +0.63) \move (0 -0.60) \move (0 0) % compensate for the text size % Input to the first stage \bsegment \Ltext{$x(n)$} \lvec (0.3 0) \bdot \lvec (0.3 +0.4) \move (0.3 0) \lvec (0.3 -0.4) \savepos (0.3 0)(*ex *ey) \esegment \move (*ex *ey) % first lattice stage \bsegment \move (0 +0.4) \avectoc (1.7 +0.4) \pcir \putwnw{\pl} \puts{\mn} \avecfrc (2.1 +0.4) \move (0 -0.4) \avec (0.4 -0.4) \delay \avectoc (1.7 -0.4) \pcir \putwsw{\pl} \putn{\mn} \avecfrc (2.1 -0.4) \move (0.9 +0.4) \bdot \avectoc (1.7 -0.4) \move (0.9 -0.4) \bdot \avectoc (1.7 +0.4) \move (0.1 +0.42) \Ttext {$f_0(n)$} \move (2.0 +0.42) \Ttext {$f_1(n)$} \move (0.1 -0.4) \Btext {$b_0(n)$} \move (2.0 -0.4) \Btext {$b_1(n)$} \textref h:L v:B \htext (1.15 +0.2){$K_1$} \textref h:L v:T \htext (1.15 -0.2){$K_1$} \savepos (2.1 0)(*ex *ey) \esegment \move (*ex *ey) % center section \bsegment \textref h:C v:C \htext (0.3 +0.4){$\cdots$} \htext (0.3 -0.4){$\cdots$} \savepos (0.6 0)(*ex *ey) \esegment \move (*ex *ey) % last lattice stage \bsegment \move (0 +0.4) \avectoc (1.7 +0.4) \pcir \putwnw{\pl} \puts{\mn} \avecfrc (2.3 +0.4) \Rtext{$e(n)$} \move (0 -0.4) \avec (0.4 -0.4) \delay \avectoc (1.7 -0.4) \pcir \putwsw{\pl} \putn{\mn} \avecfrc (2.1 -0.4) \move (0.9 +0.4) \bdot \avectoc (1.7 -0.4) \move (0.9 -0.4) \bdot \avectoc (1.7 +0.4) \move (0.1 +0.42) \Ttext {$f_{P-1}(n)$} \move (2.0 +0.42) \Ttext {$f_P(n)$} \move (0.1 -0.4) \Btext {$b_{P-1}(n)$} \move (2.0 -0.4) \Btext {$b_P(n)$} \textref h:L v:B \htext (1.15 +0.2){$K_P$} \textref h:L v:T \htext (1.15 -0.2){$K_P$} \esegment }
The macros used in this example are similar to the block diagram macros defined in the file `blockdiagram.tex'.
This example shows the response of a canonical filter. TeXdraw is not well suited for general purpose graphing -- it has no coordinate translation facility nor does it have separate x and y scaling. Nonetheless, for certain simple graphs, TeXdraw is adequate.
In this example, macro \ticklab
places a labelled axis tick at a
given position. The data is specified in a straightforward manner,
having been scaled beforehand to give the desired aspect ratio for the
graph.
\centertexdraw{ \arrowheadtype t:F \arrowheadsize l:0.08 w:0.04 \def\ds {\displaystyle} \def\ticklab (#1 #2)#3{\move(#1 #2) \bsegment \lvec (0 0.05) \textref h:C v:T \htext (0 -0.05){#3} \esegment} \def\Rtext #1{\bsegment \textref h:L v:C \htext (+0.08 0){#1} \esegment} \move (2.4 -0.3) % move to set the size \move (0 0) % Axes \avec (0 +1.4) \move (0 0) \avec (2.2 0) \Rtext{$\omega$} \ticklab (0 0) {0} \ticklab (0.8 0) {$\ds {\pi \over 2N} $} \ticklab (1.2 0) {$\omega_s$} \ticklab (1.6 0) {$\ds {\pi \over N} $} \linewd 0.025 \move (0 1) \lvec (0.4 1) \lvec (0.44 0.998) \lvec (0.48 0.988) \lvec (0.52 0.973) \lvec (0.56 0.951) ... \lvec (1.08 0.233) \lvec (1.12 0.156) \lvec (1.16 0.078) \lvec (1.20 0) \lvec (1.9 0) }
This example shows a geometric construction which places an ellipse tangent to an enclosing circle. The size of the ellipse is determined from geometric considerations. Macros are used to modularize the code. The example alters the unit scale factor. This allows the drawing to be carried out in units normalized to the radius of the circle.
\centertexdraw{ \arrowheadtype t:V \arrowheadsize l:0.08 w:0.04 \linewd 0.01 \setunitscale 1.5 % circle will have radius 1.5 inches \def\Btext #1{\bsegment \textref h:C v:T \htext (0 -0.04){#1} \esegment} \def\Ttext #1{\bsegment \textref h:C v:B \htext (0 +0.04){#1} \esegment} \def\Ltext #1{\bsegment \textref h:R v:C \htext (-0.04 0){#1} \esegment} \def\bdot {\fcir f:0 r:0.0133 } \def\vtick {\bsegment \move (0 -0.05) \lvec (0 +0.05) \esegment} \def\htick {\bsegment \move (-0.05 0) \lvec (+0.05 0) \esegment} \def\Hlen #1#2{\bsegment \vtick \avec ({#1} 0) \vtick \avec (0 0) \relsegscale 0.5 \move ({#1} 0) \Ttext {#2} \esegment} \def\Vlen #1#2{\bsegment \htick \avec (0 {#1}) \htick \avec (0 0) \relsegscale 0.5 \move (0 {#1}) \Ltext {#2} \esegment} \lcir r:1 % circle \move (-1.05 0) \lvec ( 1.05 0) % axes \move (0 -1.05) \lvec (0 1.05) \move (0 0) \lvec (0.707 0.707) \bdot \rmove (0.02 0.02) \textref h:L v:B \htext {X} \move (0.707 -0.707) \bdot \textref h:R v:T \htext(-0.02 -0.02){O} \move (0.5 0) % center of ellipse \bsegment \lellip rx:0.435 ry:0.804 \bdot \Btext {$\beta_2$} \move (0 0.15) \Hlen {0.435}{$|\beta_1{+}\beta_3|$} \move (-0.7 0) \Vlen {0.804}{$|\beta_1{-}\beta_3|$} \esegment }
Go to the first, previous, next, last section, table of contents.