Complete the code to import the signal module from scipy.
from scipy import [1]
The signal module in scipy contains functions for signal processing.
Complete the code to create a simple sine wave signal using numpy.
import numpy as np fs = 1000 # Sampling frequency T = 1.0 # seconds x = np.linspace(0, T, int(T*fs), endpoint=False) signal = np.sin(2 * np.pi * 5 * [1])
The variable x holds the time points for the sine wave.
Fix the error in the code to compute the Fourier Transform of the signal.
from scipy import signal import numpy as np fs = 1000 T = 1.0 x = np.linspace(0, T, int(T*fs), endpoint=False) sig = np.sin(2 * np.pi * 5 * x) freqs, psd = signal.welch(sig, [1])
The welch function requires the sampling frequency fs as the second argument.
Fill both blanks to create a bandpass filter and apply it to the signal.
from scipy import signal fs = 500 nyq = 0.5 * [1] low = 10 / nyq high = 50 / [2] b, a = signal.butter(4, [low, high], btype='band') filtered = signal.lfilter(b, a, sig)
fs or nyq.fs for the second blank instead of nyq.The Nyquist frequency is half the sampling frequency fs for the first blank. The second blank requires nyq to normalize the high cutoff frequency.
Fill both blanks to create a dictionary of frequencies and their power values above a threshold.
result = {freq[1]: psd for freq, psd in zip(freqs, psd) if psd [2] 0.01}We round the frequency to 2 decimals, keep power spectral density as is, and filter values greater than 0.01.