5
$\begingroup$

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: truncated square wave Does anyone know how to generate such input on Mathematica?

$\endgroup$
2
  • 2
    $\begingroup$ Take a look at Piecewise[ ] $\endgroup$ Commented May 8, 2015 at 1:17
  • $\begingroup$ 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. $\endgroup$
    – bbgodfrey
    Commented May 8, 2015 at 1:23

3 Answers 3

7
$\begingroup$

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}]

Mathematica graphics

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

enter image description here

$\endgroup$
0
4
$\begingroup$

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}]

Mathematica graphics

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

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.