% User manual for the dspTricks package
% (c) Paolo Prandoni, 2013
% For more information, authors@sp4comm.org

\documentclass[a4paper,11pt]{ltxdoc}
%\usepackage{fullpage, fleqn}
\usepackage{float}
\usepackage{fancyvrb}
\usepackage{enumitem}
%\usepackage{courier}
\usepackage[utopia]{mathdesign}
\usepackage{dspTricks, dspFunctions, dspBlocks}


\def\dspt{{\sf dspTricks}}
\def\dspf{{\sf dspFunctions}}
\def\dspb{{\sf dspBlocks}}
\def\psTricks{{\sf psTricks}}

\setlength\parindent{0pt}

\newenvironment{optList}{%
  \begin{description}[labelindent=2em,font=\rm,itemsep=-1mm,leftmargin=2cm]}%
  {\end{description}}

\def\vblock{\begin{Verbatim}[frame=single,%
        numbers=left,numbersep=2pt,%
        fontsize=\footnotesize,%
        xleftmargin=0mm,xrightmargin=0mm]}
\def\evblock{\end{Verbatim}}
\def\vopts{frame=single,%
        numbers=left,numbersep=2pt,%
        fontsize=\footnotesize,%
        xleftmargin=15mm,xrightmargin=6mm}

\newenvironment{centerfig}{%
  \begin{figure}[H]
    \begin{center}}{
    \end{center}
  \end{figure}}

\begin{document}

\title{dspTricks \\ PsTricks Macros for Digital Signal Processing}
\author{Paolo Prandoni}
\date{}
\maketitle

The package \dspt\ is a set of \psTricks\ macros for plotting graphs and figures useful in the illustration of one-dimensional signal processing concepts and applications. These macros have been developed by the author while working on the textbook ``Signal Processing for Communication'' (EPFL Press, 2007).
%\footnote{Please note that these macros have been written rather quickly and chiefly for personal use. Use at your own risk and caveat emptor.}
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 plots and pole-zero plots. The companion package \dspf\ defines some signals commonly used in basic signal processing in terms of PostScript primitives, while the package \dspb\ provides a set of macros to design simple signal processing block diagrams.



\section{Data Plots}

Data plots are defined by the {\tt dspPlot} environment as \DescribeEnv{dspPlot}
\begin{quote}
  |\begin{dspPlot}|\oarg{options}\marg{xmin, xmax}\marg{ymin, ymax} \\
  ...                                                               \\
  |\end{dspPlot}|
\end{quote}
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:

\begin{optList}
  \item[|width|=\meta{dim}]: width of the plot (using any units)
  \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 |\dspW| and |\dspH| lengths at the beginning of your document
\end{optList}

\begin{optList}
  \item[|xtype| = |time| $\mid$ |freq| ]: type of plot: time domain (default) or digital frequency plot
\end{optList}

\begin{optList}
  \item[|xticks| = |auto| $\mid$ |custom| $\mid$ |none| $\mid$ \meta{step}]: labeling of the horizontal axis
  \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.
  \item[|sidegap| = \meta{gap}]: extra space 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.
  \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.
  \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.
\end{optList}

\begin{optList}
  \item[|xlabel| = \meta{label} ]: label for the horizontal axis; placed outside the plot box
  \item[|ylabel| = \meta{label} ]: label for the vertical axis; placed outside the plot box, on the left
  \item[|rlabel| = \meta{label} ]: additional label for the horizontal axis; placed outside the plot box on the right
\end{optList}




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 scaled to the axes (i.e., they correspond to the cartesian values of the plot). Other useful commands for all data plots are the following:
\begin{itemize}
  \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.
  \item \DescribeMacro{dspPlotFrame} to redraw the framing box (useful to ``smooth out'' plots touching the frame) you can use the command |\dspPlotFrame|
  \item \DescribeMacro{dspCustomTicks} to draw arbitrarily placed ticks (and tick labels) on either axis, use
        \begin{quote}
        |\dspCustomTicks|\oarg{options}\marg{pos label pos label ...}
        \end{quote}
      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} as that will confuse the list-parsing macros.
\end{itemize}

\subsection{Time-Domain Plots}

\subsubsection{Discrete-Time Signals}
The following commands generate stem (or ``lollipop'') plots; available options in the commands are all standards \psTricks options plus other specialized options when applicable.

\begin{itemize}
  \item \DescribeMacro{dspTaps} To plot a set of discrete time points use
    \begin{quote}
      |\dspTaps|\oarg{options}\marg{data}
    \end{quote}
    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 only generic \psTricks\ options.

  \item \DescribeMacro{dspTapsFile} for large data sets, you can use
    \begin{quote}
      |\dspTapsFile|\oarg{options}\marg{fileName}
    \end{quote}
    where now \meta{fileName} points to an external text file of space-separated index-value pairs.

  \item \DescribeMacro{dspSignal} To plot a discrete-time signal defined in terms of PostScript primitives use
    \begin{quote}
      |\dspSignal|\oarg{options}\marg{PostScript code}
    \end{quote}
    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|}|.
\end{itemize}

\newpage

For example:
\vblock
  \begin{dspPlot}{-3, 22}{-1.2, 1.2}
    \dspSignal[xmin=8]{rand 2147483647 div 0.5 sub 2 mul}
    \dspTaps[linecolor=gray]{3 1 4 1 5 1}
    \dspTaps{0 0}
  \end{dspPlot}
\end{Verbatim}
produces the following plot:

\begin{centerfig}
  \begin{dspPlot}{-3, 22}{-1.2, 1.2}
    % for my postscript interpreter rand_max is 0x7FFFFFFF
    \dspSignal[xmin=8]{rand 2147483647 div 0.5 sub 2 mul}
    \dspTaps[linecolor=gray]{3 1 4 1 5 1}
    \dspTaps{0 0}
  \end{dspPlot}
\end{centerfig}

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.


\subsubsection{Continuous-Time Signals}
Continuous-time functions can be plotted with the following commands:

\begin{itemize}
  \item \DescribeMacro{dspFunc} You can draw a continuous-time signal by using the command
    \begin{quote}
      |\dspFunc|\oarg{options}\marg{PostScript code}
    \end{quote}
    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.

  \item \DescribeMacro{dspFuncData} To plot a smooth function obtained by interpolating a list of space separated time-value pairs use
    \begin{quote}
      |\dspFuncData|\oarg{options}\marg{data}
    \end{quote}
    the interpolation is performed by the PostScript interpreter and can be controlled if necessary by using the appropriate \psTricks\ options.

  \item \DescribeMacro{dspFuncFile} For a continuous-time smooth interpolation of a pre-computed set of data points, use
    \begin{quote}
      |\dspFuncFile|\oarg{options}\marg{fileName}
    \end{quote}
    where \meta{fileName} points to a text file containing the data points as a space-separated list of abscissae and ordinates.

  \item \DescribeMacro{dspDiracs} To plot one or more Dirac deltas (symbolized by a vertical arrow) use
    \begin{quote}
      |\dspDiracs|\oarg{options}\marg{pos value pos value ...}
    \end{quote}
    where the argument is a list of space-separated time-value pairs.
\end{itemize}

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}
\vblock
\begin{dspPlot}[yticks=1,sidegap=0]{0,10}{0,5}
  \begin{dspClip}\dspFunc{1 3 x sub div abs}\end{dspClip}
  \dspDiracs[linecolor=red]{3 4}
\end{dspPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPlot}[yticks=1,sidegap=0]{0,10}{0,5}
    \begin{dspClip}\dspFunc{1 3 x sub div abs}\end{dspClip}
    \dspDiracs[linecolor=red]{3 4}
  \end{dspPlot}
\end{centerfig}



\newpage


\subsubsection{Mixed-Domain Examples}

In the following examples we mix discrete- and continuous-time signals in the same plot:
\vblock
\begin{dspPlot}[xticks=10,yticks=0.2]{-5, 20}{-0.4, 1.2}
  \def\sincx{x 0 eq {1} {x RadtoDeg sin x div} ifelse}
  \dspSignal[xmax=10]{\sincx}
  \dspFunc[linewidth=0.5pt,xmax=10]{\sincx}
  \dspFunc[linestyle=dashed,linewidth=0.5pt,xmin=10]{\sincx}
\end{dspPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPlot}[xticks=10,yticks=0.2]{-5, 20}{-0.4, 1.2}
    \def\sincx{x 0 eq {1} {x RadtoDeg sin x div} ifelse}
    \dspSignal[xmax=10]{\sincx}
    \dspFunc[linewidth=0.5pt,xmax=10]{\sincx}
    \dspFunc[linestyle=dashed,linewidth=0.5pt,xmin=10]{\sincx}
  \end{dspPlot}
\end{centerfig}


\vblock
\begin{dspPlot}[sidegap=0.5,yticks=none]{-6, 6}{-1.2, 1.2}
  \def\signal{ 0.5235 mul RadtoDeg sin }
  \def\quantize{ dup 0 gt {-0.5} {0.5} ifelse sub truncate }
  \dspFunc[linecolor=gray,linewidth=2pt]{x \quantize \signal }
  \dspFunc[linestyle=dotted,linewidth=1pt]{x \signal}
  \dspSignal{x \signal}
\end{dspPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPlot}[sidegap=0.5,yticks=none]{-6, 6}{-1.2, 1.2}
    \def\signal{ 0.5235 mul RadtoDeg sin }
    \def\quantize{ dup 0 gt {-0.5} {0.5} ifelse sub truncate }
    \dspFunc[linecolor=gray,linewidth=2pt]{x \quantize \signal }
    \dspFunc[linestyle=dotted,linewidth=1pt]{x \signal}
    \dspSignal{x \signal}
  \end{dspPlot}
