-
Notifications
You must be signed in to change notification settings - Fork 438
fitfrd function #550
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
Comments
That functionality is not currently present, but it looks like it is implemented in the SLICOT SB10YD function, so it would be relatively easy to add. If you have some time and want to work on this, that would be great! Otherwise, we can mark this as "help wanted" and see if anyone has time to work on it. |
Thank you very much for your reply! I will follow your advice to try to implenment the fitfrd function. If I succeed, I am happy to share my results. Before that, friends who can work on it are welcome. |
Sorry for bother again. When I implenment the fitfrd function, using the control.freqresp function, it said i should use an interpolating FRD if I want additional points. But it doesn't show how to change the norm frd to interpolating FRD. I checked the document and there is no relevant explanation. |
Looking at the code, it looks like if you create the FRD object using |
I import the slycot package. In the dir of slycot, I can't find the SB10YD function. It's so kind to tell me how can find the SB10YD function. |
You'll likely need to write a wrapper around |
Hi, I find the sb10yd.f in slycot repository, and try to write a wrapper around SB10YD. |
I think that is all that is required. But I've not written slycot wrappers before, so you may need to open an issue in that repository to get an answer. |
Many thanks for your reply. |
I replied to python-control/Slycot#153 just before reading this thread. Please feel free to make an attempt and we can guide you along. The wrappers for SB functions should go into synthesis.pyf and synthesis.py. |
Hellow, when I use the control.freqresp function it gives me three output (mag, phase and omega). But the freqresp funciton in matlab only one output in plural form. If there has function that I can transfer the frequency response output form ? |
The following will work:
|
My understanding is that you calculated the response from a state space object. When I run the code, the error message is displayed: TypeError:'StateSpace' object is not callable. |
What version are you running? This should work in the latest release (0.8.4). In that release and later, all LTI systems are callable and return the value of the transfer function. |
My control version is 0.8.4. It also shows TypeError: 'StateSpace' object is not callable. |
Oops. I was wrong: this is something that will be in version 0.9.0, which we will release in about a week. I checked and the |
Correction to my prior note about |
Hi, Matlab implements the
|
And I have another question. When I use the tf to create a transfer function system and then use the ss create a state space system. Compared with matlab, the control results are different. matlab ——
control —— result
A = [[-1.09275252e+00 8.45135768e-01 1.60749491e+00 -3.50284601e-01
5.26406269e-01 2.78501895e-01]
[ 1.00000000e+00 -1.88597374e-17 4.11457136e-16 9.42161929e-16
-5.25031488e-17 2.81947516e-16]
[ 0.00000000e+00 1.00000000e+00 -6.29307309e-17 4.71371808e-16
7.54550775e-16 8.18501034e-17]
[ 0.00000000e+00 0.00000000e+00 -1.00000000e+00 8.37026245e-16
-5.02862888e-16 9.14800774e-16]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00
1.43285427e-16 5.61733088e-16]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
1.00000000e+00 -5.55111512e-16]]
B = [[1.]
[0.]
[0.]
[0.]
[0.]
[0.]]
C = [[ 0.03369084 0.03331414 0.01999275 0.04343376 0.056765 -0.00086861]]
D = [[0.08511411]] which n,d is the same as matlab. |
State space realizations of transfer functions are not unique. |
You could Implement You would also have to make a distinction (and document!) between what MATLAB does for |
Thank you very much for your advise, it solved my problem very well. Another problem trapped me. When I use the hinfsyn function, the internal command runs to sb10ad (out = sb10ad(n, m, np_, ncon, nmeas, gamma, P.A, P.B, P.C, P.D)), debugging cannot be performed, the console does not display content, and there is no error message. using command control.hinfsyn(P,1,1). |
When it comes to usage, independent of implementing a
--> #597 |
Slycot has a SB10YD interface thanks to python-control/Slycot#203, released as part of Slycot v0.6.0. |
here's a naive first go at fitfrd: import control as ct
from slycot import sb10yd
def fitfrd(gfrd, n, *, tol=0, minphase=False):
discfl = 0
flag = int(minphase) #
rfrdat = gfrd.fresp[0,0].real
ifrdat = gfrd.fresp[0,0].imag
omega = gfrd.omega
lendat = len(gfrd.omega)
print(discfl, flag, lendat, rfrdat, ifrdat, omega, n, tol)
nout, a, b, c, d = sb10yd(discfl, flag, lendat, rfrdat, ifrdat, omega, n, tol)
if nout != n:
# really raise a warning; can't trigger this
raise ValueError(f"asked for order {n}, got {nout}")
return ct.ss(a, b, c, d) With this fourth-order system with a notch, it doesn't do too badly. SB10YD (or our interface?) doesn't handle DC gain < 0. I also couldn't easily get non-minimum-phase results. I'm also not sure how to trigger nout != n.
|
Returns
-------
n : int
The order of the obtained system. The value of n
could only be modified if n > 0 and flag = 1. So basically only for a minimal phase system n can be chosen.
You can also compare the behavior with which also uses sb10yd. |
Good idea, thanks. I installed Octave 9.2.0 and octave-control 4.0.1, and it has much the same behaviour, i.e., low-frequency gain assumed to be positive. (One could test 1/s vs -1/s, 1/s^2 vs -1/s^2, etc., but I think this is sufficient to demonstrate the issue.)
whoops, edit to add the script:
|
Hi,
I am a student in learning speech signal processing. The control package helps me a lot. When I use python to reproduce a function, a problem bothers me for a long time.
I want to ask if there is a function can fit frequency response data with state-space model in python-control, which is similar to the fitfrd function in matlab. It would be too kind if you can provide some direction.
Sincerely.
The text was updated successfully, but these errors were encountered: