New_student
New_student

Reputation: 337

Difference between fft points and fft in vector

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

Answers (1)

Adriaan
Adriaan

Reputation: 18177

As per the documentation on fft:

Y = fft(X) computes the discrete Fourier transform (DFT) of X using a fast Fourier transform (FFT) algorithm.

If X is a vector, then fft(X) returns the Fourier transform of the vector.

Y = fft(X,n) returns the n-point DFT. If no value is specified, Y is the same size as X.

If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n.

If X is a vector and the length of X is greater than n, then X is truncated to length n.

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.

  • If n<L your input vector X will be trucated, i.e. you will use less measurements and get a shorted Fourier sequence.
  • If n=L; discussed above
  • If n>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:

enter image description here

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

Related Questions