Complete the code to apply a window function to a signal array.
import numpy as np signal = np.array([1, 2, 3, 4, 5]) window = np.[1](len(signal)) windowed_signal = signal * window
The hanning function creates a window that tapers the signal edges smoothly, reducing spectral leakage.
Complete the code to compute the Fourier Transform of a windowed signal.
import numpy as np signal = np.array([1, 2, 3, 4, 5]) window = np.hanning(len(signal)) windowed_signal = signal * window spectrum = np.fft.[1](windowed_signal)
The fft function computes the Fourier Transform, showing frequency components of the windowed signal.
Fix the error in the code to avoid spectral leakage by applying windowing before FFT.
import numpy as np signal = np.array([1, 2, 3, 4, 5]) windowed_signal = signal * [1] spectrum = np.fft.fft(windowed_signal)
Applying the Hanning window before FFT reduces spectral leakage by tapering signal edges.
Fill both blanks to create a windowed signal and compute its magnitude spectrum.
import numpy as np signal = np.array([1, 2, 3, 4, 5]) window = np.[1](len(signal)) windowed_signal = signal * window magnitude = np.abs(np.fft.[2](windowed_signal))
The hamming window reduces spectral leakage, and fft computes the frequency spectrum. Taking absolute value gives magnitude.
Fill all three blanks to create a windowed signal, compute its FFT, and normalize the magnitude.
import numpy as np signal = np.array([1, 2, 3, 4, 5]) window = np.[1](len(signal)) windowed_signal = signal * window spectrum = np.fft.[2](windowed_signal) magnitude = np.abs(spectrum) / [3](window)
The hanning window tapers the signal, fft computes the spectrum, and dividing by sum(window) normalizes the magnitude.