I have written a code which takes a vector as input (impulse) and should return another vector (impulse response).
import numpy as np
from scipy import signal
y = signal.unit_impulse(8)
def response(y):
for i in range(8):
g = np.zeros(len(y))
g[i] = 3 * y[i] -2 * y[i - 1] + 2 * y[i -2]
return g
print(g)
The signal.unit_impulse(8) creates a vector with 8 digits, where the first one is 1 and the rest are zero. When I run this, I get NameError: name 'g' is not defined. Within the function logic I receive a notification Local variable 'g' might be referenced before assignment. I think these two statements are related somehow. How can I fix this?