10
$\begingroup$

I am trying to get Mathematica to output a vibrato; a tone which has a frequency that slightly varies. To get a tone with a non-changing frequency I use this command:

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

That works as expected.

Now, I would expect to be able to express the varying frequency like this:

$$440 + \sin(5\times 2\pi t)$$

This should result in the frequency varying between 439 Hz and 441 Hz 5 times per second. If I replace the static 440 Hz in the previous Mathematica function I get the following command:

Play[Sin[(440+Sin[5*2*Pi*t])*2*Pi*t], {t, 0, 4}]

This sounds right in the beginning, but the variation in pitch (thus frequency seems to increase, if you listen to the output between 10 s and 20 s instead you can clearly hear that something is wrong.

The Mathematica documentation for the Play command mentions the following for to "Make a vibrato-like effect":

Play[(2+Cos[40t])Sin[2000t], {t, 0, 1}]

But from what I can tell that will vary the amplitude, not the frequency.

What am I doing wrong here? I'd be interested in both a solution for this specific mathematical problem as well as a more general answer to how to express a vibrato using a general mathematical function.

Most Google searches on this topic give you instructions for how to create a vibrato when singing.

$\endgroup$
  • 5
    $\begingroup$ You have not defined the "vibrato version" of the $\sin$ function correctly. Play[Sin[(Sin[5*2*Pi*t]) + 440*2*Pi*t], {t, 0, 4}] does what you want $\endgroup$ – Stelios Oct 18 '15 at 18:53
  • $\begingroup$ Oh I see, the issue with my attempt is that I end up with 440*2*Pi*t+Sin[5*2*Pi*t]*t (where the last t is wrong). I should've written it out on paper. Feel free to answer and I'll accept it (a bit more explanation would be nice, but not necessarily needed). $\endgroup$ – Jan Oct 19 '15 at 5:46
9
$\begingroup$

How about solving the harmonic oscillator equation with a time-varying frequency?

w[t_] := 2 Pi (440 + 5 Sin[10 * 2 Pi t])

func = NDSolveValue[{y''[t] + w[t]^2 y[t] == 0, y[0] == 1, y'[0] == 0}, y, {t, 0, 4}];

Play[func[t], {t, 0, 4}]
|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ While this gives the correct result, I would prefer a solution that only uses "common" mathematical functions that are also found outside of Mathematica (the trigonometrical functions in this case). $\endgroup$ – Jan Oct 18 '15 at 21:53
8
$\begingroup$

As an alternative, let's let the derivative of the phase vary with time.

A fixed tone will have $d \phi / d t = 2 \pi \cdot 440$. A vibrato that you want should have $d \phi / d t = 2 \pi (440 + \sin (2\pi\cdot5\cdot t))$. Integrating:

Integrate[440*2 π + 2 π Sin[5*2 π x], {x, 0, t}]
(* 880 π t + 2/5 Sin[5 π t]^2 *)

Playing:

Play[Sin[880 π t + 2/5 Sin[5 π t]^2], {t, 0, 4}]
|improve this answer|||||
$\endgroup$
1
$\begingroup$

As pointed out by Stelios I wrote the sinus function wrong.

Instead of

Play[Sin[(440+Sin[5*2*Pi*t])*2*Pi*t], {t, 0, 4}]

it should be

Play[Sin[(Sin[5*2*Pi*t]) + 440*2*Pi*t], {t, 0, 4}]

The first would expand from $\sin((440+\sin(5 \times 2\pi t))\times 2\pi t)$ to $\sin(440\times 2\pi t+\sin(5 \times 2\pi t)\times 2\pi t)$, thus the last $t$ would result in an increase of the amplitude of the inner sine function, and thus over time produce the continually increasing frequency difference which I heard.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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