Skip to content

How to generate an exponential curve between two values with a given amount of data points

I am trying to implement a function as follows but really lack the math skills, any help would be greatly appreciated.

The function should take an amount of data points x and return an array of size x containing exponentially increasing values from 0 to 100 (for example). Ideally it should also accept a lambda value to modify the curve.

function exponentialCurve(x, max=100, lambda=4) {
  // returns an array of size x where each entry represents a point on an exponential curve between 0 and max
}

This is for applying exponential decay to audio PCM data. Again anything to help point me in the right direction would be really great, thanks for reading.

Answer

Is this what you’re looking for (where 1 <= lambda <=10)?

function exponentialCurve(x, max=100, lambda=4) {
    // returns an array of size x where each entry represents a point on an exponential curve between 0 and max
    const base = Math.log(x) / Math.log(lambda);
    const points = Array(x).fill(max);
    return points.map((point, n) => point / Math.pow(base, n));
}