# Odd artifacts after sinc interpolation

I am trying to upsample a signal using sinc interpolation. I have written a way to do this in python.

    @staticmethod
def sinc_interp(x, s, u):
"""
Interpolates x, sampled at "s" instants
Output y is sampled at "u" instants ("u" for "upsampled")

from Matlab:
http://phaseportrait.blogspot.com/2008/06/sinc-interpolation-in-matlab.html
"""

if len(x) != len(s):
raise Exception('x and s must be the same length')

# Find the sampling period of the undersampled signal
T = s[1] - s[0]

y = []
for i in range(len(u)):
y.append(np.sum(np.multiply(x, np.sinc((1 / T) * (u[i] - s)))))

y = np.reshape(y, len(u))
return y


Here is an image of part of the undersampled signal with dots showing where the samples are.

And here is an image of the upsampled waveform. Upsampled by a lot to get a smooth waveform to test with.

You can see that in some of the peaks or troughs, there is a dip in the middle up or down. The data is from a sensor and I used an oscilloscope, with a much higher sample rate than needed to view the sensor output as well to get the true signal, and those artifacts are not truly there. So there must be something wrong with my sinc interpolation or there is some errors in my sample waveforms data.

The original sample period is 400uS per sample.

Upsampled sample period is 10uS per sample.

The scope I used to confirm the true signal has a 2uS sample period with Sin X interpolation enabled.

Can anyone see any issues with my sinc_interp method or know why those artifacts are showing up?

• I wonder if a windowed sinc would have been any different Sep 14 at 21:35
• I agree with @KnutInge , try a windowed sinc. Or maybe a spline?
– Ben
Sep 15 at 1:48

So, this is what I'd consider -- contrary to your title -- to be perfectly normal and expected artifacts from sinc interpolation.

Keep in mind that the sinc function rings forever. This means that if your source data has a sharp edge in it (like the edges of a step, or those pointy maxima and minima in your source data), that edge is going to cause the sinc's ringing to show through after interpolation.

In your case, you tend to see a bit of ringing on a flat part after or before a sharp edge -- that's the edge-induced ringing where it's not getting swamped out by steep slopes in the reconstructed waveform.

If you can live with the ringing you see -- problem solved, it wasn't odd after all!

If you can't live with that ringing, then you need to find a different interpolation function, that rings less or doesn't ring at all, while still giving you satisfactory reconstruction.

• The areas where the "artifacts" happen are where the points have the least sharp edges. The artifacts appear where the two samples are very close together on the y axis. And the surrounding points are not near as sharp as others. In fact, the sharper transitions do better in my data But flipping your theory on it's head, what if the flat parts are acting more like a square wave, the flat part at least. And we know that to create a square wave, we need MANY of the higher frequency harmonics. And my original sample rate does not meet the Nyquist criteria for those high frequency components? Sep 15 at 1:20
• @guitardenver I think Tim is right. I see what you're saying about some of the sharp points not displaying artifacts, but if you look closely, all the sharp transitions have a sample right at the max/min value, so the interpolator doesn't have to figure out the transition. It's the peaks and valleys without samples at their extrema that you have issues with (or edges, like the left edge of the data). Sep 15 at 2:20
• Thanks all! It's unfortunate since the algorithms after the reconstruction depend on finding the center of each peak and valley and measuring the width of each. I'll have to adjust accordingly. Sep 15 at 14:38
• @TimWescott I'll try upsampling with linear interpolation and see how it goes. Could you suggest another you think would be good? Or is that hard without knowing the end goal and more context to the data? I don't have enough characters here for that, maybe a different post. Sep 15 at 14:58
• @guitardenver Gaussian interpolation is free of ringing and adds less harmonics than linear interpolation. But it smooths out sharp corners.
– jpa
Sep 15 at 17:05

I agree that some amount of ringing is normal in sinc() interpolation.

However, the function you are using does the calculation as if all samples outside the input range are 0, while in your data they are closer to 3000.

Here is an example output of the function when the input data has a constant value 3000 and otherwise scaled to match your graphs:

The ringing near the beginning and end of the signal is caused by the zero truncation in the calculation.

In the middle part most of the ringing you are asking about is just normal sinc() output near sharp transitions.