(texdraw)Block diagram


Next: Filter response graph Up: Examples
Enter node , (file) or (file)node

C.1 Block diagram of a lattice filter
=====================================

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'.


automatically generated by info2www version 1.2.2.9