# A voltage graph in PGF plots

Would it be possible to achieve this in PGF plots? I can manage to get a sine wave and draw the sawtooth looking wave but cant get it all together

• For two plots on the same axis, use \addplot. groupplots will place two sets of axes above each other. Reducing the spacing to nothing might be difficult. And to add labels, define a \coordinate using cs units inside the axes environment, then use the named coordinate afterward for the label (\node). – John Kormylo Oct 4 '14 at 4:10
• @JohnKormylo If there are no marks on the y-axis, it would be easier to simply do the two plots on one axis with an offset and the tick labels removed. – Joseph Wright Oct 4 '14 at 6:09
• thanks for the help, ill eventually get there, learning along the way .. – JS60 Oct 4 '14 at 6:39
• Actually, you could probably add the node inside the axis environment. The reason for doing it later is to put the label on top of shaded areas. – John Kormylo Oct 4 '14 at 15:48

Another way to implement Jesse's plot without using loops is to use abs(sin(x)) for the rectified sine wave, exp(-(0.0015*mod(x+90,180)) for the repeating exponential function, and max(<function a>, <function b>) for combining the two:

\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
]
\end{axis}
\end{tikzpicture}
\end{document}

• Thats great, thanks alot, how could you do the sawtooth using your method? – JS60 Oct 4 '14 at 23:32
• That is what TikZ was meant to be. Genius solution Ben Quinton. – AboAmmar Oct 13 '14 at 16:30

This is one possible solution via PGFplots. The rectified curve is an exponentially decay function with a large time constant, not a sloped line.

Code

\documentclass{article}
\usepackage{pgfplots}
\usepackage{graphicx}
\begin{document}
\def\arch{1.7*pi/3}   %
\begin{figure}[!hbt]
\centering
\begin{tikzpicture}
\begin{axis}[xlabel={$t$},xmin=-3,xmax=21,
ylabel={$i_D$},ymin=0,ymax=5,
axis x line=center,
axis y line=left, enlargelimits=upper]
% draw sine functions

% draw the rectified curves automatically via foreach skill
\foreach \i/\j/\k in {-1/0/1,1/2/3,3/4/5,5/6/7}{
\addplot [thick,domain=\i*pi:{\j*pi+\arch}, ] {2*e^(-0.05*(x-\i*pi)};  % exponentially decay curves, not a line