Complete the code to define the transfer function H(z) using numerator and denominator coefficients.
from scipy.signal import TransferFunction num = [1, -0.5] den = [1, -0.9] H = TransferFunction([1], den, dt=1)
The numerator coefficients are stored in num, which define the zeros of the transfer function H(z).
Complete the code to compute the frequency response of H(z) at 512 points.
from scipy.signal import freqz w, h = freqz(H.num, H.den, worN=[1])
512 points is a common choice for smooth frequency response plots.
Fix the error in the code to correctly calculate the magnitude response in decibels.
import numpy as np magnitude_db = 20 * np.log10([1])
h directly without absolute value.The magnitude must be the absolute value of h before applying log10.
Fill both blanks to create a dictionary of frequency response with frequency in Hz and magnitude in dB.
freq_response = [1]: w * [2] / (2 * np.pi) for w, mag in zip(w, magnitude_db)
The dictionary key is 'frequency_hz' and frequency is scaled by sampling frequency fs.
Fill all three blanks to filter a signal x using the transfer function H and store the output in y.
from scipy.signal import lfilter y = lfilter([1], [2], [3])
The lfilter function takes numerator coefficients, denominator coefficients, and the input signal.