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.

[fr] La 1ere figure ci-dessous permet de représenter la conversion analogique numérique avec \NN le nombre de niveaux, réalisée avec le code suivant (il faut autoriser gnuplot). Comme vous pouvez le constater, la deuxième figure n'est pas complète, la seule différence est dans l'appel de la fonction, dans la seconde, j'ai généralisée en précisant \NN

[en] The first figure below is used to represent the analog to digital conversion with \NN the number of levels, performed with the following code (you have to allow gnuplot). As you can see, the second figure is not complete, the only difference is in the function call in the second, I generalized by specifying \NN

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\begin{document}


\begin{tikzpicture}
\def\NN{16}
\begin{scope}[xscale=6,yscale=2]
\draw[draw=red,,fill=pink] plot[id=sin9c,prefix=gnuplot/,domain=0:2,samples=60,
ybar interval] 
function{0.25*floor(\NN/4*(sin(4*x)+0.5*sin(20*x)+0.05*sin(200*x)+0.03*sin(400*x)+2))};
\draw[color=blue,thick] plot[id=sin7c,prefix=gnuplot/,domain=0:2,samples=1000,thick] 
function{sin(4*x)+0.5*sin(20*x)+0.05*sin(200*x)+0.03*sin(400*x)+2};
\foreach \nn in{0,1,2,...,\NN}{
\draw (0,{2*\nn/(\NN/2)}) node[left]{\small \nn}-- (2,{2*\nn/(\NN/2)});
}
\draw (0,0) -- (0,4);
\end{scope}
\end{tikzpicture}


\begin{tikzpicture}
\def\NN{16}
\begin{scope}[xscale=6,yscale=2]
\draw[draw=red,,fill=pink] plot[id=sin9c,prefix=gnuplot/,domain=0:2,samples=60,
ybar interval] 
function{4/\NN*floor(\NN/4*(sin(4*x)+0.5*sin(20*x)+0.05*sin(200*x)
+0.03*sin(400*x)+2))};
\draw[color=blue,thick] plot[id=sin7c,prefix=gnuplot/,domain=0:2,samples=1000,thick]
 function{sin(4*x)+0.5*sin(20*x)+0.05*sin(200*x)+0.03*sin(400*x)+2};
\foreach \nn in{0,1,2,...,\NN}{
\draw (0,{2*\nn/(\NN/2)}) node[left]{\small \nn}-- (2,{2*\nn/(\NN/2)});
}
\draw (0,0) -- (0,4);
\end{scope}
\end{tikzpicture}


\end{document}

enter image description here

Comment faire pour obtenir la courbe? / How to obtain the curve?

share|improve this question
1  
I cannot test it now, but in gnuplot 4/16 is an integer division, son 4/16=0. If you want to obtain 0.25 you must write something like 4.0/16. Look at expressions section of gnuplot manual –  Ignasi Jun 9 '12 at 7:23

1 Answer 1

up vote 6 down vote accepted

If you divide two integers (as in your second case, 4/\NN=4/16), gnuplot will use integer arithmetic, so the result of the expression is 4/16=0. Use 4.0/\NN instead, and the two plots are identical.

share|improve this answer
1  
If you want divide two integer macros (like \nn/\mm), you can use (\nn*1.0)/\mm. –  Paul Gaborit Jun 11 '12 at 0:54

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.