Question: Write a python implementation of scipy.signal.freqz. freqz calculates the frequency response (Fourier transform) of an IIR filter (difference equation). Your function should operate the same
Write a python implementation of scipy.signal.freqz. freqz calculates the frequency response (Fourier transform) of an IIR filter (difference equation). Your function should operate the same way as the scipy function (except that you don't need to implement the plot functionality within freqz). You should test against scipy.signal.freqz(use the code in the picture to test), but your code cannot call scipy.signal.freqz. Do not copy the source for freqz. In particular, do not use a FFT. Compute the frequency response directly.

Write your own version of sig.freqz. Make sure to include a useful documentation string. Make sure your code passes the tests below In [1 import numpy as np import matplotlib.pyplot as plt import scipy.signal as sig import matplotlib as mpl 1 . r cParams ['figure . figs ize'] - %matplotlib inline (5,3) in [10]: de f my_freqz(b, 1, worn-None, whole-None): a = #replace vith your an sw er pasS Tests Make sure your code passes the tests below Do not change the tests. In [11 from collections import namedtuple Test namedtuple('Test',['b',"a', 'worN, 'whole']) testsTest([1,0.5,0.1], [1,1], 256, None), Test (1,1, None, True) Test (1,1,12, False), Test (1,2],1,[0,1,2,3], None) 1 b, a -sig.iirdesign (0.2, 0.3, 1, 20) tests.append (Test (b, a, None, None)) b = sig. f1rwin(63, 0.25) tests.append (Test (b,1,1024,None) ) for test in tests: w, hsig.freqz (test.b, test.a, test.worN, test.whole) mvw, mv h= mv freGZ (testb, test.a, test.worN, te st. whole) print (np.allclose(w, myw), np.allclose (h, myh)) Write your own version of sig.freqz. Make sure to include a useful documentation string. Make sure your code passes the tests below In [1 import numpy as np import matplotlib.pyplot as plt import scipy.signal as sig import matplotlib as mpl 1 . r cParams ['figure . figs ize'] - %matplotlib inline (5,3) in [10]: de f my_freqz(b, 1, worn-None, whole-None): a = #replace vith your an sw er pasS Tests Make sure your code passes the tests below Do not change the tests. In [11 from collections import namedtuple Test namedtuple('Test',['b',"a', 'worN, 'whole']) testsTest([1,0.5,0.1], [1,1], 256, None), Test (1,1, None, True) Test (1,1,12, False), Test (1,2],1,[0,1,2,3], None) 1 b, a -sig.iirdesign (0.2, 0.3, 1, 20) tests.append (Test (b, a, None, None)) b = sig. f1rwin(63, 0.25) tests.append (Test (b,1,1024,None) ) for test in tests: w, hsig.freqz (test.b, test.a, test.worN, test.whole) mvw, mv h= mv freGZ (testb, test.a, test.worN, te st. whole) print (np.allclose(w, myw), np.allclose (h, myh))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
