Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Hann window function from scipy.signal.
SciPy
from scipy.signal import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong window function like hamming or blackman.
Misspelling the function name.
✗ Incorrect
The Hann window is imported from scipy.signal as hann.
2fill in blank
mediumComplete the code to create a Hann window of length 256.
SciPy
window = hann([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a window length different from the signal length.
Confusing window length with FFT length.
✗ Incorrect
The window length should match the signal length, here 256.
3fill in blank
hardFix the error in applying the window to the signal array named 'signal'.
SciPy
windowed_signal = signal [1] window Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding or subtracting the window instead of multiplying.
Dividing the signal by the window.
✗ Incorrect
Windowing is done by multiplying the signal by the window element-wise.
4fill in blank
hardFill the blank to compute the FFT of the windowed signal and get its magnitude.
SciPy
fft_result = np.fft.[1](windowed_signal)
magnitude = np.abs(fft_result) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inverse FFT instead of FFT.
Trying to get magnitude by accessing .real or .imag.
✗ Incorrect
Use np.fft.fft to compute the FFT and np.abs to get the magnitude.
5fill in blank
hardFill all three blanks to create a windowed signal, compute its FFT, and plot the magnitude spectrum.
SciPy
import matplotlib.pyplot as plt window = hann([1]) signal = np.sin(2 * np.pi * 5 * np.arange([2]) / [3]) windowed_signal = signal * window fft_result = np.fft.fft(windowed_signal) magnitude = np.abs(fft_result) plt.plot(magnitude) plt.title('Magnitude Spectrum') plt.xlabel('Frequency Bin') plt.ylabel('Magnitude') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different lengths for window and signal.
Not matching the range length with window length.
✗ Incorrect
The window length and signal length must match (256). The signal is created with 256 points.