summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/texdraw/texdraw_8.html
blob: 09ee5d145206a201e0cbf47df91c366bb086f3ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<HTML>
<HEAD>
<!-- Created by texi2html 1.56k from texdraw.texi on 10 March 2004 -->

<TITLE>TeXdraw - C. Examples</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="texdraw_1.html">first</A>, <A HREF="texdraw_7.html">previous</A>, <A HREF="texdraw_9.html">next</A>, <A HREF="texdraw_11.html">last</A> section, <A HREF="texdraw_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC35" HREF="texdraw_toc.html#TOC35">C. Examples</A></H1>
<P>
<A NAME="IDX183"></A>


<P>
This appendix shows examples of the use of TeXdraw.



<UL>
<LI><A HREF="texdraw_8.html#SEC36">Block diagram</A>
<LI><A HREF="texdraw_8.html#SEC37">Filter response graph</A>
<LI><A HREF="texdraw_8.html#SEC38">Geometric construction</A>
</UL>



<H2><A NAME="SEC36" HREF="texdraw_toc.html#TOC36">C.1 Block diagram of a lattice filter</A></H2>

<P>
The block diagram of a lattice filter uses a library of extended
commands built from the basic TeXdraw commands.


<P>
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, <CODE>\bdot</CODE>, draws a "big" dot which is used to mark junctions
of lines.  The <CODE>\Ttext</CODE> 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 (<CODE>\Btext</CODE>), to the left of a point (<CODE>\Ltext</CODE>) and to the
right of a point (<CODE>\Rtext</CODE>) are used in the final drawing.

<PRE>
\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}
</PRE>

<P>
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 <CODE>\cradius</CODE>.  The summing nodes will have enclosed plus
signs, appropriately scaled.  The plus sign is drawn by the macro
<CODE>\pluss</CODE>.  The macro <CODE>\pcir</CODE> 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
<CODE>\putwnw</CODE> places text west by north-west relative to the center of
the summing node.

<PRE>
\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}}
</PRE>

<P>
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 (<CODE>\avectoc</CODE>) and
an arrow vector leaving from a circle (<CODE>\avecfrc</CODE>).  The macros
will calculate the point of intersection with the circle and start or
end the vector at the intersection point.


<P>
The arrow macros use scaling and relative positioning inside of a
drawing segment.  In the case of the macro <CODE>\avectoc</CODE>, 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.



<PRE>
\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)}
</PRE>

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

<PRE>
\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
}
</PRE>

<P>
The macros used in this example are similar to the block diagram macros
defined in the file <TT>`blockdiagram.tex'</TT>.




<H2><A NAME="SEC37" HREF="texdraw_toc.html#TOC37">C.2 Filter response graph</A></H2>
<P>
<A NAME="IDX184"></A>


<P>
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 <VAR>x</VAR> and <VAR>y</VAR>
scaling.  Nonetheless, for certain simple graphs, TeXdraw is
adequate.


<P>
In this example, macro <CODE>\ticklab</CODE> 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.



<PRE>
\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)
}
</PRE>



<H2><A NAME="SEC38" HREF="texdraw_toc.html#TOC38">C.3 Geometric construction</A></H2>
<P>
<A NAME="IDX185"></A>


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



<PRE>
\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
}
</PRE>

<P><HR><P>
Go to the <A HREF="texdraw_1.html">first</A>, <A HREF="texdraw_7.html">previous</A>, <A HREF="texdraw_9.html">next</A>, <A HREF="texdraw_11.html">last</A> section, <A HREF="texdraw_toc.html">table of contents</A>.
</BODY>
</HTML>