# Interpolation by zero padding FFT

I'm currently studying the book Vibration-Based Condition Monitoring (second edition) by Robert Bond Randall.

I'm trying to implement in Matlab an algorithm to "increase" the sample rate for a given signal. The book on page 148 illustrates two ways:

• in the time domain "insert an appropriate number of zeros in between each actual sample, and then apply a digital low pass filter to limit the frequency range to the original maximum (it will also require rescaling proportional to the sampling factor);
• in the frequency domain "by padding the FFT spectrum with zeros in the center and then inverse transforming the increased (two-sided) spectrum to the same increased number of time samples."

My implementation is the following


N   = 32;

t1  = linspace(0,1,N);

s   = sin(2*pi*t1);
N   = length(s);

% FFT
S = fft(s);

% Inverse transform
K = (N+pad)/N; % Scaling factor
i = ifft(S);

% Plot
plot(t1,i, '-o')
hold on


I'm not happy with the result though, there is an artifact in the final part of the function as you can see below

I think the problem is in the "paddedS" definition but it seems correct to me, can you spot the error?

• Your paddedS is not conjugate symmetric, you may notice that MATLAB raise a warning which says that the imaginary part is ignored when plotting. Dec 22, 2021 at 10:49

Two problems: (1) your signal is not periodic to hide the effect of windowing and (2) wrong frequency domain padding.

Throw the last samples and manage carefully the lengths:

N   = 32;

t1  = linspace(0,1,N);
t1=t1(1:end-1);
t2=t2(1:end-1);

s   = sin(2*pi*t1);

% FFT
S = fft(s);

% Inverse transform
K = length(paddedS)/length(S); % Scaling factor
i = ifft(S);

You are seeing what I believe are equivalent to spectral leakage artifacts in the FFT, in this case time domain aliasing specifically. I would recommend the first approach for interpolation noting that the zero insert will replicate the spectrum at multiples of the original sampling rate. The optimum filter will pass your original passband with no distortion and completely eliminate the images that will be centered at every multiple of $$f_s$$ (for a final rate of $$N f_s$$. Multi band filters designed using the least squares algorithm (firls in MATLAB, Octave and Python scipy.signal) are efficient for doing this as they can concentrate the rejection bands only where they are needed.