-
Notifications
You must be signed in to change notification settings - Fork 438
Implement ERA, change api to TimeResponseData #1024
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
+277
−23
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cd87f2f
Implement ERA, change api to TimeResponseData
KybernetikJo 8a9c497
Add era example
KybernetikJo 562824c
Rename era example file name, small clean up
KybernetikJo 6bbad5f
Add era example to doc
KybernetikJo 614a080
Change API to work with TimeResponseData and ndarray as input, add py…
KybernetikJo 250c448
Fix few docstring things, change name to eigensys_realization
KybernetikJo 6c73062
Change _block_hankel to top-level, update docstrings and comments
KybernetikJo 8b93264
Delete the hyphen from the Impuse response.
KybernetikJo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../examples/era_msd.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ERA example, mass spring damper system | ||
-------------------------------------- | ||
|
||
Code | ||
.... | ||
.. literalinclude:: era_msd.py | ||
:language: python | ||
:linenos: | ||
|
||
|
||
Notes | ||
..... | ||
|
||
1. The environment variable `PYCONTROL_TEST_EXAMPLES` is used for | ||
testing to turn off plotting of the outputs.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# era_msd.py | ||
# Johannes Kaisinger, 4 July 2024 | ||
# | ||
# Demonstrate estimation of State Space model from impulse response. | ||
# SISO, SIMO, MISO, MIMO case | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import os | ||
|
||
import control as ct | ||
|
||
# set up a mass spring damper system (2dof, MIMO case) | ||
# Mechanical Vibrations: Theory and Application, SI Edition, 1st ed. | ||
# Figure 6.5 / Example 6.7 | ||
# m q_dd + c q_d + k q = f | ||
m1, k1, c1 = 1., 4., 1. | ||
m2, k2, c2 = 2., 2., 1. | ||
k3, c3 = 6., 2. | ||
|
||
A = np.array([ | ||
[0., 0., 1., 0.], | ||
[0., 0., 0., 1.], | ||
[-(k1+k2)/m1, (k2)/m1, -(c1+c2)/m1, c2/m1], | ||
[(k2)/m2, -(k2+k3)/m2, c2/m2, -(c2+c3)/m2] | ||
]) | ||
B = np.array([[0.,0.],[0.,0.],[1/m1,0.],[0.,1/m2]]) | ||
C = np.array([[1.0, 0.0, 0.0, 0.0],[0.0, 1.0, 0.0, 0.0]]) | ||
D = np.zeros((2,2)) | ||
|
||
xixo_list = ["SISO","SIMO","MISO","MIMO"] | ||
xixo = xixo_list[3] # choose a system for estimation | ||
match xixo: | ||
case "SISO": | ||
sys = ct.StateSpace(A, B[:,0], C[0,:], D[0,0]) | ||
case "SIMO": | ||
sys = ct.StateSpace(A, B[:,:1], C, D[:,:1]) | ||
case "MISO": | ||
sys = ct.StateSpace(A, B, C[:1,:], D[:1,:]) | ||
case "MIMO": | ||
sys = ct.StateSpace(A, B, C, D) | ||
|
||
|
||
dt = 0.1 | ||
sysd = sys.sample(dt, method='zoh') | ||
response = ct.impulse_response(sysd) | ||
response.plot() | ||
plt.show() | ||
|
||
sysd_est, _ = ct.eigensys_realization(response,r=4,dt=dt) | ||
|
||
step_true = ct.step_response(sysd) | ||
step_true.sysname="H_true" | ||
step_est = ct.step_response(sysd_est) | ||
step_est.sysname="H_est" | ||
|
||
step_true.plot(title=xixo) | ||
step_est.plot(color='orange',linestyle='dashed') | ||
|
||
plt.show() | ||
|
||
if 'PYCONTROL_TEST_EXAMPLES' not in os.environ: | ||
plt.show() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this, is there an alternative interface with a
minsigma
argument which could be used to choose r based on the singular values instead? (or maybe tol, with minsigma = tol * maxsigma ?)This probably a bit out-of-scope, and if the user needs this capability it is simple enough to implement in their own code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have thought about it, but I will not be adding this feature at this time.
I don't know the literature on this topic well enough, but I know that there are papers that study the choice of r.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postponed. Possible improvement in the future.