Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The trick in this sort of problems is to understand the relation between <a href="http://en.wikipedia.org/wiki/Frequency_modulation" rel="nofollow noreferrer">frequency modulation</a> and <a href="http://en.wikipedia.org/wiki/Phase_modulation" rel="nofollow noreferrer">phase modulation</a>, these two are closely related. A sine with a constant frequency <code>f</code> and amplitude <code>A</code> can be described as (formulas, not python code):</p> <pre><code>x(t) = A sin(2 * pi * f * t) </code></pre> <p>but a different way to write this is by first defining a phase <code>phi</code> as a function of time:</p> <pre><code>phi(t) = 2 * pi * f * t x(t) = A sin(phi(t)) </code></pre> <p>The thing to note here is that frequency <code>f</code> is the derivative of the phase, divided by 2*pi: <code>f = d/dt(phi(t)) / (2*pi)</code>.</p> <p>For a signal which has a frequency that is varying in time, you can similarly define an <strong>instantaneous frequency</strong> <code>f_inst</code>:</p> <pre><code>x(t) = A sin(phi(t)) f_inst = d/dt(phi(t)) / (2*pi) </code></pre> <p>What you want to do is the opposite of this, you have a given instantaneous frequency (your logarithmic sweep), which you need to convert into a phase. Since the opposite of derivation is integration, you can calculate the appropriate phase like this (still formulas):</p> <pre><code>phi(t) = 2 * pi * Integral_0_to_t {f_inst(t) dt} x(t) = A sin(phi(t)) </code></pre> <p>What you are doing here is some sort of phase modulation of a signal (with zero frequency) to obtain the required instantaneous frequency. This is pretty easy to do in numpy:</p> <pre><code>from pylab import * n = 1000 # number of points f1, f2 = 10, 30 # frequency sweep range in Hertz t = linspace(0,1,1000) dt = t[1] - t[0] # needed for integration # define desired logarithmic frequency sweep f_inst = logspace(log10(f1), log10(f2), n) phi = 2 * pi * cumsum(f_inst) * dt # integrate to get phase # make plot plot(t, sin(phi)) xlabel('Time (s)') ylim([-1.2, 1.2]) grid() show() </code></pre> <p>Resulting image:</p> <p><img src="https://i.stack.imgur.com/Ezwxh.png" alt="Logarithmic frequency sweep"></p> <p>But (as also noted in the <a href="https://stackoverflow.com/a/11199832/2647279">dupe</a> mentioned by Dave), you probably don't want a logarithmic sweep, but an exponential one. Your ear has a logarithmic perception of frequency, so a smooth/linear musical scale (think the keys on a piano) are therefore spaced exponentially. This can be achieved by simply redefining your instantaneous frequency <code>f_inst(t) = f1 * exp(k * t)</code>, where <code>k</code> is chosen such that <code>f_inst(t2) = f2</code>.</p> <p>If you want to use <a href="http://en.wikipedia.org/wiki/Amplitude_modulation" rel="nofollow noreferrer">amplitude modulation</a> at the same time, you can simply change <code>A</code> to a time dependent <code>A(t)</code> in the formulas.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload