Plotting a rectangular waveform with LaTeX











up vote
4
down vote

favorite












I need to plot a rectangular waveform with Latex. The main problem is how to make the height of the pulse "variable" not a "number" as you can see in the figure below. "x" here is some variable that will be found by calculations.



enter image description here










share|improve this question









New contributor




Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    4
    down vote

    favorite












    I need to plot a rectangular waveform with Latex. The main problem is how to make the height of the pulse "variable" not a "number" as you can see in the figure below. "x" here is some variable that will be found by calculations.



    enter image description here










    share|improve this question









    New contributor




    Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I need to plot a rectangular waveform with Latex. The main problem is how to make the height of the pulse "variable" not a "number" as you can see in the figure below. "x" here is some variable that will be found by calculations.



      enter image description here










      share|improve this question









      New contributor




      Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I need to plot a rectangular waveform with Latex. The main problem is how to make the height of the pulse "variable" not a "number" as you can see in the figure below. "x" here is some variable that will be found by calculations.



      enter image description here







      tikz-pgf diagrams pstricks pst-plot






      share|improve this question









      New contributor




      Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 11 hours ago









      Artificial Stupidity

      4,6641832




      4,6641832






      New contributor




      Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 14 hours ago









      Ali A.

      232




      232




      New contributor




      Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Ali A. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          A PSTricks solution just for comparison purpose.



          documentclass[pstricks,border=12pt,12pt]{standalone}
          usepackage{pst-plot}
          begin{document}
          begin{pspicture}(-1,-1)(11.5,5.5)
          psaxes[ticks=x,labels=x]{->}(0,0)(-1,-1)(11,5)[$t$,0][$A(t)$,90]
          multips(0,0)(2,0){5}{psline[linecolor=blue,linewidth=2pt](0,0)(0,4)(1,4)(1,0)(2,0)}
          uput{5pt}[180](0,4){$sqrt{R_s}$}
          end{pspicture}
          end{document}


          enter image description here






          share|improve this answer























          • Thank you so much for your help. However, when I tried to run the codes you gave me, it gives me the following error: ! Undefined control sequence. c@lor@to@ps ->PSTricks _Not_Configured_For_This_Format l.6 ...xes{->}(0,0)(-1,-1)(12,5)[$t$,0][$A(t)$,90] ?
            – Ali A.
            14 hours ago










          • Can you please help me more? How I can use these options? Thanks.
            – Ali A.
            14 hours ago










          • Yes I use win 10
            – Ali A.
            14 hours ago










          • This works.. :) One more thing please, How can I can make the height of the pulses in terms of a variable not number, as I mentioned in my post and as shown in the figure I attached to it. Many thanks..
            – Ali A.
            14 hours ago






          • 1




            Thank you so much for your time and help. It works perfectly now.. :)
            – Ali A.
            13 hours ago


















          up vote
          2
          down vote













          Since this question is tagged tikz-pgf, I thought you may also be interested in a TikZ code. (One of its advantageous is that this works with pretty much any compiler.)



          documentclass[tikz,border=3.14mm]{standalone}
          begin{document}
          begin{tikzpicture}
          pgfmathsetmacro{h}{2}
          pgfmathsetmacro{L}{4}
          draw[thick,-latex] (0,-0.5) -- (0,h+2) node[above] {$A(t)$};
          draw[thick,-latex] (-0.5,0) -- (2*L+1,0) node[right] {$t$};
          foreach X [evaluate=X as Z using {int(2*X-1)},] in {1,...,L}
          {draw[very thick,blue] (2*X-2,0) |- (2*X-1,h) |- (2*X,0);
          draw (Z,0.1) -- (Z,-0.1) node[below]{$Z$};}
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer




























            up vote
            2
            down vote













            A simple approach using TikZ.



            enter image description here



            documentclass[border=3.14mm]{standalone}
            usepackage{tikz}
            begin{document}
            begin{tikzpicture}
            defx{1} % replace 1 with desired value here
            draw[-latex] (0,0) -- ++(4,0) node[right]{$t$};
            draw[-latex] (0,0) -- ++(0,2.0x)node[left]{$A(t)$};
            draw[thick] (0,x)node[left]{$sqrt{x}$} -- ++(1,0) -- ++(0,-x)node[below]{1} -- ++(1,0) -- ++(0,x) -- ++(1,0) -- ++(0,-x)node[below]{3} -- ++(0.5,0);
            end{tikzpicture}
            end{document}





            share|improve this answer





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "85"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });






              Ali A. is a new contributor. Be nice, and check out our Code of Conduct.










               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461415%2fplotting-a-rectangular-waveform-with-latex%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              4
              down vote



              accepted










              A PSTricks solution just for comparison purpose.



              documentclass[pstricks,border=12pt,12pt]{standalone}
              usepackage{pst-plot}
              begin{document}
              begin{pspicture}(-1,-1)(11.5,5.5)
              psaxes[ticks=x,labels=x]{->}(0,0)(-1,-1)(11,5)[$t$,0][$A(t)$,90]
              multips(0,0)(2,0){5}{psline[linecolor=blue,linewidth=2pt](0,0)(0,4)(1,4)(1,0)(2,0)}
              uput{5pt}[180](0,4){$sqrt{R_s}$}
              end{pspicture}
              end{document}


              enter image description here






              share|improve this answer























              • Thank you so much for your help. However, when I tried to run the codes you gave me, it gives me the following error: ! Undefined control sequence. c@lor@to@ps ->PSTricks _Not_Configured_For_This_Format l.6 ...xes{->}(0,0)(-1,-1)(12,5)[$t$,0][$A(t)$,90] ?
                – Ali A.
                14 hours ago










              • Can you please help me more? How I can use these options? Thanks.
                – Ali A.
                14 hours ago










              • Yes I use win 10
                – Ali A.
                14 hours ago










              • This works.. :) One more thing please, How can I can make the height of the pulses in terms of a variable not number, as I mentioned in my post and as shown in the figure I attached to it. Many thanks..
                – Ali A.
                14 hours ago






              • 1




                Thank you so much for your time and help. It works perfectly now.. :)
                – Ali A.
                13 hours ago















              up vote
              4
              down vote



              accepted










              A PSTricks solution just for comparison purpose.



              documentclass[pstricks,border=12pt,12pt]{standalone}
              usepackage{pst-plot}
              begin{document}
              begin{pspicture}(-1,-1)(11.5,5.5)
              psaxes[ticks=x,labels=x]{->}(0,0)(-1,-1)(11,5)[$t$,0][$A(t)$,90]
              multips(0,0)(2,0){5}{psline[linecolor=blue,linewidth=2pt](0,0)(0,4)(1,4)(1,0)(2,0)}
              uput{5pt}[180](0,4){$sqrt{R_s}$}
              end{pspicture}
              end{document}


              enter image description here






              share|improve this answer























              • Thank you so much for your help. However, when I tried to run the codes you gave me, it gives me the following error: ! Undefined control sequence. c@lor@to@ps ->PSTricks _Not_Configured_For_This_Format l.6 ...xes{->}(0,0)(-1,-1)(12,5)[$t$,0][$A(t)$,90] ?
                – Ali A.
                14 hours ago










              • Can you please help me more? How I can use these options? Thanks.
                – Ali A.
                14 hours ago










              • Yes I use win 10
                – Ali A.
                14 hours ago










              • This works.. :) One more thing please, How can I can make the height of the pulses in terms of a variable not number, as I mentioned in my post and as shown in the figure I attached to it. Many thanks..
                – Ali A.
                14 hours ago






              • 1




                Thank you so much for your time and help. It works perfectly now.. :)
                – Ali A.
                13 hours ago













              up vote
              4
              down vote



              accepted







              up vote
              4
              down vote



              accepted






              A PSTricks solution just for comparison purpose.



              documentclass[pstricks,border=12pt,12pt]{standalone}
              usepackage{pst-plot}
              begin{document}
              begin{pspicture}(-1,-1)(11.5,5.5)
              psaxes[ticks=x,labels=x]{->}(0,0)(-1,-1)(11,5)[$t$,0][$A(t)$,90]
              multips(0,0)(2,0){5}{psline[linecolor=blue,linewidth=2pt](0,0)(0,4)(1,4)(1,0)(2,0)}
              uput{5pt}[180](0,4){$sqrt{R_s}$}
              end{pspicture}
              end{document}


              enter image description here






              share|improve this answer














              A PSTricks solution just for comparison purpose.



              documentclass[pstricks,border=12pt,12pt]{standalone}
              usepackage{pst-plot}
              begin{document}
              begin{pspicture}(-1,-1)(11.5,5.5)
              psaxes[ticks=x,labels=x]{->}(0,0)(-1,-1)(11,5)[$t$,0][$A(t)$,90]
              multips(0,0)(2,0){5}{psline[linecolor=blue,linewidth=2pt](0,0)(0,4)(1,4)(1,0)(2,0)}
              uput{5pt}[180](0,4){$sqrt{R_s}$}
              end{pspicture}
              end{document}


              enter image description here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 13 hours ago

























              answered 14 hours ago









              Artificial Stupidity

              4,6641832




              4,6641832












              • Thank you so much for your help. However, when I tried to run the codes you gave me, it gives me the following error: ! Undefined control sequence. c@lor@to@ps ->PSTricks _Not_Configured_For_This_Format l.6 ...xes{->}(0,0)(-1,-1)(12,5)[$t$,0][$A(t)$,90] ?
                – Ali A.
                14 hours ago










              • Can you please help me more? How I can use these options? Thanks.
                – Ali A.
                14 hours ago










              • Yes I use win 10
                – Ali A.
                14 hours ago










              • This works.. :) One more thing please, How can I can make the height of the pulses in terms of a variable not number, as I mentioned in my post and as shown in the figure I attached to it. Many thanks..
                – Ali A.
                14 hours ago






              • 1




                Thank you so much for your time and help. It works perfectly now.. :)
                – Ali A.
                13 hours ago


















              • Thank you so much for your help. However, when I tried to run the codes you gave me, it gives me the following error: ! Undefined control sequence. c@lor@to@ps ->PSTricks _Not_Configured_For_This_Format l.6 ...xes{->}(0,0)(-1,-1)(12,5)[$t$,0][$A(t)$,90] ?
                – Ali A.
                14 hours ago










              • Can you please help me more? How I can use these options? Thanks.
                – Ali A.
                14 hours ago










              • Yes I use win 10
                – Ali A.
                14 hours ago










              • This works.. :) One more thing please, How can I can make the height of the pulses in terms of a variable not number, as I mentioned in my post and as shown in the figure I attached to it. Many thanks..
                – Ali A.
                14 hours ago






              • 1




                Thank you so much for your time and help. It works perfectly now.. :)
                – Ali A.
                13 hours ago
















              Thank you so much for your help. However, when I tried to run the codes you gave me, it gives me the following error: ! Undefined control sequence. c@lor@to@ps ->PSTricks _Not_Configured_For_This_Format l.6 ...xes{->}(0,0)(-1,-1)(12,5)[$t$,0][$A(t)$,90] ?
              – Ali A.
              14 hours ago




              Thank you so much for your help. However, when I tried to run the codes you gave me, it gives me the following error: ! Undefined control sequence. c@lor@to@ps ->PSTricks _Not_Configured_For_This_Format l.6 ...xes{->}(0,0)(-1,-1)(12,5)[$t$,0][$A(t)$,90] ?
              – Ali A.
              14 hours ago












              Can you please help me more? How I can use these options? Thanks.
              – Ali A.
              14 hours ago




              Can you please help me more? How I can use these options? Thanks.
              – Ali A.
              14 hours ago












              Yes I use win 10
              – Ali A.
              14 hours ago




              Yes I use win 10
              – Ali A.
              14 hours ago












              This works.. :) One more thing please, How can I can make the height of the pulses in terms of a variable not number, as I mentioned in my post and as shown in the figure I attached to it. Many thanks..
              – Ali A.
              14 hours ago




              This works.. :) One more thing please, How can I can make the height of the pulses in terms of a variable not number, as I mentioned in my post and as shown in the figure I attached to it. Many thanks..
              – Ali A.
              14 hours ago




              1




              1




              Thank you so much for your time and help. It works perfectly now.. :)
              – Ali A.
              13 hours ago




              Thank you so much for your time and help. It works perfectly now.. :)
              – Ali A.
              13 hours ago










              up vote
              2
              down vote













              Since this question is tagged tikz-pgf, I thought you may also be interested in a TikZ code. (One of its advantageous is that this works with pretty much any compiler.)



              documentclass[tikz,border=3.14mm]{standalone}
              begin{document}
              begin{tikzpicture}
              pgfmathsetmacro{h}{2}
              pgfmathsetmacro{L}{4}
              draw[thick,-latex] (0,-0.5) -- (0,h+2) node[above] {$A(t)$};
              draw[thick,-latex] (-0.5,0) -- (2*L+1,0) node[right] {$t$};
              foreach X [evaluate=X as Z using {int(2*X-1)},] in {1,...,L}
              {draw[very thick,blue] (2*X-2,0) |- (2*X-1,h) |- (2*X,0);
              draw (Z,0.1) -- (Z,-0.1) node[below]{$Z$};}
              end{tikzpicture}
              end{document}


              enter image description here






              share|improve this answer

























                up vote
                2
                down vote













                Since this question is tagged tikz-pgf, I thought you may also be interested in a TikZ code. (One of its advantageous is that this works with pretty much any compiler.)



                documentclass[tikz,border=3.14mm]{standalone}
                begin{document}
                begin{tikzpicture}
                pgfmathsetmacro{h}{2}
                pgfmathsetmacro{L}{4}
                draw[thick,-latex] (0,-0.5) -- (0,h+2) node[above] {$A(t)$};
                draw[thick,-latex] (-0.5,0) -- (2*L+1,0) node[right] {$t$};
                foreach X [evaluate=X as Z using {int(2*X-1)},] in {1,...,L}
                {draw[very thick,blue] (2*X-2,0) |- (2*X-1,h) |- (2*X,0);
                draw (Z,0.1) -- (Z,-0.1) node[below]{$Z$};}
                end{tikzpicture}
                end{document}


                enter image description here






                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Since this question is tagged tikz-pgf, I thought you may also be interested in a TikZ code. (One of its advantageous is that this works with pretty much any compiler.)



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  begin{tikzpicture}
                  pgfmathsetmacro{h}{2}
                  pgfmathsetmacro{L}{4}
                  draw[thick,-latex] (0,-0.5) -- (0,h+2) node[above] {$A(t)$};
                  draw[thick,-latex] (-0.5,0) -- (2*L+1,0) node[right] {$t$};
                  foreach X [evaluate=X as Z using {int(2*X-1)},] in {1,...,L}
                  {draw[very thick,blue] (2*X-2,0) |- (2*X-1,h) |- (2*X,0);
                  draw (Z,0.1) -- (Z,-0.1) node[below]{$Z$};}
                  end{tikzpicture}
                  end{document}


                  enter image description here






                  share|improve this answer












                  Since this question is tagged tikz-pgf, I thought you may also be interested in a TikZ code. (One of its advantageous is that this works with pretty much any compiler.)



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  begin{tikzpicture}
                  pgfmathsetmacro{h}{2}
                  pgfmathsetmacro{L}{4}
                  draw[thick,-latex] (0,-0.5) -- (0,h+2) node[above] {$A(t)$};
                  draw[thick,-latex] (-0.5,0) -- (2*L+1,0) node[right] {$t$};
                  foreach X [evaluate=X as Z using {int(2*X-1)},] in {1,...,L}
                  {draw[very thick,blue] (2*X-2,0) |- (2*X-1,h) |- (2*X,0);
                  draw (Z,0.1) -- (Z,-0.1) node[below]{$Z$};}
                  end{tikzpicture}
                  end{document}


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 12 hours ago









                  marmot

                  77.6k487164




                  77.6k487164






















                      up vote
                      2
                      down vote













                      A simple approach using TikZ.



                      enter image description here



                      documentclass[border=3.14mm]{standalone}
                      usepackage{tikz}
                      begin{document}
                      begin{tikzpicture}
                      defx{1} % replace 1 with desired value here
                      draw[-latex] (0,0) -- ++(4,0) node[right]{$t$};
                      draw[-latex] (0,0) -- ++(0,2.0x)node[left]{$A(t)$};
                      draw[thick] (0,x)node[left]{$sqrt{x}$} -- ++(1,0) -- ++(0,-x)node[below]{1} -- ++(1,0) -- ++(0,x) -- ++(1,0) -- ++(0,-x)node[below]{3} -- ++(0.5,0);
                      end{tikzpicture}
                      end{document}





                      share|improve this answer

























                        up vote
                        2
                        down vote













                        A simple approach using TikZ.



                        enter image description here



                        documentclass[border=3.14mm]{standalone}
                        usepackage{tikz}
                        begin{document}
                        begin{tikzpicture}
                        defx{1} % replace 1 with desired value here
                        draw[-latex] (0,0) -- ++(4,0) node[right]{$t$};
                        draw[-latex] (0,0) -- ++(0,2.0x)node[left]{$A(t)$};
                        draw[thick] (0,x)node[left]{$sqrt{x}$} -- ++(1,0) -- ++(0,-x)node[below]{1} -- ++(1,0) -- ++(0,x) -- ++(1,0) -- ++(0,-x)node[below]{3} -- ++(0.5,0);
                        end{tikzpicture}
                        end{document}





                        share|improve this answer























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          A simple approach using TikZ.



                          enter image description here



                          documentclass[border=3.14mm]{standalone}
                          usepackage{tikz}
                          begin{document}
                          begin{tikzpicture}
                          defx{1} % replace 1 with desired value here
                          draw[-latex] (0,0) -- ++(4,0) node[right]{$t$};
                          draw[-latex] (0,0) -- ++(0,2.0x)node[left]{$A(t)$};
                          draw[thick] (0,x)node[left]{$sqrt{x}$} -- ++(1,0) -- ++(0,-x)node[below]{1} -- ++(1,0) -- ++(0,x) -- ++(1,0) -- ++(0,-x)node[below]{3} -- ++(0.5,0);
                          end{tikzpicture}
                          end{document}





                          share|improve this answer












                          A simple approach using TikZ.



                          enter image description here



                          documentclass[border=3.14mm]{standalone}
                          usepackage{tikz}
                          begin{document}
                          begin{tikzpicture}
                          defx{1} % replace 1 with desired value here
                          draw[-latex] (0,0) -- ++(4,0) node[right]{$t$};
                          draw[-latex] (0,0) -- ++(0,2.0x)node[left]{$A(t)$};
                          draw[thick] (0,x)node[left]{$sqrt{x}$} -- ++(1,0) -- ++(0,-x)node[below]{1} -- ++(1,0) -- ++(0,x) -- ++(1,0) -- ++(0,-x)node[below]{3} -- ++(0.5,0);
                          end{tikzpicture}
                          end{document}






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 12 hours ago









                          nidhin

                          1,700920




                          1,700920






















                              Ali A. is a new contributor. Be nice, and check out our Code of Conduct.










                               

                              draft saved


                              draft discarded


















                              Ali A. is a new contributor. Be nice, and check out our Code of Conduct.













                              Ali A. is a new contributor. Be nice, and check out our Code of Conduct.












                              Ali A. is a new contributor. Be nice, and check out our Code of Conduct.















                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461415%2fplotting-a-rectangular-waveform-with-latex%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Bundesstraße 106

                              Verónica Boquete

                              Ida-Boy-Ed-Garten