Complete the code to create a rectangular window of length 50 using NumPy.
import numpy as np window = np.[1](50)
The rectangular window is created by an array of ones, so np.ones is used.
Complete the code to compute the Fourier Transform of the rectangular window using NumPy's FFT.
import numpy as np window = np.ones(50) fft_window = np.fft.[1](window)
The Fourier Transform is computed using np.fft.fft.
Fix the error in the code to plot the magnitude of the FFT of the rectangular window using matplotlib.
import numpy as np import matplotlib.pyplot as plt window = np.ones(50) fft_window = np.fft.fft(window) plt.plot(np.abs(fft_window[1])) plt.title('Magnitude of FFT of Rectangular Window') plt.show()
To plot the first half of the FFT magnitude, slice with [:25].
Fill in the blank to create a dictionary of window lengths and their main lobe widths, assuming main lobe width is 2 divided by window length.
window_lengths = [20, 40, 80] main_lobe_widths = {length: 2 [1] length for length in window_lengths}
The main lobe width is calculated as 2 divided by each window length, so the expression is 2 / length. The dictionary comprehension iterates over window_lengths.
Fill all three blanks to create a plot comparing the rectangular window and its FFT magnitude normalized by the maximum value.
import numpy as np import matplotlib.pyplot as plt N = 50 window = np.ones(N) fft_window = np.fft.fft(window) fft_magnitude = np.abs(fft_window) / np.[1](np.abs(fft_window)) plt.plot(window, label='Rectangular Window') plt.plot(fft_magnitude[:N//2], label='Normalized FFT Magnitude') plt.[2]('Window Samples') plt.[3]('Amplitude') plt.legend() plt.show()
The FFT magnitude is normalized by its maximum value using np.max. The x-axis label is set with plt.xlabel and the y-axis label with plt.ylabel.