# Zero-Padding seems to CHANGE FFT of signal!

I am having trouble with zero-padding. As I understand it, in theory, zero-padding in the time-domain should 'sinc-interpolate' the FFT of the signal in the frequency domain.

This would mean, that 1) none of the values of the original signal change. 2) the overall profile of the FFT doesnt change- aka the peaks remain around the same point.

However, in simulations this does not work.

For example, I FFT the following sequence

x=[0 1 0 1 0 1 0 1]

at an imaginary same frequency, Fs=1Hz. With no zero-padding (FFT-8),

|X(f=.3125)|=4.

|X(f=.3125)|=2.6.

As $N \rightarrow \infty$, $|X(f=.3125)| \rightarrow 0\$. Also, the peak of the FFT shifts from .3125 to .25 as $N \rightarrow \infty$.

Here is my code. The relavent parameter is ZP, which controls the amount of zero-padding (N=8*ZP):

ZP=0;       % of times of original length of signal to ZP with

x=[0 1 0 1 0 1 0 1];
x=[x,zeros(1,length(x)*2^ZP-length(x))];
X=fft(x);

Fs=1;
L=length(x);
df=.5*Fs/L;
t=(1:L)*(1/Fs);
f=(1:L)*df;

figure(12),
subplot(211), stem(x);
subplot(212), stem(f,abs(X)); xlim([-.02,.52])

test_pnt=.3125;
I=find(f==test_pnt);
title(['abs[X(' mat2str(test_pnt) ')]=' mat2str(abs(X(I)))]);

• An alternating sequence should have a spectral peak at Fs/2. So you may be computing the FFT peak incorrectly even in the unpadded case. – hotpaw2 May 10 '13 at 0:19

Your problem is these two lines:

t=(1:L)*(1/Fs);
f=(1:L)*df;


t=(0:L-1)*(1/Fs);
f=(0:L-1)*df;


If I modify your script as below (for scilab, not matlab), I get the following plot. The peaks all line up correctly.

And the peak of the FFT is at 0.25 not 0.3125.

for ZP=0:5       // of times of original length of signal to ZP with

x=[0 1 0 1 0 1 0 1];
x=[x,zeros(1,length(x)*2^ZP-length(x))];
X=fft(x);

Fs=1;
L=length(x);
df=.5*Fs/L;
t=(0:L-1)*(1/Fs);
f=(0:L-1)*df;

figure;
subplot(211), plot(x);
subplot(212), plot(f,abs(X)); //xlim([-.02,.52])

test_pnt=.3125;
I=find(f==test_pnt);
title('abs[X(' + string(test_pnt) +']='+ string(abs(X(I))));

end;

• @DankMasterDan: You're welcome! Any chance of the tick? – Peter K. May 14 '13 at 7:21