def TransferFunction(num:list[float], den:list[float], deadtime: float = 0.0, dt:float=0.0) -> control.TransferFunction: """ Creates a discrete-time transfer function with the given numerator and denominator coefficients. Also adds deadtime to the transfer function if given. Parameters ---------- num : list Numerator coefficients of the transfer function den : list Denominator coefficients of the transfer function deadtime : float, optional Deadtime of the transfer function, by default 0 dt : float, optional Sampling time of the transfer function, by default 0.1 Returns ------- control.TransferFunction Discrete-time transfer function with the given parameters Examples -------- >>> import matplotlib.pyplot as plt >>> num = [0.9958683] >>> den = [1, -0.0041317] >>> deadtime = 5 >>> dt = 0.5 >>> Gz = TransferFunction(num, den, deadtime, dt) >>> print(Gz.dcgain) >>> y, t = Gz.step_response >>> plt.title('Stepresponse (Y per U)') >>> plt.plot(t, y, '-r') >>> plt.xlabel('Time(min)') >>> plt.ylabel('Amplitude') >>> plt.grid() >>> plt.show() """ if dt: Gz = control.TransferFunction(num, den, dt) else: Gs = control.TransferFunction(num, den) # dt = get_dt(Gs) dt = 0.1 Gz = control.sample_system(Gs, dt, 'tustin') if deadtime >= 1: deadtime_samples = int(np.ceil(deadtime/dt)) + 1 theta = np.full(deadtime_samples, 0.0) for i in range(len(theta)): if i % 2 != 0: theta[i] = -0.0 denz = np.concatenate((Gz.den[0][0].flatten(), theta), axis=None) Gz.den[0][0] = denz return Gz