def plotPolesAndZeros(tf): num = [tf[0], tf[1], tf[2]] den = [tf[3], tf[4], tf[5]] sistema = cl.TransferFunction(num, den) cl.pzmap(sistema, Plot=True) plt.show() return
def plot_zpk_from_H(H, title=None, w0=1): control.pzmap(H, Plot=True, title=title) theta = np.linspace(0, 2*np.pi, 100) r = w0 x1 = r*np.cos(theta) x2 = r*np.sin(theta) plt.plot(x1, x2, 'r', label=r'$\Omega _0$ = {}'.format(w0)) plt.legend(fancybox=True, framealpha=1, shadow=True, borderpad=1, fontsize='x-large', bbox_to_anchor=(1, 1)) plt.grid() plt.tight_layout()
def locate_poles(): """ Finds location of a system's zeros and poles """ n1 = np.array([1, 1]) n2 = np.array([1, 2]) d1 = np.array([1, 2j]) d2 = np.array([1, -2j]) d3 = np.array([1, 3]) numerator_g, denominator_g = np.array([6, 0, 1]), np.array([1, 3, 3, 1]) sys_g = ct.tf(numerator_g, denominator_g) zeros_g = ct.zero(sys_g) pole_g = ct.pole(sys_g) numerator_h = np.convolve(n1, n2) denominator_h = np.convolve(d1, np.convolve(d2, d3)) sys_h = ct.tf(numerator_h, denominator_h) sys_tf = sys_g / sys_h pzmap_sys = ct.pzmap(sys_tf) print(AsciiTable([['Poles and Zeros']]).table) data = [['Function', 'Result Ouput'], ['G(s)', sys_g], ['Zeros(g)', zeros_g], ['Pole(g)', pole_g], ['H(s)', sys_h], ['T(s)', sys_tf], ['Pzmap(s)', pzmap_sys]] print(AsciiTable(data).table)
def pzmap(W): f = con.pzmap(W) plt.title("Расположение полюсов на комплексной плоскости") plt.grid(True) plt.show() g = f[0] # возвращает список всех полюсов - корней знаменателя D = True j = 0 G = False while D and j < len(g): r = g[j].real if float(r) <= 0.000000: # print("Левый корень = " + str(r)) D = True if float(r) == 0.0: G = True else: D = False print("Первый правый корень = " + str(r)) j = j + 1 if D and G: print("Система на границе устойчивости, есть нулевые корни") elif D: print("Система устойчива, все корни левые") else: print("Cистема не устойчива, есть хотя бы один правый корень")
def TranformadaZ(titutlo,num,den): h1 = control.TransferFunction(num,den) [zeros,poles,gain] = signal.tf2zpk(num,den) print(titutlo) print("zeros") print(zeros) print("polos ") print(poles) print("\n") control.pzmap(h1, Plot=True, grid=False, title=titutlo) [t,y] = signal.impulse( (num,den) ) plt.figure() plt.suptitle(titutlo) plt.plot(t, y) plt.title('Respuesta al impulso')
def dpzmap(sys, title): """Plot poles and zeroes of discrete system. Keyword arguments: sys -- the system to plot title -- the title of the plot """ cnt.pzmap(sys, title=title) circle = plt.Circle((0, 0), radius=1, fill=False) ax = plt.gca() ax.add_artist(circle) plt.xlim([-1, 1]) plt.ylim([-1, 1]) x0, x1 = ax.get_xlim() y0, y1 = ax.get_ylim() ax.set_aspect(abs(x1 - x0) / abs(y1 - y0))
def test_pzmap(kwargs, setdefaults, dt, editsdefaults, mplcleanup): """Test pzmap""" # T from from pvtol-nested example T = TransferFunction([ -9.0250000e-01, -4.7200750e+01, -8.6812900e+02, +5.6261850e+03, +2.1258472e+05, +8.4724600e+05, +1.0192000e+06, +2.3520000e+05 ], [ 9.02500000e-03, 9.92862812e-01, 4.96974094e+01, 1.35705659e+03, 2.09294163e+04, 1.64898435e+05, 6.54572220e+05, 1.25274600e+06, 1.02420000e+06, 2.35200000e+05 ], dt) Pref = [ -23.8877 + 19.3837j, -23.8877 - 19.3837j, -23.8349 + 15.7846j, -23.8349 - 15.7846j, -5.2320 + 0.4117j, -5.2320 - 0.4117j, -2.2246 + 0.0000j, -1.5160 + 0.0000j, -0.3627 + 0.0000j ] Zref = [ -23.8877 + 19.3837j, -23.8877 - 19.3837j, +14.3637 + 0.0000j, -14.3637 + 0.0000j, -2.2246 + 0.0000j, -2.0000 + 0.0000j, -0.3000 + 0.0000j ] pzkwargs = kwargs.copy() if setdefaults: for k in ['plot', 'grid']: if k in pzkwargs: v = pzkwargs.pop(k) config.set_defaults('pzmap', **{k: v}) P, Z = pzmap(T, **pzkwargs) np.testing.assert_allclose(P, Pref, rtol=1e-3) np.testing.assert_allclose(Z, Zref, rtol=1e-3) if kwargs.get('plot', True): ax = plt.gca() assert ax.get_title() == kwargs.get('title', 'Pole Zero Map') # FIXME: This won't work when zgrid and sgrid are unified children = ax.get_children() has_zgrid = False for c in children: if isinstance(c, matplotlib.text.Annotation): if r'\pi' in c.get_text(): has_zgrid = True has_sgrid = isinstance(ax, mpltAxes) if kwargs.get('grid', False): assert dt == has_zgrid assert dt != has_sgrid else: assert not has_zgrid assert not has_sgrid else: assert not plt.get_fignums()
def question1(Gpr, plot=True): print(spacer + "Question 1" + spacer) # 1. POLES AND ZEROS poles = ct.pole(Gpr) zeros = ct.zero(Gpr) print("\t Poles of the system are {}, and zeroes are {}".format( poles, zeros)) # 2. PZ MAP H = 1 OLTF = Gpr * H plt.figure("Q1 - PZ map") ct.pzmap(OLTF) if plot: plt.show # 3. STABILITY stable = True for pole in poles: if (pole > 0): stable = False temp = "unstable" if (stable): temp = "stable" print("\t Since {} are the poles, the system is {}".format(poles, temp)) # 4. STEP RESPONSE t, c = ct.step_response(OLTF) end_value = c[c.size - 1] print("\t The end value of the OL step_response is {}".format(end_value)) plt.figure("Q1 - Step response") plt.plot(t, c) # plot asymptote x_coordinates = [t[0], t[t.size - 1]] y_coordinates = [end_value, end_value] plt.plot(x_coordinates, y_coordinates) if plot: plt.show() return OLTF
def grafic_pol(f, name): # x = cm.pole(f).real # y = cm.pole(f).imag # plt.plot(x, y) # plt.plot(cm.pole(f)) ctr.pzmap(f, Plot=True, title='Pole Zero Map {}'.format(name)) [p, z] = ctr.pzmap(f) # x = ctr.pzmap(f).real # y = ctr.pzmap(f).imag print("Полюса {}: \n".format(name)) print("p = {}".format(p)) print("z = {}".format(z)) # print("x ={} \n".format(x)) # print("y = {} \n".format(y)) # plt.title("График полюсов функции {}".format(name)) # plt.ylabel("Мниманя ось") # plt.xlabel("Действительная часть") # plt.grid(True) plt.show()
def multi_loop(): """ Gives the transfer funtion of multi-loop system Feedback[ R(s) -> (G1 - H2) -> G2 -> feedback(G3G4, H1) , H3]-> C(s) """ g1 = np.array([ [1], [1, 10]]) g2 = np.array([ [1], [1, 1]] ) g3 = np.array([ [1, 0, 1], [1, 4, 4] ]) g4 = np.array([ [1, 1], [1, 6] ]) h1 = np.array([ [1, 1], [1, 2] ]) h2 = np.array([[2], 1]) h3 = np.array([[1], 1]) sys_g1 = get_sys(g1, sys_name='tf') sys_g2 = get_sys(g2, 'tf') sys_g3 = get_sys(g3, 'tf') sys_g4 = get_sys(g4, 'tf') sysh1 = get_sys(h1, 'tf') sysh2 = get_sys(h2, 'tf') sysh3 = get_sys(h3, 'tf') td.ouput(title='Exercise One', keys=['G1', 'G2', 'G3', 'G4', 'H1', 'H2', 'H3'], values=[sys_g1, sys_g2, sys_g3, sys_g4, sysh1, sysh2, sysh3]) sys_t = ct.series(sys_g1 - sysh2, sys_g2) sys_t = ct.series(sys_t, ct.feedback( ct.series(sys_g3, sys_g4), sysh1, sign=1)) tS = ct.feedback(sys_t, sysh3) zeros, poles = ct.pzmap(tS, Plot=True, grid=True) show_plot(zeros, poles)
import control as co import matplotlib.pyplot as plt s = co.tf('s') g = (s + 1) / (s**3 + 6 * s - 5) plt.figure(1) siso = co.sisotool(g) plt.figure(2) co.pzmap(g) # control function k = 11 z = -1 cs = k * (s - z) """Δοκιμάζοντας τιμές για μηδενικά, προσθέτω μόνο ένα πραγματικό μηδενικό, άρα το cs θα έχει πολυώνυμο στο αριθμητή και 1 στον παρονομαστή""" # the controlled system g_feedback = co.feedback(co.series(g, cs), 1, sign=-1) print(g_feedback) # pole zero plot of the closed controlled system plt.figure(3) co.pzmap(g_feedback) plt.show()
plt.subplot(2, 1, 2) plt.semilogx(w / (2 * np.pi), np.unwrap(phasec) * 180 / np.pi, label='Continous') plt.semilogx(w / (2 * np.pi), np.unwrap(phased) * 180 / np.pi, '--', label='Discrete') plt.grid(which='major', linestyle='-', linewidth='0.5', color='gray') plt.grid(which='minor', linestyle=':', linewidth='0.5', color='gray') plt.xlabel('Frequency [Hz]') plt.ylabel('Phase [Deg]') # plt.title('Frequency Response - Comparison') plt.legend() con.pzmap(sysc, title='Cont System Laplace plane') con.pzmap(sysd, title='Discrete System Z plane') if sysd.isdtime(): cir_phase = np.linspace(0, 2 * np.pi, 500) plt.plot(np.real(np.exp(1j * cir_phase)), np.imag(np.exp(1j * cir_phase)), 'r--') plt.axis('equal') plt.figure() real, imag, freq = con.nyquist_plot(sysc) scale = K / 2 + 1 plt.axis([-scale, scale, -scale, scale]) plt.title('Nyquist plot discrete') # plt.figure()
# plot unit circle def Circle(x,y): return (x*x+y*y) plt.figure(1) xx=numpy.linspace(-2,2,400) yy=numpy.linspace(-2,2,400) [X,Y]=numpy.meshgrid(xx,yy) Z=Circle(X,Y) plt.contour(X,Y,Z,[1]) # zero / pole plot tf_bw = control.TransferFunction(b_bw, a_bw) control.pzmap(tf_bw) plt.show() # plot frequency response w, h = scipy.signal.freqz(b_bw, a_bw) plt.figure(2) plt.title('Butterworth Frequency Response') plt.plot(w, 20 * numpy.log10(abs(h)), 'b') plt.ylabel('Amplitude [dB]', color='b') plt.ylim(-450, 100) plt.xlabel('Frequency [rad/sample]') plt.show()
label='Freq response from z-plane') else: plt.plot(w / (2 * np.pi), freq_resp_dB[int(freq_resp_dB.size / 2):], label='Freq response from s-plane') plt.plot(w / (2 * np.pi), hf.db(mag), 'r--', label='Freq response from con.freqresp') plt.xlabel('Frequency [Hz]') plt.ylabel('Mag [dB]') plt.title('Comparing freq response from s/z plane to con.freqresp') plt.legend() # pole zero plot poles, zeros = con.pzmap(sys_und_tst) plt.axis('equal') print(f'ploes are {poles}') print(f'zeros are {zeros}') # plt.figure() # plt.grid() # plt.axis('equal') # if len(poles) > 0: # plt.plot(poles.real, poles.imag, 'bx') # if len(zeros) > 0: # plt.plot(zeros.real, zeros.imag, 'bo') if sys_und_tst.isdtime(): cir_phase = np.linspace(0, 2 * np.pi, nsamp_single)
#Encontrar la fucnion de transferencia #Usar signal.tf2zpk para encontrar polos y zeros de cada función #A num = [1, -3] den = [1, 4, 4] h1 = control.TransferFunction(num, den) [zeros, poles, gain] = signal.tf2zpk(num, den) print("h1") print("zeros") print(zeros) print("polos ") print(poles) print("\n") control.pzmap(h1, Plot=True, grid=False, title='H1') [t, y] = signal.impulse(([1, -3], [1, 4, 4])) plt.figure() plt.suptitle("H1") plt.subplot(211) plt.plot(t, y) plt.title('Respuesta al impulso') [t, y] = signal.step(([1, -3], [1, 4, 4])) plt.subplot(212) plt.plot(t, y) plt.title('Respuesta al escalon') #B num = [1] den = [1, 4, 4] h2 = control.TransferFunction(num, den)
den = np.array([1, 0, 0]) z, p, k = sig.tf2zpk(num, den) ww, hh = sig.freqz(num, den) print("Z =", z, "\n", "P =", p, "\n", "K =", k, "\n") ww, hh = sig.freqz(num, den) ww = ww / np.pi eps = np.finfo(float).eps plt.figure("Filtro FIR") ax1 = plt.subplot(2, 1, 1) ax1.set_title('Módulo') ax1.plot(ww, 20 * np.log10(abs(hh + eps))) ax1.set_xlabel('Frequencia normalizada') ax1.set_ylabel('Modulo [dB]') plt.grid() ax2 = plt.subplot(2, 1, 2) ax2.set_title('Fase') ax2.plot(ww, np.angle(hh)) ax2.set_xlabel('Frequencia normalizada') ax2.set_ylabel('[Rad]') plt.grid() plt.show() plt.tight_layout() tf = control.TransferFunction(num, den, 1) print(tf) control.pzmap(tf, Plot=True, title='Pole Zero Map', grid=True)
#if using termux import subprocess import shlex #end if p1 = 2 * np.pi * 1e4 p2 = 2 * np.pi * 1e5 H = 81 / (4 * 1e4) num = [1000] den = [(1 / (p1 * p2)), ((1 / p1) + (1 / p2)), (1000 * H + 1)] #den=[(1e-9), (11*1e-5), 3.025] sys = control.tf(num, den) pole, zero = control.pzmap(sys, Plot=False) print("Poles are :", pole) x = (pole.real) y = (pole.imag) plt.plot(x[0], y[0], marker="X") plt.plot(x[1], y[1], marker="X") plt.grid() plt.axhline(y=0, color='k') plt.axvline(x=0, color='k') plt.savefig('./figs/ee18btech11036/ee18btech11036_1.pdf') plt.savefig('./figs/ee18btech11036/ee18btech11036_1.eps') subprocess.run( shlex.split("termux-open ./figs/ee18btech11036/ee18btech11036_1.pdf")) #else #plt.show()
h1 = co.feedback(g1, 2, -1) h2 = co.feedback(g1, 3, -1) h3 = co.feedback(g1, 5, -1) print("poles (k=2)") for elem in co.pole(h1): print(f'{elem: .2f}') print("poles (k=3)") for elem in co.pole(h2): print(f'{elem: .2f}') print("poles (k=5)") for elem in co.pole(h3): print(f'{elem: .2f}') plt.figure(1) h1_map = co.pzmap(h1, plot=True, title='pzmap (k=2)') plt.figure(2) h2_map = co.pzmap(h2, plot=True, title='pzmap (k=3)') plt.figure(3) h3_map = co.pzmap(h3, plot=True, title='pzmap (k=5)') t = np.linspace(0, 10, 1000) t1, imp1 = co.impulse_response(h1, t) t2, imp2 = co.impulse_response(h2, t) t3, imp3 = co.impulse_response(h3, t) t4, stp1 = co.step_response(h1, t) t5, stp2 = co.step_response(h2, t) t6, stp3 = co.step_response(h3, t)
t = Symbol('t') K = Symbol('K') #Some hard-coded values num = [1] den = [1, 3, 2] H = 1 #Transfer Function G = control.tf(num, den) G_feedbacked = control.feedback(G, H) control.sisotool(G_feedbacked) print("OPEN LOOP TRANSFER FUNCTION") print(G) print("CLOSE LOOP TRANSFER FUNCTION") print(G_feedbacked) poles, zeros = control.pzmap(G, True, True) all_points = np.concatenate([[-np.Infinity], zeros, poles]) all_points.sort() all_real_points = np.real(all_points[np.isreal(all_points)]) print("Range in real axis :") range_of_real_axis = [] for i in range(len(all_real_points) - 1, 0, -2): print("From " + str(all_real_points[i - 1]) + " to " + str(all_real_points[i])) range_of_real_axis += [all_real_points[i - 1], all_real_points[i]] print("The starting points are:" + str(poles)) print("The ending points are:" + str(zeros)) print("The total number of branches is: " + str(len(poles))) sum_of_inverse_zeros = 0 sum_of_inverse_poles = 0 for zero in zeros:
plt.clf() # plt.setp(plt.gca(), autoscale_on=False) # tellme('click to begin') # plt.waitforbuttonpress() plt.ion() plt.show(block=False) # the output can be collected by this variable result for i in range(-80, 80): den = [1, 6, 11, 6, i * 0.25] # result = checkStability(den) # confirmation by plotting pole-zero graph on s-plane p, z = ctrl.pzmap(ctrl.TransferFunction(num, den), Plot=False, title="when k=10.1") if i == -80: t1 = plt.plot(p[0].real, p[0].imag, 'k*') plt.setp(t1, markersize=24.0, markeredgewidth=2.0) t1 = plt.plot(p[1].real, p[1].imag, 'k*') plt.setp(t1, markersize=24.0, markeredgewidth=2.0) t1 = plt.plot(p[2].real, p[2].imag, 'k*') plt.setp(t1, markersize=24.0, markeredgewidth=2.0) t1 = plt.plot(p[3].real, p[3].imag, 'k*') plt.setp(t1, markersize=24.0, markeredgewidth=2.0) if i == 79: t1 = plt.plot(p[0].real, p[0].imag, 'kx') plt.setp(t1, markersize=24.0, markeredgewidth=2.0) t1 = plt.plot(p[1].real, p[1].imag, 'kx') plt.setp(t1, markersize=24.0, markeredgewidth=2.0)
color = 'b' # Add arrows to the plot # H1 = L.evalfr(0.4); H2 = L.evalfr(0.41); # arrow([real(H1), imag(H1)], [real(H2), imag(H2)], AM_normal_arrowsize, \ # 'EdgeColor', color, 'FaceColor', color); # H1 = freqresp(L, 0.35); H2 = freqresp(L, 0.36); # arrow([real(H2), -imag(H2)], [real(H1), -imag(H1)], AM_normal_arrowsize, \ # 'EdgeColor', color, 'FaceColor', color); plt.figure(9) Tvec, Yvec = ct.step_response(T, np.linspace(0, 20)) plt.plot(Tvec.T, Yvec.T) Tvec, Yvec = ct.step_response(Co * S, np.linspace(0, 20)) plt.plot(Tvec.T, Yvec.T) plt.figure(10) plt.clf() P, Z = ct.pzmap(T, plot=True, grid=True) print("Closed loop poles and zeros: ", P, Z) # Gang of Four plt.figure(11) plt.clf() ct.gangof4_plot(Hi * Po, Co) if 'PYCONTROL_TEST_EXAMPLES' not in os.environ: plt.show()
import scipy.signal as signal from base.impseq import * from base.stepseg import * b = np.array([0, 0.866, 0.0306, -2.486, 3.2094, -1.62, 0.84]) a = np.array([1, -2.9, 4.8, -4.7, 2.8, -0.9]) R, p, c = signal.residuez(b, a) # print(R) print("poles:") print(p) # print(c) print("roots:") roots = np.roots(b) # b = np.array([3]) # a = np.array([1,-1]) delta, n1 = impseg(0, 0, 10) delta = delta.astype('float64') xb1 = signal.lfilter(b, a, delta) step, n2 = stepseg(0, 0, 10) step_minus_2, _ = stepseg(2, 0, 10) xb2 = n2 * np.sin(np.pi / 3 * n2) * step + np.power(0.9, n2) * step_minus_2 err = xb1 - xb2 print(err) tfx = control.tf(b, a) control.pzmap(tfx) plt.show()
# C = np.array([[0, 1, 0, 0]]) D = np.array([[0]]) S = ctl.ss(A, B, C, D) print('S =', S) ######################################################### # Funcao de transferencia ######################################################### G = ctl.ss2tf(S) print('G =', G) ######################################################### # Polos e zeros ######################################################### (p, z) = ctl.pzmap(G) print('polos =', p) print('zeros =', z) plt.show() ######################################################### # Plot da resp no dominio do tempo ao impulso unitario ######################################################### # T, yout = ctl.impulse_response(G) # plt.plot(T, yout) # plt.show() ######################################################### # Plot da resp no dominio do tempo ao degrau unitario ######################################################### T, yout = ctl.step_response(G)
den = den.subs({f0: 77500, r3: 100000, r4: 47000}) poles = [] zeros = [] max_r_jfet = 10000 for i in range(0, max_r_jfet + 1000, 100): new_den = sympy.Poly(den.subs(r_jfet, i), s) new_num = sympy.Poly(num.subs(r_jfet, i), s) num_coeffs = list(new_num.coeffs()) den_coeffs = list(new_den.coeffs()) num_coeffs = [float(e) for e in num_coeffs] den_coeffs = [float(e) for e in den_coeffs] sys = control.tf(num_coeffs, den_coeffs) new_poles, new_zeros = control.pzmap(sys, Plot=False) poles.extend(new_poles) zeros.extend(new_zeros) x_poles = [pole.real for pole in poles] y_poles = [pole.imag for pole in poles] x_zeros = [zero.real for zero in zeros] y_zeros = [zero.imag for zero in zeros] fig, (poles_plot, zeros_plot) = plt.subplots(1, 2) fig.suptitle('Diagrama de polos y ceros') poles_plot.scatter(x_poles, y_poles, marker='x', c='red') zeros_plot.scatter(x_zeros, y_zeros, marker='o', c='blue') poles_plot.set_xlabel('Parte real σ (Hz)') poles_plot.set_ylabel('Parte imaginaria jω (Hz)')
# ---------------- Initiate Plant ------------------ num = 2 * gamma * v_bar / (r_bar**2) p1 = 2 * gamma * v_bar**2 / r_bar**3 den = [1, 0, p1] Gsys = control.TransferFunction(num, den) # ------------- Initiate Controller --------------- Kgain = 100 tau = .025 # 1/intended zero placement numC = np.array([tau, 1]) * Kgain Csys = control.TransferFunction(numC, 1) # ---------------- Multiply the transfer functions ------------- CGsys = control.series(Csys, Gsys) control.pzmap(CGsys, Plot=True, title='Pole Zero Map of Plant') print(Csys) print(Gsys) print(CGsys) plt.figure() tout, y, x = control.forced_response(CGsys, t, step, R_hat_0) plt.plot(t, y) plt.show() # tout,y,x = signal.lsim(CG, step, t, R_hat_0) # print(y) # plt.plot(t,y) # #plt.legend(loc='best') # plt.show()
for i in range(len(rowArray) - 1): if rowArray[i][0] * rowArray[i + 1][0] < 0: flag = 1 if flag == 0: print('Stable System! CoolControlEngineer!') return True else: print('System Unstable! Get back to work!') return False # numerator and denominator may be given as input here num = [30, 150, -900] # den = [1, 12, 49, 78, 40] #example1 # den = [1, 1, 10, 72, 152, 240] #example2 # den = [1, 1, 2, 2, 5] #example3 den = [1, 2, 11, 18, 18] # the output can be collected by this variable result result = checkStability(den) # confirmation by plotting pole-zero graph on s-plane p, z = ctrl.pzmap(ctrl.TransferFunction(num, den), Plot=True, title="pole zero plot") plt.show()
import subprocess import shlex #end if p1 = 2 * np.pi * 1e4 p2 = 2 * np.pi * 1e5 H = ((p1 - p2)**2) / (4000 * p1 * p2) num = [1000] den = [(1 / (p1 * p2)), ((1 / p1) + (1 / p2)), (1000 * H + 1)] #den=[(1e-9), (11*1e-5), 3.025] sys = control.tf(num, den) s = signal.lti(num, den) w, mag, phase = signal.bode(s) pole, zero = control.pzmap(sys, Plot=True, title='Pole Zero Map') print("Poles are :", pole) gain_y = np.full((len(w)), 44.3866) x_val = abs(pole[0]) y_val = 44.3866 plt.figure() plt.plot(w, mag) plt.plot(w, gain_y) plt.plot(x_val, y_val, 'ro') plt.text(x_val, y_val, "(345575, 44.3866)") plt.grid() print("Low frequency Gain ", mag[0]) print("Gain at crossover frequency dB ", 44.3866)
b_el, a_el = scipy.signal.ellip(N_el, Rp * -1, Rs * -1, wp1_el, output='ba') # plot unit circle def Circle(x, y): return (x * x + y * y) plt.figure(1) xx = numpy.linspace(-2, 2, 400) yy = numpy.linspace(-2, 2, 400) [X, Y] = numpy.meshgrid(xx, yy) Z = Circle(X, Y) plt.contour(X, Y, Z, [1]) # zero / pole plot tf_el = control.TransferFunction(b_el, a_el) control.pzmap(tf_el) plt.show() # plot frequency response w, h = scipy.signal.freqz(b_el, a_el) plt.figure(2) plt.title('Chebyshev Type II Frequency Response') plt.plot(w, 20 * numpy.log10(abs(h)), 'b') plt.ylabel('Amplitude [dB]', color='b') plt.ylim(-120, 10) plt.xlabel('Frequency [rad/sample]') plt.show()
acbas = co.series(acp, bap) acbaef = co.feedback(acbas, e, +1) print(acbaef) g_poles = co.pole(acbaef) print("G poles") for elem in g_poles: print(f'{elem: .2f}') g_zeros = co.zero(acbaef) print("G zeros") for elem in g_zeros: print(f'{elem: .2f}') g1_map = co.pzmap(acbaef, plot=True) t = np.linspace(0, 25, 100) t1, stp = co.step_response(acbaef, t) t2, imp = co.impulse_response(acbaef, t) # Warning for infinite impulse at t=0 plt.figure(2) plt.plot(t1, stp) plt.title("Step Response") plt.ylabel("Amplitude") plt.xlabel("Time") plt.grid() plt.figure(3) plt.plot(t2, imp) plt.title("Impulse Response")
# Hitung eigenvalue dari sistem pegas massa tersebut poles = mySys.pole() print('Poles sistem adalah: \n', poles, '\n') # Nyatakan apakah sistem stabil atau tidak. Apabila nilai poles nya bukan bilangan complex # sistem tidak stabil if str(type(poles[1])) == "<class 'numpy.float64'>": print('===> sistem tidak stabil \n') else: print('===> sistem stabil \n') # Visualisasikan pula lokasi poles dengan memetakannya di ruang kompleks C. # Seluruh poles dari sistem yang stabil berada di sebelah kanan sumbu # imajiner pzmap(mySys) #fig = plt.figure() # Berikutnya dilakukan perhitungan dinamika sistem pegas-massa # Membuat array selang waktu dari 0 sampai 20 dengan time frame 0.05 dt = 0.05 t = np.arange(0.0, 20, dt) yt = [] for i in range(len(t)): yt.append(-0.5) # Mendefinisikan kondisis awal masing-masing state vInit = 1.0 # kecepatan awal sInit = 0.0 # posisi/simpangan awal # Kondisi awal state