Challenge - 5 Problems
2D FFT Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of 2D FFT on a simple matrix
What is the output of the following code using
scipy.fft.fft2 on a 2x2 matrix?SciPy
import numpy as np from scipy.fft import fft2 matrix = np.array([[1, 2], [3, 4]]) result = fft2(matrix) print(np.round(result, 2))
Attempts:
2 left
💡 Hint
Recall that 2D FFT sums over rows and columns with complex exponentials.
✗ Incorrect
The 2D FFT of the matrix [[1,2],[3,4]] results in [[10, -2], [-4, 0]] with zero imaginary parts. This matches option D.
❓ data_output
intermediate1:30remaining
Shape of 2D FFT result
If you apply
scipy.fft.fft2 to a 5x3 matrix, what will be the shape of the output?SciPy
import numpy as np from scipy.fft import fft2 matrix = np.random.rand(5,3) result = fft2(matrix) print(result.shape)
Attempts:
2 left
💡 Hint
The FFT output shape matches the input shape unless specified otherwise.
✗ Incorrect
The 2D FFT output shape is the same as the input matrix shape by default.
❓ visualization
advanced3:00remaining
Visualizing magnitude spectrum of 2D FFT
Which option correctly plots the magnitude spectrum of the 2D FFT of a 256x256 image stored in
image?SciPy
import numpy as np import matplotlib.pyplot as plt from scipy.fft import fft2, fftshift # image is a 256x256 numpy array f_transform = fft2(image) f_shifted = fftshift(f_transform) magnitude_spectrum = np.abs(f_shifted) plt.imshow(np.log1p(magnitude_spectrum), cmap='gray') plt.title('Magnitude Spectrum') plt.show()
Attempts:
2 left
💡 Hint
Centering the zero frequency with fftshift and using log scale helps visualize details.
✗ Incorrect
Option B correctly applies fft2, shifts zero frequency to center, takes magnitude, applies log scale, and plots in grayscale for clear visualization.
🧠 Conceptual
advanced2:00remaining
Effect of zero-padding on 2D FFT resolution
What is the main effect of zero-padding a 2D signal before applying
fft2?Attempts:
2 left
💡 Hint
Think about how zero-padding affects the FFT output size and frequency bins.
✗ Incorrect
Zero-padding adds more points, increasing the number of frequency bins, which interpolates the FFT and improves frequency resolution without changing original frequencies.
🔧 Debug
expert2:00remaining
Identify the error in 2D FFT magnitude calculation
What error will this code raise when calculating the magnitude of a 2D FFT result?
SciPy
import numpy as np from scipy.fft import fft2 matrix = np.array([[1, 2], [3, 4]]) result = fft2(matrix) magnitude = np.abs(result.real) print(magnitude)
Attempts:
2 left
💡 Hint
Check how magnitude should be calculated from complex numbers.
✗ Incorrect
The code runs without error but magnitude is wrong because it takes absolute value of only the real part, ignoring imaginary parts.