1
$\begingroup$

I will perform an experiment which consists of deadlift trials during 5 minutes. To control the rhythm of this fatiguing exercise, I would like to generate a sound file which gives a buzzer noise every 7.5 seconds.

In Mathematica's documentation,

Play[Sin[440 2 Pi t], {t, 0, 1}]

can generate a 1-second buzzer noise. But how do I generate a 6.5-second silence and merge the noise-silence together, and repeat them as much as we want?

$\endgroup$
4
  • $\begingroup$ What have you tried? Where did you get stuck? Generating a buzz (did you look at Play)? Stitching it together with a stretch of silence? Proceed step by step and ask specific questions. $\endgroup$
    – Szabolcs
    Commented Oct 3, 2017 at 9:24
  • $\begingroup$ Thank you, I can now generate a buzzer. This question gets more specific now. $\endgroup$
    – Tough Kid
    Commented Oct 3, 2017 at 9:38
  • $\begingroup$ With AudioJoin. $\endgroup$
    – Szabolcs
    Commented Oct 3, 2017 at 9:49
  • $\begingroup$ Here's something to think about: what do you think would you get if you multiplied your sinusoid with a square wave with appropriate amplitude and period? $\endgroup$ Commented Oct 3, 2017 at 10:06

4 Answers 4

2
$\begingroup$

Here's one possibility:

Make a 1 second beep with harmonics:

Play[Sum[1/k Sin[k 400 2 Pi t], {k, 1, 4}], {t, 0, 1}]

Modulate it with another sine wave if you want to make it sound rougher:

beep = Play[Sum[1/k Sin[k 400 2 Pi t] (0.75 + 0.25 Sin[60 2 Pi t]), {k, 1, 4}], {t, 0, 1}]

Add 6.5 seconds of silence for a total of 7.5 seconds

au = AudioJoin[{beep, AudioGenerator["Silence", 6.5]}]

Repeat this 40 times for 5 minutes of data.

result = AudioJoin@ConstantArray[au, 40]

Export["result.wav", result]
$\endgroup$
3
  • $\begingroup$ Thank you very much. What a pity that my MMA is a student version (available as long as I am a student), The version of 10.4.1 can not be updated to have AudioGenerator and AudioJoin functions. $\endgroup$
    – Tough Kid
    Commented Oct 3, 2017 at 12:54
  • 1
    $\begingroup$ @ToughKid Create the data directly then, with Table, and use ListPlay (or SampledSoundList) $\endgroup$
    – Szabolcs
    Commented Oct 3, 2017 at 12:59
  • $\begingroup$ Thanks very much, SampledSoundList do the job. I've done it this way. Export["Beep.mp3", Sound[SampledSoundList[ Flatten[ConstantArray[ Join[Table[Sin[2 [Pi] 500 t], {t, 0, 1, 1./2000}], ConstantArray[0, 13000]], 100]], 2000]]] $\endgroup$
    – Tough Kid
    Commented Oct 3, 2017 at 14:02
2
$\begingroup$

First make a $440 \text{ Hz}$ wave ($1 \text{ s}$):

a = Audio @ Play[Sin[440 2 Pi t], {t, 0, 1}];

Add $6.5 \text{ s}$ silence:

b = AudioPad[a, 6.5]

Join them. Repeat b for $5\times 60/7.5=40$ times.

au = AudioJoin[Table[b, Round[5*60/7.5]]];
AudioPlot[au, AspectRatio -> 1/10]

enter image description here

$\endgroup$
1
$\begingroup$

Thanks to @Szabolcs 's answer and idea of SampledSoundList, I've done it in this way. I post it out for those who have not the lastest version of MMA.

Export["C:\\Users\\Wei\\Downloads\\Beep2.mp3",
 Sound[
  SampledSoundList[
   Flatten[
    ConstantArray[
     Join[
      Table[Sin[2 \[Pi] 500 t], {t, 0, 1, 1./2000}],
      ConstantArray[0, 13000]
      ],
     200]
    ],
   2000
   ]
  ]
 ]
$\endgroup$
1
$\begingroup$

Here's an implementation of the idea I gave in the comments. Piecewise[] is quite convenient to use here when using Play[]:

With[{n = 6},
     Play[Piecewise[{{Sin[440 2 Pi t], 0 <= Mod[t, 15/2] <= 1}}, 0],
          {t, 0, 15 n/2}, SampleRate -> 8192]]

For the Audio[] version:

With[{n = 6},
     ts = TimeSeries[Transpose[{FoldList[Plus, 0, PadRight[{}, 2 n, {1, 13/2}]], 
                                PadRight[{}, 2 n + 1, {440, 0}]}]];
     AudioGenerator[{"Sin", ts}]]
$\endgroup$

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.