Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

Sound[SampledSoundFunction[
  Function[{Play`Time24}, 
   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

1 Answer 1

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:

HeavisidePi[.5]

HeavisidePi[0.5]

share|improve this answer

Your Answer

 
discard

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.