Debian Codegraph @

texmf-dist/doc/latex/dsptricks/dspTricksManual.tex

raw
1 % User manual for the DSPTricks package
2 % (c) Paolo Prandoni, 2014-2023
3 % v1.1, November 2023
4 % For more information, [email protected]
5
6 \documentclass[a4paper,14pt]{ltxdoc}
7 \usepackage{float}
8 \usepackage{fancyvrb}
9 \usepackage{enumitem}
10 \usepackage{newpxtext,newpxmath}
11 \usepackage{url}
12 \usepackage{dsptricks,dspfunctions,dspblocks}
13
14
15 \def\dspt{{DSPTricks}}
16 \def\dspf{{DSPFunctions}}
17 \def\dspb{{DSPBlocks}}
18 \def\psTricks{{PSTricks}}
19
20 \setlength\parindent{0pt}
21
22 \newenvironment{optList}{%
23 \begin{description}[labelindent=2em,font=\rm,itemsep=-1mm,leftmargin=2cm]}%
24 {\end{description}}
25
26 \def\vblock{\begin{Verbatim}[frame=single,%
27 numbers=left,numbersep=2pt,%
28 fontsize=\footnotesize,%
29 xleftmargin=0mm,xrightmargin=0mm]}
30 \def\evblock{\end{Verbatim}}
31 \def\vopts{frame=single,%
32 numbers=left,numbersep=2pt,%
33 fontsize=\footnotesize,%
34 xleftmargin=15mm,xrightmargin=6mm}
35
36 \newenvironment{centerfig}{%
37 \begin{figure}[H]
38 \begin{center}}{
39 \end{center}
40 \end{figure}}
41
42 \begin{document}
43
44 \title{\dspt: a Set of Macros \\ for Digital Signal Processing Plots}
45 \author{Paolo Prandoni}
46 %\date{}
47 \maketitle
48
49
50
51 The package \dspt\ provides a set of \LaTeX\ macros for plotting the kind of graphs and figures that are usually employed in digital signal processing publications\footnote{The original macros have been written by the author while working on the manuscript for~\cite{PV}.}; the package relies on \psTricks~\cite{TVZ93,HV} to generate its graphic output.
52 %\footnote{Please note that these macros have been written rather quickly and chiefly for personal use. Use at your own risk and caveat emptor.}
53 \\
54
55 The basic \dspt\ plot is a boxed chart displaying a discrete-time or a continuous-time signal, or a superposition of both; discrete-time signals are plotted using the ``lollipop'' formalism while continuous-time functions are rendered as smooth curves. Other types of plots that commonly occur in the signal processing literature, and for which \dspt\ offers macros, are frequency-domain plots and pole-zero plots. \dspt\ comes with two companion packages:
56 \begin{itemize}
57 \item \dspb\ provides a set of macros to design simple signal processing block diagrams;
58 \item \dspf\ provides a set of signal shapes commonly used in basic signal processing in terms of PostScript primitives (such as rect, sinc, etc), as well as macros to compute DFTs, frequency responses, and filter outputs on the fly.
59 \end{itemize}
60
61
62 The idea behind these macros is to be able to write a completely self-contained signal processing manuscript without the need of an external numerical package to precompute the necessary signals.
63
64
65
66 \section{Drawing Signals}
67
68 Signal plots in \dspt\ use a Cartesian grid enclosed by a box; there are three fundamental types of plots:
69 \begin{itemize}
70 \item discrete-time plots,
71 \item continuous-time plots,
72 \item frequency-domain plots;
73 \end{itemize}
74 discrete- and continuous-time plots can be mixed in the same box, whereas frequency-domain plots involve a re-labeling of the horizontal axis using trigonometric units.
75
76
77 \subsection{The {\tt dspPlot} environment}
78 Data plots are defined by the {\tt dspPlot} environment as \DescribeEnv{dspPlot}
79 \begin{quote}
80 |\begin{dspPlot}|\oarg{options}\marg{xmin, xmax}\marg{ymin, ymax} \\
81 ... \\
82 |\end{dspPlot}|
83 \end{quote}
84 This sets up a data plot with the horizontal axis spanning the \meta{xmin}-\meta{xmax} interval and with the vertical axis spanning the \meta{ymin}-\meta{ymax} interval. The following options are available for all data plots:
85
86 \begin{optList}
87 \item[|width|=\meta{dim}]: width of the plot (using any units)
88 \item[|height|=\meta{dim}]: height of the plot. Width and height specify the size of the active plot area, i.e., of the \emph{boxed region} of the cartesian plane specified by the $x$ and $y$ ranges for the plot. This is possibly augmented by the space required by the optional labels and axis marks. You can set the default size for a plot by setting the \DescribeEnv{dspW, dspH} |\dspW| and |\dspH| lengths at the beginning of your document
89 \end{optList}
90
91 \begin{optList}
92 \item[|xtype| = |time| $\mid$ |freq| ]: type of plot: time domain (default) or digital frequency plot
93 \end{optList}
94
95 \begin{optList}
96 \item[|xticks| = |auto| $\mid$ |custom| $\mid$ |none| $\mid$ \meta{step}]: labeling of the horizontal axis
97 \item[|yticks| = |auto| $\mid$ |custom| $\mid$ |none| $\mid$ \meta{step}]: labeling of the vertical axis. When the option specifies a numeric value \meta{step}, that will be the spacing between two consecutive ticks on the axis\footnote{For digital frequency plots, |xticks| has a different meaning; see Section~\ref{freqPlots} for details.}. When |auto| is selected, the spacing will be computed automatically as a function of the axis range. When |none| is selected, no ticks will be drawn. When |custom| is selected, no ticks will be drawn but the plot will include the appropriate spacing for ticks to be drawn later via the |\dspCustomTicks| macro.
98 \item[|sidegap| = \meta{gap}]: extra space (in horizontal units) to the left and the right of the $x$-axis range. Useful in discrete-time plots not to have stems overlapping the plot's frame. By default, it's automatically determined as a function of the range; use a value of zero to eliminate the side gap.
99 \item[|xout| = |true| $\mid$ |false|]: normally, ticks and tick labels for the horizontal axis are placed on the axis, which may be inside the box; set this option to |true| if you want to place the ticks on the lower edge of the box in all cases.
100 \item[|inticks| = |true| $\mid$ |false|]: x-axis ticks are normally extending downwards; by setting this option to |true| ticks will be pointing upwards, i.e. they will be inside the plot box even when the x-axis coincides with the bottom of the box.
101 \end{optList}
102
103 \begin{optList}
104 \item[|xlabel| = \meta{label} ]: label for the horizontal axis; placed outside the plot box
105 \item[|ylabel| = \meta{label} ]: label for the vertical axis; placed outside the plot box, on the left
106 \item[|rlabel| = \meta{label} ]: additional label for the vertical axis; placed outside the plot box on the right
107 \end{optList}
108
109
110
111
112 Within a |dspPlot| environment you can use the plotting commands described in the next sections, as well as any \psTricks\ command; in the latter case, the \psTricks\ values for |xunit| and |yunit| are equal to the units used for the axes. Other useful commands for all data plots are the following:
113 \begin{itemize}
114 \item \DescribeEnv{dspClip} in order to make sure that all drawing commands are clipped to the bounding box defined by the box chart, you can enclose them individually in a predefined |dspClip| environment. See section~\ref{clipEx} for an example.
115 \item \DescribeMacro{dspPlotFrame} to redraw the framing box (useful to ``smooth out'' plots touching the frame) you can issue the command |\dspPlotFrame|
116 \item \DescribeMacro{dspCustomTicks} to draw arbitrarily placed ticks (and tick labels) on either axis, use
117 \begin{quote}
118 |\dspCustomTicks|\oarg{options}\marg{pos label pos label ...}
119 \end{quote}
120 where the axis is specified in the options field as either |axis=x| (default) or |axis=y| and where the argument is a list of space-separated coordinate-label pairs. If you use math mode for the labels, \emph{do not use spaces in your formulas} since that will confuse the list-parsing macros.
121
122 \textbf{NOTE}: there is an incompatibility between |\dspCustomTicks| and the |tabular| environment. When using |\dspCustomTicks| in a table, enclose all lines between |\begin{dspPlot}| and |\end{dspPlot}| in a group (\{ ~\}).
123 \item \DescribeMacro{dspText} place a text label anywhere in the plot using the axes coordinates:
124 \begin{quote}
125 |\dspText|(x, y)\marg{label}
126 \end{quote}
127 \end{itemize}
128
129
130 \subsection{Plotting Discrete-Time Signals}
131 The following commands generate stem (or ``lollipop'') plots; available options in the commands are all standards \psTricks options plus other specialized options when applicable:
132
133 \begin{itemize}
134 \item \DescribeMacro{dspTaps} to plot a set of discrete time points use
135 \begin{quote}
136 |\dspTaps|\oarg{options}\marg{data}
137 \end{quote}
138 where \meta{data} is a list of space-separated index-value pairs (e.g., values pre-computed by an external numerical package). Allowed options are the generic \psTricks\ plot options.
139
140 \item \DescribeMacro{dspTapsAt} to plot a set of discrete time points use
141 \begin{quote}
142 |\dspTapsAt|\oarg{options}\marg{start}\marg{data}
143 \end{quote}
144 where \meta{start} is the initial index value and \meta{data} is a list of space-separated signal values. Allowed options are the generic \psTricks\ plot options.
145
146 \item \DescribeMacro{dspTapsFile} for large data sets, you can use
147 \begin{quote}
148 |\dspTapsFile|\oarg{options}\marg{fileName}
149 \end{quote}
150 where now \meta{fileName} points to an external text file of space-separated index-value pairs.
151
152 \item \DescribeMacro{dspSignal} to plot a discrete-time signal defined in terms of PostScript primitives use
153 \begin{quote}
154 |\dspSignal|\oarg{options}\marg{PostScript code}
155 \end{quote}
156 The PostScript code must use the variable |x| as the independent variable; the |\dspPlot| environment sweeps |x| over all integers in the \meta{xmin}-\meta{xmax} interval defined for the plot; this can be changed for each individual signal by using the options \DescribeMacro{xmin,xmax} |xmin|=\meta{m} and/or |xmax|=\meta{n}. If you use \TeX\ macros in your PS code, make sure you include a space at the end of the macro definition. For instance, use |\def\gain\{0.75|\textvisiblespace|}|.
157
158 \item \DescribeMacro{dspSignalOpt} to perform a PostScript initialization sequence before plotting the discrete-time signal, use
159 \begin{quote}
160 |\dspSignalOpt|\oarg{options}\marg{init}\marg{PostScript code}
161 \end{quote}
162 where \meta{init} is a valid PostScript sequence (e.g. {\tt \{/A [1 2 3] def\}} to initialize an array of data).
163 \end{itemize}
164
165
166 For example:
167 \vblock
168 \begin{dspPlot}{-3, 22}{-1.2, 1.2}
169 % for my postscript interpreter rand_max is 0x7FFFFFFF
170 \dspSignal[xmin=8]{rand 2147483647 div 0.5 sub 2 mul}
171 \dspTaps[linecolor=red]{3 1 4 1 5 1}
172 \dspTapsAt[linecolor=blue!60]{-2}{-.5 .5}
173 \end{dspPlot}
174 \end{Verbatim}
175 produces the following plot:
176
177 \begin{centerfig}
178 \begin{dspPlot}{-3, 22}{-1.2, 1.2}
179 % for my postscript interpreter rand_max is 0x7FFFFFFF
180 \dspSignal[xmin=8]{rand 2147483647 div 0.5 sub 2 mul}
181 \dspTaps[linecolor=red]{3 1 4 1 5 1}
182 \dspTapsAt[linecolor=blue!60]{-2}{-.5 .5}
183 \end{dspPlot}
184 \end{centerfig}
185
186 If you are viewing this document in a PostScript viewer, you can see that the random signal is different every time you reload the page, since the taps values are computed on the fly by the PostScript interpreter.
187
188
189 \subsection{Plotting Continuous-Time Signals}
190 Continuous-time functions can be plotted with the following commands:
191
192 \begin{itemize}
193 \item \DescribeMacro{dspFunc} You can draw a continuous-time signal by using the command
194 \begin{quote}
195 |\dspFunc|\oarg{options}\marg{PostScript code}
196 \end{quote}
197 again, the PostScript code must use |x| as the independent variable; the range for |x| is the \meta{xmin}-\meta{xmax} interval and can be controlled for each signal independently via the|xmin| and |xmax| options.
198
199 \item \DescribeMacro{\dspFuncOpt} to perform a PostScript initialization sequence before plotting the continuous-time signal, use
200 \begin{quote}
201 |\dspFuncOpt|\oarg{options}\marg{init}\marg{PostScript code}
202 \end{quote}
203 where \meta{init} is a valid PostScript sequence.
204
205 \item \DescribeMacro{dspFuncData} To plot a smooth function obtained by interpolating a list of space separated time-value pairs use
206 \begin{quote}
207 |\dspFuncData|\oarg{options}\marg{data}
208 \end{quote}
209 the interpolation is performed by the PostScript interpreter and can be controlled if necessary by using the appropriate \psTricks\ options.
210
211 \item \DescribeMacro{dspFuncDataAt} To plot a smooth function obtained by interpolating a list of space separated values use
212 \begin{quote}
213 |\dspFuncDataAt|\oarg{options}\marg{start}\marg{data}
214 \end{quote}
215 This macro works like |\dspFuncData| but the time indices are assumed to be increasing integers beginning at \meta{start}.
216
217 \item \DescribeMacro{dspFuncFile} For a continuous-time smooth interpolation of a pre-computed set of data points, use
218 \begin{quote}
219 |\dspFuncFile|\oarg{options}\marg{fileName}
220 \end{quote}
221 where \meta{fileName} points to a text file containing the data points as a space-separated list of abscissae and ordinates.
222
223 \item \DescribeMacro{dspDiracs} To plot one or more Dirac deltas (symbolized by a vertical arrow) use
224 \begin{quote}
225 |\dspDiracs|\oarg{options}\marg{pos value pos value ...}
226 \end{quote}
227 where the argument is a list of space-separated time-value pairs.
228 \end{itemize}
229
230 In the following example, note the use of the |dspClip| environment when plotting the hyperbola\footnote{Make sure not to leave any blank space in between the beginning and end of the |dspClip| environment, otherwise the axis labels may fall out of alignment.}:\label{clipEx}
231 \vblock
232 \begin{dspPlot}[yticks=1,sidegap=0]{0,10}{0,5}
233 \begin{dspClip}\dspFunc{1 3 x sub div abs}\end{dspClip}
234 \dspDiracs[linecolor=red]{3 4}
235 \end{dspPlot}
236 \end{Verbatim}
237
238 \begin{centerfig}
239 \begin{dspPlot}[yticks=1,sidegap=0]{0,10}{0,5}
240 \begin{dspClip}\dspFunc{1 3 x sub div abs}\end{dspClip}
241 \dspDiracs[linecolor=red]{3 4}
242 \end{dspPlot}
243 \end{centerfig}
244
245
246
247
248 \subsection{Plotting Discrete- and Continuous-Time Signals Together}
249
250 In the following examples we mix discrete- and continuous-time signals in the same plot:
251 \vblock
252 \begin{dspPlot}[xticks=10,yticks=0.2]{-5, 20}{-0.4, 1.2}
253 \def\sincx{x 0 eq {1} {x RadtoDeg sin x div} ifelse}
254 \dspSignal[xmax=10]{\sincx}
255 \dspFunc[linewidth=0.5pt,xmax=10]{\sincx}
256 \dspFunc[linestyle=dashed,linewidth=0.5pt,xmin=10]{\sincx}
257 \end{dspPlot}
258 \end{Verbatim}
259
260 \begin{centerfig}
261 \begin{dspPlot}[xticks=10,yticks=0.2]{-5, 20}{-0.4, 1.2}
262 \def\sincx{x 0 eq {1} {x RadtoDeg sin x div} ifelse}
263 \dspSignal[xmax=10]{\sincx}
264 \dspFunc[linewidth=0.5pt,xmax=10]{\sincx}
265 \dspFunc[linestyle=dashed,linewidth=0.5pt,xmin=10]{\sincx}
266 \end{dspPlot}
267 \end{centerfig}
268
269
270 \vblock
271 \begin{dspPlot}[sidegap=0.5,yticks=none]{-6, 6}{-1.2, 1.2}
272 \def\signal{ 0.5235 mul RadtoDeg sin }
273 \def\quantize{ dup 0 gt {-0.5} {0.5} ifelse sub truncate }
274 \dspFunc[linecolor=gray,linewidth=2pt]{x \quantize \signal }
275 \dspFunc[linestyle=dotted,linewidth=1pt]{x \signal}
276 \dspSignal{x \signal}
277 \end{dspPlot}
278 \end{Verbatim}
279
280 \begin{centerfig}
281 \begin{dspPlot}[sidegap=0.5,yticks=none]{-6, 6}{-1.2, 1.2}
282 \def\signal{ 0.5235 mul RadtoDeg sin }
283 \def\quantize{ dup 0 gt {-0.5} {0.5} ifelse sub truncate }
284 \dspFunc[linecolor=gray,linewidth=2pt]{x \quantize \signal }
285 \dspFunc[linestyle=dotted,linewidth=1pt]{x \signal}
286 \dspSignal{x \signal}
287 \end{dspPlot}
288 \end{centerfig}
289
290
291
292 \subsection{Plotting Digital Spectra}\label{freqPlots}
293
294 Digital frequency\footnote{By ``digital spectrum'' of a discrete-time sequence $x[n]$ we refer to the Discrete-Time Fourier transform
295 \[
296 X(e^{j\omega}) = \sum_{n = -\infty}^{\infty} x[n] e^{-j\omega n}
297 \]} plots are set up by setting the option |xtype=freq| in the |dspPlot| environment; they are very similar to continuous-time plots, except for the following:
298
299 \begin{itemize}
300 \item the horizontal axis represents angular frequency; its range is specified in normalized units so that, for instance, a range of {\tt \{-1,1\}} as the first argument to |dspPlot| indicates the frequency interval $[-\pi, \pi]$.
301 \item tick labels on the horizontal axis are expressed as integer fractions of $\pi$; in this sense, the |xticks| parameter, when set to a numeric value, indicates the denominator of said fractions.
302 \item |sidegap| is always zero in digital frequency plots.
303 \end{itemize}
304
305 All digital spectra are $2\pi$-periodic, hence the $[-\pi, \pi]$ interval is sufficient to completely represent the function. However, if you want to explicitly plot the function over a wider interval, it is your responsibility to make the plotted data $2\pi$-periodic; the \DescribeMacro{dspPeriodize} |\dspPeriodize| macro can help you do that, as shown in the examples below. Also, when writing PostScript code, don't forget to scale the $x$ variable appropriately; in particular, PostScript functions of an angle use units in degrees, so you need to multiply |x| by 180 before computing trigonometric functions.
306
307
308
309
310 \vblock
311 \def\lambda{0.9 }
312 \def\magn{\lambda 1 sub dup mul 1 \lambda \lambda mul %
313 add x 180 mul cos 2 mul \lambda mul sub div }
314 \def\phase{\lambda x 180 mul sin mul -1 mul 1 \lambda %
315 x 180 mul cos mul sub atan 180 div 3.1415 mul }
316
317 \begin{dspPlot}[xtype=freq,xticks=3,yticks=0.2, %
318 ylabel={Square magnitude $|H(e^{j\omega})|^2$}]{-1,1}{0,1.1}
319 \dspFunc{\magn }
320 \end{dspPlot}
321
322 \begin{dspPlot}[xtype=freq,xticks=3,yticks=custom, %
323 ylabel={Phase (radians)}]{-1,1}{-1.57,1.57}
324 \dspFunc[xmax=0]{\phase }
325 \dspFunc[xmin=0]{-\phase -1 mul}
326 \dspCustomTicks[axis=y]{-1.57 $-\pi/2$ 0 0 1.57 $\pi/2$}
327 \end{dspPlot}
328 \end{Verbatim}
329 %
330
331
332 \def\lambda{0.9 }
333 \def\magn{\lambda 1 sub dup mul 1 \lambda \lambda mul %
334 add x 180 mul cos 2 mul \lambda mul sub div }
335 \def\phase{\lambda x 180 mul sin mul -1 mul 1 \lambda %
336 x 180 mul cos mul sub atan 180 div 3.1415 mul }
337
338 \DeleteShortVerb{\|}
339 \begin{centerfig}
340 \begin{center}
341 \begin{dspPlot}[xtype=freq,xticks=3,yticks=0.2, %
342 ylabel={Square magnitude $|H(e^{j\omega})|^2$}]{-1,1}{0,1.1}
343 \dspFunc{\magn }
344 \end{dspPlot}
345
346 \begin{dspPlot}[xtype=freq,xticks=3,yticks=custom,ylabel={Phase (radians)}]{-1,1}{-1.57,1.57}
347 \dspFunc[xmax=0]{\phase }
348 \dspFunc[xmin=0]{-\phase -1 mul}
349 \dspCustomTicks[axis=y]{-1.57 $-\pi/2$ 0 0 1.57 $\pi/2$}
350 \end{dspPlot}
351 \end{center}
352 \end{centerfig}
353 \MakeShortVerb{\|}
354
355
356
357 \newpage
358
359
360 \vblock
361 \begin{dspPlot}[xtype=freq,xticks=1,yticks=1,xout=true]{0,1}{-0.5,1.5}
362 \psframe[fillstyle=vlines,%
363 hatchcolor=lightgray,hatchangle=20,%
364 linecolor=lightgray]%
365 (0,1.1)(0.4,0.9)
366 \psframe[fillstyle=vlines,%
367 hatchcolor=lightgray,hatchangle=20,%
368 linecolor=lightgray]%
369 (0.6,0.3)(1,-0.3)
370 \psline[linewidth=0.5pt](0.4,-.5)(0.4,1.5)
371 \psline[linewidth=0.5pt](0.6,-.5)(0.6,1.5)
372 \dspFunc[linecolor=red]{x 3.14 mul 0.5 mul 10 exp 1 add 1 exch div}
373 \dspPlotFrame
374 \dspCustomTicks{0.4 $0.4\pi$ 0.6 $0.6\pi$}
375 \end{dspPlot}
376 \end{Verbatim}
377
378 \begin{centerfig}
379 \begin{dspPlot}[xtype=freq,xticks=1,yticks=1,,xout=true]{0, 1}{-0.5,1.5}
380 \psframe[fillstyle=vlines,%
381 hatchcolor=lightgray,hatchangle=20,%
382 linecolor=lightgray]%
383 (0,1.1)(0.4,0.9)
384 \psframe[fillstyle=vlines,%
385 hatchcolor=lightgray,hatchangle=20,%
386 linecolor=lightgray]%
387 (0.6,0.3)(1,-0.3)
388 \psline[linewidth=0.5pt](0.4,-.5)(0.4,1.5)
389 \psline[linewidth=0.5pt](0.6,-.5)(0.6,1.5)
390 \dspFunc[linecolor=red]{x 3.14 mul 0.5 mul 10 exp 1 add 1 exch div}
391 \dspPlotFrame
392 \dspCustomTicks{0.4 $0.4\pi$ 0.6 $0.6\pi$}
393 \end{dspPlot}
394 \end{centerfig}
395
396
397 The following example shows how to repeat an arbitrary spectral shape over more than one period. First let's define (and plot) a non-trivial spectral shape making sure that the free variable $x$ appears only at the beginning of the PostScript code:
398 \vblock
399 % triangular shape:
400 \def\triFun{abs 0.25 sub 1 0.25 sub div }
401 % parabolic shape:
402 \def\parFun{abs 0.25 div dup mul 1 exch sub }
403 % composite shape (cutoff at 0.5pi)
404 \def\comFun{
405 dup dup dup dup %
406 -0.5 lt {pop pop pop pop 0} { % zero for x < -0.5
407 0.5 gt {pop pop pop 0 } { % zero for x > 0.5
408 -0.25 lt {pop \triFun } { % triangle between
409 0.25 gt {\triFun } % -.25 and -.5
410 {\parFun} % else parabola
411 ifelse }%
412 ifelse }%
413 ifelse }%
414 ifelse }
415
416 \begin{dspPlot}[xtype=freq,ylabel={$X(e^{j\omega})$}]{-1,1}{0,1.1}
417 \dspFunc{x \comFun }
418 \end{dspPlot}
419 \end{Verbatim}
420 %
421
422
423 % triangular shape:
424 \def\triFun{abs 0.25 sub 1 0.25 sub div }
425 % parabolic shape:
426 \def\parFun{abs 0.25 div dup mul 1 exch sub }
427 % composite shape (cutoff at 0.5pi)
428 \def\comFun{
429 dup dup dup dup %
430 -0.5 lt {pop pop pop pop 0} { % zero for x < -0.5
431 0.5 gt {pop pop pop 0 } { % zero for x > 0.5
432 -0.25 lt {pop \triFun } { % triangle between
433 0.25 gt {\triFun } % -.25 and -.5
434 {\parFun} % else parabola
435 ifelse }%
436 ifelse }%
437 ifelse }%
438 ifelse }
439 \begin{centerfig}
440 \begin{dspPlot}[xtype=freq,ylabel={$X(e^{j\omega})$}]{-1,1}{0,1.1}
441 \dspFunc{x \comFun }
442 \end{dspPlot}
443 \end{centerfig}
444
445
446 \DescribeMacro{dspPeriodize} Now we can periodize the function using the |\dspPeriodize| macro; plotting multiple periods becomes as simple as changing the axis range:
447 \vblock
448 \begin{dspPlot}[xtype=freq]{-2,2}{0,1.1}
449 \dspFunc{x \dspPeriodize \comFun }
450 \end{dspPlot}
451
452 \begin{dspPlot}[xtype=freq,xticks=1]{-5,5}{0,1.1}
453 \dspFunc{x \dspPeriodize \comFun }
454 \end{dspPlot}
455 \end{Verbatim}
456
457 \begin{centerfig}
458 \begin{dspPlot}[xtype=freq]{-2,2}{0,1.1}
459 \dspFunc{x \dspPeriodize \comFun }
460 \end{dspPlot}
461
462 \begin{dspPlot}[xtype=freq,xticks=1]{-5,5}{0,1.1}
463 \dspFunc{x \dspPeriodize \comFun }
464 \end{dspPlot}
465 \end{centerfig}
466
467
468 %\end{document}
469
470 \subsection{Plotting Analog Spectra}
471 To plot analog spectra, just set up a plot environment as you would to plot a continuous-time signal, then set the option |xticks=custom| and place your own frequency labels using |\dspCustomTicks| as in the example below:
472
473 \vblock
474 \begin{dspPlot}[xtype=freq,xticks=custom,xlabel={freq. (Hz)},%
475 yticks=2,ylabel={$X(f)$}]{-10,10}{-1,5}
476 \dspFunc{x abs 4 gt {0} {x abs 2 div dup mul 4 exch sub} ifelse}
477 \dspCustomTicks[axis=x]{-4 $-f_N$ 0 $0$ 4 $f_N$ 8 $F_s$}
478 \end{dspPlot}
479 \end{Verbatim}
480
481 \begin{centerfig}
482 \begin{dspPlot}[xtype=freq,xticks=custom,xlabel={freq. (Hz)},yticks=2,ylabel={$X(f)$}]{-10,10}{0,5}
483 \dspFunc{x abs 4 gt {0} {x abs 2 div dup mul 4 exch sub} ifelse}
484 \dspCustomTicks[axis=x]{-4 $-f_N$ 0 $0$ 4 $f_N$ 8 $F_s$}
485 \end{dspPlot}
486 \end{centerfig}
487
488
489
490 \subsection{Common Signal Shapes and Helper Functions}
491 To facilitate the creation of plots that commonly occur in signal processing theory, the package \dspf\ provides a PostScript implementation for the following set of functions; each macro acts on the free variable $x$ in a plot command (see examples below).
492
493 \subsubsection*{Basic Shapes:}
494 \begin{itemize}
495 \item \DescribeMacro{\dspRect} |\dspRect{a}{b}| computes the function $\mbox{rect}((x-a)/b)$ where
496 \[
497 \mbox{rect}(x) = \left\{\begin{array}{ll}
498 1 & \mbox{if $|x|<1/2$} \\
499 0 & \mbox{otherwise}
500 \end{array}\right.
501 \]
502 i.e. a rectangular (box) function centered in $a$ and with support $2b$.
503 \item \DescribeMacro{\dspTri} |\dspTri{a}{b}| computes a triangular function centered in $a$ and with support $2b$
504 \item \DescribeMacro{\dspSinc} |\dspSinc{a}{b}| computes the scaled sinc function $\mbox{sinc}((x-a)/b)$, where
505 \[
506 \mbox{sinc}(x) = \frac{\sin(\pi x)}{\pi x}
507 \]
508 \item \DescribeMacro{\dspQuad} |\dspQuad{a}{b}| computes a quadratic function (inverted parabola) centered in $a$ and with support $2b$
509 \item \DescribeMacro{\dspExpDec} |\dspExpDec{a}{b}| computes the decaying exponential response $b^{(x-a)}u[x-a]$
510 \item \DescribeMacro{\dspPorkpie} |\dspPorkpie{a}{b}| computes a ``porkpie hat'' shape centered in $a$ and with support $2b$
511 \item \DescribeMacro{\dspRaisedCos} |\dspRaisedCos{a}{b}{r}| computes a raised cosine centered in $a$ with cutoff $b$ and rolloff $r$
512 \item \DescribeMacro{\dspSincS} |\dspSincS{a}{N}| computes the function
513 \[
514 \frac{\sin(\omega(2N+1)/2)}{\sin(\omega/2)} \qquad{\omega = \pi(x-a)}
515 \]
516 that is, the Discrete-Time Fourier transform (DTFT) of a zero-centered, symmetric $2N+1$-tap rectangular signal. This is used in frequency plots and in this case the free variable $x$, which ranges from $-1$ to $1$, is rescaled as $\omega = \pi x$.
517 The parameter $a$ can be used to shift the DTFT to the chosen center frequency over the $[-1, 1]$ interval.
518 \item \DescribeMacro{\dspSincC} |\dspSincC{a}{N}| computes the DTFT \textit{magnitude} for a causal $N$-tap rectangular signal:
519 \[
520 \vert \frac{\sin(\omega(N/2))}{\sin(\omega/2)} \vert \qquad {\omega = \pi(x-a)}
521 \]
522 See |\dspSincS{a}{N}| for details on $x$ and $a$.
523 \end{itemize}
524
525 \subsubsection*{Discrete Fourier Transform:}
526 \begin{itemize}
527 \item \DescribeMacro{\dspDFTMAG} |\dspDFTMAG{a_0 a_1 ... a_{N-1}}| computes the magnitude of the Discrete Fourier transform (DFT) of the provided data points\footnote{Please note that the underlying implementation of the macro is not optimized; the computing time will be quadratic in the number of data points.}:
528 \[
529 \vert \sum_{n=0}^{N-1}a_n e^{j\frac{2\pi}{N}nk} \vert \qquad n = x;
530 \]
531 the value of $x$ should range over integers only.
532 \item |\dspDFTRE{a_0 a_1 ... a_{N-1}}| computes the real part of the DFT
533 \item |\dspDFTIM{a_0 a_1 ... a_{N-1}}| computes the imaginary part of the DFT
534 \end{itemize}
535
536
537
538 \subsubsection*{Frequency Responses:}
539 \begin{itemize}
540 \item \DescribeMacro{\dspFIRI} |\dspFIRI{b_0 b_1 ... b_{N-1}}| computes the (real-valued) frequency response for $\omega = \pi x$ of a zero centered $(2N-1)$-tap Type-I FIR filter with coefficients
541 \[
542 b_{N-1}, b_{N-2}, \ldots, b_{1}, b_{0}, b_{1}, b_{2}, \ldots, b_{N-1}.
543 \]
544 The coefficient $b_0$ is the center tap and you need only specify the coefficients from $b_0$ to $b_{N-1}$.
545
546 \item \DescribeMacro{\dspTFM} |\dspTFM{b_0 b_1 b_2 ... b_{M-1}}{a_1 ... a_{N-1}}| computes the magnitude response for $\omega = \pi x$ of a generic digital filter defined by the constant-coefficient difference equation:
547 \[
548 y[n] = b_0 x[n] + ... + b_{N-1} x[n-N+1] - a_1 y[n-1] - ... - a_{M-1} y[n-M+1]
549 \]
550 \end{itemize}
551
552 \subsubsection*{Filtering Data:}
553 \begin{itemize}
554 \item \DescribeMacro{\dspFilter} |\dspFilter| computes the output of a generic IIR filter
555 \[
556 y[n] = b_0 x + b_1 x[n-1] + ... + b_{N-1} x[n-N+1] - a_1 y[n-1] - ... - a_{M-1} y[n-M+1]
557 \]
558 The filter coefficients should be set in the initialization portion of either |\dspSignalOpt| or |\dspFuncOpt| via the macro:\\ |\dspSetFilter{b_0 b_1 ... b_{M-1}}{a_1 ... a_{N-1}}}|
559 \end{itemize}
560
561
562 For instance:
563
564 \vblock
565 \usepackage{dspFunctions}
566 ...
567 \begin{dspPlot}[sidegap=1]{-2,10}{-1.2, 1.2}
568 \dspFunc{x \dspRect{-1}{1}}
569 \dspFunc{x \dspPorkpie{6}{2}}
570 \dspSignal[linecolor=gray]{x \dspSinc{2}{3} -1 mul}
571 \end{dspPlot}
572 \end{Verbatim}
573
574 \begin{centerfig}
575 \begin{dspPlot}[sidegap=1]{-2,10}{-1.2, 1.2}
576 \dspFunc{x \dspRect{-1}{1}}
577 \dspFunc{x \dspPorkpie{6}{2}}
578 \dspSignal[linecolor=gray]{x \dspSinc{2}{3} -1 mul}
579 \end{dspPlot}
580 \end{centerfig}
581
582
583 We can generate a finite-length signal and plot its DFT magnitude as in this example, where the 32-point input signal is $\cos(2\pi/32 \cdot (27/5)n)$:
584
585 \vblock
586 \begin{dspPlot}{0, 31}{0, 18}
587 \dspSignalOpt{/A [ 0 1 31 {360 32 div 5.4 mul mul cos} for ] def}
588 {x \dspDFTMAG{ A aload pop }}
589 \end{dspPlot}
590 \end{Verbatim}
591
592 \begin{centerfig}
593 \begin{dspPlot}{0, 31}{0, 18}
594 \dspSignalOpt{/A [ 0 1 31 {360 32 div 5.4 mul mul cos} for ] def}
595 {x \dspDFTMAG{ A aload pop }}
596 \end{dspPlot}
597 \end{centerfig}
598
599
600
601 The magnitude of simple FIR and IIR filter can be graphed easily like so:
602 \vblock
603 \begin{dspPlot}[xtype=freq,xout=true]{-1,1}{-0.5,1.5}
604 \dspFunc[linecolor=gray,linestyle=dashed]{x \dspSincS{0}{6} 13 div}
605 \dspFunc{x \dspFIRI{ 0.3501 0.2823 0.1252 -0.0215 -0.0876
606 -0.0868 0.0374} }
607 \end{dspPlot}
608 \end{Verbatim}
609
610 \begin{centerfig}
611 \begin{dspPlot}[xtype=freq,xout=true]{-1,1}{-0.5,1.5}
612 \dspFunc[linecolor=gray,linestyle=dashed]{x \dspSincS{0}{6} 13 div}
613 \dspFunc{x \dspFIRI{ 0.3501 0.2823 0.1252 -0.0215 -0.0876 -0.0868 0.0374} }
614 \end{dspPlot}
615 \end{centerfig}
616
617 \vblock
618 \begin{dspPlot}[xtype=freq,xticks=4]{-1,1}{0,1.1}
619 % 8-th order Chebyshev filter example
620 % Coefficients from Matlab using [b a]=cheby1(8,0.5,0.25)
621 \dspFunc{x \dspTFM{0.000008952611389 0.000071620891113
622 0.000250673118897 0.000501346237795 0.000626682797244
623 0.000501346237795 0.000250673118897 0.000071620891113
624 0.000008952611389}{ -5.975292291885454 16.581223292021008
625 -27.714232735429224 30.395097583553124 -22.347296704268793
626 10.745098004349103 -3.089246336974975 0.407076858898017}}
627 \end{dspPlot}
628 \end{Verbatim}
629
630 \begin{centerfig}
631 \begin{dspPlot}[xtype=freq,xticks=4]{-1,1}{0,1.1}
632 % 8-th order Chebyshev filter example
633 % Coefficients from Matlab using [b a]=cheby1(8,0.5,0.25)
634 \dspFunc{x \dspTFM{0.000008952611389 0.000071620891113
635 0.000250673118897 0.000501346237795 0.000626682797244
636 0.000501346237795 0.000250673118897 0.000071620891113
637 0.000008952611389}{ -5.975292291885454 16.581223292021008
638 -27.714232735429224 30.395097583553124 -22.347296704268793
639 10.745098004349103 -3.089246336974975 0.407076858898017}}
640 \end{dspPlot}
641 \end{centerfig}
642
643
644 In this example we plot a triangular signal and its filtered version using the Chebyshev lowpass filter defined above:
645
646 \vblock
647 \begin{dspPlot}[xtype=freq,xticks=4]{-1,1}{0,1.1}
648 \begin{dspPlot}[xout=true]{0,40}{-.4,1.1}
649 \dspSignal[linecolor=lightgray]{x \dspTri{5}{5}}
650 \dspSignalOpt[linecolor=blue!60]{
651 \dspSetFilter{0.000008952611389 0.000071620891113
652 0.000250673118897 0.000501346237795 0.000626682797244
653 0.000501346237795 0.000250673118897 0.000071620891113
654 0.000008952611389}{ -5.975292291885454 16.581223292021008
655 -27.714232735429224 30.395097583553124 -22.347296704268793
656 10.745098004349103 -3.089246336974975 0.407076858898017}}
657 {x \dspTri{5}{5} \dspFilter}
658 \end{dspPlot}
659 \end{Verbatim}
660
661 \begin{centerfig}
662 \begin{dspPlot}[xout=true]{0,40}{-.4,1.1}
663 \dspSignal[linecolor=lightgray]{x \dspTri{5}{5}}
664 \dspSignalOpt[linecolor=blue!60]{\dspSetFilter{0.000008952611389 0.000071620891113
665 0.000250673118897 0.000501346237795 0.000626682797244
666 0.000501346237795 0.000250673118897 0.000071620891113
667 0.000008952611389}{ -5.975292291885454 16.581223292021008
668 -27.714232735429224 30.395097583553124 -22.347296704268793
669 10.745098004349103 -3.089246336974975 0.407076858898017}}
670 {x \dspTri{5}{5} \dspFilter}
671 \end{dspPlot}
672 \end{centerfig}
673
674
675
676
677
678 \section{Drawing Regions of Convergence, Poles and Zeros}
679
680 \DescribeEnv{dspPZPlot} Pole-zero plots are defined by the environment
681 \begin{quote}
682 |\begin{dspPZPlot}|\oarg{options}\marg{M} \\
683 ... \\
684 |\end{dspPZPlot}|
685 \end{quote}
686 This plots a square section of the complex plane in which both axes span the $[-M, M]$ interval. Options for the plot are:
687
688 \begin{optList}
689 \item[|width| = \meta{dim}]: width of the plot
690 \item[|height| = \meta{dim}]: height of the plot. Normally, since the range is the same for both the real and the imaginary axis, width and height should be equal. You can therefore specify just one of them and the other will be automatically set. If you explicitly specify both, you will be able to obtain an asymmetric figure. By default, width and height are equal to |\dspH|.
691 \end{optList}
692
693 \begin{optList}
694 \item[|xticks| = |auto| $\mid$ |none| $\mid$ \meta{d}]: labeling of the real axis
695 \item[|yticks| = |auto| $\mid$ |none| $\mid$ \meta{d}]: labeling of the imaginary axis. When the option specifies a numeric value \meta{d}, that will be the spacing between two consecutive ticks on the axis.
696 \item[|cunits| = |true| $\mid$ |false|]: if true, labels the real and imaginary axis with ``Re'' and ``Im'' respectively.
697 \end{optList}
698
699 \begin{optList}
700 \item[|circle| = \meta{r} ]: draws a circle centered in $z=0$ with radius $r$; by default $r=1$, so that the unit circle will be drawn; set to zero for no circle.
701 \item[|clabel| = \meta{label} ]: for a circle of radius $r$, places the selected label text at $z=r + j0$. By default the label is equal to the value of $r$.
702 \end{optList}
703
704 \begin{optList}
705 \item[|roc| = \meta{r} ]: draws a {\em causal} region of convergence with radius $r$.
706 \item[|antiroc| = \meta{r} ]: draws an {\em anticausal} region of convergence with radius $r$.
707 \end{optList}
708
709
710
711 \subsection{Poles and Zeros}
712 \DescribeMacro{dspPZ} To plot a pole or a zero at $z=a+jb$ use
713 \begin{quote}
714 |\dspPZ|\oarg{options}\marg{a, b} \\
715 \end{quote}
716 which plots a pole by default; to plot a zero use the option |type=zero|. To associate a label to the point, use the option |label=|\meta{text}; if \meta{text} is |none| no label is printed; if \meta{text} is |auto| (which is the default) the point's coordinates are printed; otherwise the specified text is printed. Finally, you can specify the position of the label using the option |lpos=|\meta{angle}; by default, the angle's value is 45 degrees.
717
718 \vblock
719 \begin{dspPZPlot}[clabel={$r_0$},roc=0.5]{1.5}
720 \dspPZPoint[label=none]{0.5,0.5}
721 \dspPZPoint[type=zero,label={$x[1]$},lpos=135]{0,1}
722 \dspPZPoint[type=zero,label={$x[0]$},lpos=90]{1.25, 0.78}
723 \end{dspPZPlot}
724 \end{Verbatim}
725
726 \begin{centerfig}
727 \begin{dspPZPlot}[width=6cm,clabel={$r_0$},roc=0.5]{1.7}
728 \dspPZ[label=none]{0.5,0.5}
729 \dspPZ[type=zero,label={$x[1]$},lpos=135]{0,1}
730 \dspPZ[type=zero,label={$x[0]$},lpos=90]{1.25, 0.78}
731 \end{dspPZPlot}
732 \end{centerfig}
733
734
735
736
737 \section{Block Diagrams}
738 \DescribeEnv{dspBlocks} Block diagrams rely heavily on \psTricks ' |psmatrix| environment, for which ample documentation is available. To set up a block diagram use the environment
739 \begin{quote}
740 |\begin{dspBlocks}|\marg{x}\marg{y}\\
741 ... \\
742 |\end{dspBlocks}|
743 \end{quote}
744 where \meta{x} and \meta{y} define the horizontal and vertical spacing of the blocks in the diagram. Predefined functional blocks are listed in the table below and they can be used anywhere a node is required. Nodes are labeled in top-left matrix notation, i.e. the topmost leftmost node is at coordinates $(1,1)$ and indices increase rightward and downward. Connections between nodes can be drawn using \psTricks ' standard primitive |\ncline|; the package defines the following shorthands:
745 \begin{itemize}
746 \item \DescribeMacro{BDConnHNext} to connect with an arrow a node at $(n,m)$ to its neighboring node at $(n,m+1)$ use |\BDConnHNext|\marg{n}\marg{m}
747 \item \DescribeMacro{BDConnH} to connect with an arrow a node at $(n,m)$ to a node on the same row at $(n,p)$ use |\BDConnH|\oarg{options}\marg{n}\marg{m}\marg{p}\marg{label}, which uses \meta{options} as line options and \meta{label} as the label for the connection
748 \item \DescribeMacro{BDConnV} to connect with an arrow a node at $(n,m)$ to a node on the same column at $(q,m)$ use |\BDConnV|\oarg{options}\marg{n}\marg{m}\marg{q}\marg{label}
749 \end{itemize}
750
751 \DeleteShortVerb{\|}
752 \MakeShortVerb{\#}
753
754 \begin{center}
755 \begin{tabular}{|l|l|c|}
756 \hline
757 \bf function & \bf macro & \bf output \\
758 \hline & & \\
759 nodes & #\BDsplit# & \begin{dspBlocks}{1}{1}\BDsplit\end{dspBlocks} \\
760 & & \\
761 & #\BDadd# & \begin{dspBlocks}{1}{1}\BDadd\end{dspBlocks} \\
762 & & \\
763 & #\BDmul# & \begin{dspBlocks}{1}{1}\BDmul\end{dspBlocks} \\
764 & & \\ \hline & & \\
765 delays & #\BDdelay# & \begin{dspBlocks}{1}{1}\BDdelay\end{dspBlocks} \\
766 & & \\
767 & #\BDdelayN#\marg{N} & \begin{dspBlocks}{1}{1}\BDdelayN{N}\end{dspBlocks} \\
768 & & \\ \hline & & \\
769 filters & #\BDfilter#\marg{label} & \begin{dspBlocks}{1}{1}\BDfilter{$H(z)$}\end{dspBlocks} \\
770 & & \\
771 & #\BDfilterMulti#\marg{labels} & \begin{dspBlocks}{1}{1}\BDfilterMulti{multiple \\ lines}\end{dspBlocks} \\
772 & {\footnotesize (use #\\# to separate lines)} & \\
773 & & \\
774 & #\BDlowpass# & \begin{dspBlocks}{1}{1}\BDlowpass[0.5em]\end{dspBlocks} \\
775 & {\footnotesize (you can specify the size of the block, eg #\BDlowpass[2em]#)} & \\
776 & & \\ \hline
777 \end{tabular}
778
779 \begin{tabular}{|l|l|c|}
780 \hline
781 \bf function & \bf macro & \bf output \\
782 \hline & & \\
783 sampler & #\BDsampler# & \begin{dspBlocks}{1}{1}\BDsampler\end{dspBlocks} \\
784 & & \\
785 & #\BDsamplerFramed# & \begin{dspBlocks}{1}{1}\BDsamplerFramed[0.5em]\end{dspBlocks} \\
786 & {\footnotesize (you can specify the size of the block, eg #\BDsamplerFramed[2em]#)} & \\
787 & & \\
788 interpolator & #\BDsinc# & \begin{dspBlocks}{1}{1}\BDsinc[0.5em]\end{dspBlocks} \\
789 & {\footnotesize (you can specify the size of the block, eg #\BDsinc[2em]#)} & \\
790 & & \\ \hline & & \\
791 upsampler & #\BDupsmp#\marg{N} & \begin{dspBlocks}{1}{1}\BDupsmp{3}\end{dspBlocks} \\
792 & & \\
793 downsampler & #\BDdwsmp#\marg{N} & \begin{dspBlocks}{1}{1}\BDdwsmp{3}\end{dspBlocks} \\
794 & & \\ \hline
795 \end{tabular}
796 \end{center}
797
798
799 \newpage
800
801
802 \vblock
803 \begin{dspBlocks}{.3}{1}
804 % first row:
805 $x[n]$ & & & \BDsplit & \BDdelay &%
806 \BDsplit & \BDdelay & \BDsplit & \BDdelay & \BDsplit & \hspace{3em} & %
807 & \BDdelay & \\
808 %
809 % second row:
810 & & & & &%
811 \BDadd & & \BDadd & & \BDadd & \hspace{3em} & %
812 & & \BDadd & & $y[n]$
813 %
814 % connections:
815 \ncline{1,1}{1,3}
816 \ncline{1,3}{1,5}
817 \ncline{1,5}{1,7}
818 \ncline{1,7}{1,9}
819 \ncline{1,9}{1,10}
820 \ncline[linestyle=dotted]{1,10}{1,12}
821 \ncline{1,12}{1,13}
822 \ncline{1,13}{1,14}
823 \ncline{2,10}{2,11}
824 \ncline[linestyle=dotted]{2,10}{2,13}
825 \ncline{1,4}{2,4}\tlput{$b_0$}
826 \BDConnH{2}{4}{6}{}
827 \BDConnV{1}{6}{2}{$b_1$}
828 \BDConnH{2}{6}{8}{}
829 \BDConnV{1}{8}{2}{$b_2$}
830 \BDConnH{2}{8}{10}{}
831 \BDConnV{1}{10}{2}{$b_3$}
832 \BDConnHNext{2}{13}
833 \BDConnV{1}{14}{2}{$b_{M-1}$}
834 \BDConnH{2}{14}{16}{}
835 \end{dspBlocks}
836 \end{Verbatim}
837
838 \centerline{
839 \begin{dspBlocks}{.3}{1}
840 \begin{dspBlocks}{.3}{1}
841 % first row:
842 $x[n]$ & & & \BDsplit & \BDdelay &%
843 \BDsplit & \BDdelay & \BDsplit & \BDdelay & \BDsplit & \hspace{3em} & %
844 & \BDdelay & \\
845 %
846 % second row:
847 & & & & &%
848 \BDadd & & \BDadd & & \BDadd & \hspace{3em} & %
849 & & \BDadd & & $y[n]$
850 %
851 % connections:
852 \ncline{1,1}{1,3}
853 \ncline{1,3}{1,5}
854 \ncline{1,5}{1,7}
855 \ncline{1,7}{1,9}
856 \ncline{1,9}{1,10}
857 \ncline[linestyle=dotted]{1,10}{1,12}
858 \ncline{1,12}{1,13}
859 \ncline{1,13}{1,14}
860 \ncline{2,10}{2,11}
861 \ncline[linestyle=dotted]{2,10}{2,13}
862 \ncline{1,4}{2,4}\tlput{$b_0$}
863 \BDConnH{2}{4}{6}{}
864 \BDConnV{1}{6}{2}{$b_1$}
865 \BDConnH{2}{6}{8}{}
866 \BDConnV{1}{8}{2}{$b_2$}
867 \BDConnH{2}{8}{10}{}
868 \BDConnV{1}{10}{2}{$b_3$}
869 \BDConnHNext{2}{13}
870 \BDConnV{1}{14}{2}{$b_{M-1}$}
871 \BDConnH{2}{14}{16}{}
872 \end{dspBlocks}
873 \end{dspBlocks}
874 }
875 \vspace{1em}
876
877
878 \vblock
879 \begin{dspBlocks}{2}{0.4}
880 $x(t)$~~ & \BDlowpass[0.8em] & \BDsamplerFramed[0.8em] & ~~$x[n]$
881 \ncline{->}{1,1}{1,2}
882 \ncline{1,2}{1,3}^{$x_{LP}(t)$}
883 \ncline{->}{1,3}{1,4}
884 \end{dspBlocks}
885 \end{Verbatim}
886
887
888 \centerline{
889 \begin{dspBlocks}{2}{0.4}
890 $x(t)$~~ & \BDlowpass[0.8em] & \BDsamplerFramed[0.8em] & ~~$x[n]$
891 \ncline{->}{1,1}{1,2}
892 \ncline{1,2}{1,3}^{$x_{LP}(t)$}
893 \ncline{->}{1,3}{1,4}
894 \end{dspBlocks}
895 }
896 \vspace{3em}
897
898 If you need to label nodes for complex connections, you may need to revert to the actual code for the node element, eg:
899
900 \vblock
901 \begin{dspBlocks}{0.8}{0}
902 & & & [name=A1] \BDfilter{$H(z)$} & & $e^{-j\omega_c n}$ \\
903 $\hat{s}(t)$~~ & \BDsampler
904 & [name=A,mnode=dot,linewidth=2pt] &
905 & [name=B,mnode=circle] + & \BDmul & [name=C]
906 %
907 \psset{arrows=->}
908 \ncangle[angleA=90,angleB=180,linewidth=\BDwidth]{A}{A1}
909 \ncangle[angleA=0,angleB=90,linewidth=\BDwidth]{A1}{B}^{~~~~$j$}
910 \ncbar[angleA=-90,angleB=-90,linewidth=\BDwidth]{A}{B}
911 \ncline{-}{2,1}{2,2}
912 \ncline{-}{2,2}{2,3}^{~~~~~~$\hat{s}[n]$}
913 \ncline{2,5}{2,6}^{$\hat{c}[n]$}
914 \ncline{-}{2,6}{2,7}^{~~~$\hat{b}[n]$}
915 \ncline{1,6}{2,6}
916 \end{dspBlocks}
917
918 \vspace{7ex}
919
920 \begin{dspBlocks}{1.2}{0}
921 [name=D,mnode=circle] $K \downarrow$ & \BDfilter{Slicer} &
922 \BDfilter{Descrambler} &
923 \hspace{1ex}\parbox{4ex}{\small \tt \bf ..01100\\ 01010...}
924 \psset{arrows=->}
925 \ncline{1,1}{1,2}^{$\hat{a}[n]$}
926 \ncline{1,2}{1,3}
927 \ncline{1,3}{1,4}
928 \end{dspBlocks}
929 \ncbarr[angleA=0,linewidth=1.2pt,linearc=0.2]{C}{D}
930 \end{Verbatim}
931
932
933 \begin{center}
934 \begin{dspBlocks}{0.8}{0}
935 & & & [name=A1] \BDfilter{$H(z)$} & & $e^{-j\omega_c n}$ \\
936 $\hat{s}(t)$~~ & \BDsampler
937 & [name=A,mnode=dot,linewidth=2pt] &
938 & [name=B,mnode=circle] + & \BDmul & [name=C]
939 %
940 \psset{arrows=->}
941 \ncangle[angleA=90,angleB=180,linewidth=\BDwidth]{A}{A1}
942 \ncangle[angleA=0,angleB=90,linewidth=\BDwidth]{A1}{B}^{~~~~$j$}
943 \ncbar[angleA=-90,angleB=-90,linewidth=\BDwidth]{A}{B}
944 \ncline{-}{2,1}{2,2}
945 \ncline{-}{2,2}{2,3}^{~~~~~~$\hat{s}[n]$}
946 \ncline{2,5}{2,6}^{$\hat{c}[n]$}
947 \ncline{-}{2,6}{2,7}^{~~~$\hat{b}[n]$}
948 \ncline{1,6}{2,6}
949 \end{dspBlocks}
950
951 \vspace{7ex}
952
953 \begin{dspBlocks}{1.2}{0}
954 [name=D,mnode=circle] $K \downarrow$ & \BDfilter{Slicer} &
955 \BDfilter{Descrambler} & \hspace{1ex}\parbox{4ex}{\small \tt \bf ..01100\\ 01010...}
956 \psset{arrows=->}
957 \ncline{1,1}{1,2}^{$\hat{a}[n]$}
958 \ncline{1,2}{1,3}
959 \ncline{1,3}{1,4}
960 \end{dspBlocks}
961 \ncbarr[angleA=0,linewidth=1.2pt,linearc=0.2]{C}{D}
962 \end{center}
963
964 \newpage
965
966 \begin{thebibliography}{1}
967
968 \bibitem{TVZ93} Timothy Van Zandt, {\em PSTricks - PostScript macros for generic TEX}, \url{http://www.tug.org/application/PSTricks}, 1993.
969
970 \bibitem{HV} PSTricks Web pages, maintened by Herbert Vo{\ss}. \url{http://www.pstricks.de}
971
972 \bibitem{ps} Adobe Systems Incorporated, {\em PostScript Language Reference Manual}, Addison-Wesley, 3 edition, 1999.
973
974 \bibitem{BC} Bill Casselman {\em Mathematical Illustrations}, Cambridge University Press, 2005.
975
976 \bibitem{fp} Michael Mehlich, {\em ``fp'': Fixed point arithmetic for TEX}, \url{CTAN:macros/latex/contrib/fp}.
977
978 \bibitem{PV} Paolo Prandoni and Martin Vetterli, {\em Signal Processing for Communications}, 2008, \url{http://www.sp4comm.org}
979
980 \end{thebibliography}
981
982
983 \end{document}