fft2
Two-dimensional fast Fourier transform.
| Library |
|
Syntax
Function call
-
Y = fft2(X)— returns two-dimensional Fourier transform matricesXusing the fast Fourier transform algorithm, which is equivalent to computingfft(fft(X).').'.If
X— multidimensional array,fft2calculates the two-dimensional Fourier transform for the first two dimensions of each subarrayX, which can be considered as a two - dimensional matrix for dimensions greater than2. For example, ifX— an array of sizem×n×1×2ThenY(:,:,1,1) = fft2(X(:,:,1,1))andY(:,:,1,2) = fft2(X(:,:,1,2)). Output sizeYmatches the size ofX.
Arguments
Input arguments
# X — input array
+
the matrix | multidimensional array
Details
The input array, specified as a matrix or multidimensional array. If X has a type Float32, then the function fft2 it is initially calculated with single precision, and Y It also has a type Float32. Otherwise, Y returns as Float64.
| Типы данных |
|
| Support for complex numbers |
Yes |
# m — number of conversion lines
+
a positive integer scalar
Details
The number of conversion lines specified as a positive integer.
| Типы данных |
|
# n is the number of conversion columns
+
a positive integer scalar
Details
The number of conversion columns, set as a positive integer.
| Типы данных |
|
Output arguments
# Y — output array
+
the matrix | multidimensional array
Details
The output array returned as a matrix or multidimensional array.
Examples
Two-dimensional transformation
Details
The two-dimensional Fourier transform is useful for processing two-dimensional signals and other two-dimensional data such as images.
Let’s create and display two-dimensional data with repeating blocks on the graph.
function peaks(n)
x = range(-3, 3, length=n)
y = range(-3, 3, length=n)
X = repeat(x', n, 1)
Y = repeat(y, 1, n)
Z = 3 * (1 .- X).^2 .* exp.(-X.^2 .- (Y .+ 1).^2) .-
10 * (X/5 .- X.^3 .- Y.^5) .* exp.(-X.^2 .- Y.^2) .-
1/3 * exp.(-(X .+ 1).^2 .- Y.^2)
return Z
end
P = peaks(20)
X = repeat(P, 5, 10)
heatmap(X, aspect_ratio=1, c=:viridis, yflip=true)
Calculate the two-dimensional Fourier transform of the data. Shift the zero frequency component to the center of the output signal and plot the resulting matrix size 100 on 200, which corresponds to the size X.
import EngeeDSP.Functions: fft2, fftshift
Y = fft2(X)
Y_shifted = fftshift(Y)
heatmap(abs.(Y_shifted), aspect_ratio=1, c=:viridis, yflip=true)
Adding more X with zeros to calculate the transformation size 128 on 256.
n1 = nextpow(2, 100) # 2^7 = 128
n2 = nextpow(2, 200) # 2^8 = 256
Y_padded = fft2(X, n1, n2)
Y_padded_shifted = fftshift(Y_padded)
heatmap(abs.(Y_padded_shifted), aspect_ratio=1, c=:viridis, yflip=true)
Additional Info
Two-dimensional Fourier transform
Details
This formula defines the discrete Fourier transform. matrices size on :
where and — complex roots of unity:
where — imaginary unit. and — indexes ranging from before , and and — indexes ranging from before . This formula shifts the indexes and on 1 to reflect the indexes of the matrices in Engee.