Why does linear interpolation produce aliasing?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

I'm using linear interpolation to read from a delay line. I've noticed that this technique produces audible aliasing, even at high sampling frequencies.

I've read that oversampling or using a better method of interpolation may fix this problem. However, the aliasing is still audible when I set the sample rate of my application to 192,000kHz, so I guess that I'd need to oversample by more than 4x the destination sampling rate to get rid of the aliasing. Is it common to oversample by more than 4x the destination sampling rate?

Could someone help me to gain some intuition about why the aliasing is occurring, and suggest the best method for getting rid of it?

Thank you.
Last edited by davidspry on Fri Jul 03, 2020 3:12 am, edited 1 time in total.

Post

Try using Sinc64.

More about aliasing at https://www.discodsp.com/bliss/aliasing/

Post

The aliasing occurs because when you change the speed of the pointer you then have to estimate values in between samples. Linear interpolation is simply a poor estimation. If your input is a pure sine wave, due to the error of this estimation, the output is no longer a pure sine wave; tones at new frequencies are introduced by the error, and these tones can alias.

EDIT: now I've written this I'm not entirely sure about it. I think there's some truth there, and I wrote it because it feels intuitive, but I'm struggling to link the idea to a more proper explanation.....

A more proper explanation is that what you are doing is a fractional delay, which is equivalent to doing resampling, and the reconstruction filter you are implicitly using, which is defined by your interpolation method, is crap, and lets spectral images of the original signal alias when you effectively downsample. Better interpolation methods = better reconstruction filters.

Post

It probably depends... If the sample being interpolated is 1348 samples long (base note C0 @ 32.7 Hz, always upsampling) you'd get whole different results than when it's 21 samples long (C6 @ 2.1 kHz, mostly downsampling).
We are the KVR collective. Resistance is futile. You will be assimilated. Image
My MusicCalc is served over https!!

Post

Linear interpolation produces saw or triangle waves, and these have infinite spectrum.
I'm using linear interpolation to move a read pointer smoothly over a delay line.
But I'm not quite sure what do you interpolate? What is your input signal?
Blog ------------- YouTube channel
Tricky-Loops wrote: (...)someone like Armin van Buuren who claims to make a track in half an hour and all his songs sound somewhat boring(...)

Post

I don’t know how you are moving your reading pointer, but even with a perfect resampling algorithm, it can cause frequency modulation artefacts which sometimes sounds a bit like aliasing.

Post

Thanks for your helpful replies. I appreciate it.

I guess that I should use a better interpolation algorithm.

To clarify: I'm building an echo effect for a synthesiser app that I'm working on. The read position is a floating point number so I'm using linear interpolation to read from the buffer.

The read position is set approximately like the following, where `delay` and `target` are each some number of samples.

Code: Select all

delay = delay + 1e-3f * (target - delay);
read_position = write_position - delay;
The sample is interpolated as you'd expect:

Code: Select all

int a = (int) read_position;
int b = a + 1;
float k = read_position - a;
return buffer[a] + k * (buffer[b] - buffer[a])
The aliasing is not always obvious. It's most obvious when the tempo of the delay is decreased, which increases `target` and widens the distance between the delay line's write position and read position. Once the value of `delay` becomes stable, the aliasing ceases to be audible.
Last edited by davidspry on Fri Jul 03, 2020 3:15 am, edited 1 time in total.

Post

Consider that linear interpolation is equivalent to a FIR lowpass filter with a triangular impulse response. For instance, say you want to interpolate another point between each existing sample—essentially to upsample by 2x. The FIR coefficients are (0), 0.5, 1.0, 0.5, (0). Place the 1.0 at the point you want to create, then it's x(n-1) * 0.5 + x(n) * 0.5. If you wanted 4 instead, the coefficients would be (0), 0.25, 0.5, 0.75, 1.0, 0.75, 0.5, 0.25, (0), etc. linear ramp up, a linear ramp down—linear interpolation.

The impulse response of a perfect lowpass filter is the sinc function. For a practical (and linear phase) lowpass filter, it's a windowed sinc function or something close. In general, the longer it is (the more lobes), the steeper the filter. There are no lobes in a triangular impulse response. So, a linear interpolator is a crappy lowpass filter. In fact, the response is only down 6 dB at half the sample rate, and the side lobes are large. And the passband rolloff has a slow soft corner.

Linear interpolation is fine if the signal is already well-lowpass-filtered—in other words, sufficiently oversampled. Linear interpolation works great on a 300 Hz sine wave sampled at 48k, but absolute junk for an 18k sine.

Take a look at the frequency response of linear interpolation. You might get an intuitive sense that you probably want to be oversampled something like 8x minimum for high quality, depending on how much of the audio band you actually need to preserve (4x might be adequate, for instance). Or, of course, use better interpolation, but sticking to the subject of linear.

