# Matlab: Different 1-D FFT results with and without zero-padded

Recently I am implementing FFT with C code. So I use Matlab for algorithm verification. As Radix-2 FFT was chosen, I've learned that zero-padding technique could help to reach 2^N limitation without messing up the result. However, hesitation has shown.

Let's say a set of acceleration data with the size of 150 (x) comes across. If FFT function is called directly like:

X = fft(x);
abs_X = abs(X);
figure
plot(abs_X(2:75)); % discard first data (DC)


The result looks reasonable: With this result I can easily indicate the highest amplitude and get the main frequency with frequency step. However, after zero-padding the data to the size of 256 and then apply fft, a confusing result is obtained.

x = [x; zeros(106,1)]; % pad 0 to 256
X = fft(x);
abs_X = abs(X);
figure
plot(abs_X(2:128)); % discard first data (DC) Now I cannot identify the main frequency since the decreasing pattern is shown.

From here I have learned that the fft function in Matlab will automatically adjust the data size with zero-padding in order to perform FFT. So theoretically two operations demonstrated above should perform same results. I know that zero-padding will increase the visual resolution (not data resolution). But the difference between the beginning of the figures, where main frequency can't be determined, is confusing me.

Can anyone help to clarify the situation? Or do I misunderstand something important about the statement "Zero padding is going to perform a same result."? Any comment is appreciated. Thank you for browsing my question!

• Hi! it's much appreciated if you could upload those 150 data points here too, so that people can exactly replicate your results. In the mean time, as you've stated: zero padding only improves the visual resolution and not the spectral data resolution. However note that the sampling associated with DFT might create interesting results depending on what the original DTFT looked like. Apr 16, 2019 at 10:53
• Matlab will only adjust the data size when you specifically call it to do so with the optional number of points. So to make these equivalent use X = fft(x, 181) if your total number of points after zero padding is indeed 181. Apr 16, 2019 at 11:43
• Hi, @Fat32. Thanks for the reply. I think I might have to clarify the DTFT and DFT first. Apr 22, 2019 at 9:29
• Hi, @DanBoschen! Thanks for your comment. I did try to the specify the N points to produce the same result. So is it implying that we can't prove the statement about zero-padding with Matlab in-build fft function? Apr 22, 2019 at 9:39
• No Matlab will not adjust the data size without specifically telling it to do so; if it does it internally for some reason and mathematically manipulates it to be equivalent may happen but what I mean to say is the answer is true to the DFT for the length of the sequence, for any length even if not 2^n Apr 22, 2019 at 14:56

What you see in your diagrams is a convolution with a $$\text{si}$$ function, which is the fourier transform of a rectangle function. If you just take the signal as it is and transform it, you essentially multiply it by a rectangle function.