Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

?
share|improve this question

2 Answers 2

up vote 4 down vote accepted

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

share|improve this answer
    
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)};
    \addplot [densely dotted, samples=51] {sin(x)};
    \end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Should the samples be an odd integer? –  stalking is prohibited Mar 19 '13 at 15:38
    
@Jake. Thank you for this wonderful answer. I would very much like to use your coding which runs on pdfLaTeX. –  Khaaba Mar 19 '13 at 17:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.