[Tex/LaTex] plotting graphs with dspPlot functions

plotpstricks

I have tried plotting graphs with dspPlot as explained by Prof. Paolo Prandoni and Prof. Martin Vetterli in their site but failed. They have run the following code to generate curve in their DSP book available online in their site. However, when I run the same, it does not work. Anybody can help me out please. [I wrote to authors few days back and reply is yet to receive from their end]

\documentclass[a4paper,11pt]{ltxdoc}
\usepackage{float}
\usepackage{fancyvrb}
\usepackage{enumitem}
%\usepackage{courier}
\usepackage[utopia]{mathdesign}
\usepackage{dspTricks, dspFunctions, dspBlocks}

\newenvironment{centerfig}{%
  \begin{figure}[H]
    \begin{center}}{
    \end{center}
  \end{figure}}


\begin{document}
\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}

Program fragment and its output is appended below for your kind reference:

enter image description here

Error I got after running the code is:

! Undefined control sequence.
<recently read> \c@lor@to@ps

l.19 ...sidegap=0.5,yticks=none]{-6, 6}{-1.2, 1.2}

?

Best Answer

run the document with xelatex or the sequence latex -> dvips -> ps2pdf or use the package auto-pst-pdf. However, no need to use the package float:

\documentclass[a4paper,11pt]{article}
\usepackage{caption}
\usepackage[utopia]{mathdesign}
\usepackage{dspTricks, dspFunctions, dspBlocks}

\newenvironment{centerfig}
  {\begin{minipage}{\linewidth}\centering}
  {\end{minipage}}

\begin{document}

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

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

enter image description here