Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Bas's answer is great, but doesn't actually give an analytic solution, so here's that part...</p> <p>As far as I can tell, you want something like <code>sin(Aexp(Bt))</code> where <code>A</code> and <code>B</code> are constants. I'll assume time starts at <code>0</code> and continues to <code>C</code> (if it starts at some other time, subtract that from both).</p> <p>Then, as Bas said, I think, if we have <code>sin(g(t))</code> frequency <code>f</code> is such that <code>2 * pi * f = dg / dt</code>. And we want that to be <code>f0</code> at time <code>0</code> and <code>fC</code> at time <code>C</code>.</p> <p>If you go through the maths, which is easy (it really is - last year of school level), you get:</p> <pre><code>B = 1/C * log(fC/f0) A = 2 * pi * f0 / B </code></pre> <p>and here's some code that goes from 1 to 10Hz in 5 seconds using 1000 samples:</p> <pre><code>from math import pi, sin, log, exp def sweep(f_start, f_end, interval, n_steps): b = log(f_end/f_start) / interval a = 2 * pi * f_start / b for i in range(n_steps): delta = i / float(n_steps) t = interval * delta g_t = a * exp(b * t) print t, 3 * sin(g_t) sweep(1, 10, 5, 1000) </code></pre> <p>which gives:</p> <p><img src="https://i.stack.imgur.com/rFA2X.png" alt="a pretty plot"></p> <p>(and you can add in a constant - <code>sin(g_t + k)</code> - to get the starting phase wherever you want).</p> <p><strong>Update</strong></p> <p>To show that the issue you are seeing is an artefact of sampling, here's a version that does oversampling (if you set it as an argument):</p> <pre><code>from math import pi, sin, log, exp def sweep(f_start, f_end, interval, n_steps, n_oversample=1): b = log(f_end/f_start) / interval a = 2 * pi * f_start / b for i in range(n_steps): for oversample in range(n_oversample): fractional_step = oversample / float(n_oversample) delta = (i + fractional_step) / float(n_steps) t = interval * delta g_t = a * exp(b * t) print t, 3 * sin(g_t) sweep(16000.0, 16500.0, 256.0/48000.0, 256) # looks strange sweep(16000.0, 16500.0, 256.0/48000.0, 256, 4) # looks fine with better resolution </code></pre> <p>If you check the code you'll see that all that setting <code>n_oversample</code> to 4 does (the second call) is add a higher resolution to the timesteps. In particular, the code when <code>oversample = 0</code> (ie <code>fractional_step = 0</code>) is <em>identical</em> to before, so the second plot includes the points in the first plot, plus extra ones that "fill in" the missing data and make everything look much less surprising.</p> <p>Here's a close-up of the original and the oversampled curve near the start, showing what is happening in detail:</p> <p><img src="https://i.stack.imgur.com/br3WX.png" alt="enter image description here"></p> <p>Finally, this kind of thing is completely normal and does not indicate any kind of error. When an analogue signal is generated from the digital waveform you'll get "the right" result (assuming the hardware is working right). <a href="http://www.xiph.org/video/vid2.shtml" rel="nofollow noreferrer">This excellent video</a> will explain things if they are not clear.</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. 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.
 

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