\end{centerfig}

%\end{document}

\subsection{Digital Frequency Plots}\label{freqPlots}

Digital frequency\footnote{By ``digital spectrum'' of a discrete-time sequence $x[n]$ I mean the Discrete-Time Fourier transform
\[
  X(e^{j\omega}) = \sum_{n = -\infty}^{\infty} x[n] e^{-j\omega n}
\]} 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:

\begin{itemize}
  \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]$.
  \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.
  \item |sidegap| is always zero in digital frequency plots.
\end{itemize}

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.



\newpage


\vblock
\def\lambda{0.9 }
\def\magn{\lambda 1 sub dup mul 1 \lambda \lambda mul %
  add  x 180 mul cos 2 mul \lambda mul sub div }
\def\phase{\lambda x 180 mul sin mul -1 mul 1 \lambda %
  x 180 mul cos mul sub atan 180 div 3.1415 mul }

\begin{dspPlot}[xtype=freq,xticks=3,yticks=0.2, %
  ylabel={Square magnitude $|H(e^{j\omega})|^2$}]{-1,1}{0,1.1}
  \dspFunc{\magn }
\end{dspPlot}

\begin{dspPlot}[xtype=freq,xticks=3,yticks=custom, %
  ylabel={Phase (radians)}]{-1,1}{-1.57,1.57}
  \dspFunc[xmax=0]{\phase }
  \dspFunc[xmin=0]{-\phase -1 mul}
  \dspCustomTicks[axis=y]{-1.57 $-\pi/2$ 0 0 1.57 $\pi/2$}
\end{dspPlot}
\end{Verbatim}
%


  \def\lambda{0.9 }
  \def\magn{\lambda 1 sub dup mul 1 \lambda \lambda mul %
    add  x 180 mul cos 2 mul \lambda mul sub div }
  \def\phase{\lambda x 180 mul sin mul -1 mul 1 \lambda %
    x 180 mul cos mul sub atan 180 div 3.1415 mul }

\DeleteShortVerb{\|}
\begin{centerfig}
  \begin{center}
    \begin{dspPlot}[xtype=freq,xticks=3,yticks=0.2, %
      ylabel={Square magnitude $|H(e^{j\omega})|^2$}]{-1,1}{0,1.1}
      \dspFunc{\magn }
    \end{dspPlot}

    \begin{dspPlot}[xtype=freq,xticks=3,yticks=custom,ylabel={Phase (radians)}]{-1,1}{-1.57,1.57}
      \dspFunc[xmax=0]{\phase }
      \dspFunc[xmin=0]{-\phase -1 mul}
      \dspCustomTicks[axis=y]{-1.57 $-\pi/2$ 0 0 1.57 $\pi/2$}
    \end{dspPlot}
  \end{center}
\end{centerfig}
\MakeShortVerb{\|}



\newpage


\vblock
\begin{dspPlot}[xtype=freq,xticks=1,yticks=1,,xout=true]{0, 1}{-0.5,1.5}
  \psframe[fillstyle=vlines,%
            hatchcolor=lightgray,hatchangle=20,%
            linecolor=lightgray]%
            (0,1.1)(0.4,0.9)
  \psframe[fillstyle=vlines,%
            hatchcolor=lightgray,hatchangle=20,%
            linecolor=lightgray]%
            (0.6,0.3)(1,-0.3)
  \psline[linewidth=0.5pt](0.4,-.5)(0.4,1.5)
  \psline[linewidth=0.5pt](0.6,-.5)(0.6,1.5)
  \dspFunc[linecolor=red]{x 3.14 mul 0.5 mul 10 exp 1 add 1 exch div}
  \dspPlotFrame
  \dspCustomTicks{0.4 $0.4\pi$ 0.6 $0.6\pi$}
\end{dspPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPlot}[xtype=freq,xticks=1,yticks=1,,xout=true]{0, 1}{-0.5,1.5}
    \psframe[fillstyle=vlines,%
              hatchcolor=lightgray,hatchangle=20,%
              linecolor=lightgray]%
              (0,1.1)(0.4,0.9)
    \psframe[fillstyle=vlines,%
              hatchcolor=lightgray,hatchangle=20,%
              linecolor=lightgray]%
              (0.6,0.3)(1,-0.3)
    \psline[linewidth=0.5pt](0.4,-.5)(0.4,1.5)
    \psline[linewidth=0.5pt](0.6,-.5)(0.6,1.5)
    \dspFunc[linecolor=red]{x 3.14 mul 0.5 mul 10 exp 1 add 1 exch div}
    \dspPlotFrame
    \dspCustomTicks{0.4 $0.4\pi$ 0.6 $0.6\pi$}
  \end{dspPlot}
\end{centerfig}



\newpage

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:
\vblock
% triangular shape:
\def\triFun{abs 0.25 sub 1 0.25 sub div }
% parabolic shape:
\def\parFun{abs 0.25 div dup mul 1 exch sub }
% composite shape (cutoff at 0.5pi)
\def\comFun{
  dup dup dup dup %
  -0.5 lt {pop pop pop pop 0} {  % zero for x < -0.5
     0.5 gt {pop pop pop 0 } {   % zero for x > 0.5
      -0.25 lt {pop \triFun } {  % triangle between
        0.25 gt {\triFun }       %    -.25 and -.5
          {\parFun}              % else parabola
        ifelse }%
      ifelse }%
    ifelse }%
  ifelse }

\begin{dspPlot}[xtype=freq,ylabel={$X(e^{j\omega})$}]{-1,1}{0,1.1}
  \dspFunc{x \comFun }
\end{dspPlot}
\end{Verbatim}
%


% triangular shape:
\def\triFun{abs 0.25 sub 1 0.25 sub div }
% parabolic shape:
\def\parFun{abs 0.25 div dup mul 1 exch sub }
% composite shape (cutoff at 0.5pi)
\def\comFun{
  dup dup dup dup %
  -0.5 lt {pop pop pop pop 0} {  % zero for x < -0.5
     0.5 gt {pop pop pop 0 } {   % zero for x > 0.5
      -0.25 lt {pop \triFun } {  % triangle between
        0.25 gt {\triFun }       %    -.25 and -.5
          {\parFun}              % else parabola
        ifelse }%
      ifelse }%
    ifelse }%
  ifelse }
\begin{centerfig}
  \begin{dspPlot}[xtype=freq,ylabel={$X(e^{j\omega})$}]{-1,1}{0,1.1}
    \dspFunc{x \comFun }
  \end{dspPlot}
\end{centerfig}


\DescribeMacro{dspPeriodize} Now we can periodize the function using the |\dspPeriodize| macro; plotting multiple periods becomes as simple as changing the axis range:
\vblock
\begin{dspPlot}[xtype=freq]{-2,2}{0,1.1}
  \dspFunc{x \dspPeriodize  \comFun }
\end{dspPlot}

\begin{dspPlot}[xtype=freq,xticks=1]{-5,5}{0,1.1}
  \dspFunc{x \dspPeriodize  \comFun }
\end{dspPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPlot}[xtype=freq]{-2,2}{0,1.1}
    \dspFunc{x \dspPeriodize  \comFun }
  \end{dspPlot}

  \begin{dspPlot}[xtype=freq,xticks=1]{-5,5}{0,1.1}
    \dspFunc{x \dspPeriodize  \comFun }
  \end{dspPlot}
\end{centerfig}


%\end{document}

\subsubsection{Analog Frequency Plots}
To plot analog spectra, just set up the plot environment with the option |xticks=custom| and place your own frequency labels using |\dspCustomTicks| as in the example below:

\vblock
\begin{dspPlot}[xtype=freq,xticks=custom,xlabel={freq. (Hz)},%
    yticks=2,ylabel={$X(j\Omega)$}]{-10,10}{-1,5}
  \dspFunc{x abs 4 gt {0} {x abs 2 div dup mul 4 exch sub} ifelse}
  \dspCustomTicks{-4 $-\Omega_N$ 0 $0$  4 $\Omega_N$ 8 $\Omega_s$}
\end{dspPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPlot}[xtype=freq,xticks=custom,xlabel={freq. (Hz)},%
      yticks=2,ylabel={$X(j\Omega)$}]{-10,10}{-1.5,5}
    \dspFunc{x abs 4 gt {0} {x abs 2 div dup mul 4 exch sub} ifelse}
    \dspCustomTicks{-4 $-\Omega_N$ 0 $0$  4 $\Omega_N$ 8 $\Omega_s$}
  \end{dspPlot}
\end{centerfig}


\subsection{Common Functions}
To facilitate the creation of plots that commonly occur in signal processing theory, the package \dspf\ provides the PostScript code for the following functions:
\begin{itemize}
  \item |\dspRect{a}{b}| plots the function $\mbox{rect}((x-a)/b)$
  \item |\dspSinc{a}{b}| plots the function $\mbox{sinc}((x-a)/b)$
  \item |\dspSincN{a}{b}| plots the function $(1/b)\mbox{sinc}((x-a)/b)$
  \item |\dspTri{a}{b}| plots a triangle function centered in $a$ and with support $2b$
  \item |\dspQuad{a}{b}| plots a quadratic function (inverted parabola) centered in $a$ and with support $2b$
  \item |\dspPorkpie{a}{b}| plots a ``porkpie hat'' shape centered in $a$ and with support $2b$
  \item |\dspRaisedCos{c}{r}| plots a raised cosine centered in zero with cutoff $c$ and rolloff $r$
  \item |\dspSincS{a}{N}| plots the Fourier transform (DTFT) of a symmetric $2N+1$-tap rectangular signal $\sin((x-a)(2N+1)/2)/\sin((x-a)/2)$
  \item |\dspSincC{a}{N}| plots the DTFT magnitude of a causal $N$-tap rectangular signal $\sin((x-a)(N/2))/\sin((x-a)/2)$
  \item |\dspFIRI{a_0 a_1 ... a_{N-1}}| plots the magnitude response of a $(2N+1)$-tap Type-I FIR filter, zero centered; $a_0$ is the center tap
