Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON: The scipy library of matplotlib in Python 3 contains a function scipy.signal.freqz which computes the frequency response of a digital filter. I am

IN PYTHON:

The scipy library of matplotlib in Python 3 contains a function "scipy.signal.freqz" which computes the frequency response of a digital filter. I am trying to write my own version of this function, to relay the same output as this imbedded function. I plan to use the inputs: freqz(b, a = 1, worN=None, whole=None): [b=numerator of linear filter; a=denominator of linear filter; worN=at none, compute at 512 frequencies equally spaced around the unit circle; whole=at none, frequency computed around upper half of unit circle, from 0 to pi]. This function should output two outputs: w and h

After implementing the function, it should pass all the tests provided in the last part of code. Need to implement scipy.signal.freqz using different ways other than source code and FFT.

DON'T USE FFT FUNCTIONimage text in transcribed

I am going to provide the code that I am given. Supposed to translate the equation into code.

Code:

import numpy as np import matplotlib.pyplot as plt import scipy.signal as sig import matplotlib as mpl mpl.rcParams['figure.figsize'] = (5,3) %matplotlib inline

# Implementation of freqz using different way.

Please use the same variables

def my_freqz(b, a = 1, worN=None, whole=None): #replace with your answer pass

Testing code:

from collections import namedtuple Test = namedtuple('Test',['b','a','worN','whole']) tests = [ Test([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) ]

b,a = sig.iirdesign(0.2, 0.3, 1, 20) tests.append(Test(b,a,None,None))

b = sig.firwin(63, 0.25) tests.append(Test(b,1,1024,None))

for test in tests: w, h = sig.freqz(test.b, test.a, test.worN, test.whole) my_w, my_h = my_freqz(test.b, test.a, test.worN, test.whole) print(np.allclose(w, my_w), np.allclose(h, my_h))

Tests should output TRUE for all.

Output should look like

True True

True True

True True

True True

jll jw jwM h(e )= -= jw jwN jll A(eala[1]e + a[N]e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

What internal control objectives are met by physical controls?

Answered: 1 week ago

Question

What are the benefits from equipping their riders with PDAs?

Answered: 1 week ago

Question

=+1 Why are local employment laws important to IHRM?

Answered: 1 week ago

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago