Since the process can be applied in either domain to increase the sampling rate in the other domain, I am trying to apply zero-padding in frequency space to recover a 'cleaner' interpolated signal in temporal space. To do so, I insert zero-valued frequencies in the spectrum at the location of higher frequencies, which is a common practice.
However I don't seem to recover the original signal very well (in black below) after zero-padding (in red).
import numpy as np
import matplotlib.pyplot as plt
# odd dimension for simplicity
n = 19
npad = 99
x = np.linspace(0.,4.*np.pi,n)
xpad = np.linspace(0.,4.*np.pi,npad)
f = np.cos(x) + 1j*np.sin(x)
f_fwd = np.fft.fft(f)
f_fwd_pad = np.zeros(npad,dtype=complex)
h = (n-1)//2
f_fwd_pad[0:h+1] = f_fwd[0:h+1]
f_fwd_pad[npad-h:] = f_fwd[h+1:]
f_interpolated = np.fft.ifft(f_fwd_pad)*npad/n
fig, ax = plt.subplots(1,2)
ax[0].plot(x,np.real(f),linestyle=None,marker='x',color='k')
ax[0].plot(xpad,np.real(f_interpolated),color='r')
ax[1].plot(x,np.imag(f),linestyle=None,marker='x',color='k')
ax[1].plot(xpad,np.imag(f_interpolated),color='r')
Is that result expected? Is there some fundamental understanding that I am missing?