hzi-notebook
4/16/2019 - 9:01 AM

nyquist

def drawcycle(cent, rad):
    x = []
    y = []
    for j in range(360):
        x +=[cos(j*pi/180)*rad+cent[0]]
        y +=[sin(j*pi/180)*rad+cent[1]]
    return(x,y)

def nyq2(G1, G2, txt=[' ',' '], sp=5):
    wi = np.logspace(-4,4,10000)
    
    re1, im1, om1 = cnt.nyquist(G1,wi,Plot=False)
    re2, im2, om2 = cnt.nyquist(G2,wi,Plot=False)
    
    cx1, cy1 = drawcycle([0,0], 1)
    
    plt.plot(re1,im1, label=txt[0])
    plt.plot(re2,im2, label=txt[1])
    plt.plot(-1,0,'ro')
    plt.plot(cx1,cy1,'-.', alpha=0.3)
    plt.axhline(0,c='k', alpha=0.3)
    plt.axvline(0,c='k', alpha=0.3)
    plt.xlim(-sp,sp)
    plt.ylim(-sp,sp)
    plt.title('Nyquist-Plot')
    plt.xlabel('Realteil')
    plt.ylabel('Imaginärteil')
    plt.legend()
    plt.grid()
    return

def plotstep(G, tmax):
    T = np.linspace(0,tmax,1000)
    T, yout = cnt.step_response(cnt.feedback(G,1),T)
    plt.plot(T,yout)
    plt.xlabel('Zeit [s]')
    plt.ylabel('Sprungantwort [Einheiten]')
    plt.grid()
    return

def tf_regler(kr, Ti, Td):
    if Ti==0:
        if Td==0:
            Gr = cnt.tf([kr],[1]) # P-Regler
        else:
            Gr = cnt.tf([kr*Td, kr],[1]) # PD-Regler
    else:
        if Td==0:
            Gr = cnt.tf([kr*Ti, kr],[Ti, 0]) # PI-Regler
        else:
            Gr = cnt.tf([kr*Td*Ti, kr*Ti, kr],[Ti, 0]) # PID-Regler
    return(Gr)