9

I have a fully rectified sinusoidal wave that I am trying to place a sawtooth wave form on top of as the image bellow,

enter image description here

I originally had a messy solution but it was not very good, I have a tex sine wave im trying to place it on bellow.

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    domain=0:1.5*360,
    samples=4*360,
    xtick=\empty,
    width=10cm, height=4cm,
    ymin=0,
    enlarge x limits=false
]
\addplot [densely dashed] {abs(sin(x))};

\end{axis}
\end{tikzpicture}
\end{document}
  • Creating such a plot looks easy enough given either a data file or formula for the sawtooth. Could you explain where you issue is, exactly? – Joseph Wright Oct 5 '14 at 6:01
  • Yeh well thats my question, I can plot a sawtooth by drawing lines but what formula would I use..this is where im at.. \addplot [very thick] {0.5-atan(cot((pi*x)/2))}; – JS60 Oct 5 '14 at 7:13
  • well throwing in some magic numbers i have a solution for it,\addplot [very thick] {0.91+0.001*atan(cot(95+ ((0.63*pi*x)/2)))}; – JS60 Oct 5 '14 at 7:29
10

You can use 1 - 1/(3*180)*mod(x+90,180) to plot a sawtooth wave. mod(x,180) repeats every 180 units, 1/(3*180) scales the values (1/180 would result in a sawtooth wave running from 0 to 1).

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    domain=0:1.5*360,
    samples=4*360,
    xtick=\empty,
    width=10cm, height=4cm,
    ymin=0,
    enlarge x limits=false
]
\addplot [densely dashed] {abs(sin(x))};
\addplot [very thick] {1-1/(3*180)*mod(x+90,180)};
\end{axis}
\end{tikzpicture}
\end{document}
6

This is one possible solution where foreach loop is used with a line approximation with sawtooth waveform.

if one wants the line to touch the curve without penetrating into the sine wave then remove the vertical line and change \arch definition to 60

enter image description here

Code

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}

\begin{document}
\def\arch{90}
\begin{tikzpicture}
\begin{axis}[
    domain=0:1.5*360,
    samples=360,
    xtick={0,90,180,270,360,450,540},
    width=10cm, height=5cm,
    ymin=0, ymax=1.5, xmin=0,
    enlarge x limits=false
]
\addplot [densely dashed] {abs(sin(x))};
% draw the rectified line approximation via foreach skill
\foreach \i/\j in {-1/0,1/2,3/4}{
\addplot [thick,domain=\i*90:{\j*90+\arch}] 
{1-0.001*(x-\i*90)};
\addplot[thick] coordinates{(\i*90,1)(\i*90,{1-0.001*(\j*90+\arch-\i*90)})}; % remove this line if the vertical line is undesired  and change arch to 90
}
\node[coordinate, pin =above:{\parbox{2cm}{\tiny Voltage Simplified by Approximation}}] at (axis cs: 180,0.9) {};
\end{axis}

\end{tikzpicture}
\end{document}

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.