You are on page 1of 4

Created: 5/19/2006 Last compiled: Wednesday 7th June, 2006 12:03 File name: FFTzeropad.

tex Here we show the eect and benet of zeropadding in Fourier space.

1D

If we need to multiply two signals of dierent lengths in Fourier space we can extend the shorter signal by zero-padding it in Fourier space. Note that it is generally not a good idea to zero-pad the signal in physical space before taking the transform as this will likely result in spurious oscillations. Of course, the zeropadded signal should be well resolved such that the coecients of the FFT smoothly go to zero in Fourier-space as they approach the Nyquist frequency (if this were not the case then there would be a problem with the analysis anyways!). It is important to keep track of how the coecients of the FFT are stored. The domain of the frequencies1 returned by the FFT ranges from zero to the Nyquist frequency [N/2, N/2) and the order of the coecients2 corresponds to the frequencies N N N 1), , ( 1), , 2, 1] (1) 2 2 2 The rst element is always the zero mode followed by increasing positive frequencies until (N/2 1) and then negative frequencies starting from the Nyquist frequency N/2 until 1. Note that each mode has a corresponding mode of the opposite sign except for the k = 0 and the k = N/2 mode. An example signal, a complex Morlet wavelet, displayed in physical space is shown in gure 1. Also shown is the inverse FFT of the zero-padded (in Fourier-space) FFT of the signal. The corresponding Fourier-space representation is shown in gure 2. To zero-pad in Fourier space, we must therefore split the vector of coecients in half and then insert zeros in between the two halves. This is shown in the right side of gure 2. Note that zero-padding does not add any information to the signal, but it will make the signal appear smoother when inverse transformed back to physical space. k : [0, 1, 2, , (

2D

The zero-padding in 2D is a bit more tricky than that of 1D due to the way that the coecients of the FFT are stored and the addition of a second index (thus the vector of coecients becomes a matrix). However, fortunately the coecients in the rows and columns of the FFT are stored in the same order as in the 1D case. The rst element in the matrix returned by the 2D FFT, in the position (1, 1), corresponds to the kx = ky = 0 mode.
Note that the frequencies do not include 2 and are inverse length scale 1/l, not a wavenumber, due to the denition of the FFT. See the note on usage of Matlabs FFT. 2 Note that the matlab documentation does not explicitly say the order, however this is likely how it is stored based upon the behavior of the fftshift function (swapping of the left and right halves of the vector). In practice mode N/2 and mode N/2 are equivalent so that the only dierence is in terms of where it is stored.
1

8 6

10 RE(zpd(x)) 0 RE((x)) RE( (x))


high

10 4 0.5 2 0 2 4 6 0.06 0.04

0.5

0.02

0 x

0.02

0.04

0.06

Figure 1: We take a complex Morlet wavelet (real part shown) sampled at N = 256 points and calculated from the physical space representation (using the corrected formula), at scale 1/8. The FFT zero-padded and reconstructed signal is shown for padding to length Nz = 512 points, twice the length of the original signal. You can see that the zero-padded version has twice the number of points, but that the corresponding points match to within machine precision. The green curve shows the wavelet calculated in physical space at the higher resolution. The inset shows the signal over the full interval.

0.4 0.35 0.3 0.25 0.2 0.15 0.1 0.05 0 0.05 200 100 0 k 100 200 FFT()zpd FFT((x))

0.4 FFT() 0.35 0.3 0.25 0.2 0.15 0.1 0.05 0 0.05 0 100 200 300 indices of coefficients 400 500
zpd

added zeros

Figure 2: Left: The FFT of the signal (red symbols) and with zero padding (black symbols). Right: The position of the coecients of the FFT, showing the location of the inserted zeros (green symbols).

Physicalspace 0.4 0.3 0.2 0.1 0 0.1 0.2 0.3 0.4 0.5 0.4 0.2 0 x 0.2 0.4 y 50 40 30
50

FFT, before zeropadding 0.1 100 0.09 0.08 0.07 0.06


y

20 10 0 10 20 30 40 50
100 100 50 0 kx 50 100 50 0 k

0.05 0.04 0.03 0.02 0.01

Figure 3: Left: Complex Morlet in 2D sampled at N = 256, at scale 1/8. Right: FFT of the signal.
FFT indices, zeropadded 0.1 50 100 150 ky index 200 250 300 350 400 450 500 100 200 300 kx index 400 500 0.09 0.08 0.07 0.06
ky 250 200 150 100 50 0 50 100 150 200 250 200 100 0 kx 100 200 FFT, shifted, zeropadded 0.1 0.09 0.08 0.07 0.06 0.05 0.04 0.03 0.02 0.01 0

0.05 0.04 0.03 0.02 0.01 0

Figure 4: Left: FFT of signal displayed by indices, showing the location of zero-padded elements in white. Right: same but shifted to display the zero frequency at the center. We take a complex Morlet wavelet in 2D as our signal, shown in gure 3. Note that the 1D wavelet and a cut down the middle3 of the 2D wavelet, properly normalized by 1/ a, agree to within 1014 . The procedure to zero-pad in 2D is similar to that in 1D, with the obvious modications to the algorithm to account for the coecients being stored in a matrix. We must insert zeros between the rst and second halves of the coecients. In a matrix, this means inserting rows of zeros between the top and bottom halves and then columns of zeros between the resulting left and right halves of the matrix. The result of the zero-padding is shown in gure 4. The algorithm is shown in the Matlab code section.
3

The middle index actually corresponds to N/2+1, when the wavelet is in the center of the domain.

3
3.1

Matlab code
Zero-padding in Fourier space

The code for 1D zeropadding in Fourier space: nFy = length(Fy); % length of the original signal nzs = N - nFy; % number of zeros to add zpd = zeros(1,nzs); % vector of zeros to add zpdFy = [Fy(1:nFy/2) zpd Fy(nFy/2+1:end)]; % insert the zeros The code for 2D zero-padding: [m,n] = size(Fy); % size of the original matrix nzsr = N - m; % number of zero rows to add nzsc = N - n; % number of zero columns to add % quadrants of the FFT, starting in the upper left q1 = Fy(1:m/2,1:n/2); q2 = Fy(1:m/2,n/2+1:n); q3 = Fy(m/2+1:m,n/2+1:n); q4 = Fy(m/2+1:m,1:n/2); zpdr = zeros(nzsr,n/2); % zeropad rows to insert zpdc = zeros(nzsr+m,nzsc); % zeropad columns to insert zpdFy = [ [q1;zpdr;q4] , zpdc , [q2;zpdr;q3] ]; % insert the zeros

You might also like