0
$\begingroup$

I'm trying to pad $N=16$ zeros to the DFT of a $16$ point sinewave, but something is wrong either with my code or with my method. The method is this : I create a new $32$ point DFT where $F'(0),...,F'(N/2 - 1)$ are the elements of the original DFT, $F(0),...,F(N/2 - 1)$. I start to add $16$ zeros starting from $F'(N/2)$. The remaining values of $F'(k)$ need to have the proper conjugate symmetry, so that $F'(k) = (F'(N' - k))^*$ holds. I am using Python and numpy.

# parameters
f_s = 1  
f_1 = 0.25
f_2 = 0.4
t_s = 1/f_s
N = 16

# define sinewave
def sinewave(x):
 return np.sin(2 * pi * f_1 * x * t_s) + 1.5*np.sin(2 * pi * f_2 * x * t_s)

y = np.zeros(N)
for i in range(0, N):
y[i] = sinewave(i)

# zero-pad in frequency domain by 16 points
zero_pad = 16

zero_padded_transform = np.zeros(N + zero_pad, dtype = complex)

zero_padded_transform[0 : 8] = np.fft.fft(y)[0 : 8] # 8 since N/2 = 16/2 = 8
zero_padded_transform[8 + zero_pad + 1:] = np.fft.fft(y)[9:]

The symmetry is correct as the inverse transform has zero imaginary part, but the number of zeros is not correct. As such, this method does not seem to interpolate the sinewave correctly in the time domain.

$\endgroup$
5
  • 1
    $\begingroup$ I dunno if it's a British thing or something else, I just wish that we would stay away from "$f(t)$" or "$F(\omega)$" or "$f$" anything so that this symbol can be reserved for "ordinary frequency". $$ f \triangleq \frac{\omega}{2\pi} $$ The only "$f(t)$" we should see is if there is an instantaneous frequency that varies with time. $\endgroup$ Jan 16 at 17:55
  • $\begingroup$ "the number of zeros is not correct": what do you mean? what do you get? and what do you expect? $\endgroup$
    – Jdip
    Jan 16 at 20:00
  • $\begingroup$ I can't tell what "number of zeros" is supposed to be but most likely the difference between your results and what you expect is spectral leakage. Your second frequency isn't in the center of an FFT bin, so you get leakage over all bins including Nyquist. If Nyquist is non-zero, zero padding in the frequency domain doesn't work without artifacts. $\endgroup$
    – Hilmar
    Jan 16 at 20:12
  • $\begingroup$ To second @Hilmar‘s comment, Try with a pure sine wave with your f_1 frequency, you’ll see that your implementation is correct $\endgroup$
    – Jdip
    Jan 16 at 23:33
  • $\begingroup$ The problem is that this code pads 17 zeros instead of 16. But anyway, I tried this with a pure tone sinewave, and it seems to work, kind of. The interpolation sort of works, but there is a small phase difference between the interpolated signal and the original after some time passes. $\endgroup$ Jan 17 at 7:51

1 Answer 1

2
$\begingroup$

Zero padding the frequency samples (just as the OP has done in padding out the center of the array and maintaining symmetry) and using the inverse DFT is almost identical to interpolating with a Sinc in the time domain. To be precise, the result in time is the convolution of the original time domain samples with the Dirichlet Kernel (which is identical to an aliased Sinc function). As $N$ the total number of samples gets larger, the Dirichlet Kernel approaches a Sinc function. This is also consistent how for small $N$ we will have larger error due to time domain aliasing.

Zero padding in frequency will interpolate more samples in time of the Discrete Frequency Inverse Fourier Transform (DFIFT) which is discrete in frequency and continuous in time. This would be the Frequency to Time equivalent of the DTFT which is discrete in time and continuous in frequency.

Plots comparing the magnitude of the ideal Sinc to the Dirichlet Kernel for different total number of samples $N$ are shown below:

Sinc vs Dirichlet Kernel

$\endgroup$
2
  • $\begingroup$ Interesting answer Dan (+1)! I didn't know the Dirichlet kernel was an aliased sinc, or that it was the equivalent time domain interpolator of zero-padding in the frequency domain. Perhaps you could expand on it more. Or maybe I'll try to ask another question to tee up for you! $\endgroup$
    – Gillespie
    Jan 19 at 1:47
  • $\begingroup$ @Gillespie Thanks! Please check out this other answer where I do expand on that concept further: dsp.stackexchange.com/questions/83860/… $\endgroup$ Jan 19 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.