0
import control
import numpy as np
import matplotlib.pyplot as plt
Ts = 1
G1 = control.tf([60], [1,0.1])
G2 = control.tf([0.5, 3], [1, 5, 12])
G3 = control.tf([1], [1, 5])
Gs= G1*G2*G3
Gz = control.c2d(Gs,Ts, method='tustin' )

print(Gz)
print(Gs)

cltf=(Gs/(1+Gs))
Zcltf=(Gz/(1+Gz))

T = np.arange(0, 15)
za = control.step_response(cltf, T)
Tout, y = control.step_response(cltf, T)
Tout, x = control.step_response(Zcltf, T) 

plt.subplot(2,1,1)
plt.plot(Tout, y)
plt.subpolt(2,1,2)
plt.plot(Tout,y.Tout)

Hello everyone, this is my code. I am new to Python. And my step responses always look like this:This Graph

In Matlab I got those for the two step responses Like those

I couldn't figured it out what is the reason of it.

Klaromin
  • 1
  • 1

1 Answers1

1

the time vector T need more points, if you do not put step use de default value. You can try whiht T = np.arange(0, 15,0.1).

on the other hand, if you dont use T in the function step_response calculate a time vector, but have some problems with some plants, for example, stiff plants.

try this:

Tout, y = control.step_response(cltf)

finaly, you never plot x (the digital step output), you can try use plt.step() in place of plt.plot() to stairs plot.

import control
import numpy as np
import matplotlib.pyplot as plt
Ts = 1
G1 = control.tf([60], [1,0.1])
G2 = control.tf([0.5, 3], [1, 5, 12])
G3 = control.tf([1], [1, 5])
Gs= G1*G2*G3
Gz = control.c2d(Gs,Ts, method='tustin' )

print(Gz)
print(Gs)

cltf=(Gs/(1+Gs))
Zcltf=(Gz/(1+Gz))

Tout1, y = control.step_response(cltf)
Tout2, x = control.step_response(Zcltf) 


plt.plot(Tout1, y)
plt.figure()
plt.step(Tout2,x)

steps plots

phoenixstudio
  • 1,776
  • 1
  • 14
  • 19