Complete the code to create a simple sine wave signal.
import numpy as np fs = 1000 # Sampling frequency f = 5 # Frequency of the sine wave t = np.arange(0, 1, 1/fs) signal = np.sin(2 * np.pi * [1] * t)
fs instead of signal frequency f.The sine wave frequency is given by f, so it should multiply 2 * np.pi * f * t.
Complete the code to compute the FFT of the signal.
from numpy.fft import fft N = len(signal) fft_values = fft([1])
t instead of the signal.The FFT should be computed on the signal data, which is stored in signal.
Fix the error in the code to correctly compute the frequency bins for the FFT.
freqs = np.fft.fftfreq([1], d=1/fs)
fs instead of number of samples N.The fftfreq function needs the number of samples N and the sample spacing d=1/fs.
Fill both blanks to create a windowed signal and compute its FFT.
window = np.[1](N) windowed_signal = signal * window fft_windowed = np.fft.[2](windowed_signal)
ifft instead of fft.hanning when the question expects hamming.Applying a Hamming window reduces spectral leakage. Then compute FFT with fft.
Fill both blanks to create a dictionary of frequency magnitudes above a threshold.
threshold = 10 freq_magnitudes = {freq: abs(fft_windowed[i]) [1] threshold for i, freq in enumerate(freqs) if freq >= 0 and abs(fft_windowed[i]) [2] threshold}
, instead of colon : in dictionary comprehension.>= instead of > inconsistently.The dictionary comprehension syntax requires a colon : between key and value. We filter frequencies and magnitudes greater than the threshold using >.