# plotting graphs with dspPlot functions

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:

Error I got after running the code is:

! Undefined control sequence.

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

?

-

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}


-
Thanks. It works! – Khaaba Mar 19 '13 at 17:13

Not a direct answer to your question, but here's a way to draw the graph without specialised packages using TikZ instead of PSTricks (so it can be run with any compiler):

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=0:360,
hide y axis,
axis x line*=middle,
xtick=\empty,
samples=13,
width=10cm, height=5cm
]
\addplot [const plot mark mid, very thick, gray] {sin(x)};
\addplot [ycomb, mark=*, thick, mark size=1] {sin(x)};

Should the samples be an odd integer? – kiss my armpit Mar 19 '13 at 15:38