A. Noise induced by interpolation

Interpolation does not generally yield the ideal result. One way of looking at interpolation errors is with Fourier spectra.

In Fourier analysis one regards signals as superpositions of plane waves (i.e. sines and cosines). Given the sampling rate and the length of the signal, we can only compute the amplitudes of a finite sequence of frequencies (and we constructed those frequencies in class for an audio signal).

Consider the following function and arrays:


In [1]:
import numpy as np

def func(val):
    return np.sin(4*np.pi*val) + np.cos(6*np.pi*val)

samples = np.linspace(0, 1, 17, endpoint = False)
x = np.linspace(0, 1, 51, endpoint = False)

Compute the value of this function at every point in samples. Create an interpolator object (using the class we defined in our lectures) from samples and the values you have obtained. Afterwards, create 2 more arrays. One which will contain the interpolated values at the points in x, and one which will contain the exact values.

Compute the Fourier transforms of these 3 arrays (the coarse grained version, the interpolated version, and the exact fine-grained version). Construct the frequencies corresponding to samples and x, and then plot the power spectra for the 3 arrays (i.e. $|\hat{f}(k)|^2$ for the various $\hat{f}$ you get). Use logarithmic scale on the $y$ axis. Discuss the plot.

B. Dependence on samples

Follow a similar procedure for different numbers of samples: 15, 18, 21, ..., 30. Compare the spectra you obtain by interpolating on the differently sampled data.