# Interpolating irregularly missing data points of regularly spaced data

If I have a set of regularly spaced sample data (spacing $\delta x$) and some of my data is missing (zero) but not at regular intervals, i.e.

$[a_0, (missing), (missing), (missing), a_4, a_5, (missing), a_7, a_8, a_9, a_{10}, ...]$

Can digital signal processing techniques be used to interpolate the missing data?

I've only read of interpolating by a FIR or IIR when the missing data is every nth element.

There is a lot more data present than missing.

The interpolation can be done offline.

The first or last data point(s) might be missing.

## 3 Answers

If you want to have just a working example, you can consider the functionality of scipy.interpolate:

N = 128
n = np.arange(N)
x = np.sin(2*np.pi*n/32)
plt.plot(n, x)

pos = np.random.randint(N, size=(50,))

x_received = np.delete(x, pos)
n_received = np.delete(n, pos)
plt.stem(n_received, x_received)

import scipy.interpolate

interpolated = scipy.interpolate.interp1d(n_received, x_received, bounds_error=False, kind='cubic')
plt.plot(n, interpolated(n), 's')


This code generates a signal x for n=0,...,127. Then, it deletes some values out of it and interpolates the missing values by spline cubic interpolation. See that the blue vertical lines denote the received samples, the green squares denote the interpolated values. The approximation is quite good.

• That looks good enough for my purposes, does it cope with data at the start or end being missing? Mar 14, 2017 at 12:25
• According to the scipy documentation for interp1d (where the server currently appears to be down for me), there is the parameter fill_value='extrapolate' to yield values outside of the sampling points. It's available after version 0.17 (which I don't have here, so I cannot try this out) Mar 14, 2017 at 12:31
• Nice demo @MaximilianMatthé, I didn't realize the scipy interpolate handled this case so well! Mar 14, 2017 at 16:49

I found a method similar to the zero-padding FFT interpolation but in which the missing samples can be nonuniformly spaced. I think it exactly solves the problem you have. The method is described here:

J. Selva, "FFT interpolation from nonuniform samples lying in a regular grid", IEEE Trans. on Signal Processing, vol. 63, n. 11, June 2015.

The code is available here.

Use inpainting method. Check this question. Inpainting methods also work for 1D signals.

• I didn't know about inpainting so that's good to learn, although the technique is a bit computationally heavy for my needs - thanks though. Mar 15, 2017 at 9:48