# Truncated square wave input

I'm investigating the response of some dynamic system on Mathematica and I want to generate a tailored square input like the one in the following picture: Does anyone know how to generate such input on Mathematica?

• Take a look at Piecewise[ ] Commented May 8, 2015 at 1:17
• Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. Commented May 8, 2015 at 1:23

Yet another approach; However you do not have to worry about truncating the signal, just scale it.

Plot[WaveletPsi[HaarWavelet[], x/4], {x, 0, 10}, Exclusions -> None,
PlotRange -> {{0, 10}, {-2, 2}}, AxesOrigin -> {0, -1.5}]

tsw[n_?NumericQ] := Piecewise[{{1, n <= 2}, {-1, 2 <= n <= 4}}]
Plot[tsw[n], {n, 0, 10}, Exclusions -> None]

You can also use Boole to truncate SquareWave:

Plot[SquareWave[x/4] Boole[0 <= x <= 4], {x, 0, 10}, Exclusions -> None,
BaseStyle -> Thick, Frame -> True, Axes -> False, PlotRangePadding -> {0, 1}]

Using Piecewise[{{SquareWave[x/4], 0 <= x <= 4}}] instead of SquareWave[x/4] Boole[0 <= x <= 4] gives the same result.