0
$\begingroup$

The problem I'm trying to solve is described here.

In my script, I used Euler's identity to calculate z^-n, such that z^-n = cos(omegan) - jsin(omegan). I find the magnitude of these values from a range of 0 to pi, and then plot them. However, the resulting graph aperiodically oscillates between 0 and ~ -8 dB, and I'm honestly not sure why.

I'd appreciate any help! The code is as follows:

import math 
import matplotlib.pyplot as plt

# define constants 
b0 = .125 a1 = .875 x = [] total = 0

while total <= math.pi: x.append(total) total += math.pi/256

return the magnitude of z-n

def find_z(n, omega):

# z = re^jw # e^jw = cos(w) + jsin(w) # z^-n = cos(wn) - jsin(wn) 
ret = abs(math.cos(omega * n) - (1j * math.sin(omega * n))) return ret

h = [] 
for i in x: h.append(b0 / (1 - (a1 * find_z(-1, i))))

for i in range(len(h)): h[i] = 20 * math.log10(h[i])  plt.plot(x, h, color='blue', marker='o', linestyle='-',  linewidth=2, markersize=12) 
plt.xscale("log") fig = plt.figure(figsize=(12, 6)) plt.show()

print(h)
$\endgroup$
  • $\begingroup$ Did you notice the 1e-15 on your vertical axis? $\endgroup$ – Dan Boschen Dec 7 '19 at 12:26
  • $\begingroup$ Looks like you are doing everything just fine- you haven’t solved for your frequency response yet but I assume you were just plotting the unit circle first to confirm your processing results in a 0 dB response- which it does; pay attention to that scaling indicated on the vertical axis in your graph $\endgroup$ – Dan Boschen Dec 7 '19 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.