\end{itemize}

For instance:

\vblock
\begin{dspPlot}[sidegap=0]{-2,10}{-1.2, 1.2}
  \dspFunc{x \dspRect{-1}{1}}
  \dspSignal[linecolor=gray]{x \dspSinc{2}{3} -1 mul}
  \dspFunc{x \dspPorkpie{6}{2}}
\end{dspPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPlot}[sidegap=0]{-2,10}{-1.2, 1.2}
    \dspFunc{x \dspRect{-1}{1}}
    \dspSignal[linecolor=gray]{x \dspSinc{2}{3} -1 mul}
    \dspFunc{x \dspPorkpie{6}{2}}
  \end{dspPlot}
\end{centerfig}


\vblock
\begin{dspPlot}[xtype=freq,xout=true]{-1,1}{-0.5,1.5}
  \dspFunc[linecolor=gray,linestyle=dashed]{x \dspSincS{0}{6} 13 div}
  \dspFunc{x \dspFIRI{ 0.3501    0.2823    0.1252   -0.0215   -0.0876
     -0.0868    0.0374} }
\end{dspPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPlot}[xtype=freq,xout=true]{-1,1}{-0.5,1.5}
    \dspFunc[linecolor=gray,linestyle=dashed]{x \dspSincS{0}{6} 13 div}
    \dspFunc{x \dspFIRI{ 0.3501    0.2823    0.1252   -0.0215   -0.0876   -0.0868    0.0374} }
\end{dspPlot}
\end{centerfig}


%\end{document}

\section{Pole-Zero Plots}

\DescribeEnv{dspPZPlot} Pole-zero plots are defined by the environment
\begin{quote}
  |\begin{dspPZPlot}|\oarg{options}\marg{M} \\
  ...                                                               \\
  |\end{dspPZPlot}|
\end{quote}
This plots a square section of the complex plane in which both axes span the $[-M, M]$ interval. Options for the plot are:

\begin{optList}
  \item[|width| = \meta{dim}]: width of the plot
  \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|.
\end{optList}

\begin{optList}
  \item[|xticks| = |auto| $\mid$ |none| $\mid$ \meta{d}]: labeling of the real axis
  \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.
  \item[|cunits| = |true| $\mid$ |false|]: if true, labels the real and imaginary axis with ``Re'' and ``Im'' respectively.
\end{optList}

\begin{optList}
  \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.
  \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$.
\end{optList}

\begin{optList}
  \item[|roc| = \meta{r} ]: draws a {\em causal} region of convergence with radius $r$.
  \item[|antiroc| = \meta{r} ]: draws an {\em anticausal} region of convergence with radius $r$.
\end{optList}



\subsection{Poles and Zeros}
\DescribeMacro{dspPZ} To plot a pole or a zero at $z=a+jb$ use
\begin{quote}
  |\dspPZ|\oarg{options}\marg{a, b} \\
\end{quote}
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.

\vblock
\begin{dspPZPlot}[clabel={$r_0$},roc=0.5]{1.5}
  \dspPZPoint[label=none]{0.5,0.5}
  \dspPZPoint[type=zero,label={$x[1]$},lpos=135]{0,1}
  \dspPZPoint[type=zero,label={$x[0]$},lpos=90]{1.25, 0.78}
\end{dspPZPlot}
\end{Verbatim}

\begin{centerfig}
  \begin{dspPZPlot}[width=6cm,clabel={$r_0$},roc=0.5]{1.7}
    \dspPZ[label=none]{0.5,0.5}
    \dspPZ[type=zero,label={$x[1]$},lpos=135]{0,1}
    \dspPZ[type=zero,label={$x[0]$},lpos=90]{1.25, 0.78}
  \end{dspPZPlot}
\end{centerfig}




\section{Block Diagrams}
\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
\begin{quote}
  |\begin{dspBlocks}|\marg{x}\marg{y}\\
  ...                                                               \\
  |\end{dspBlocks}|
\end{quote}
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 $(0,0)$ and indices increase rightward and downward. Connections between nodes can be drawn using \psTricks ' standard primitive |\ncline|; the package defines the following shorthands:
\begin{itemize}
  \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}
  \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
  \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}
\end{itemize}

