Reputation: 337
Given a vector X
of length L
, what is the difference between fft(X)
and fft(X,L)
?
Does it mean we are taking the fft
on L
points when using fft(X)
and the fft
of vector L
when doing fft(X,L)
?
Upvotes: 2
Views: 722
Reputation: 18177
As per the documentation on fft
:
Y = fft(X)
computes the discrete Fourier transform (DFT) ofX
using a fast Fourier transform (FFT) algorithm.If
X
is a vector, thenfft(X)
returns the Fourier transform of the vector.
Y = fft(X,n)
returns then
-point DFT. If no value is specified,Y
is the same size asX
.If
X
is a vector and the length ofX
is less thann
, thenX
is padded with trailing zeros to lengthn
.If
X
is a vector and the length ofX
is greater thann
, thenX
is truncated to lengthn
.
Meaning that in case you have a vector X
of length L
, fft(X)
and fft(X,L)
are equivalent.
The interesting bit comes when you call fft(X,n)
with n~=L
.
n<L
your input vector X
will be trucated, i.e. you will use less measurements and get a shorted Fourier sequence.n=L
; discussed aboven>L
your vector X
is zero-padded: X = [X zeros(L-n,1)]
(for a row vector X
). What this will do is interpolation in the frequency domain. This is most easily seen from the formulae at the bottom of the documentation:if we increase n
, we get a longer vector Y
. However, since you padded zeros, and not a continuation of the signal, its Fourier transform will be an interpolation between frequencies. Normally you'd have the frequencies as given by W(n)
running from your sampling frequency, f_s
all the way up to f_n = Nyquist/2
in L
steps, i.e. as many data points as you have: linspace(F_s,f_n,L)
. What you are doing when zero padding is putting more points into the same space: linspace(F_s,f_n,n)
, without adding information.
Upvotes: 6