CPCLAB-UNIPI / SIPPY

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

tsample Not Affecting Identification Result #14

Closed mzahana closed 4 years ago

mzahana commented 4 years ago

Hi.

I am trying to get a discrete model using N4SID with input/output data from a real system. The sampling time is 0.001. However, whether I set the tsample parameter to that value or not, I get the same identified system. Is this normal, or the resulting matrices (A, B, ...) should be different for different tsample? Thanks

gpannocchia commented 4 years ago

Please supply an example code that explains the problem. Thank you.

On 19 Nov 2019, at 21:35, Mohamed Abdelkader Zahana notifications@github.com wrote:

Hi.

I am trying to get a discrete model using N4SID with input/output data from a real system. The sampling time is 0.001. However, whether I set the tsample parameter to that value or not, I get the same identified system. Is this normal, or the resulting matrices (A, B, ...) should be different for different tsample? Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CPCLAB-UNIPI/SIPPY/issues/14?email_source=notifications&email_token=AATL7GXVMQUNFZ6SZDUY64TQUREZZA5CNFSM4JPJBCP2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4H2OWLLA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATL7GTAX7NWOUDE6Q5RMI3QUREZZANCNFSM4JPJBCPQ.

mzahana commented 4 years ago

Thank you for your response. Here are two example codes for two different tsamples

tsample=0.001

method = 'N4SID'
sys_id_roll = system_identification(y_debiased, u_debiased, method, SS_fixed_order=2, SS_p=150, SS_f=150, tsample=0.001,centering='MeanVal', SS_A_stability=True)
print("A",sys_id_roll.A)
print("B",sys_id_roll.B)
print("C",sys_id_roll.C)
print("D",sys_id_roll.D)
print("Sampling time", sys_id_roll.ts)

the result is

('A', array([[ 1.00371294, -0.01182933],
       [ 0.00383558,  0.99355665]]))
('B', array([[-0.12127474],
       [ 0.04202324]]))
('C', array([[-0.80885037, -0.51574664]]))
('D', array([[0.]]))
('Sampling time', 0.001)

tsample=1.0

method = 'N4SID'
sys_id_roll = system_identification(y_debiased, u_debiased, method, SS_fixed_order=2, SS_p=150, SS_f=150, tsample=1.0,centering='MeanVal', SS_A_stability=True)
print("A",sys_id_roll.A)
print("B",sys_id_roll.B)
print("C",sys_id_roll.C)
print("D",sys_id_roll.D)
print("Sampling time", sys_id_roll.ts)
('A', array([[ 1.00371294, -0.01182933],
       [ 0.00383558,  0.99355665]]))
('B', array([[-0.12127474],
       [ 0.04202324]]))
('C', array([[-0.80885037, -0.51574664]]))
('D', array([[0.]]))
('Sampling time', 1.0)

As you can see, setting tsample does not seem to affect the identified system matrices (A,B,C,D). Is this normal? Cheers

mzahana commented 4 years ago

Sorry. Was closed by mistake.

gpannocchia commented 4 years ago

Thanks for the code sample.

This is not a bug. If you supply the same (Y, U) discrete-time data, you will necessarily get the same discrete-time model by any identification method. The argument 'tsample=0.001’ that is supplied to the call is only used at the end to append the sample time to the identified discrete-time model.

If you want to identify data at tsample=1, you need to do one of the following: 1) supply discrete-time data at tsample=1 or 2) a) use the discrete-time data at tsample=0.001 and identify the discrete-time model with such tsample=0.001 b) convert the identified model in continuous-time (e.g. using python control function c2d) c) sample the continuous-time system at the new tsample=1.

Method 2 is usually less accurate.

Best regards,

On 20 Nov 2019, at 05:29, Mohamed Abdelkader Zahana notifications@github.com wrote:

Thank you for your response. Here are two example codes for two different tsamples

tsample=0.001

method = 'N4SID' sys_id_roll = system_identification(y_debiased, u_debiased, method, SS_fixed_order=2, SS_p=150, SS_f=150, tsample=0.001,centering='MeanVal', SS_A_stability=True) print("A",sys_id_roll.A) print("B",sys_id_roll.B) print("C",sys_id_roll.C) print("D",sys_id_roll.D) print("Sampling time", sys_id_roll.ts) the result is

('A', array([[ 1.00371294, -0.01182933], [ 0.00383558, 0.99355665]])) ('B', array([[-0.12127474], [ 0.04202324]])) ('C', array([[-0.80885037, -0.51574664]])) ('D', array([[0.]])) ('Sampling time', 0.001) tsample=1.0

method = 'N4SID' sys_id_roll = system_identification(y_debiased, u_debiased, method, SS_fixed_order=2, SS_p=150, SS_f=150, tsample=1.0,centering='MeanVal', SS_A_stability=True) print("A",sys_id_roll.A) print("B",sys_id_roll.B) print("C",sys_id_roll.C) print("D",sys_id_roll.D) print("Sampling time", sys_id_roll.ts) ('A', array([[ 1.00371294, -0.01182933], [ 0.00383558, 0.99355665]])) ('B', array([[-0.12127474], [ 0.04202324]])) ('C', array([[-0.80885037, -0.51574664]])) ('D', array([[0.]])) ('Sampling time', 1.0) Cheers

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/CPCLAB-UNIPI/SIPPY/issues/14?email_source=notifications&email_token=AATL7GQJGJMAA5TQPOMIAF3QUS4KXA5CNFSM4JPJBCP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEQVJUY#issuecomment-555832531, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATL7GQDYRQUQ6CWE6S6FGLQUS4KXANCNFSM4JPJBCPQ.

mzahana commented 4 years ago

Thanks @gpannocchia for the explanation.