\DeleteShortVerb{\|}
\MakeShortVerb{\#}
\begin{table}
\center
\renewcommand{\arraystretch}{4}
\begin{tabular}{|l|l|c|}
\hline
\bf function & \bf macro & \bf example \\
\hline
adder         & #\BDadd#                & \begin{dspBlocks}{1}{1}\BDadd\end{dspBlocks} \\
multiplier    & #\BDmul#                & \begin{dspBlocks}{1}{1}\BDmul\end{dspBlocks} \\
delay         & #\BDdelay#              & \begin{dspBlocks}{1}{1}\BDdelay\end{dspBlocks} \\
delay by $N$  & #\BDdelayN#\marg{N}     & \begin{dspBlocks}{1}{1}\BDdelayN{N}\end{dspBlocks} \\
filter        & #\BDfilter#\marg{label} & \begin{dspBlocks}{1}{1}\BDfilter{$H(z)$}\end{dspBlocks} \\
splitter      & #\BDsplit#              & \begin{dspBlocks}{1}{1}\BDsplit\end{dspBlocks} \\
upsampler     & #\BDupsmp#\marg{N}      & \begin{dspBlocks}{1}{1}\BDupsmp{3}\end{dspBlocks} \\
downsampler   & #\BDdwsmp#\marg{N}      & \begin{dspBlocks}{1}{1}\BDdwsmp{3}\end{dspBlocks} \\
\hline
\end{tabular}
\caption{Block diagram macros }\label{BDmacros}
\end{table}


\newpage


\vblock
\begin{dspBlocks}{.3}{1}
% first row:
$x[n]$   &          &          & \BDsplit & \BDdelay &%
\BDsplit & \BDdelay & \BDsplit & \BDdelay & \BDsplit & \hspace{3em} & %
         & \BDdelay &  \\
%
% second row:
         &          &          &          &          &%
\BDadd   &          & \BDadd   &          & \BDadd   & \hspace{3em} & %
         &          & \BDadd & &  $y[n]$
%
% connections:
  \ncline{1,1}{1,3}
  \ncline{1,3}{1,5}
  \ncline{1,5}{1,7}
  \ncline{1,7}{1,9}
  \ncline{1,9}{1,10}
  \ncline[linestyle=dotted]{1,10}{1,12}
  \ncline{1,12}{1,13}
  \ncline{1,13}{1,14}
  \ncline{2,10}{2,11}
  \ncline[linestyle=dotted]{2,10}{2,13}
  \ncline{1,4}{2,4}\tlput{$b_0$}
  \BDConnH{2}{4}{6}{}
  \BDConnV{1}{6}{2}{$b_1$}
  \BDConnH{2}{6}{8}{}
  \BDConnV{1}{8}{2}{$b_2$}
  \BDConnH{2}{8}{10}{}
  \BDConnV{1}{10}{2}{$b_3$}
  \BDConnHNext{2}{13}
  \BDConnV{1}{14}{2}{$b_{M-1}$}
  \BDConnH{2}{14}{16}{}
\end{dspBlocks}
\end{Verbatim}

\centerline{
\begin{dspBlocks}{.3}{1}
\begin{dspBlocks}{.3}{1}
% first row:
$x[n]$   &          &          & \BDsplit & \BDdelay &%
\BDsplit & \BDdelay & \BDsplit & \BDdelay & \BDsplit & \hspace{3em} & %
         & \BDdelay &  \\
%
% second row:
         &          &          &          &          &%
\BDadd   &          & \BDadd   &          & \BDadd   & \hspace{3em} & %
         &          & \BDadd & &  $y[n]$
%
% connections:
  \ncline{1,1}{1,3}
  \ncline{1,3}{1,5}
  \ncline{1,5}{1,7}
  \ncline{1,7}{1,9}
  \ncline{1,9}{1,10}
  \ncline[linestyle=dotted]{1,10}{1,12}
  \ncline{1,12}{1,13}
  \ncline{1,13}{1,14}
  \ncline{2,10}{2,11}
  \ncline[linestyle=dotted]{2,10}{2,13}
  \ncline{1,4}{2,4}\tlput{$b_0$}
  \BDConnH{2}{4}{6}{}
  \BDConnV{1}{6}{2}{$b_1$}
  \BDConnH{2}{6}{8}{}
  \BDConnV{1}{8}{2}{$b_2$}
  \BDConnH{2}{8}{10}{}
  \BDConnV{1}{10}{2}{$b_3$}
  \BDConnHNext{2}{13}
  \BDConnV{1}{14}{2}{$b_{M-1}$}
  \BDConnH{2}{14}{16}{}
\end{dspBlocks}
\end{dspBlocks}
}
\vspace{1em}


\newpage

More complicated building blocks can be drawn using standard \psTricks primitives:

\vblock
\begin{dspBlocks}{1.3}{0.4}
  $x(t)$
  &
  \raisebox{-1.6em}{\psframebox[linewidth=1.5pt]{%
    \psset{xunit=1em,yunit=1em}%
    \pspicture(-3,-2)(3,2)%
      \psline{->}(-2.8,-1)(2.8,-1)%
      \psline{->}(0,-1.8)(0,1.8)%
      \psline[linewidth=1.8pt](-1,-1)(-1,0.8)(1,0.8)(1,-1)%
    \endpspicture}}
  &
  &
  \raisebox{-1.4em}{\psframebox[linewidth=1.5pt]{%
    \psset{xunit=1em,yunit=1em,linewidth=1.8pt}%
    \pspicture(-3,-1.8)(2,1.8)%
      \psline(-2.8,0)(-1.6,0)(1.2,1.4)
      \psline(1.1,0)(1.8,0)
      \psarc[linewidth=1pt]{<-}(-1.6,0){2em}{-10}{55}
    \endpspicture}}
  &
  $x[n]$
%
  \psset{linewidth=1.5pt}
  \ncline{->}{1,1}{1,2}
  \ncline{1,2}{1,4}^{$x_{LP}(t)$}
  \ncline{->}{1,4}{1,5}
\end{dspBlocks}
\end{Verbatim}
\centerline{
\begin{dspBlocks}{1.3}{0.4}
  $x(t)$
  &
  \raisebox{-1.6em}{\psframebox[linewidth=1.5pt]{%
    \psset{xunit=1em,yunit=1em}%
    \pspicture(-3,-2)(3,2)%
      \psline{->}(-2.8,-1)(2.8,-1)%
      \psline{->}(0,-1.8)(0,1.8)%
      \psline[linewidth=1.8pt](-1,-1)(-1,0.8)(1,0.8)(1,-1)%
    \endpspicture}}
  &
  &
  \raisebox{-1.4em}{\psframebox[linewidth=1.5pt]{%
    \psset{xunit=1em,yunit=1em,linewidth=1.8pt}%
    \pspicture(-3,-1.8)(2,1.8)%
      \psline(-2.8,0)(-1.6,0)(1.2,1.4)
      \psline(1.1,0)(1.8,0)
      \psarc[linewidth=1pt]{<-}(-1.6,0){2em}{-10}{55}
    \endpspicture}}
  &
  $x[n]$
%
  \psset{linewidth=1.5pt}
  \ncline{->}{1,1}{1,2}
  \ncline{1,2}{1,4}^{$x_{LP}(t)$}
  \ncline{->}{1,4}{1,5}
\end{dspBlocks}
}



\end{document}

{
  \center %\small
    \begin{dspBlocks}{1.3}{0.4}
      $x(t)$~ &
      \raisebox{-1.6em}{\psframebox[linewidth=1.5pt]{%
        \psset{xunit=1em,yunit=1em}%
        \pspicture(-3,-2)(3,2)%
          \psline{->}(-2.8,-1)(2.8,-1)%
          \psline{->}(0,-1.8)(0,1.8)%
          \psline[linewidth=1.8pt]%
            (-1,-1)(-1,0.8)(1,0.8)(1,-1)%
        \endpspicture}} &
      &
      \raisebox{-1.4em}{\psframebox[linewidth=1.5pt]{%
        \psset{xunit=1em,yunit=1em,linewidth=1.8pt}%
        \pspicture(-3,-1.8)(2,1.8)%
          \psline(-2.8,0)(-1.6,0)(1.2,1.4)
          \psline(1.1,0)(1.8,0)
          \psarc[linewidth=1pt]{<-}(-1.6,0){2em}{-10}{55}
        \endpspicture}} &
         $x[n]$

    \psset{linewidth=1.5pt}
    \ncline{->}{1,1}{1,2}
    \ncline{1,2}{1,4}^{$x_{LP}(t)$}
    \ncline{->}{1,4}{1,5}
    \end{dspBlocks}
}




\def\spectrumShape{0.74 mul RadtoDeg %
                   dup         cos         exch %
                   dup  3 mul cos    2 mul exch %
                       12 mul cos -0.7 mul  %
                   add add 0.31 mul 0.017 add }

\def\periodSpec#1{%
    3.14 sub 6.28 div dup floor sub 2 mul 1 sub dup dup % periodization
    -\specHW lt {pop pop 0} {%
     \specHW gt {pop 0} {#1 } ifelse } %
        ifelse }

\def\sincInt{dup 0 eq {pop 1} {0.5 mul dup RadtoDeg sin exch div abs} ifelse }

\def\doOmegaLabels{%
      \psset{xunit=3.14}
      \selectPlotFont
      \psticklab{0}{0}
      \psticklab{1}{$\Omega_N$}
      \psticklab{2}{$2\Omega_N$}
      \psticklab{4}{$4\Omega_N$}
      \psticklab{6}{$6\Omega_N$}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[tp]
  \center
  \def\specHW{0.8 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1]{0}{1.1}
      \psDFplotFunction{x \periodSpec{\spectrumShape } }
      \psset{xunit=3.14}
      \uput[-135](1,1.1){$X(e^{j\omega})$}
    \end{psDFplot}
    \\ \\
    \begin{psDFplot}[dy=1,reps=6,labelx=false,fmin=0]{0}{1.1}
      \psDFplotFunction{x \periodSpec{\spectrumShape }}
      \psline[linestyle=dashed,linecolor=gray,linewidth=2pt]%
        (0,1)(3.14,1)(3.14,0)
      \doOmegaLabels
    \end{psDFplot}
  \\
    \begin{psDFplot}[dy=1,reps=6,labelx=false,fmin=0]{0}{1.1}
      \psDFplotFunction{x dup 3.14 gt {pop 0} {\periodSpec{\spectrumShape } x \sincInt mul } ifelse}
      \doOmegaLabels
    \end{psDFplot}
  \end{tabular}

\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[tp]
  \center
  \def\specHW{0.8 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1]{0}{1.1}
      \psDFplotFunction{x \periodSpec{\spectrumShape } }
      \psset{xunit=3.14}
      \uput[-135](1,1.1){$X(e^{j\omega})$}
    \end{psDFplot}
    \\ \\
    \begin{psDFplot}[dy=1,reps=6,labelx=false,fmin=0]{0}{1.1}
      \psDFplotFunction{x \periodSpec{\spectrumShape }}
      \psDFplotFunction[linestyle=dotted,linecolor=gray]{x \sincInt}
      \doOmegaLabels
    \end{psDFplot}
  \\
    \begin{psDFplot}[dy=1,reps=6,labelx=false,fmin=0]{0}{1.1}
      \psDFplotFunction{x \periodSpec{\spectrumShape } x \sincInt mul }
      \doOmegaLabels
    \end{psDFplot}
  \end{tabular}

\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[tp]
  \center
  \def\specHW{0.4 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,pifrac=2]{0}{1.1}
      \def\specHW{0.8 }
      \psDFplotFunction[linecolor=lightgray]%
        {x 2 mul \periodSpec{ \spectrumShape } }
      \def\specHW{0.4 }
      \psDFplotFunction{x \periodSpec{2 mul  \spectrumShape } }
      \psset{xunit=3.14}
      \psline[linestyle=dotted,linecolor=gray,linewidth=2pt]%
        (-.5,0)(-.5,1)(.5,1)(.5,0)
      \uput[-90](0.7,1.1){$X(e^{j\omega})$}
    \end{psDFplot}
    \\ \\
    \begin{psDFplot}[dy=1,reps=6,labelx=false,fmin=0]{0}{1.1}
      \psDFplotFunction{x 0.5 mul \periodSpec{2 mul \spectrumShape }}
      \psDFplotFunction[linestyle=dashed,linecolor=gray]{x 0.5 mul \sincInt}
      \psset{xunit=3.14}
      \selectPlotFont
      \psticklab{0}{0}
      %\psticklab{1}{$\Omega_N$}
      \psticklab{2}{$\Omega_{N,O}=2\Omega_N$}
      \psticklab{4}{$2\Omega_{N,O}$}
      \psticklab{6}{$3\Omega_{N,O}$}
    \end{psDFplot}
  \\
    \begin{psDFplot}[dy=1,reps=6,labelx=false,fmin=0]{0}{1.1}
      \psDFplotFunction{x 0.5 mul \periodSpec{2 mul \spectrumShape } x 0.5 mul  \sincInt mul }
      \doOmegaLabels
    \end{psDFplot}
  \end{tabular}
\end{figure}

\clearpage

% triangular shape
\def\specFun{abs \specHW exch sub \specHW div }
\def\periodSpec{%
    3.14 sub 6.28 div dup floor sub 2 mul 1 sub dup dup % periodization
    -\specHW lt {pop pop 0} {%
     \specHW gt {pop 0} {\specFun } ifelse } %
        ifelse }

\begin{figure}
  \center
  \def\specHW{0.5 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction{x \periodSpec }
      \uput[180]{90}(-3.14,0.6){$X(e^{j\omega})$}
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]{x \periodSpec }
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]%
        {x \periodSpec }
      \psDFplotFunction[linecolor=gray]%
        {x 3.14 sub \periodSpec}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,reps=3,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linecolor=darkgray,linestyle=dashed]%
        {x 0.5 mul           \periodSpec 0.5 mul}
      \psDFplotFunction[linecolor=gray,linestyle=dashed]%
        {x  0.5 mul 3.14 sub \periodSpec 0.5 mul}
      \psDFplotFunction{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linewidth=2pt]{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \end{tabular}

  \caption{Downsampling by~2; the discrete-time signal's highest frequency is $\pi/2$ and no aliasing occurs.}
\end{figure}


\clearpage


\begin{figure}
  \center
  \def\specHW{0.666 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction{x \periodSpec }
      \uput[180]{90}(-3.14,0.6){$X(e^{j\omega})$}
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]{x \periodSpec }
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]%
        {x \periodSpec }
      \psDFplotFunction[linecolor=gray]%
        {x 3.14 sub \periodSpec}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,reps=3,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linecolor=darkgray,linestyle=dashed]%
        {x 0.5 mul           \periodSpec 0.5 mul}
      \psDFplotFunction[linecolor=gray,linestyle=dashed]%
        {x  0.5 mul 3.14 sub \periodSpec 0.5 mul}
      \psDFplotFunction{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
      \psset{xunit=3.14}\psticklab{1.5}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linewidth=2pt]{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \end{tabular}

  \caption{Downsampling by~2; the discrete-time signal's highest frequency is larger than $\pi/2$ (here, $\omega_M = 2\pi/3$) and aliasing corrupts the downsampled signal.}
\end{figure}


\clearpage



\begin{figure}
  \center
  \def\specHW{0.6666 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction{x \periodSpec }
      \uput[180]{90}(-3.14,0.6){$X(e^{j\omega})$}
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]{x \periodSpec }
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]%
        {x \periodSpec }
      \psDFplotFunction[linecolor=gray]%
        {x 2.09 sub \periodSpec}
      \psDFplotFunction[linecolor=lightgray]%
        {x 4.19 sub \periodSpec}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.3,reps=3,height=0.5\psDSPheight]{0}{0.4}
      \psDFplotFunction[linecolor=darkgray,linestyle=dashed]%
        {x 3 div           \periodSpec 3 div}
      \psDFplotFunction[linecolor=gray,linestyle=dashed]%
        {x  3 div 2.09 sub \periodSpec 3 div}
      \psDFplotFunction[linecolor=lightgray,linestyle=dashed]%
        {x  3 div 4.19 sub \periodSpec 3 div}
      \psDFplotFunction{%
        x 3 div 4.19 sub \periodSpec %
        x 3 div 2.09 sub \periodSpec %
        x 3 div          \periodSpec %
          add add 3 div}
      \psset{xunit=3.14}\psticklab{1.23}{$3\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.3,height=0.5\psDSPheight]{0}{0.4}
      \psDFplotFunction[linewidth=2pt]{%
        x 3 div 4.19 sub \periodSpec %
        x 3 div 2.09 sub \periodSpec %
        x 3 div          \periodSpec %
          add add 3 div}
    \end{psDFplot}
  \end{tabular}

  \caption{Downsampling by~3; the discrete-time signal's highest frequency is larger than $\pi/3$ (here, $\omega_M = 2\pi/3$) and aliasing corrupts the downsampled signal. Note the three replicas which contribute to the final spectrum.}
\end{figure}


\clearpage


% highpass shape
\def\specFun{abs \specHW sub 1 \specHW sub div }
\def\periodSpec{%
    3.14 sub 6.28 div dup floor sub 2 mul 1 sub dup dup % periodization
    -\specHW lt {pop \specFun } {%
     \specHW gt {\specFun } {pop 0} ifelse } %
        ifelse }

\begin{figure}
  \center
  \def\specHW{0.5 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction{x \periodSpec }
      \uput[180]{90}(-3.14,0.6){$X(e^{j\omega})$}
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]{x \periodSpec }
      \uput[180]{90}(-3,0.6){$X(e^{j\omega})$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]%
        {x \periodSpec }
      \psDFplotFunction[linecolor=gray]%
        {x 3.14 sub \periodSpec}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,reps=3,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linecolor=darkgray,linestyle=dashed]%
        {x 0.5 mul           \periodSpec 0.5 mul}
      \psDFplotFunction[linecolor=gray,linestyle=dashed]%
        {x  0.5 mul 3.14 sub \periodSpec 0.5 mul}
      \psDFplotFunction{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linewidth=2pt]{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \end{tabular}

  \caption{Downsampling by~2 of a highpass signal; note how aliasing changes the nature of the spectrum.}
\end{figure}


\clearpage


% complex shape
\def\specFunPar{abs 1 sub \specHW 2 mul div dup mul 1 exch sub }
\def\specFun{abs \specHW sub 1 \specHW sub div }
\def\periodSpec{%
    3.14 sub 6.28 div dup floor sub 2 mul 1 sub dup dup % periodization
    -\specHW lt {pop \specFunPar } {%
     \specHW gt {\specFun } {pop 0} ifelse } %
        ifelse }


\begin{figure}
  \center
  \def\specHW{0.5 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction{x \periodSpec }
      \uput[180]{90}(-3.14,0.6){$X(e^{j\omega})$}
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]{x \periodSpec }
      \uput[180]{90}(-3,0.6){$X(e^{j\omega})$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]%
        {x \periodSpec }
      \psDFplotFunction[linecolor=gray]%
        {x 3.14 sub \periodSpec}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,reps=3,height=0.5\psDSPheight,fmin=-9.41]{0}{0.6}
      \psDFplotFunction[linecolor=darkgray,linestyle=dashed]%
        {x 0.5 mul           \periodSpec 0.5 mul}
      \psDFplotFunction[linecolor=gray,linestyle=dashed]%
        {x  0.5 mul 3.14 sub \periodSpec 0.5 mul}
      \psDFplotFunction{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linewidth=2pt,fmin=-3.13]{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \end{tabular}

  \caption{Downsampling by~2 of a {\em complex} highpass signal; the asymmetric spectrum helps to understand how aliasing works.}
\end{figure}

\clearpage


\begin{figure}
\def\specFun{abs \specHW exch sub \specHW div }
\def\periodSpec{%
    3.14 sub 6.28 div dup floor sub 2 mul 1 sub dup dup % periodization
    -\specHW lt {pop pop 0} {%
     \specHW gt {pop 0} {\specFun } ifelse } %
        ifelse }
\def\periodSpecFilt{%
    3.14 sub 6.28 div dup floor sub 2 mul 1 sub dup dup % periodization
    -.5 lt {pop pop 0} {%
     .5 gt {pop 0} {\specFun } ifelse } %
        ifelse }
  \center
  \def\specHW{0.75 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,height=0.5\psDSPheight,pifrac=2]{0}{1.1}
      \psDFplotData[linecolor=gray,linestyle=dotted](-.5,0)(-.5,1)(.5,1)(.5,0)
      \psDFplotFunction{x \periodSpec }
      \uput[180]{90}(-3.14,0.6){$X(e^{j\omega})$}
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]{x \periodSpecFilt }
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]%
        {x \periodSpecFilt }
      \psDFplotFunction[linecolor=gray]%
        {x 3.14 sub \periodSpecFilt}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,reps=3,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linecolor=darkgray,linestyle=dashed]%
        {x 0.5 mul           \periodSpecFilt 0.5 mul}
      \psDFplotFunction[linecolor=gray,linestyle=dashed]%
        {x  0.5 mul 3.14 sub \periodSpecFilt 0.5 mul}
      \psDFplotFunction{%
        x 0.5 mul 3.14 sub \periodSpecFilt %
        x 0.5 mul          \periodSpecFilt %
          add 0.5 mul}
      \psset{xunit=3.14}\psticklab{1.5}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linewidth=2pt]{%
        x 0.5 mul 3.14 sub \periodSpecFilt %
        x 0.5 mul          \periodSpecFilt %
          add 0.5 mul}
    \end{psDFplot}
  \end{tabular}

  \caption{Downsampling by~2 with pre-filtering to avoid aliasing; an ideal lowpass with cutoff frequency of $\pi/2$ is used.}
