11

I have sinus wave and want to draw an electrical ripple on it, so I used the decoration option to draw a zigzag line. But the zigzag line is oriented in a right angle to the wave. I need a zigzag line which followed the sinus wave oriented at the x-axis. This is what I have:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\tikzset{snake it/.style={decorate, decoration=snake}}

\newcommand{\drawCoordinateSystem}[2]{
        \draw[color=#1, step=.5cm, very thin] (0,-2) grid (7.5,2);
        \draw [#2, thick, ->] (0,0) -- (8,0) node[right]{$T$}; 
        \draw [#2, thick, <->](0,2.5) -- (0,-2.5) node[above] {$F$};
    }%\end{tikzpicture}%end newCommand

\begin{document}
\vspace*{2cm}
\begin{center}

    \begin{tikzpicture}[scale=0.8]  
        \drawCoordinateSystem{lightgray}{black}         
         \draw[domain=0:6.5, black, thick]   plot (\x,{sin(\x r)})   node[right, above,] {$I$};         
         \draw[decorate, decoration={zigzag,segment length = .15cm, amplitude = 1.5mm}, domain=0:6.5, thick] plot (\x,{sin(\x r)});             
    \end{tikzpicture}
\end{center}
\end{document}

And that's what I need: Ripple oriented to X-Axis

Can someone help me to solve this problem?

2
  • Can someone confirm this is called a "sinus wave" (from maths here) and I've never heard of sinus wave. Sine wave, totally fine, sinusoidal, totally fine, ducking sinus? beech what? – Alec Teal Oct 9 '15 at 11:33
  • @AlecTeal If you are interested in the word sinus, you can look at the description in History of Mathematics by Katz. Go to page 253, where you will find something about the history of the word. Basically sinus is Latin which was a mistranslation of an Arabic term, which in turn was a translation of a Hindu term. The OP probably just isn't native in English and used a reasonable transcription, as in this form sinus is used in quite a few languages. – WalyKu Oct 9 '15 at 14:33
13

I guess the "ripple" is another sine wave of higher frequency, added to the main one, so you can plot it as another function on top of the first one.

I had to drop the r (for radians) and adjust the numbers, to avoid overflow errors ("number too big").

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}

\newcommand{\drawCoordinateSystem}[2]{
        \draw[color=#1, step=.5cm, very thin] (0,-2) grid (7.5,2);
        \draw [#2, thick, ->] (0,0) -- (8,0) node[right]{$T$}; 
        \draw [#2, thick, <->](0,2.5) -- (0,-2.5) node[above] {$F$};
    }%\end{tikzpicture}%end newCommand

\begin{document}
\vspace*{2cm}
\begin{center}

    \begin{tikzpicture}[scale=0.8]  
        \drawCoordinateSystem{lightgray}{black}         
         \draw[domain=0:6.5, black, thick]   plot (\x,{sin(\x*60.0)})   node[right, above,] {$I$};         
         %\draw[decorate, decoration={zigzag,segment length = .15cm, amplitude = 1.5mm}, domain=0:6.5, thick] plot (\x,{sin(\x r)});             
        \draw[domain=0:6.4, black, thick, samples=200]   plot (\x,{sin(\x*60.0)+0.5*sin(\x*960.0});     

    \end{tikzpicture}
\end{center}
\end{document}

Result

Update

If your ripple has to be more "triangular", then you can cheat and reduce the number of samples. If you choose it appropiately, you can sample the sine noise only at its peaks, an get a triangular wave. For example:

\begin{tikzpicture}[scale=0.8]  
    \drawCoordinateSystem{lightgray}{black}         
     \draw[domain=0:6.5, black, thick]   plot (\x,{sin(\x*60.0)})   node[right, above,] {$I$};         
    \draw[domain=0:6.45, black, thick, samples=87]   plot (\x,{sin(\x*60.0)+0.5*sin(\x*1200.0});     
\end{tikzpicture}

produces:

Result

3
  • And if you don' t want to cheat you can use Fourier' s theorem to add more sine waves and compose the wanted signal. – Johannes Linkels Oct 14 '15 at 1:14
  • @jlinkels Smart! However, in order to properly reconstruct a good enough triangular wave, high frequency terms should be included, which means (by Niquist theorem) even higher sampling frequency, and thus a very high number for the samples parameter. This will increase the computational cost of the plot (not only for its generation, but also for its rendering in the pdf) – JLDiaz Oct 14 '15 at 6:54
  • yes, correct. One doesn't escape from Nyquist. My experience is that for a plot like this about 600 samples are needed for a nice triangular wave. Experience is from Gnuplot which might come easy to experiment to get the settings right before implementing it in Tikz – Johannes Linkels Oct 15 '15 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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