Image
My audio DSP blog: earlevel.com

Post

Needs an edit

Post

Thanks for your clear explanation, earlevel. That's very helpful.

Post

Adding to earlevel's great explanation, when your delay time is not changing or only changing slowly, the interpolation becomes a static FIR filter, so there's no aliasing just a high frequency roll-off depending on the fractional position. It would be possible to compensate for the roll-off, but a better interpolator (and/or oversampling) will also result in a flatter frequency response, so that's the way to go.

Post

Let's paste this PDF here once more. It has tons of information, comparisons and ready made interpolation algorithms in it. See the comparison chart on page 60 to choose a suitable interpolation method for your purposes.

http://yehar.com/blog/wp-content/upload ... 8/deip.pdf

Post

Yes, mda makes a good point. Since you're using this for a delay line, whenever you aren't using this for pitch change you're reading at the same rate as writing and not rate converting. The worst case error, then, would be if the time offset ends up with a half-sample offset. For typical musical delay effect, you can just round to the nearest exact sample—no one can hear the difference and you're not interpolating anymore.

But you probably wanted to interpolate because you're doing something like summing an LFO for vibrato, etc., which means you are pitch shifting. Here's where "it all depends". In a lot of cases, you can still get away with some pitch modulation, because it probably won't be a lot (for typical musical effects), your input often doesn't have extended high frequencies (natural instruments like voice, acoustic guitar—even in amp simulations, cabinets drop off a cliff above 5k), and maybe you're emulating an analog delay that rolls off lot of highs anyway. (Still, round the base time to an even sample boundary so you have consistent frequency response, especially when you turn the modulation amount to zero.)

A lot of people look at linear interpolation and immediately determine it's useless for audio, but it depends on the circumstances. Most samplers ever made used linear interpolation—it works great if your sample tables have some oversampling and you don't need to shift much, and that's true of typical multisampled keyboards.
My audio DSP blog: earlevel.com

Post

Kraku wrote: Fri Jul 03, 2020 6:49 am Let's paste this PDF here once more. It has tons of information, comparisons and ready made interpolation algorithms in it. See the comparison chart on page 60 to choose a suitable interpolation method for your purposes.

http://yehar.com/blog/wp-content/upload ... 8/deip.pdf
This is a classic paper. Just be sure to note that it's "Polynomial Interpolators for High-Quality Resampling of Oversampled Audio". I've seen a lot of people miss the importance of starting with oversampled audio (from a fixed upsampling stage, for instance), and are disappointed jumping into some of these low-order interpolators.
My audio DSP blog: earlevel.com

Post

earlevel wrote: Fri Jul 03, 2020 7:16 am
Kraku wrote: Fri Jul 03, 2020 6:49 am Let's paste this PDF here once more. It has tons of information, comparisons and ready made interpolation algorithms in it. See the comparison chart on page 60 to choose a suitable interpolation method for your purposes.

http://yehar.com/blog/wp-content/upload ... 8/deip.pdf
This is a classic paper. Just be sure to note that it's "Polynomial Interpolators for High-Quality Resampling of Oversampled Audio". I've seen a lot of people miss the importance of starting with oversampled audio (from a fixed upsampling stage, for instance), and are disappointed jumping into some of these low-order interpolators.
There's a few other things to keep in mind too. For example the "optimal" filters are generally designed to be "optimal" when combined with a bunch of oversampling (ie. only the side-lobs that alias into the base-band are considered, the response elsewhere might be worse than other filters) and some of the interpolators are not safe for feedback loops because not all of them has response bounded by unity.

That said, especially in feedback applications I would highly suggest everyone start from Catmull-Rom (ie. 3rd order 4-point Hermite with two-sided finite differences used to approximate the derivatives, though one can also think of it as a linear blend between 3-point quadratic Lagrange polynomials at around the two-closest sampling points; the latter approach is probably the easiest way to construct these in a non-uniform context). It has reasonably flat pass-band (bounded by unity, so safe for feedback) and zeroes in the middle of the side-lobes (and I guess C1 continuity gives it faster decay, though usually we mostly care about the first, highest side-band), giving it better stop-band than a pure Lagrange (which would be optimal in terms of passband flatness).

This doesn't mean that other polynomial interpolators couldn't perform better in some application, but I would argue that usually when Catmull-Rom doesn't do the trick, you probably want some form of sinc-interpolation instead (or just more oversampling). I also think that it's probably better to just try it first, before getting too confused with all the graphs and different curves and what not in that paper and wasting a few years only to eventually converge back to Catmull-Rom anyway. :)

Post Reply

Return to “DSP and Plugin Development”