What is the output magnitude array when applying a Hamming window before FFT on a simple sine wave?
import numpy as np from scipy.signal import windows fs = 1000 f = 50 N = 256 t = np.arange(N) / fs signal = np.sin(2 * np.pi * f * t) window = windows.hamming(N) windowed_signal = signal * window fft_result = np.fft.fft(windowed_signal) magnitude = np.abs(fft_result)[:5] print(np.round(magnitude, 2))
Recall that the Hamming window reduces spectral leakage but scales the amplitude.
The Hamming window scales the amplitude close to 0.54 times the sum of the window. The FFT magnitude peak is about 32 for this sine wave with windowing.
Why do we apply a window function to a signal before computing its FFT?
Think about what happens at the edges of a signal segment when FFT assumes periodicity.
Windowing smooths the edges of the signal segment, reducing abrupt changes that cause spectral leakage in the FFT.
Given a noisy signal, which option shows the correct difference in FFT magnitude peak when using a rectangular window vs a Hann window?
import numpy as np from scipy.signal import windows fs = 500 f = 60 N = 128 t = np.arange(N) / fs signal = np.sin(2 * np.pi * f * t) + 0.5 * np.random.randn(N) rect_window = np.ones(N) hann_window = windows.hann(N) fft_rect = np.fft.fft(signal * rect_window) fft_hann = np.fft.fft(signal * hann_window) peak_rect = np.max(np.abs(fft_rect)) peak_hann = np.max(np.abs(fft_hann)) diff = round(peak_rect - peak_hann, 2) print(diff)
Windowing usually reduces the peak magnitude due to tapering.
The Hann window tapers the signal edges, reducing the peak FFT magnitude compared to the rectangular window, so the difference is negative.
What error occurs when this code tries to apply a window before FFT?
import numpy as np from scipy.signal import windows signal = np.array([1, 2, 3, 4, 5]) window = windows.hann(10) windowed_signal = signal * window fft_result = np.fft.fft(windowed_signal) print(np.round(np.abs(fft_result), 2))
Check the sizes of the signal and window arrays before multiplying.
The signal has length 5 but the window has length 10, so element-wise multiplication fails with a ValueError.
You want to detect two close frequencies in a signal using FFT. Which window choice helps best to resolve them?
Frequency resolution depends on main lobe width in window's frequency response.
The rectangular window has the narrowest main lobe, giving the best frequency resolution to distinguish close frequencies, despite higher side lobes.