Skip to content

Fix impuse response, input data only contains one input[0]==1 in each trace #1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions control/tests/timeresp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,32 @@ def test_discrete_time_impulse(self, tsystem):
sysdt = sys.sample(dt, 'impulse')
np.testing.assert_array_almost_equal(impulse_response(sys, t)[1],
impulse_response(sysdt, t)[1])

def test_discrete_time_impulse_input(self):
# discrete time impulse input, Only one active input for each trace
A = [[.5, 0.25],[.0, .5]]
B = [[1., 0,],[0., 1.]]
C = [[1., 0.],[0., 1.]]
D = [[0., 0.],[0., 0.]]
dt = True
sysd = ct.ss(A,B,C,D, dt=dt)
response = ct.impulse_response(sysd,T=dt*3)

Uexpected = np.zeros((2,2,4), dtype=float).astype(object)
Uexpected[0,0,0] = 1./dt
Uexpected[1,1,0] = 1./dt

np.testing.assert_array_equal(response.inputs,Uexpected)

dt = 0.5
sysd = ct.ss(A,B,C,D, dt=dt)
response = ct.impulse_response(sysd,T=dt*3)

Uexpected = np.zeros((2,2,4), dtype=float).astype(object)
Uexpected[0,0,0] = 1./dt
Uexpected[1,1,0] = 1./dt

np.testing.assert_array_equal(response.inputs,Uexpected)

@pytest.mark.parametrize("tsystem", ["siso_ss1"], indirect=True)
def test_impulse_response_warnD(self, tsystem):
Expand Down
2 changes: 1 addition & 1 deletion control/timeresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ def impulse_response(sys, T=None, input=None, output=None, T_num=None,
yout[:, inpidx, :] = response.y if output is None \
else response.y[output]
xout[:, inpidx, :] = response.x
uout[:, inpidx, :] = U[i]
uout[:, inpidx, :] = U if input is None else U[i]

# Figure out if the system is SISO or not
issiso = sys.issiso() or (input is not None and output is not None)
Expand Down
Loading