\end{figure}


\clearpage




% multi-shape
\def\specFun{abs \specHWM sub 1 \specHWM sub div }
\def\specFunPar{abs \specHWM div dup mul 1 exch sub }
\def\periodSpec{%
    3.14 sub 6.28 div dup floor sub 2 mul 1 sub %
    dup dup dup dup % periodization
    -\specHW lt {pop pop pop pop 0} {%
     \specHW gt {pop pop pop 0 } {
        -\specHWM lt {pop \specFun } {%
         \specHWM gt {\specFun } {\specFunPar}
          ifelse } ifelse }
      ifelse } ifelse }

 \def\specHWM{0.25 }
\begin{figure}
  \center
  \def\specHW{0.5 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction{x \periodSpec }
      \uput[180]{90}(-3.14,0.6){$X(e^{j\omega})$}
      \psset{xunit=3.14}\psticklab{\specHW}{$\omega_M$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction{x \periodSpec }
      \uput[180]{90}(-3,0.6){$X(e^{j\omega})$}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=1,reps=3,height=0.5\psDSPheight]{0}{1.1}
      \psDFplotFunction[linecolor=darkgray]%
        {x \periodSpec }
      \psDFplotFunction[linecolor=gray]%
        {x 3.14 sub \periodSpec}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,reps=3,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linecolor=darkgray,linestyle=dashed]%
        {x 0.5 mul           \periodSpec 0.5 mul}
      \psDFplotFunction[linecolor=gray,linestyle=dashed]%
        {x  0.5 mul 3.14 sub \periodSpec 0.5 mul}
      \psDFplotFunction{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \\
  \\
    \begin{psDFplot}[dy=0.5,height=0.5\psDSPheight]{0}{0.6}
      \psDFplotFunction[linewidth=2pt]{%
        x 0.5 mul 3.14 sub \periodSpec %
        x 0.5 mul          \periodSpec %
          add 0.5 mul}
    \end{psDFplot}
  \end{tabular}

  \caption{Frequency-domain plot}
\end{figure}



\clearpage



\begin{figure}
  \center
  \def\specHW{1 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=1,reps=5,labelx=false]{0}{1.2}
      \psDFplotFunction[linewidth=2pt]%
        {x 3.14 div  dup dup %
          -\specHW lt {pop pop 0} {%
              \specHW gt {pop 0} {\specFunPar } ifelse} %
          ifelse}

      \psset{xunit=3.14}
      \uput[180]{90}(-5,0.5){$X(j\Omega)$}
      \selectPlotFont
      \psticklab{0}{0}
      \psticklab{1}{$\Omega_N$} %\psticklab{-1}{$-\Omega_N$}
      \psticklab{2}{$\Omega_s$} \psticklab{-2}{$-\Omega_s$}
      \psticklab{4}{$2\Omega_s$} \psticklab{-4}{$-2\Omega_s$}
      %\psticklab{\specHW}{$\Omega_{\max}$}
    \end{psDFplot}

    \\

    \begin{psDFplot}[dy=1,reps=5,labelx=false]{0}{1.2}
      \psDFplotFunction[linewidth=2pt,linecolor=gray]%
        {x 3.14 sub 6.28 div dup floor sub 2 mul 1 sub dup dup % periodization
        -\specHW lt {pop pop 0} {%
            \specHW gt {pop 0} {\specFunPar } ifelse} %
        ifelse}

      \psDFplotFunction[fmin=-3.14,fmax=3.14,linewidth=2pt]%
        {x 3.14 div  dup dup %
         -\specHW lt {pop pop 0} {%
              \specHW gt {pop 0} {\specFunPar } ifelse} %
          ifelse}

      \psset{xunit=3.14}
      \uput[180]{90}(-5,0.5){$\tilde{X}_c(j\Omega)$}
      \selectPlotFont
      \psticklab{0}{0}
      \psticklab{1}{$\Omega_N$} \psticklab{-1}{$-\Omega_N$}
      \psticklab{2}{$\Omega_s$} \psticklab{-2}{$-\Omega_s$}
      \psticklab{4}{$2\Omega_s$} \psticklab{-4}{$-2\Omega_s$}
    \end{psDFplot}

    \\
    \\

    \begin{psDFplot}[dy=1,pifrac=3]{0}{1.2}
      \psDFplotFunction[linewidth=2pt]%
        {x 3.14 div  dup dup %
         -\specHW lt {pop pop 0} {%
              \specHW gt {pop 0} {\specFunPar } ifelse} %
          ifelse}

      \psset{xunit=3.14}
      \uput[180]{90}(-1,0.5){$X(e^{j\omega})$}
      %\selectPlotFont
      %\psticklab{0.333}{$\Omega_N/\Omega_s$}
    \end{psDFplot}

  \end{tabular}

  \caption{Frequency-domain plot}
\end{figure}




\clearpage



\begin{figure}
  \center
  \begin{psCTplot}[dx=3.14,dy=0.5,labelx=false]{-10}{10}{0}{10}
%  \psclip{\psframe(-2.5,-0.8)(2.5,1.6)}
%    \psCTplotFunction[linewidth=2pt,linecolor=lightgray]%
%      {x 3.14 sub 6.28 div dup floor sub 2 mul 1 sub
%         dup -0.5 lt {pop 0} {0.5 gt {0} {1} ifelse} ifelse }
    \def\specHW{0.333 }
    \def\specFun{abs \specHW exch sub \specHW div }
    \psCTplotFunction[linewidth=2pt]%
      {x 3.14 sub 6.28 div dup floor sub 2 mul 1 sub dup dup
      -\specHW lt {pop pop 0} {\specHW gt {pop 0} {\specFun 5 mul} ifelse} ifelse }

%    \endpsclip
  \end{psCTplot}

  \caption{Frequency-domain plot}
\end{figure}



\clearpage


\begin{figure}
\center
\begin{psPZplot}[unit=$r_0$]{2.8}
\psPZplotROC[roctype=anticausal]{0.5}
\psPZplotPoint{0.5}{0.5}
\psPZplotPoint[type=zero]{0}{1}
\psPZplotPoint[type=zero,labelpos=45,label={$x[0]$}]{1.25}{0.78}
\end{psPZplot}
\caption{Example of pole-zero plot}
\end{figure}




\begin{figure}
  \center
  \begin{psDFplot}[dy=1,pifrac=2]{-1.0}{3}
    \psDFplotData(-1,0)(-0.5, 0)(-0.5,1.5)(0.5,1.5)(0.5,0)(1,0)
    \psDFplotDelta[linecolor=blue]{0.25}{2}
  \end{psDFplot}

  \caption{Frequency-domain plot}
\end{figure}

\begin{figure}
  \center
  \def\lambda{0.9 }
  \begin{tabular}{c}
    \begin{psDFplot}[dy=0.2,pifrac=3]{0}{1.1}
      \def\fresp{\lambda 1 sub dup mul 1 \lambda \lambda mul add  x RadtoDeg cos 2 mul \lambda mul sub div}
      \psDFplotFunction{\fresp}
      \DFylabel{Square magnitude $|H(e^{j\omega})|^2$}
    \end{psDFplot}

    \\
    \\

    \begin{psDFplot}[dy=1,pifrac=3,labely=false]{-2}{2}
      \psDFplotFunction[fmax=0]{\lambda x RadtoDeg sin mul -1 mul 1 \lambda x RadtoDeg cos mul sub atan DegtoRad}
      \psDFplotFunction[fmin=0]{\lambda x RadtoDeg sin mul  1 \lambda x RadtoDeg cos mul sub atan DegtoRad -1 mul}
      \DFylabel{Phase (radians)}
    \end{psDFplot}

  \end{tabular}

  \caption{Frequency-domain plot}
\end{figure}


\clearpage



\begin{figure}
\center
\begin{psDTplot}[dx=1,dy=0.5,sidegap=0.5,labelx=false,labely=false]{-6}{6}{-1.2}{1.2}
  % 2pi/12
  \psDTplotFunction[linestyle=dotted,linecolor=darkgray,linewidth=1pt]%
    {x 0.5235 mul RadtoDeg sin}
  \psDTplotFunction[linecolor=gray,linewidth=2pt]%
    {x x 0 gt {-0.5} {0.5} ifelse sub truncate 0.5235 mul RadtoDeg sin}
  \psDTplotSignal{x 0.5235 mul RadtoDeg sin}
\end{psDTplot}

\caption{Discrete- and continuous-time signals}
\end{figure}

\begin{figure}
\center
\begin{psDTplot}[dx=1,dy=0.5,sidegap=0.5]{-6}{6}{-1.2}{1.2}
  % 2pi/12
  \psDTplotFunction[linecolor=gray,linewidth=2pt]%
    {x x floor sub dup 1 exch sub %
     x floor   0.5235 mul RadtoDeg sin mul exch %
     x ceiling 0.5235 mul RadtoDeg sin mul add}
  \psDTplotFunction[linestyle=dotted,linecolor=darkgray,linewidth=1pt]%
    {x 0.5235 mul RadtoDeg sin}
  \psDTplotSignal{x 0.5235 mul RadtoDeg sin}
\end{psDTplot}

\caption{Discrete- and continuous-time signals}
\end{figure}




\clearpage




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pole-zero plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\vspace{3em}



\begin{figure}
\center
\begin{tabular}{cc}
    \begin{dspBlocks}{0.6}{0.6}
 $x[n]$ & \BDadd & \BDsplit & [mnode=circle,name=end1] +         \\
        &        & \BDdelay &                \\
        & \BDadd & \BDsplit & \BDadd         \\
        &        & \BDdelay &                \\
        &        & \BDsplit &
    \end{dspBlocks}
    \psset{arrows=->,linewidth=1.5pt}
    \ncline{1,1}{1,2} \ncline{-}{1,2}{1,3}
    \ncline{1,3}{1,4} \taput{$b_{1,0}$}
    \ncline{3,3}{3,2} \taput{$a_{1,1}$} \ncline{3,3}{3,4}\taput{$b_{1,1}$}
    \ncline{-}{5,3}{5,2} \taput{$a_{1,2}$}
    \ncline{-}{5,3}{5,4}\taput{$b_{1,2}$}

    \ncline{1,3}{2,3} \ncline{2,3}{4,3} \ncline{-}{4,3}{5,3}
    \ncline{5,2}{3,2} \ncline{5,4}{3,4}
    \ncline{3,2}{1,2} \ncline{3,4}{1,4}
&
    \begin{dspBlocks}{0.6}{0.6}
& [mnode=circle,name=beg2] + & \BDsplit & \BDadd & $y[n]$ \\
        &        & \BDdelay &        &        \\
        & \BDadd & \BDsplit & \BDadd &        \\
        &        & \BDdelay &        &        \\
        &        & \BDsplit &        &
    \end{dspBlocks}
    \psset{arrows=->,linewidth=1.5pt}
    \ncline{end1}{beg2}\ncline{-}{1,2}{1,3}
    \ncline{1,3}{1,4} \taput{$b_{2,0}$}
    \ncline{3,3}{3,2} \taput{$a_{2,1}$} \ncline{3,3}{3,4}\taput{$b_{2,1}$}
    \ncline{-}{5,3}{5,2} \taput{$a_{2,2}$}
    \ncline{-}{5,3}{5,4}\taput{$b_{2,2}$}

    \ncline{1,3}{2,3} \ncline{2,3}{4,3} \ncline{-}{4,3}{5,3}
    \ncline{5,2}{3,2} \ncline{5,4}{3,4}
    \ncline{3,2}{1,2} \ncline{3,4}{1,4}
\end{tabular}
\end{figure}


\clearpage




\begin{figure}
\center
    \begin{dspBlocks}{1.3}{0.6}
 $x[n]$ & \BDadd & \BDsplit & \BDadd & $y[n]$ \\
        &        & \BDdelay &        &        \\
        & \BDadd & \BDsplit & \BDadd &        \\
        &        & \BDdelay &        &        \\
        &        & \BDsplit &        &
    \end{dspBlocks}
    \psset{arrows=->,linewidth=1.5pt}
    \ncline{1,1}{1,2} \ncline{-}{1,2}{1,3}
    \ncline{1,3}{1,4} \taput{$b_0$} \ncline{1,4}{1,5}
    \ncline{3,3}{3,2} \taput{$a_1$} \ncline{3,3}{3,4}\taput{$b_1$}
    \ncline{-}{5,3}{5,2} \taput{$a_2$} \ncline{-}{5,3}{5,4}\taput{$b_2$}

    \ncline{1,3}{2,3} \ncline{2,3}{4,3} \ncline{-}{4,3}{5,3}
    \ncline{5,2}{3,2} \ncline{5,4}{3,4}
    \ncline{3,2}{1,2} \ncline{3,4}{1,4}
\end{figure}


\clearpage


\begin{figure}
\center
    \begin{dspBlocks}{1.3}{0.6}
 $x[n]$ & \BDsplit & \BDadd & \BDadd & \BDsplit & $y[n]$ \\
        & \BDdelay &        &        & \BDdelay          \\
        & \BDsplit & \BDadd & \BDadd & \BDsplit          \\
        & \BDdelay &        &        & \BDdelay          \\
        & \BDsplit & \BDadd & \BDadd & \BDsplit          \\
        &          &        &        &                   \\
        & \BDdelay &        &        & \BDdelay          \\
        &          &        &        &                   \\
    \end{dspBlocks}
    \psset{arrows=->,linewidth=1.5pt}
    \ncline{-}{1,1}{1,2} \ncline{1,2}{1,3} \taput{$b_0$}
    \ncline{1,3}{1,4} \ncline{1,4}{1,6}
    \ncline{3,2}{3,3} \taput{$b_1$} \ncline{3,5}{3,4}\taput{$a_1$}
    \ncline{5,2}{5,3} \taput{$b_2$} \ncline{5,5}{5,4}\taput{$a_2$}
    \ncline{-}{8,3}{8,2} \taput{$b_{N-1}$}
    \ncline{-}{8,4}{8,5}\taput{$a_{M-1}$}

    \ncline{1,2}{2,2} \ncline{2,2}{4,2} \ncline{-}{4,2}{5,2}
    \ncline[linestyle=dotted]{5,2}{7,2} \ncline{-}{7,2}{8,2}
    \ncline{8,3}{7,3} \ncline[linestyle=dotted]{7,3}{5,3}
    \ncline{5,3}{3,3} \ncline{3,3}{1,3}

    \ncline{1,5}{2,5} \ncline{2,5}{4,5} \ncline{-}{4,5}{5,5}
    \ncline[linestyle=dotted]{5,5}{7,5} \ncline{-}{7,5}{8,5}
    \ncline{8,4}{7,4} \ncline[linestyle=dotted]{7,4}{5,4}
    \ncline{5,4}{3,4} \ncline{3,4}{1,4}
\end{figure}

\begin{figure}
\center
    \begin{dspBlocks}{1.3}{0.6}
 $x[n]$ & \BDadd & \BDsplit & \BDsplit & \BDadd & $y[n]$ \\
        &        & \BDdelay & \BDdelay                   \\
        & \BDadd & \BDsplit & \BDsplit & \BDadd          \\
        &        & \BDdelay & \BDdelay                   \\
        & \BDadd &          &          & \BDadd          \\
    \end{dspBlocks}
    \psset{arrows=->,linewidth=1.5pt}
    \ncline{1,1}{1,2} \ncline{-}{1,2}{1,4}
    \ncline{1,4}{1,5} \taput{$b_0$}
    \ncline{1,5}{1,6}
    \ncline{3,3}{3,2} \taput{$a_1$} \ncline{3,4}{3,5}\taput{$b_1$}
    \ncline{5,3}{5,2} \taput{$a_2$} \ncline{5,4}{5,5}\taput{$b_2$}

    \ncline{1,3}{2,3} \ncline{2,3}{4,3} \ncline{-}{4,3}{5,3}
    \ncline{5,2}{3,2} \ncline{3,2}{1,2}

    \ncline{1,4}{2,4} \ncline{2,4}{4,4} \ncline{-}{4,4}{5,4}
    \ncline{5,5}{3,5} \ncline{3,5}{1,5}
\end{figure}


\clearpage




\begin{figure}
  \center
  \begin{dspBlocks}{0.2}{0.6}

$x[n]$ & & & \BDsplit & \BDdelay & \BDsplit & \BDdelay & \BDsplit & \BDdelay & \BDsplit & \hspace{3em} &  & \BDdelay & \BDsplit  \\ \\
& & & & & & & & \BDadd \\
& & & & & & & & $y[n]$
  \end{dspBlocks}
  \psset{linewidth=1.5pt}
  \ncline{1,1}{1,3}\ncline{1,3}{1,5}
  \ncline{1,5}{1,7}\ncline{1,7}{1,9}
  \ncline{1,9}{1,10}
  \ncline[linestyle=dotted]{1,10}{1,12}\ncline{1,12}{1,13}
  \ncline{1,13}{1,14}
  \psset{arrows=->}
  \ncdiagg[angleA=-90,armA=1.5]{1,4}{3,9}\tlput{$b_0$}
  \ncdiagg[angleA=-90,armA=1.5]{1,6}{3,9}\tlput{$b_1$}
  \ncdiagg[angleA=-90,armA=1.5]{1,8}{3,9}\tlput{$b_2$}
  \ncdiagg[angleA=-90,armA=1.5]{1,10}{3,9}\tlput{$b_3$}
  \ncdiagg[angleA=-90,armA=1.5]{1,14}{3,9}\tlput{$b_{M-1}$}
  \ncline{3,9}{4,9}
\end{figure}


\clearpage


\begin{figure}
  \center
  \begin{dspBlocks}{0.1}{0.6}

$x[n]$ & & & \BDsplit & \BDdelay & \BDsplit & \BDdelay & \BDsplit & \BDdelay & \BDsplit & \hspace{3em} &  & \BDdelay &  \\
       & & &  &  & \BDadd &  & \BDadd &  & \BDadd & \hspace{3em} &  &  & \BDadd & &  $y[n]$
  \end{dspBlocks}
  \psset{linewidth=1.5pt}
  \ncline{1,1}{1,3}\ncline{1,3}{1,5}
  \ncline{1,5}{1,7}\ncline{1,7}{1,9}
  \ncline{1,9}{1,10}
  \ncline[linestyle=dotted]{1,10}{1,12}\ncline{1,12}{1,13}
  \ncline{1,13}{1,14}
  \ncline{1,4}{2,4}\tlput{$b_0$}
  \psset{arrows=->}
  \ncline{2,4}{2,6}\ncline{1,6}{2,6}\tlput{$b_1$}
  \ncline{2,6}{2,8}\ncline{1,8}{2,8}\tlput{$b_2$}
  \ncline{2,8}{2,10}\ncline{1,10}{2,10}\tlput{$b_3$}
  \ncline{-}{2,10}{2,11}
  \ncline[linestyle=dotted]{-}{2,10}{2,13}
  \ncline{2,13}{2,14}\ncline{1,14}{2,14}\tlput{$b_{M-1}$}
  \ncline{2,14}{2,16}
\end{figure}






\clearpage





\begin{figure}
\center
\begin{pspicture}(-10,-10)(10,10)
\psaxes[trigLabels=true,trigLabelBase=2](3,0)(5,0)
\end{pspicture}
\end{figure}
\clearpage


\begin{figure}[tb]
  \center
  \def\FIRmm{x RadtoDeg %
             dup       cos  0.3105  mul exch %
             dup 2 mul cos  0.01812 mul exch %
             dup 3 mul cos -0.09527 mul exch %
             dup 4 mul cos -0.0198  mul exch %
             dup 5 mul cos  0.04893 mul exch %
                 6 mul cos  0.03344 mul %
             add add add add add %
             2 mul 0.475019 add }
  \def\FIRerr{0.1169}
  \begin{tabular}{cc}
    \begin{psDFplot}[size=medium,pifrac=2,dy=.1,fmin=0, fmax=1.6]{0.35}{1.11}
       \psDFplotFunction[fmax=1.55]{\FIRmm}
     \end{psDFplot}
&
    \\
&
    \begin{psDFplot}[size=medium,,pifrac=2,%
                     dy=1,fmin=1.5,labelx=false]{-.03}{.35}
      \psDFplotFunction{\FIRmm}
    \end{psDFplot}
  \end{tabular}
\caption{Details of passband and stopband of the frequency response in Figure~\ref{FiltDesIntermed}.}
\label{StopPass}
\end{figure}

%\end{document}

\begin{psDFplot}[dy=1,fmin=0]{-0.2}{1.2}
  \def\FIRmm{x RadtoDeg %
             dup       cos  0.3105  mul exch %
             dup 2 mul cos  0.01812 mul exch %
             dup 3 mul cos -0.09527 mul exch %
             dup 4 mul cos -0.0198  mul exch %
             dup 5 mul cos  0.04893 mul exch %
                 6 mul cos  0.03344 mul %
             add add add add add %
             2 mul 0.475019 add}
  \psDFplotFunction{\FIRmm}
\end{psDFplot}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[t!]
  \center
  \def\FIRmm{x RadtoDeg %
             dup       cos  0.3105  mul exch %
             dup 2 mul cos  0.01812 mul exch %
             dup 3 mul cos -0.09527 mul exch %
             dup 4 mul cos -0.0198  mul exch %
             dup 5 mul cos  0.04893 mul exch %
                 6 mul cos  0.03344 mul %
             add add add add add %
             2 mul 0.475019 add }
  \def\FIRnn{180 x RadtoDeg sub %
             dup       cos  0.31357  mul exch %
             dup 2 mul cos  0.021065 mul exch %
             dup 3 mul cos -0.1155   mul exch %
                 4 mul cos -0.06632  mul  %
             add add add %
             2 mul 0.47745987 add }

  \def\FIRerr{0.2169}
  \begin{tabular}{cc}
    \begin{psDFplot}[size=medium,%
                     dy=1,fmin=0,fmax=1.255,labelx=false]{-\FIRerr}{\FIRerr}
      \psDFplotFunction{\FIRnn -10 mul }
      \psset{xunit=3.14}
      \qdisk(0.17,-\FIRerr){3pt}\uput[u](0.17,-\FIRerr){1}
      \qdisk(.33,\FIRerr){3pt} \uput[d](.33,\FIRerr){2}
      \qdisk(0.4,-\FIRerr){3pt} \uput[ul](0.4,-\FIRerr){3}
    \end{psDFplot}
    &
    \begin{psDFplot}[size=medium,%
                     dy=1,fmin=1.885,labelx=false]{-\FIRerr}{\FIRerr}
      \psDFplotFunction{1 \FIRnn sub }
      \psset{xunit=3.14}
      \qdisk(0.6,\FIRerr){3pt} \uput{6pt}[dr](0.6,\FIRerr){4}
      \qdisk(.76,-\FIRerr){3pt}\uput[u](.76,-\FIRerr){5}
      \qdisk(1,\FIRerr){3pt}\uput[dl](1,\FIRerr){6}
    \end{psDFplot}
  \end{tabular}
  \caption{Approximation error function $E(x)$ for a 9-tap lowpass prototype; alternations are marked by a dot.}
  \label{figMSEvsMM}
\end{figure}



%\end{document}


\begin{psDFplot}[dy=1,pifrac=2,fmin=0]{-0.5}{1.5}
\psset{xunit=3.14}
\psframe[fillstyle=vlines,fillcolor=lightgray,%
         hatchcolor=lightgray,hatchangle=20,%
         linecolor=lightgray]%
         (0,1.1)(0.4,0.9)
\psline[linewidth=2pt](0,1)(0.4,1)
\psframe[fillstyle=vlines,fillcolor=lightgray,%
         hatchcolor=lightgray,hatchangle=20,%
         linecolor=lightgray]%
         (0.6,0.3)(1,-0.3)
\psline[linewidth=2pt](0.6,0)(1,0)
\psline[linewidth=0.5pt](0.4,-.5)(0.4,1.5)
\psline[linewidth=0.5pt](0.6,-.5)(0.6,1.5)
\selectPlotFont
\rput[t](0.4,-0.61){$0.4\pi$}
\rput[t](0.6,-0.61){$0.6\pi$}
\rput[b](0.2,1.55){passband}
\rput[b](0.5,1.55){transition band}
\rput[b](0.8,1.55){stopband}
\end{psDFplot}

\begin{psDFplot}[dy=1,pifrac=2,fmin=0]{-0.5}{1.5}
\psset{xunit=3.14}
\psframe[fillstyle=vlines,%
         hatchcolor=lightgray,hatchangle=20,%
         linecolor=lightgray]%
         (0,1.1)(0.4,0.9)
\psframe[fillstyle=vlines,%
         hatchcolor=lightgray,hatchangle=20,%
         linecolor=lightgray]%
         (0.6,0.3)(1,-0.3)
\psline[linewidth=0.5pt](0.4,-.5)(0.4,1.5)
\psline[linewidth=0.5pt](0.6,-.5)(0.6,1.5)
\selectPlotFont
\rput[t](0.4,-0.61){$0.4\pi$}
\rput[t](0.6,-0.61){$0.6\pi$}
\psset{xunit=\psDSPunitX}
\psDFplotFunction{x 0.5 mul 10 exp 1 add 1 exch div}
\end{psDFplot}

\begin{psDFplot}[dy=1,pifrac=2,fmin=0]{-0.5}{1.5}
\psset{xunit=3.14}
\psframe[fillstyle=vlines,%
         hatchcolor=lightgray,hatchangle=20,%
         linecolor=lightgray]%
         (0,1.1)(0.4,0.9)
\psframe[fillstyle=vlines,%
         hatchcolor=lightgray,hatchangle=20,%
         linecolor=lightgray]%
         (0.6,0.3)(1,-0.3)
\psline[linewidth=0.5pt](0.4,-.5)(0.4,1.5)
\psline[linewidth=0.5pt](0.6,-.5)(0.6,1.5)
\selectPlotFont
\rput[t](0.4,-0.61){$0.4\pi$}
\rput[t](0.6,-0.61){$0.6\pi$}
\psset{xunit=\psDSPunitX}
\psDFplotFunction{x 0.6 mul 14 exp 1 add 1 exch div}
\end{psDFplot}

\begin{psDFplot}[dy=1,pifrac=2,fmin=0]{-0.5}{1.5}
\psset{xunit=3.14}
\psframe[fillstyle=vlines,%
         hatchcolor=lightgray,hatchangle=20,%
         linecolor=lightgray]%
         (0,1.1)(0.4,0.9)
\psframe[fillstyle=vlines,%
         hatchcolor=lightgray,hatchangle=20,%
         linecolor=lightgray]%
         (0.6,0.3)(1,-0.3)
\psline[linewidth=0.5pt](0.4,-.5)(0.4,1.5)
\psline[linewidth=0.5pt](0.6,-.5)(0.6,1.5)
\selectPlotFont
\rput[t](0.4,-0.61){$0.4\pi$}
\rput[t](0.6,-0.61){$0.6\pi$}
\psset{xunit=\psDSPunitX}
\def\acoef{0.5002 }
\def\bcoef{0.4133 }
\def\ccoef{0.0001 }
\def\dcoef{-0.1195 }
\psDFplotFunction{x RadtoDeg cos %
             dup count 2 sub index mul %
             dup count 2 sub index mul %
             8 \dcoef mul mul 3 1 roll %
             4 \ccoef mul mul 3 1 roll %
             2 \bcoef mul 6 \dcoef mul sub mul %
             \acoef 2 \ccoef mul sub %
             add add add}
\end{psDFplot}


%\end{document}



\clearpage


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Discrete-time plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{figure}
\center
\begin{psDTplot}{-32}{32}{-1.2}{1.2}
  \psDTplotSignal[nmax=-1]{ 0 }
  \psDTplotSignal[nmin=0,
               %linecolor=red
               ]{ 11.25 x mul sin }
\end{psDTplot}
\caption{Large discrete-time plot}
\end{figure}


\begin{figure}
\center
\begin{tabular}{cc}

\begin{psDTplot}[size=small]{0}{63}{-1.2}{1.2}
  \psDTplotSignal{ 11.25 x mul sin }
\end{psDTplot}

&

\begin{psDTplot}[size=small]{0}{63}{-1.2}{1.2}
  \psDTplotSignal[linecolor=green]{ 11.25 x mul cos }
\end{psDTplot}

\end{tabular}

\caption{Side-by-side pictures}
\end{figure}


\begin{figure}
\center
\begin{psDTplot}[size=medium]{0}{31}{-1.2}{1.2}
  \psDTplotSignal{ 11.25 x mul sin }
\end{psDTplot}
\caption{Medium-size picture}
\end{figure}



\begin{figure}
\center
\begin{psDTplot}[dx=10,dy=0.2]{-50}{50}{-0.6}{1.2}
  \psDTplotSignal[nmax=-1]{ 0.5 x mul RadtoDeg sin x div}
  \psDTplotPoint{0}{1}
  \psDTplotSignal[nmin=1]{ x RadtoDeg sin x div}
  \psplot[plotpoints=1500,linecolor=red]%
      {-50}{50}{ x RadtoDeg sin x div }
\end{psDTplot}
\caption{Discrete- and continuous-time signals}
\end{figure}


\begin{figure}
\center
\begin{psDTplot}[dx=10,dy=0.2]{0}{50}{-0.6}{1.2}
  \def\sincx{x 0 eq {1} {x RadtoDeg sin x div} ifelse}
  \psDTplotSignal{\sincx}
  \psDTplotFunction[linestyle=dashed,linecolor=darkgray,linewidth=0.5pt]{\sincx}
\end{psDTplot}

\caption{Discrete- and continuous-time signals}
\end{figure}



\end{document}
