# Effects of linear interpolation of a time series on its frequency spectrum

## Situation

In order to synchonisize different time series i have to apply linear interpolation on them. After the interpolation and synchronization the signal is transferred into its frequency domain for further analysis. The interpolation step should therefore not alter the frequency domain information.

## Experiment

Via python I created a signal of white noise. The second signal is based on the first but shifted by half of the original sampling interval. The third signal was created by oversampling the original signal by the factor 5.0. Afterward all three signals were transferred to the frequency domain (Bottom of the Figure)

## Questions

1. Why does the curve of the shifted signal decline for higher frequencies?
2. Why does the curve of the over sampled signal decline for higher frequencies? Though the over sampled signal has the exact same shape as the original signal.
3. What can i improve in order to interpolate the original signal at specific points but minimize the effects on its frequency spectrum?

My python code for the experiment and the plot: https://pastebin.com/iz08Hiud

Many thanks in advance!

## Update

Thank you all for your comprehensive adn helpfull answers, especially robert bristow-johnson and howpow2 for directing me on the right path. I am using now an implementation of the sinc kernel interpolation, which shows an almost perfect frequency response. See the bottom row of the plot for the results in form of the error between the original frequency spectrum and the frequency spectrums of the interpolated signals

• Would you mind sharing the code for the sinc kernel interpolation? – Joost Dec 18 '18 at 14:11

A linear interpolator is a filter with a really bad frequency response. Higher order interpolators may do better, but the ideal for samples of a bandlimited signal is to use Sinc kernel interpolation (references here and here). I have pseudo-code for an arbitrary time position windowed Sinc interpolator here (but better window functions are available).

Another possibility, for a constant time shift, is to use an FFT and IFFT, with a tiny linear (with frequency) phase rotation done in between, to perform a sub-sample time shift interpolation. Zero-pad beforehand to avoid wrap around artifacts.

• hot, thanks for the link to your stuff. i got something to read. – robert bristow-johnson Jul 29 '17 at 6:38

Duane Wise and i wrote a paper back in the 90s that we presented to an AES convention that spelled out how to model time-domain polynomial interpolation (of which linear interpolation is an example) in the frequency domain.

i think you can get a copy here: Performance of Low-Order Polynomial Interpolators in the Presence of Oversampled Input

• I am glad you shared this one. Progressively, I am going back to basics, like (low-order) polynomials – Laurent Duval Jul 30 '17 at 17:10
• @LaurentDuval, it's why, assuming you're interpolating for the purpose of SRC, if you want to kill the error from folding back the images that should be beaten down by the interpolation function, that the impulse response should be a B-spline, which is a rect() function convolved with itself $N$ times. the frequency response will be $\operatorname{sinc}^{N-1}(f/f_\text{s})$ with no other terms corrupting the deep notches at integer multiples of $f_\text{s}$. any other $(N-1)$th-order polynomial, like Lagrange or Hermite will have less deep (and wide) notches. – robert bristow-johnson Jul 30 '17 at 18:07
• but the B-splines will do more low-pass filtering in the passband, so you might want to boost the highs a little with a high-shelf filter to compensate it. if you want to be more exact, then use a Kaiser-windowed-sinc() function and, because your table of coefficients must be finite in size, think of that as the oversampling ratio. if you oversample (using windowed-sinc()) by a factor of 512 (remember you need not calculate the intervening subsamples), you'll get 120 dB S/N with linear interpolation between the two closest subsamples. – robert bristow-johnson Jul 30 '17 at 18:11

Linear interpolation of a sampled sequence corresponds to convolution with a triangle signal which has a frequency response of $(1/f_s^2)\,\mathop{\rm sinc}^2(f/f_s)$ where $f_s$ is the sampling frequency and $\mathop{\rm sinc}(f) = \frac{\sin \pi f}{\pi f}$.

So it has the low-pass behavior of two short-time integrators in sequence. Usually you are better off using a less ad-hoc approach to low-pass filtering when upsampling: $\mathop{\rm sinc}^2$ is a far cry from the rectangular frequency response you'd optimally want.

Said another way, one can upsample a signal to a higher sampling rate by inserting zeros inbetween the actual samples. Then, thinking in the time domain, the zero stuffed signal is run through a FIR low pass filter. Thinking about it this way, that interpolation is a lowpass operation helps explain this behavior. See this diagram for the frequency domain description Upsampling, figure 1

It looks like you are using Linear interpolation for the half shift. If you plot a single sine wave at near Nyquist frequency, you will see that adjacent samples are nearly $\pi$ radians apart. The sine will approach only two samples per cycle . A Linear interpolation does a poor job resampling the intermediate point. At low frequency, a sine wave is densely sampled, so a Linear trend between samples has small error. A higher order interpolation can reduce the error, but as you get near Nyquist, you need to approach sinc interpolation on a window of samples that approaches infinity.