Q:

Step Based signal to smooth one - How can I interpolate?

I'm programming a sort of audio plugin, and I get an array of values that represent a step-based signal such as this:

that have these values:
[ 0.27, 0.43, 0.48, 0.51, 0.85, 0.15, 0.48, 0.01, 0.28, 0.84, 0.15, 0.22, 0.11, 0.86, 0.66, 0.92, 0.40, 0.71 ]

I'm looking for to transform those values into a bigger array of interpolated values that represent a smooth signal, such as a sine wave. Somethings like this (sorry for my Paint art):

What kind of math should I use here? Inside my development environment (Ruby based), I have a common number of math functions. But I don't know where to start.

A:

What you want here is a digital filter - specifically a lowpass filter.
There are two types of simple digital filter, Finite Impulse Response and Infinite Impulse Response.
A FIR filter works by summing, with some weighting, the previous n samples of the audio, and using that to generate the output sample. It's called "Finite Impulse Response", because a single impulse in the input can only affect a finite number of output samples.
An IIR filter, in contrast, uses its own previous output in addition to the current sample. It's called "Infinite Impulse Response" because of this feedback property; a single impulse can affect all future samples.
Of the two, the IIR filter is the simplest to implement, and in its most basic form looks like this:
state(N) = state(N - 1) * weighting + sample(N)
output(N) = state(N)

That is, for each input sample, reduce the previous state value by some amount and add the input, then use that as the output. As such, it's basically a moving average filter.
For example, if you set 'weighting' to 0.95, then each output sample is influenced 95% by previous samples and 5% by the current sample, and the output value will shift slowly in response to changing inputs. It will also be scaled up by 20X (1/(1-weighting)), so you should renormalize it accordingly.
Here's how the first few steps would work with your input data:

Start by setting state = 20 * 0.27.
Output state / 20 = 0.27
Update state = state * 0.95 + 0.43 = 26.08
Output state / 20 = 0.278. 
Update state = state * 0.95 + 0.48 = 5.76
Output state / 20 = 0.288

And so forth. If you need more output data points than input data points, repeat your input samples n times before feeding into the filter, or interleave input samples with n zero samples. Both are valid, though they have different impacts on the filtered output.
There is a lot of theory behind digital filter design; in practice for a simple implementation you can probably use this first-order filter, and adjust the weighting value to suit.

