Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I define:

aNote[x_] := Sin[440 * 2 * Pi * x];

then this works (i.e. it produces a widget with a Play button, and clicking on this button produces an A note):

Play[aNote[x], {x, 0, 3.5}]

but this doesn't:

env[x_] := HeavisidePi[x - 1] + HeavisidePi[x - 2.5];
Play[env[x] aNote[x], {x, 0, 3.5}]

The latter just produces something like:

   Block[{x = 
      0. + 0.000125 Play`Time24}, ((HeavisidePi[x - 1] + 
          HeavisidePi[x - 2.5]) aNote[x] + 0.00024672) 1.00025]], 
  28000, 8000]]

...but no widget, and no sound.

The difference between the two is that in the second one, the sinusoidal sound wave is multiplied by an "envelope" consisting of two rectangular unit bumps of width 1, and centered at 1 and 2.5, respectively.

share|improve this question
up vote 4 down vote accepted

You can produce an identical signal by using UnitBox instead of HeavisidePi:

aNote[x_] := Sin[440*2*Pi*x];
unv[x_] := UnitBox[x - 1] + UnitBox[x - 2.5];
Play[unv[x] aNote[x], {x, 0, 3.5}]

enter image description here

Use UnitStep and Piecewise for more sophisticated functions.

Not sure, but maybe the reason for your trouble is that HeavisidePi does not evaluate at 1/2:



share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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