Complete the code to compute the frequency spectrum of a signal using FFT.
spectrum = np.fft.[1](signal)ifft) instead of FFT.fftshift which only shifts zero frequency component.The fft function computes the frequency spectrum of the signal.
Complete the code to calculate the magnitude spectrum from the FFT result.
magnitude = np.abs([1])The magnitude spectrum is the absolute value of the FFT result stored in spectrum.
Fix the error in the code to correctly compute the frequency bins for the FFT.
freqs = np.fft.fftfreq(len(signal), d=[1])
fs directly instead of its inverse.The d parameter is the sample spacing, which is the inverse of sampling frequency fs.
Fill both blanks to create a dictionary of frequencies and their magnitudes for frequencies above zero.
freq_magnitude = {f: m for f, m in zip(freqs, magnitude) if f [1] 0 and m [2] 0}We want frequencies greater than zero and magnitudes not equal to zero.
Fill all three blanks to create a filtered dictionary of frequencies and magnitudes where magnitude is above threshold and frequency is positive.
filtered = { [1]: [2] for [3] in zip(freqs, magnitude) if [1] > 0 and [2] > threshold }Use f and m as keys and values, and unpack f, m from the zipped frequencies and magnitudes.
