CPCLAB-UNIPI / SIPPY

Systems Identification Package for PYthon
GNU Lesser General Public License v3.0
269 stars 92 forks source link

Subspace Methods Always Give Unstable Zero #16

Closed mzahana closed 4 years ago

mzahana commented 4 years ago

Hello. When I use subspace methods e.g. N4SID, I always get a model with unstable zero(s) for the I/O data provided for identification. The accuracy I get compared with actual data is great e.g. 95% fit. However, the unstabl zero(s) doesn't not really represent the response of the actual system as it is not non-minimum phase. On the other hand, I don't get unstable zero(s) if I use the ARX or ARMAX methods. However, I get less accurate models that fit the provided I/O data.

Are there some settings in the subspace mehtods to avoid these unstable zero(s)?

Cheers.

CPCLAB-UNIPI commented 4 years ago

Dear mzahana, when opening a new issue, in order for us to be able to find a solution for the proposed problem, a full example of the code is needed. Please consider to give all the information needed to run the code so that we can test it. Answering to an example-specific question like this it is not possible without looking at the example itself. Please consider it for this issue and others you may open.

Looking forward to find the best solution to your problem.

Thanks for your interest in SIPPY.

mzahana commented 4 years ago

Thanks @CPCLAB-UNIPI for your reply. I have attached a csv file of I/O data. Please use the u and y columns as input and output data, respectively.

I used the following SIPPY commands for identification.

sys_id_roll_tf = system_identification(y u, 'ARMAX', ARMAX_orders=[2,1,1,0],ARMAX_max_iterations=300, tsample=0.001)

and

sys_id_roll = system_identification(y, u, 'N4SID', SS_fixed_order=2, SS_p=50, SS_f=50, tsample=0.001, SS_A_stability=True)

I used the following range from data [10000:20000]

With that, I get unstable zero with subspace method N4SID, but not with ARMAX. However ARMAX gives less accurate fitting.

Please let me know if you require more information.

Thanks.

sysid.csv.zip

fpelagagge commented 4 years ago

Dear Mohamed ,

Thanks for the code example and the associated data.

First of all, the algorithm does not have a way to force stability of the zeros.

We have analyzed your case example and we can make the following observations.

  1. What is the settling time of the system? Apparently, it is of the order of seconds. If so, your I/O data appear be oversampled. Consider to make a new data collection with dt = 0.01 or even larger (0.05).

  2. With a small tsample/tsettiling ratio, SS_p=50 and SS_f=50 could be too short. (For example with SS_p = 250 or 500 the State-Space identified model has no unstable zero).

  3. The periods with constant I/O data are strange, consider to check if there have been no problems with saving.

  4. Note that the Transfer Funcion conversion of a StateSpace model provide an order of the equivalent ARMAX of "na=nb=nc" equal to "SS_fixed_order".

I hope this helps, thanks you, best regards

mzahana commented 4 years ago

Thank you so much @fpelagagge for your detailed answer. Maybe I should give a brief about the problem to help make things clear. The I/O data come from log file from a flight controller (autopilot, namely PX4 ) which is installed on an drone. I am using this data to do system identification for further PID controller tuning. The PID loops are already implemented on the autopilot, and I just need to do optimal tuning of the PID gains as much as possible. So, I am doing system identification and then tuning a PID for the identified model in hope that the linear model captures good enough dynamics of the system.

The input and output data are logged differently, but almost at the same rate which is 250Hz. I do some pre-processing to the data as follows.

  1. The I/O data sizes are not exactly the same, but very very close. So, first I make them of equal. length
  2. I resample (upsample) the data at 1ms=1KHz, and use interpolation between points
  3. I smooth the data by doing some rolling window averaging to remove the bias
  4. I also use portion of the resulting data for system identification as it can be very large.

The data I provided to you is the result of the previous steps. The data I provided correspond to roll rate loop (input is the roll rate, and output is the measured roll speed). Such dynamics are relatively fast and I don't expect the settling time to be in seconds. Maybe 1 second max! most likely less than that as the drone is not really huge.

I hope this clarifies the problem a bit. If you require original data, please let me know.

Thanks!

CPCLAB-UNIPI commented 4 years ago

Dear Mohamed,

thank you very much for these detailed clarifications.

We believe that problems arise with your pre-processing procedure, as re-sampling is highly unrecommended, since it may significantly alter system identification results. Please consider to re-try identification with a revised procedure, best without your point 2.

If no other clarifications are needed, we may consider this issue closed. Best regards.

mzahana commented 4 years ago

Thanks for your help.Closing the issue for now.

nrgopalrao commented 4 years ago

Hi @mzahana

Could you kindly tell me if the identification worked without resampling? My problem is very similar to yours where the sys response, from the sys iden matrix using N4SID, is completely off at t=0 but then it fits the data well from t=1 even if i don't resample my data. Thank you

mzahana commented 4 years ago

@nrgopalrao Not really. It really depends on your data and how well it capture your system dynamics.