100% found this document useful (1 vote)
25 views

Python Programming Homework Help

The document discusses Python programming homework help and provides examples of signals and systems, object oriented programming, state machines, and difference equations.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
25 views

Python Programming Homework Help

The document discusses Python programming homework help and provides examples of signals and systems, object oriented programming, state machines, and difference equations.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

For any Assignment related queries, Call us at : -  

+1 678 648 4277


You can mail us at :- [email protected] or
reach us at :- https://www.pythonhomeworkhelp.com/

Python Programming Homework Help


1 OOP
The following definitions have been entered into the Python shell:

class F:
x = 0
y = 10
def i n i t ( s e l f , y ):
self.x = y
def a1(self, y):
self.x = max(self.x, y)
return se lf.x
def a2(self):
self.x = max(self.x, sel f.y)
return sel f.x
class G(F):
def b(self):
self.y = sel f.x * self.x
return self.y

Write the values of the following expressions (enter None when there is
no value; write Error when an error results and explain briefly why
it’s an error). Assume these expressions are evalu ated one after the
other (in each column).
2 Signals
Given a signal x, we want to construct a signal y such that:

y[n] = a*x[n-1] + (1-a)*x[n-2]

for 0 � a � 1.
Part a. Define a Signal subclass that represents this signal, given an
instance of the Signal class representing x and the value of a.
Construct the new signal, given a signal instance x, and a variable a,
as follows:
y = MySig(x, a)

Do not use any of the existing Signal subclasses, such as Rn or


PolyR.

class
MySig(sig.Signal):
def init (self, x, a):
self.x = x
self.a = a
def
sample(self,
Part b.n):
Given a signal instance x, and a variable a, write an expression
return
involving sig.PolyR that constructs an equivalent signal. To construct a
self.a*self.x.
polynomial use poly.Polynomial.
sample(n-1)
+ (1- poly.Polynomial([1-a, a, 0]))
sig.PolyR(x,
self.a)*self.x
Part c. .sample(n-2)
Write a Python procedure settleTime that is given:

• s: an instance of the Signal class;


• m: an integer, representing the max index to look at;
• bounds: a tuple of two values ( l o , hi).
It returns an integer or None. The integer corresponds to the smallest
sample index (w) such that the sample at index w and all the samples
from w up to m are between l o and hi (less than or equal to hi and
greater or equal to lo). It returns None if no such sample exists.
def settleTime(s, m,
bounds): (lo,hi)=bounds
def inBounds(x):
return x>=lo and
x<=hi w = 0
for i in range(m):
if not
inBounds(s.sample(i)):
w = i+1
if w == m: return None
else: return w
3 State Machines
Write a state machine whose inputs are the characters of a string of
“words” separated by spaces. For each input character, the machine
should:
• output the string ’ x ’ if the character is within a word, or
• if the input character is a space, then
—output the most recent word if the most recent word is a number
(all numerical digits), or
—output None if the most recent input word is empty or contains any
non-digits.
Assume there is never more than one consecutive space. For example:
>>> x = ’ v1 11 1v ’
>>> FindNumbers().transduce(x)
[None, ’ x ’ , ’ x ’ , None, ’ x ’ , ’ x ’ , ’11’, ’ x ’ , ’ x ’ , None]

Do not add any instance attributes to the state machines.


If foo is a single-character or multi-character string, the Python
method f o o . i s d i g i t ( ) returns
True if there is at least one character in foo and all of the characters
in foo are all digits.

class
FindNumbers(sm.SM
): startState = ’’
def getNextValues(self,
state, inp): if inp == ’ ’:
if state.isdigit():
return (’’, state)
else:
return (’’, None)
else:
return
(state+inp, ’x’)
4 Difference Equations
Newton’s law of cooling states that:
The change in an object’s temperature from one time step to the next
is proportional to the dif­ ference (on the earlier step) between the
temperature of the object and the temperature of the environment, as
well as to the length of the time step.
Let

• o[n] be temperature of object


• s[n] be temperature of environment
• T be the duration of a time step
• K be the constant of proportionality
Part a. Write a difference equation for Newton’s law of cooling. Be
sure the signs are such that the temperature of the object will
eventually equilibrate with that of the environment.

o[n] = o[n − 1] + TK(s[n − 1] − o[n − 1])

Part b. Write the system function corresponding to this equation


(show your work):
5 Signals and Systems

Consider the following system:

Part a. Write the system function:

Part b. Let k1 = 1 and k2 = −2. Assume that the system starts “at rest” (all
signals are zero) and that th input signal X is the unit sample signal.
Determine y[0] through y[3].
Part c. Let k1 = 1 and k2 = −2, determine the poles
of H.
Enter poles or none if there are poles: 2, -2 no

Part d. For each of the systems below indicate whether the system is
equivalent to this one: (Remember that there can be multiple
“equivalent” representations for a system.) If you write clearly the
system function for these systems, we may be able to give you partial
credit.

Equivalent to H (yes/no)? No

Equivalent to H (yes/no)? Yes


Equivalent to H (yes/no)? Yes

Equivalent to H (yes/no)? No

6 System Behaviors
Part a. Find the poles for the following
system functions:

0. Poles: 5 ± 0.5j

Poles: 0.5, −0.1

Consider the following poles:

>>> H1.poles() = [-1.0, -0.5]


>>> H2.poles() = [(0.375+0.330j), (0.375-
0.330j)]
>>> H3.poles() = [(0.05+0.234j), (0.05-
0.234j)]
>>> H4.poles() = [1.2, -0.5]
Part b. Deleted
Part c. Which (if any) of the poles lead to the following unit
sample response?

Circle all correct answers(s):


H1 H2 H3 H4 none

Part d. Which (if any) of the poles lead to the following unit sample
response?

Circle all correct answers(s): H1


H 2 H 3H 4 none
Part e. Which (if any) of the poles lead to convergent unit-sample
responses?

Circle all correct answers(s): H1 H2 H3 H4 none

You might also like