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 enter image description here

  • 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
  • 1
    @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:



    width=10cm, height=4cm,
    enlarge x limits=false
\addplot [densely dashed] {abs(sin(x))};
\addplot [very thick] {max(abs(sin(x)), exp(-(0.0015*mod(x+90,180)))};
  • 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.

enter image description here


\def\arch{1.7*pi/3}   %
             axis x line=center, 
             axis y line=left, enlargelimits=upper]
% draw sine functions
\addplot [dashed,thin,domain=-pi:6*pi,smooth]{-2*sin(deg(0.5*x))};
\addplot [dashed,thin,domain=-pi:6*pi,smooth]{ 2*sin(deg(0.5*x))};

% 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
\addplot [thick,domain={\j*pi+\arch}:\k*pi, smooth]{ 2*sin(deg(0.5*x))};
\addplot [thick,domain={\j*pi+\arch}:\k*pi, smooth]{-2*sin(deg(0.5*x))};
\caption{Half-Wave Rectifier Waveform}


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.