Package: pylib-sakata
pylib-sakata User's Manual version-0.1.171. Introduction2. Environment Setup2.1. Installation of Python2.2. Installation  of required Python libraries2.3. Installation of pylib-sakata2.4. Installation of IDE for Python2.4.1. Visual Studio Code (VSCode)2.4.1.1. Installation of VSCode2.4.1.2. Initial setting of VSCode2.4.2. Spyder2.4.2.1. Installation of Spyder2.4.2.2. Initial setting of Spyder2.4.3. PyCharm2.4.3.1. Installation of PyCharm2.4.3.2. Initial setting of PyCharm2.4.4. Comparison between  VSCode and Spyder and PyCharm2.5. Getting started3. pylib_sakata.ctrl3.1. ZpkModel3.2. tf3.3. ss3.4. zpk3.5. tf2ss3.6. tf2zpk3.7. ss2tf3.8. ss2zpk3.9. zpk2tf3.10. zpk2ss3.11. sys2frd3.12. feedback3.13. frdfeedback3.14. c2d3.15. pi3.16. pd3.17. pid3.18. pl1st3.19. pl2nd3.20. lpf1st3.21. lpf2nd3.22. hpf1st3.23. hpf2nd3.24. nf3.25. pf3.26. pfoptparam3.27. pfopt3.28. dob3.29. zpetc3.30. filt3.31. minreal3.32. makeprmset3.33. defprmset4. pylib_sakata.fft4.1. FreqResp4.2. fft4.3. fft_ave4.4. tfestimate4.5. frdresize4.6. frdsim5. pylib_sakata.meas5.1. MeasData5.2. getcsvdata5.3. gettxtdata5.4. getmatdata5.5. getdata5.6. getdataindex5.7. measdata2frd6. pylib_sakata.traj6.1. TrajInf6.2. traj3rd6.3. traj3rd26.4. traj4th6.5. trajSinStep7. pylib_sakata.plot7.1. plot_xy7.2. plot_tf7.3. plot_tffrd7.4. plot_nyquist7.5. plot_nyquist_assistline7.6. makefig7.7. savefig7.8. showfig8. pylib_sakata.init8.1. close_all8.2. clear_all1. IntroductionThe pylib-sakata package is a set of python classes and functions that make the python-control package more convenient. This package provides practical level's tools to design controls and  to analysis of performance and stability of SISO LTI systems. These development environments are available on free.2. Environment Setup2.1. Installation of PythonPython installation exe file can be downloadedHEREfor Windows. Check "Add Python 3.x to PATH" when you install Python.2.2. Installation  of required Python librariesThe pylib-sakata package requiresnumpy,scipy,matplotlib,pandas, andpython-control. In addition, some routines require theslycotlibrary in order to implement more advanced features.
First, pip should be upgraded by the following command on the command prompt for Windows OS.python-mpipinstall--upgradepipFor Linux OS, pip can be upgraded by the following command on the shell.$sudopip3install--upgradepipThe required python libraries can be installed using pip as the following commands on the command prompt or on the shell.pipinstallnumpy
pipinstallscipy
pipinstallmatplotlib
pipinstallpandas
pipinstallcontrolIf those libraries can not be installed, please use pip3 instead of pip.2.3. Installation of pylib-sakataThepylib-sakatapackage can be installed using pip using pip as following on the command prompt or on the shell.pipinstallpylib-sakata2.4. Installation of IDE for PythonThere are three recommended IDEs.2.4.1. Visual Studio Code (VSCode)Although VSCode is actually an editor, it is available as Python IDE due to extensions. It is recommended to install it easily because of the versatility of extensions. The following figure shows VSCode IDE window.2.4.1.1. Installation of VSCodeThe latest version of VSCode installation exe file can be downloadedHEREfor Windows OS.
For Linux OS, VSCode can be installed by the following command on the shell.$sudoaptupdate$sudoaptinstallcode2.4.1.2. Initial setting of VSCodeInstall Python extension for Visual Studio Code from extensions in the activity bar on the left side.Command (Ctrl+Shift+P) to open the command palette.Select your installed python.exe on  "Python: select interpreter".2.4.2. SpyderSpyder is an IDE like MATLAB. If you are used to MATLAB, this IDE is recommended. The following figure shows Spyder IDE window.2.4.2.1. Installation of SpyderThe latest version of Spyder installation exe file can be downloadedHEREfor Windows OS.
For Linux OS, Spyder can be installed by the following command on the shell.$sudoaptupdate$sudoaptinstallspyder32.4.2.2. Initial setting of SpyderOpen Tools>Preferences>Python interpreter.Check "Use the following Python interpreter."Enter the path of your installed python.exe.Install spyder-kernels for your python version by the following commandpip install spyder-kernels==2.0.*on the command prompt or on the shell.Reboot your PC.2.4.3. PyCharmProfessional version is charged. Community version is free. Community version is enough for control system development. The following figure shows PyCharm window.2.4.3.1. Installation of PyCharmThe latest version of PyCharm installation exe file can be downloadedHERE.2.4.3.2. Initial setting of PyCharmIt is not necessary.2.4.4. Comparison between  VSCode and Spyder and PyCharmVSCodeSpyderPyCharmCostFreeFreeFree/PaidBoot timeFastSlowNormalProcessing speedFastNormalNormalREPL modeneed to switch REPL terminalAvailableAvailableVariable ExplorerAvailable on Jupyter terminalAvailable (Class variables are invisible.)AvailableSpyder is more suitable than VSCode for early debugging. On the other hand, VSCode is stress-free than Spyder for late debugging you do not need to check inter states of variables. PyCharm is generally well-balanced. My recommendation is PyCharm.2.5. Getting startedThe pylib-sakata package can be imported as follows.>>>importpylib_sakataThis package consists of six modules as follows.ctrl: to design controllers and filtersfft: to analysis FFTmeas: to treat measurement datatraj: to generate target trajectoryplot: to plot figuresinit: to initialize current variableThese modules can be imported individually as follows.>>>frompylib_sakataimportctrl>>>frompylib_sakataimportfft>>>frompylib_sakataimportmeas>>>frompylib_sakataimporttraj>>>frompylib_sakataimportplot>>>frompylib_sakataimportinitExample codes areHERE.3. pylib_sakata.ctrl3.1. ZpkModelclass pylib_sakata.ctrl.ZpkModel(z, p, k, dt=0)Parameters:z: zeros array of the LTI modelp: poles array of the LTI modelk: gain of the LTI model. Note: the gain is not system dc gain but coefficient of monic polynomials. This is different from the definition of dc gain in TransferFunction class.dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.Examples>>>ctrl.ZpkModel([-1.,-2.],[-3.,-4.,-5.],2.)(s+1)(s+2)2*---------------(s+3)(s+4)(s+5)If you set same zeros and poles, the pole-zero cancellation is automatically done as following. Unnecessary increase of the system order can be avoided.>>>ctrl.ZpkModel([0.1,0.3,0.4],[0.3,0.4,0.5],2.,0.001)Thecommonpole-zerosofthezpkmodelhavebeendeleted.(z-0.1)2*-------(z-0.5)dt=0.001Methods__neg__()
Negate a zpk model.__add__(other)
Add two zpk models (parallel connection).__radd__(other)
Right add two zpk models (parallel connection).__sub__(other)
Subtract two zpk models.__rsub__(other)
Right subtract two zpk models.__mul__(other)
Multiply two zpk models (serial connection).__rmul__(other)
Right multiply two zpk models (serial connection).__truediv__(other)
Divide two zpk models.__rtruediv__(other)
Right divide two zpk models.__pow__(other)
A zpk model to the power of x.feedback(other=1, sys='S')
Calculate the feedback system that consist of two zpk model (P: self and C: other).
sys: FB type (Optional), Default: 'S', Set in 'S': sensitivity function, 'T': complementary sensitivity function, 'SP': response from input disturbance to output3.2. tfpylib_sakata.ctrl.tf(num, den, dt=0)This function callstffunction in control library.Parameters:num: polynomial coefficients of the numerator of the LTI modelden: polynomial coefficients of the denominator of the LTI modeldt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.Returns:out: instance of TransferFuntion classExamples>>>print(ctrl.tf([1.,2.],[3.,4.,5.]))s+2---------------3s^2+4s+53.3. sspylib_sakata.ctrl.ss(A, B, C, D, dt=0)This function callsssfunction in control library.Parameters:A, B, C, D: state space matricesdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.Returns:out: instance of StateSpace classExamples>>>print(ctrl.ss("1. -2.; 3. -4.","5.; 7.","6. 8.","9."))A=[[1.-2.][3.-4.]]B=[[5.][7.]]C=[[6.8.]]D=[[9.]]3.4. zpkpylib_sakata.ctrl.zpk(z, p, k, dt=0)Parameters:A, B, C, D: state space matricesdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.Returns:out: instance of ZpkModel classExamples>>>ctrl.zpk([-1.,-2.],[-3.,-4.,-5.],2.)(s+1)(s+2)2*---------------(s+3)(s+4)(s+5)3.5. tf2sspylib_sakata.ctrl.tf2ss(tf, form='reachable')Parameters:tf: instance of TransferFunction classform: canonical form (Optional), Default: reachable. You can select the canonical form in reachable, observable, and modal.Returns:out: instance of StateSpace classExamples>>>Sys_tf=ctrl.tf([1.,2.],[3.,4.,5.])>>>print(ctrl.tf2ss(Sys_tf))A=[[-1.33333333-1.66666667][1.0.]]B=[[1.][0.]]C=[[0.333333330.66666667]]D=[[0.]]3.6. tf2zpkpylib_sakata.ctrl.tf2zpk(tf)Parameters:tf: instance of TransferFunction classReturns:out: instance of ZpkModel classExamples>>>Sys_tf=ctrl.tf([1.,2.],[3.,4.,5.])>>>ctrl.tf2zpk(Sys_tf)(s+2)0.3333*----------------------------------(s+0.6667+1.106j)(s+0.6667-1.106j)3.7. ss2tfpylib_sakata.ctrl.ss2tf(ss)Parameters:ss: instance of StateSpace classReturns:out: instance of TransferFunction classExamples>>>Sys_ss=ctrl.ss("1. -2.; 3. -4.","5.; 7.","6. 8.","9.")>>>print(ctrl.ss2tf(Sys_ss))9s^2+113s+118-------------------s^2+3s+23.8. ss2zpkpylib_sakata.ctrl.ss2zpk(ss)Parameters:ss: instance of StateSpace classReturns:out: instance of ZpkModel classExamples>>>Sys_ss=ctrl.ss("1. -2.; 3. -4.","5.; 7.","6. 8.","9.")>>>ctrl.ss2zpk(Sys_ss)(s+11.41)(s+1.149)9*------------------(s+2)(s+1)3.9. zpk2tfpylib_sakata.ctrl.zpk2tf(zpk)Parameters:zpk: instance of ZpkModel classReturns:out: instance of TransferFunction classExamples>>>Sys_zpk=ctrl.zpk([-1.,-2.],[-3.,-4.,-5.],2.)>>>print(ctrl.zpk2tf(Sys_zpk))2s^2+6s+4------------------------s^3+12s^2+47s+603.10. zpk2sspylib_sakata.ctrl.zpk2ss(zpk, form='reachable')Parameters:zpk: instance of ZpkModel classform: canonical form (Optional), Default: reachable. You can select the canonical form in reachable, observable, and modal.Returns:out: instance of StateSpace classExamples>>>Sys_zpk=ctrl.zpk([-1.,-2.],[-3.,-4.,-5.],2.)>>>print(ctrl.zpk2ss(Sys_zpk))A=[[-12.-47.-60.][1.0.0.][0.1.0.]]B=[[1.][0.][0.]]C=[[2.6.4.]]D=[[0.]]3.11. sys2frdpylib_sakata.ctrl.sys2frd(sys, freq)Parameters:sys: LTI model (StateSpace or TransferFunction or ZpkModel)freq: 1-D array frequency data [Hz]Returns:freqresp: instance of FreqResp class (Refer4.1. FreqResp.)Examples>>>importnumpyasnp>>>freq=np.logspace(np.log10(1.),np.log10(1000.),10000,base=10)>>>Sys_tf=ctrl.tf([1.,2.],[3.,4.,5.])>>>ctrl.sys2frd(Sys_tf,freq)freq=array([1.1.000691081.00138264...998.61926487999.309393971000.])resp=array([-5.10821217e-03-5.65218353e-02j-5.10191815e-03-5.64779702e-02j-5.09563061e-03-5.64341455e-02j...-5.64453060e-09-5.31250027e-05j-5.63673700e-09-5.30883142e-05j-5.62895416e-09-5.30516511e-05j])>>>Sys_zpk=ctrl.zpk([-1.,-2.],[-3.,-4.,-5.],2.)>>>ctrl.sys2frd(Sys_zpk,freq)freq=array([1.1.000691081.00138264...998.61926487999.309393971000.])resp=array([1.89109027e-01-0.06951671j1.89033162e-01-0.06962001j1.88957165e-01-0.0697232j...4.57206511e-07-0.00031875j4.56575231e-07-0.00031853j4.55944822e-07-0.00031831j])3.12. feedbackpylib_sakata.ctrl.feedback(sysP, sysC, sys='S')This function is for calculating the feedback system that consist of two LTI model (P: plant and C: controller).Parameters:sysP: LTI model (StateSpace or TransferFunction or ZpkModel) of the plantsysC: LTI model (StateSpace or TransferFunction or ZpkModel) of the controllersys: FB type (Optional), Default: 'S', Set in 'S': sensitivity function, 'T': complementary sensitivity function, 'SP': response from inputReturns:out: LTI model (StateSpace or TransferFunction or ZpkModel) of the feedback systemExamples>>>P_tf=ctrl.tf([1.],[1.,2.,0.])>>>C_tf=ctrl.tf([2.,4.,1.],[1.,2.,0.])>>>print(ctrl.feedback(P_tf,C_tf))s^4+4s^3+4s^2-----------------------------s^4+4s^3+6s^2+4s+1>>>P_zpk=ctrl.zpk([],[0.,-2.])>>>C_zpk=ctrl.zpk([-1.7071067811865475,-0.29289321881345254],[0.,-2.],2.)>>>ctrl.feedback(P_zpk,C_zpk)s(s+2)(s+2)s1*-----------------------------------------------(s+1)(s+1-0.0001508j)(s+1+0.0001508j)(s+0.9998)3.13. frdfeedbackpylib_sakata.ctrl.frdfeedback(frdP, frdC, sys='S')This function is for calculating the feedback system that consist of two freqresp (P: plant and C: controller).Parameters:frdP: 1-D array complex data of the frequency response of the plantfrdC: 1-D array complex data of the frequency response of the controllersys: FB type (Optional), Default: 'S', Set in 'S': sensitivity function, 'T': complementary sensitivity function, 'SP': response from inputReturns:out: 1-D array complex data of the frequency response of the feedback systemExamples>>>importnumpyasnp>>>freq=np.logspace(np.log10(1.),np.log10(1000.),10000,base=10)>>>P_tf=ctrl.tf([1.],[1.,2.,0.])>>>C_tf=ctrl.tf([2.,4.,1.],[1.,2.,0.])>>>P_frd=ctrl.tf2frd(P_tf,freq)>>>C_frd=ctrl.tf2frd(C_tf,freq)>>>ctrl.frdfeedback(P_frd,C_frd)array([1.04746047+1.56990662e-02j,1.04739933+1.56671729e-02j,1.04733826+1.56353434e-02j,...,1.00000005+1.61927479e-11j,1.00000005+1.61592227e-11j,1.00000005+1.61257668e-11j])3.14. c2dpylib_sakata.ctrl.c2d(sysC, dt, method='tustin')The matched method ofc2din control library does not supported for pure integrals and pure derivatives because of dc gain inf error. This function solved this problem.Parameters:sysC: continuous time LTI model (StateSpace or TransferFunction or ZpkModel) of the plantdt: sampling time of the LTI model (Optional), Default: 0, set the value > 0.method: discretized method (Optional), Default: 'tustin', set a method in 'tustin', 'matched', 'zoh', and etc.Returns:out: discrete time LTI model (StateSpace or TransferFunction or ZpkModel) of the feedback systemExamples>>>C_tf=ctrl.tf([1.,3.,2.],[1.,3.,0.])>>>print(ctrl.c2d_matched(C_tf,0.001))z^2-1.997z+0.997---------------------z^2-1.997z+0.997dt=0.001>>>C_zpk=ctrl.zpk([-1.,-2.,],[0.,-3.,],1.)>>>ctrl.c2d_matched(C_zpk,0.001)(z-0.999)(z-0.998)1*------------------(z-1)(z-0.997)dt=0.0013.15. pipylib_sakata.ctrl.pi(freq, zeta, L, R, dt=None, method='tustin')This function is for design of a PI controller.
$$C_{PI}(s) = K_P + \frac{K_I}{s} = \frac{b_1s+b_0}{s}$$
$$P(s) = \frac{1}{Ls+R}$$Parameters:freq: frequency[Hz] of the pole pair of the feedback system with the PI controllerzeta: damping of the pole pair of the feedback system with the PI controllerL: inductance[H] of the plantR: resistance[$\Omega$] of the plantdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the PI controllerExamples>>>print(ctrl.pi(1000.,0.7,0.1,10.))869.6s+3.948e+06-------------------s>>>print(ctrl.pi(1000.,0.7,0.1,10.,0.001))2844z+1104-------------z-1dt=0.0013.16. pdpylib_sakata.ctrl.pd(freq1, freq2, zeta2, M, C, K, dt=None, method='tustin')This function is for design of a PD controller.
$$C_{PD}(s) = K_P + \frac{K_D s}{\tau_D s+1} = \frac{b_1s+b_0}{s+a_0}$$
$$P(s) = \frac{1}{Ms^2+Cs+K}$$Parameters:freq1: frequency[Hz] of the first pole of the feedback system with the PD controllerfreq2: frequency[Hz] of the second pole pair of the feedback system with the PD controllerzeta2: damping of the second pole pair of the feedback system with the PD controllerM: mass[kg] of the plantC: viscosity[N/(m/s)] of the plantK: stiffness[N/m] of the plantdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the PD controllerExamples>>>print(ctrl.pd(10.,10.,0.7,2.,10.,0.))1.749e+04s+4.961e+05-----------------------s+145.8>>>print(ctrl.pd(10.,10.,0.7,2.,10.,0.,0.001))1.653e+04z-1.607e+04-----------------------z-0.8641dt=0.0013.17. pidpylib_sakata.ctrl.pid(freq1, zeta1, freq2, zeta2, M, C, K, dt=None, method='tustin')This function is for design of a PID controller.
$$C_{PID}(s) = K_P + \frac{K_I}{s} + \frac{K_D s}{\tau_D s+1} = \frac{b_2s^2+b_1s+b_0}{s^2+a_1s}$$
$$P(s) = \frac{1}{Ms^2+Cs+K}$$Parameters:freq1: frequency[Hz] of the first pole pair of the feedback system with the PID controllerzeta1: damping of the first pole pair of the feedback system with the PID controllerfreq2: frequency[Hz] of the second pole pair of the feedback system with the PID controllerzeta2: damping of the second pole pair of the feedback system with the PID controllerM: mass[kg] of the plantC: viscosity[N/(m/s)] of the plantK: stiffness[N/m] of the plantdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the PID controllerExamples>>>print(ctrl.pid(10.,1.,10.,0.7,2.,10.,0.))3.581e+04s^2+1.687e+06s+3.117e+07---------------------------------------s^2+208.6s>>>print(ctrl.pid(10.,1.,10.,0.7,2.,10.,0.,0.001))3.32e+04z^2-6.485e+04z+3.167e+04--------------------------------------z^2-1.811z+0.8111dt=0.0013.18. pl1stpylib_sakata.ctrl.pl1st(freq1, freq2, dt=None, method='tustin')This function is for design of a first order phase lead filter.
$$F_{PL}(s) = \frac{f_2}{f_1} * \frac{s+2\pi f_1}{s+2\pi f_2}$$Parameters:freq1: frequency[Hz] of numerator of the phase lead filterfreq2: frequency[Hz] of denominator of the phase lead filterdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the phase lead filterExamples>>>ctrl.tf2zpk(ctrl.pl1st(50.,100.))(s+314.2)2*---------(s+628.3)>>>ctrl.tf2zpk(ctrl.pl1st(50.,100.,0.001))(z-0.7285)1.761*----------(z-0.5219)dt=0.0013.19. pl2ndpylib_sakata.ctrl.pl2nd(freq1, zeta1, freq2, zeta2, dt=None, method='tustin')This function is for design of a second order phase lead filter.
$$F_{PL^2}(s) = \left( \frac{f_2}{f_1} \right)^2 * \frac{s^2+2\zeta_1 (2\pi f_1)s+(2\pi f_1)^2}{s^2+2\zeta_2 (2\pi f_2)s+(2\pi f_2)^2}$$Parameters:freq1: frequency[Hz] of numerator of the phase lead filterzeta1: damping of numerator of the phase lead filterfreq2: frequency[Hz] of denominator of the phase lead filterzeta2: damping of denominator of the phase lead filterdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the phase lead filterExamples>>>print(ctrl.pl2nd(50.,0.7,100.,0.7))2s^2+879.6s+1.974e+05---------------------------s^2+879.6s+3.948e+05>>>print(ctrl.pl2nd(50.,0.7,100.,0.7,0.001))1.618z^2-2.536z+1.046---------------------------z^2-1.172z+0.4283dt=0.0013.20. lpf1stpylib_sakata.ctrl.lpf1st(freq, dt=None, method='tustin')This function is for design of a first order low pass filter.
$$F_{LP}(s) = \frac{2\pi f}{s+2\pi f}$$Parameters:freq: frequency[Hz] of the low pass filterdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the low pass filterExamples>>>print(ctrl.lpf1st(100.))628.3---------s+628.3>>>print(ctrl.lpf1st(100.,0.001))0.2391z+0.2391-----------------z-0.5219dt=0.0013.21. lpf2ndpylib_sakata.ctrl.lpf2nd(freq, zeta, dt=None, method='tustin')This function is for design of a second order low pass filter.
$$F_{LP^2}(s) = \frac{(2\pi f)^2}{s^2+2\zeta (2\pi f)s+(2\pi f)^2}$$Parameters:freq: frequency[Hz] of the low pass filterzeta1: damping of the low pass filterdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the low pass filterExamples>>>print(ctrl.lpf2nd(100.,0.7))3.948e+05-------------------------s^2+879.6s+3.948e+05>>>print(ctrl.lpf2nd(100.,0.7,0.001))0.06415z^2+0.1283z+0.06415--------------------------------z^2-1.172z+0.4283dt=0.0013.22. hpf1stpylib_sakata.ctrl.hpf1st(freq, dt=None, method='tustin')This function is for design of a first order high pass filter.
$$F_{HP}(s) = 1 - F_{LP}(s) = \frac{s}{s+2\pi f}$$Parameters:freq: frequency[Hz] of the high pass filterdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the high pass filterExamples>>>print(ctrl.hpf1st(100.))s---------s+628.3>>>print(ctrl.hpf1st(100.,0.001))0.7609z-0.7609-----------------z-0.5219dt=0.0013.23. hpf2ndpylib_sakata.ctrl.hpf2nd(freq, zeta, dt=None, method='tustin')This function is for design of a second order high pass filter.
$$F_{HP^2}(s) = 1 - F_{LP^2}(s) = \frac{s^2+2\zeta (2\pi f)s}{s^2+2\zeta (2\pi f)s+(2\pi f)^2}$$Parameters:freq: frequency[Hz] of the high pass filterzeta1: damping of the high pass filterdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: instance of TransferFunction class of the high pass filterExamples>>>print(ctrl.hpf2nd(100.,0.7))s^2+879.6s-------------------------s^2+879.6s+3.948e+05>>>print(ctrl.hpf2nd(100.,0.7,0.001))0.9358z^2-1.3z+0.3641---------------------------z^2-1.172z+0.4283dt=0.0013.24. nfpylib_sakata.ctrl.nf(freq, zeta, depth, dt=None, method='matched')This function is for design of notch filters.
$$F_{notch}(s) = \frac{s^2+2d\zeta (2\pi f)s+(2\pi f)^2}{s^2+2\zeta (2\pi f)s+(2\pi f)^2}$$Parameters:freq: array of frequency[Hz] of the notch filterszeta: array of damping of the notch filtersdepth: array of depth of the notch filters (0 < depth < 1)dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'matched', set a method if dt > 0Returns:out: array of instance of TransferFunction class of the notch filtersExamples>>>ctrl.nf([100.,200.,300.],[0.02,0.02,0.02],[0.01,0.01,0.01])array([TransferFunction(array([1.00000000e+00,2.51327412e-01,3.94784176e+05]),array([1.00000000e+00,2.51327412e+01,3.94784176e+05])),TransferFunction(array([1.00000000e+00,5.02654825e-01,1.57913670e+06]),array([1.00000000e+00,5.02654825e+01,1.57913670e+06])),TransferFunction(array([1.00000000e+00,7.53982237e-01,3.55305758e+06]),array([1.00000000e+00,7.53982237e+01,3.55305758e+06]))],dtype=object)>>>ctrl.nf([100.,200.,300.],[0.02,0.02,0.02],[0.01,0.01,0.01],0.001)array([TransferFunction(array([0.9876627,-1.59787102,0.9874145]),array([1.,-1.59797428,0.97518046]),0.001),TransferFunction(array([0.97553399,-0.6027617,0.97504375]),array([1.,-0.60316088,0.95097692]),0.001),TransferFunction(array([0.96362486,0.59532837,0.96289858]),array([1.,0.59447771,0.92737411]),0.001)],dtype=object)3.25. pfpylib_sakata.ctrl.pf(freq, zeta, k, phi, dt=None, method='tustin')This function is for design of peak filters (resonant filters).
$$F_{peak}(s) = \frac{k(s^2-\phi s)}{s^2+2\zeta (2\pi f)s+(2\pi f)^2}$$Parameters:freq: array of frequency[Hz] of the peak filterszeta: array of damping of the peak filtersk: array of peak width of the peak filtersphi: array of phase lead of the peak filterdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: array of instance of TransferFunction class of the peak filtersExamples>>>ctrl.pf([2.,3.,5.],[0.001,0.001,0.001],[-0.00025695,-0.00049616,0.0003898],[860.21053991,633.22924516,-1090.49879949])>>>ctrl.pf([2.,3.,5.],[0.001,0.001,0.001],[-0.00025695,-0.00049616,0.0003898],[860.21053991,633.22924516,-1090.49879949])array([TransferFunction(array([-0.00025695,0.2210311,0.]),array([1.00000000e+00,2.51327412e-02,1.57913670e+02])),TransferFunction(array([-0.00049616,0.31418302,0.]),array([1.00000000e+00,3.76991118e-02,3.55305758e+02])),TransferFunction(array([3.89800000e-04,4.25076432e-01,0.00000000e+00]),array([1.00000000e+00,6.28318531e-02,9.86960440e+02]))],dtype=object)>>>ctrl.pf([2.,3.,5.],[0.001,0.001,0.001],[-0.00025695,-0.00049616,0.0003898],[860.21053991,633.22924516,-1090.49879949],0.001)array([TransferFunction(array([-0.00014643,0.00051387,-0.00036745]),array([1.,-1.99981696,0.99997487]),0.001),TransferFunction(array([-0.00033903,0.00099221,-0.00065318]),array([1.,-1.99960704,0.9999623]),0.001),TransferFunction(array([0.00060217,-0.00077938,0.00017721]),array([1.,-1.9989505,0.99993719]),0.001)],dtype=object)3.26. pfoptparampylib_sakata.ctrl.pfoptparam(freq, zeta, depth, sysT)This function is for getting parameters of optimized peak filters (resonant filters).Parameters:freq: array of frequency[Hz] of the peak filterszeta: array of damping of the peak filtersdepth: array of depth of the peak filters (0 < depth < 1)sysT: LTI model (StateSpace or TransferFunction or ZpkModel or FreqResp) of complementary sensitivity function of the previous feedback systemReturns:freq: array of frequency[Hz] of the peak filterszeta: array of damping of the peak filtersk: array of peak width of the peak filtersphi: array of phase lead of the peak filterExamples>>>Ps=ctrl.tf([1.],[2.,10.,0.])>>>Cs=ctrl.pid(10.,1.,10.,0.7,2.,10.,0.)>>>ctrl.pfoptparam([2.,3.,5.],[0.001,0.001,0.001],[0.1,0.1,0.1],ctrl.feedback(Ps,Cs,sys='T'))Thecommonpole-zerosofthezpkmodelhavebeendeleted.([2.0,3.0,5.0],[0.001,0.001,0.001],array([-0.00025695,-0.00049616,0.0003898]),array([860.21053991,633.22924516,-1090.49879949]))3.27. pfoptpylib_sakata.ctrl.pfopt(freq, zeta, depth, sysT, dt=None, method='tustin')This function is for design of optimized peak filters (resonant filters).Parameters:freq: array of frequency[Hz] of the peak filterszeta: array of damping of the peak filtersdepth: array of depth of the peak filters (0 < depth < 1)sysT: LTI model (StateSpace or TransferFunction or ZpkModel or FreqResp) of complementary sensitivity function of the previous feedback systemdt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.method: discretized method (Optional), Default: 'tustin', set a method if dt > 0Returns:out: array of instance of TransferFunction class of the peak filtersExamples>>>Ps=ctrl.tf([1.],[2.,10.,0.])>>>Cs=ctrl.pid(10.,1.,10.,0.7,2.,10.,0.)>>>ctrl.pfopt([2.,3.,5.],[0.001,0.001,0.001],[0.1,0.1,0.1],ctrl.feedback(Ps,Cs,sys='T'))Thecommonpole-zerosofthezpkmodelhavebeendeleted.array([TransferFunction(array([0.00486434,0.24323591,0.]),array([1.00000000e+00,2.51327412e-02,1.57913670e+02])),TransferFunction(array([0.00723091,0.35823306,0.]),array([1.00000000e+00,3.76991118e-02,3.55305758e+02])),TransferFunction(array([0.01199547,0.56160871,0.]),array([1.00000000e+00,6.28318531e-02,9.86960440e+02]))],dtype=object)>>>ctrl.pfopt([2.,3.,5.],[0.001,0.001,0.001],[0.1,0.1,0.1],ctrl.feedback(Ps,Cs,sys='T'),0.001)Thecommonpole-zerosofthezpkmodelhavebeendeleted.array([TransferFunction(array([0.0049857,-0.00972818,0.00474248]),array([1.,-1.99981696,0.99997487]),0.001),TransferFunction(array([0.00740923,-0.01446026,0.00705103]),array([1.,-1.99960704,0.9999623]),0.001),TransferFunction(array([0.01227286,-0.02398427,0.01171141]),array([1.,-1.9989505,0.99993719]),0.001)],dtype=object)3.28. dobpylib_sakata.ctrl.dob(freq, zeta, M, C, K, dt, nd = 0)This function is for design of a discrete-time disturbance observer (DOB).
$$\hat{d} = -z^{-n_d} Q[z] u + Q[z] P^{-1}[z] y$$Here, it is defined that disturbance $d$ is injected in the system as plus sign.Parameters:freq: frequency[Hz] of the pole pair of the DOBzeta: damping of the pole pair of the DOBM: mass[kg] of the plantC: viscosity[N/(m/s)] of the plantK: stiffness[N/m] of the plantdt: sampling time of the systemnd: sampling number of the dead-time of the systemReturns:DOBu: $z^{-n_d} Q[z]$DOBy: $Q[z] P^{-1}[z]$Examples>>>DOBu,DOBy=ctrl.dob(5.,0.7,1.,10.,0.,0.001,1)>>>print(DOBu)0.0004836z+0.0004819-------------------------z^3-1.956z^2+0.957zdt=0.001>>>print(DOBy)970.3z^2-1931z+960.7--------------------------z^2-1.956z+0.957dt=0.0013.29. zpetcpylib_sakata.ctrl.zpetc(Pz, dt, zerothr=0.99)This function is for design of a zero phase error tracking controller (ZPETC).Parameters:Pz: instance of TransferFunction class of discrete-time LTI systemdt: sampling time of the systemzerothr: threshold to recognize unstable zeros (Optional), Default: 0.99Returns:Czpetc: instance of TransferFunction class of ZPETCNzpetc: number of forward samples>>>Ps=ctrl.tf([1.],[1.,10.,0.])>>>Pz=ctrl.c2d(Ps,0.001)>>>print(Pz)2.488e-07z^2+4.975e-07z+2.488e-07---------------------------------------z^2-1.99z+0.99dt=0.001>>>Czpetc,Nzpetc=ctrl.zpetc(Pz)Thecommonpole-zerosofthezpkmodelhavebeendeleted.>>>print(Czpetc)2.512e+05z^4+2500z^3-5e+05z^2-2500z+2.487e+05---------------------------------------------------------z^4dt=0.001>>>Nzpetc23.30. filtpylib_sakata.ctrl.filt(num, den, dt)This function is to create transfer functions as rational expressions in $z^{-1}$ and to order the numerator and denominator terms in ascending powers of $z^{-1}$.Parameters:num: polynomial coefficients of the numerator of the discrete-time LTI modelden: polynomial coefficients of the denominator of the discrete-time LTI modeldt: sampling time of the discrete-time LTI modelReturns:out: instance of TransferFunction class of ZPETC3.31. minrealpylib_sakata.ctrl.minreal(sys)This function is to delete the common pole-zeros of the system.Parameters:sys: LTI model (StateSpace or TransferFunction or ZpkModel)Returns:out: LTI model whose the common pole-zeros were deleted3.32. makeprmsetpylib_sakata.ctrl.makeprmset(path='.')This function is to create Cpp and header files of controller parameter setsParameters:path: path to create Cpp and header files of controller parameter setsReturns:None3.33. defprmsetpylib_sakata.ctrl.defprmset(tfz, prmSetName, path='.', mode='a')Parameters:tfz: discrete time TransferFunction modelprmSetName: parameter set name of the following struct in Cpppath: path to create Cpp and header files of controller parameter setsmode: mode to open Cpp and header filesReturns:Nonetypedefstruct{doubledA[2];doubledB[2];doubledInPre;doubledOutPre;}TF1_INF;// 1st order TF informationtypedefstruct{doubledA[3];doubledB[3];doubledInPre[2];doubledOutPre[2];}TF2_INF;// 2nd order TF informationtypedefstruct{doubledA[4];doubledB[4];doubledInPre[3];doubledOutPre[3];}TF3_INF;// 3rd order TF information4. pylib_sakata.fft4.1. FreqRespclass pylib_sakata.fft.FreqResp(freq, resp, dt=0)Parameters:freq: 1-D array frequency data [Hz]resp: 1-D array frequency response data [complex data]dt: sampling time (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.ExamplesRefer examples of3.11. sys2frd.Methods__neg__()
Negate a FRD.__add__(other)
Add two FRDs (parallel connection).__radd__(other)
Right add two FRDs (parallel connection).__sub__(other)
Subtract two FRDs.__rsub__(other)
Right subtract two FRDs.__mul__(other)
Multiply two FRDs (serial connection).__rmul__(other)
Right multiply two FRDs (serial connection).__truediv__(other)
Divide two FRDs.__rtruediv__(other)
Right divide two FRDs.__pow__(other)
A FRD to the power of x.4.2. fftpylib_sakata.fft.fft(data, dt)This function is for calculating FFT from 1-D array data.Parameters:data: 1-D array time response datadt: sampling time of the time response dataReturns:freq_data: 1-D array frequency data [Hz]fft_data: 1-D array FFT dataExamplesimportnumpyasnp>>>dt=0.001>>>t=np.linspace(0.0,10.,int(10./dt))>>>x=np.sin(2*np.pi*10.0*t)+np.sin(2*np.pi*50.0*t)>>>fft.fft(x,dt)(array([0.00000000e+00,1.00010001e-01,2.00020002e-01,...,9.99799980e+02,9.99899990e+02,1.00000000e+03]),array([3.93463040e-17,2.39600781e-06,4.79322523e-06,...,7.19286425e-06,4.79322523e-06,2.39600781e-06]))4.3. fft_avepylib_sakata.fft.fft_ave(data, dt, windivnum=4, overlap=0.5)This function is for calculating averaged FFT from 1-D array data.Parameters:data: 1-D array time response datadt: sampling time of the time response datawindivnum: number of windows to divide the time response dataoverlap: overlap ratio divided time response data (0 <= overlap < 1)Returns:freq_data: 1-D array frequency data [Hz]fft_data: 1-D array FFT dataExamplesimportnumpyasnp>>>dt=0.001>>>t=np.linspace(0.0,10.,int(10./dt))>>>x=np.sin(2*np.pi*10.0*t)+np.sin(2*np.pi*50.0*t)>>>fft.fft_ave(x,dt,4,0.5)(array([0.00000000e+00,4.88519785e-01,9.77039570e-01,...,9.99022960e+02,9.99511480e+02,1.00000000e+03]),array([5.33388114e-05,5.46444944e-05,5.85999322e-05,...,6.53498409e-05,5.85999322e-05,5.46444944e-05]))4.4. tfestimatepylib_sakata.fft.tfestimate(x, y, freq, dt, windivnum=4, overlap=0.5)This function is for system identification from input and output time response data.Parameters:x: 1-D array time response data of inputy: 1-D array time response data of outputfreq: 1-D array frequency data [Hz]dt: sampling time of the time response datawindivnum: number of windows to divide the time response dataoverlap: overlap ratio divided time response data (0 <= overlap < 1)Returns:freqresp: instance of FreqResp classcoh: 1-D array coherence dataExamples>>>importnumpyasnp>>>fromscipyimportsignal>>>fromcontrolimportmatlab>>>P_tf=ctrl.tf([1.],[1.,2.,0.])>>>C_tf=ctrl.tf([2.,4.,1.],[1.,2.,0.])>>>dt=0.001>>>t=np.linspace(0.0,10.,int(10./dt))>>>d=signal.chirp(t,f0=0.1,f1=500.,t1=50.,method='logarithmic',phi=-90.)>>>u,tout,xout=matlab.lsim(ctrl.feedback(P_tf,C_tf),d,t)>>>y,tout,xout=matlab.lsim(ctrl.feedback(P_tf,C_tf,'SP'),d,t)Thecommonpole-zerosofthezpkmodelhavebeendeleted.>>>freq=np.logspace(np.log10(1.),np.log10(500.),10000,base=10)>>>fft.tfestimate(u,y,freq,dt)(array([-0.11586071-1.49076948e-01j,-0.11590257-1.49078279e-01j,-0.11594446-1.49079611e-01j,...,-0.13155661-1.45847229e-01j,-0.14201211-1.03211830e-01j,-0.15745492-1.88460358e-14j]),array([0.77271576,0.77244166,0.7721674,...,0.23080322,0.32843388,0.43848208]))4.5. frdresizepylib_sakata.fft.frdresize(freqresp, freq)This function is for resizing a frequency response data.Parameters:freqresp: instance of FreqResp classfreq: new 1-D array frequency data [Hz] for resizeReturns:freqresp: resized instance of FreqResp class based on new frequency data arrayExamples>>>importnumpyasnp>>>freq=np.logspace(np.log10(1.),np.log10(1000.),100,base=10)>>>Sys_tf=ctrl.tf([1.,2.],[3.,4.,5.])>>>freqresp=ctrl.sys2frd(Sys_tf,freq)>>>freq_resize=np.logspace(np.log10(1.),np.log10(1000.),10000,base=10)>>>fft.frdresize(freqresp,freq_resize)freq=array([1.1.000691081.00138264...998.61926487999.309393971000.])resp=array([-5.10821217e-03-5.65218353e-02j-5.10244172e-03-5.64813436e-02j-5.09666728e-03-5.64408239e-02j...-5.64622394e-09-5.31301950e-05j-5.63759203e-09-5.30909366e-05j-5.62895416e-09-5.30516511e-05j])4.6. frdsimpylib_sakata.fft.frdsim(freqresp, x, dt)This function is for simulation steady time response data when a time-domain data is input to a system written by frequency response data.
$$y(t) = \text{ifft}(\text{FreqResp}(\omega)\times\text{fft}(u(t)))$$Parameters:freqresp: instance of FreqResp classx: 1-D array time response data of inputdt: sampling time of the time response dataReturns:t: 1-D array time data [s]y: 1-D array time response data of outputExamples>>>importnumpyasnp>>>freq=np.logspace(np.log10(1.),np.log10(1000.),100,base=10)>>>Sys_tf=ctrl.tf([1.,2.],[3.,4.,5.])>>>freqresp=ctrl.sys2frd(Sys_tf,freq)>>>dt=0.001>>>t=np.linspace(0.0,10.,int(10./dt))>>>x=np.sin(2*np.pi*10.0*t)+np.sin(2*np.pi*50.0*t)>>>fft.frdsim(freqresp,x,dt)(array([0.000e+00,1.000e-03,2.000e-03,...,9.996e+00,9.997e+00,9.998e+00]),array([-0.00635301,-0.00630568,-0.00612106,...,-0.00610225,-0.0062943,-0.00634922]))5. pylib_sakata.meas5.1. MeasDataclass pylib_sakata.meas.MeasData(time, list, value, time, dt)Parameters:dataList: array of data list (str)value: array of data valuetime: 1-D array time data [s]dt: sampling time of the time response data5.2. getcsvdatapylib_sakata.meas.getcsvdata(filePath)This function is for getting measurement data from a csv file.Parameters:filePath: csv file path of measurement fileReturns:instance of MeasData classExamplesmeasdata=meas.getcsvdata('data\001-inject.csv')5.3. gettxtdatapylib_sakata.meas.gettxtdata(filePath)This function is for getting measurement data from a txt file.Parameters:filePath: txt file path of measurement fileReturns:instance of MeasData classExamplesmeasdata=meas.gettxtdata('data\001-inject.txt')5.4. getmatdatapylib_sakata.meas.getmatdata(filePath)This function is for getting measurement data from a mat file.Parameters:filePath: mat file path of measurement fileReturns:instance of MeasData classExamplesmeasdata=meas.getmatdata('data\001-inject.mat')5.5. getdatapylib_sakata.meas.getdata(filePath)This function is for getting measurement data from a file.Parameters:filePath: file path of measurement file (.csv, .txt, and .mat are supported.)Returns:instance of MeasData classExamplesmeasdata=meas.getdata('data\001-inject.csv')measdata=meas.getdata('data\001-inject.txt')measdata=meas.getdata('data\001-inject.mat')5.6. getdataindexpylib_sakata.meas.getdataindex(measdata, dataName)Parameters:measdata: instance of MeasData classdataName: data nameReturns:index: index of dataNameExamplesindex=meas.getdataindex(measdata,'ServoOut')5.7. measdata2frdpylib_sakata.meas.measdata2frd(filePath, inputName, outputName, flagName, freq, inputGain=1.0, outputGain=1.0, windivnum=4, overlap=0.5)This function is for system identification from input and output time response data of measurement file.Parameters:filePath: file path of measurement file (.csv, .txt, and .mat are supported.)inputName: input data name in the measurement fileoutputName: output data name in the measurement fileflagName: flag data name in the measurement filefreq: 1-D array frequency data [Hz]inputGain: inputdata gain (Optional), Default: 1.0, unit of input can be fixed by this parameter.outputGain: outputdata gain (Optional), Default: 1.0, unit of output can be fixed by this parameter.dt: sampling time of the time response datawindivnum: number of windows to divide the time response dataoverlap: overlap ratio divided time response data (0 <= overlap < 1)Returns:freqresp: instance of FreqResp classcoh: 1-D array coherence dataExamplesimportnumpyasnpfreq=np.logspace(np.log10(1.),np.log10(1000.),10000,base=10)freqresp,coh=measdata2frd('data\001-inject.csv','ServoOut','PosErrUm','FlagNoise',freq,1.,1.e-6)6. pylib_sakata.traj6.1. TrajInfclass pylib_sakata.traj.TrajInf(time, pos, vel, acc, T, dt)Parameters:time: 1-D array time data [s]pos: 1-D array position trajectory data [m]vel: 1-D array velocity trajectory data [m/s]acc: 1-D array acceleration trajectory data [m/s^2]T: moving time [s]dt: sampling time of the trajectory data6.2. traj3rdpylib_sakata.traj.traj3rd(posStart, posStep, velMax, accAve, dt, Tstay=0)This function is for generation of a 3rd order polynomial trajectory.Parameters:posStart: start position of the trajectoryposStep: step position of the trajectoryvelMax: maximum of velocity of the trajectoryaccAve: average of accelation (= decelation) of the trajectorydt: sampling time of the trajectory data.Tstay: time after the step movingReturns:out: instance of TrajInf class of the 3rd order polynomial trajectoryExamplestraj=traj.traj3rd(0,100,100,200,0.001,0.5)6.3. traj3rd2pylib_sakata.traj.traj3rd2(posStart, posStep, velMax, accAve, jerkRatio, dt, Tstay=0)This function is for generation of a 3rd order polynomial trajectory as trapezoidal accelaration trajectory.Parameters:posStart: start position of the trajectoryposStep: step position of the trajectoryvelMax: maximum of velocity of the trajectoryaccAve: average of accelation (= decelation) of the trajectoryjerkRatio: ratio of jerk time per accelaration time (0 < jerkRatio <= 0.5)dt: sampling time of the trajectory data.Tstay: time after the step movingReturns:out: instance of TrajInf class of the 3rd order polynomial trajectoryExamplestraj=traj.traj3rd2(0,100,100,200,0.001,0.2,0.5)6.4. traj4thpylib_sakata.traj.traj4th(posStart, posStep, velMax, accAve, dt, Tstay=0)pylib_sakata.traj.traj4th2(posStart, posStep, velMax, accAve, dt, Tstay=0)This function is for generation of a 4th order polynomial trajectory.Parameters:posStart: start position of the trajectoryposStep: step position of the trajectoryvelMax: maximum of velocity of the trajectoryaccAve: average of accelation (= decelation) of the trajectorydt: sampling time of the trajectory data.Tstay: time after the step movingReturns:out: instance of TrajInf class of the 4th order polynomial trajectoryExamplestraj=traj.traj4th(0,100,100,200,0.001,0.5)6.5. trajSinSteppylib_sakata.traj.trajSinStep(posStart, posStep, velMax, accAve, dt, Tstay=0)
pylib_sakata.traj.trajSinStep2(posStart, posStep, velMax, accAve, dt, Tstay=0)
pylib_sakata.traj.trajSinStep3(posStart, posStep, velMax, accAve, dt, Tstay=0)This function is for generation of a trajectory based on sine waves.Parameters:posStart: start position of the trajectoryposStep: step position of the trajectoryvelMax: maximum of velocity of the trajectoryaccAve: average of accelation (= decelation) of the trajectorydt: sampling time of the trajectory data.Tstay: time after the step movingReturns:out: instance of TrajInf class of the trajectory based on sine wavesExamplestraj=traj.SinStep(0,100,100,200,0.001,0.5)The comparison of these trajectories under the specification: posStep = 1, velMax = 1, accAve = 2 is shown as follows.7. pylib_sakata.plot7.1. plot_xypylib_sakata.plot.plot_xy(ax, x, y, styl='-', col='b', width=1.5, alpha=1.0, xrange=None, yrange=None, xlabel=None, ylabel=None, legend=None, loc='best', title=None, xscale='linear', yscale='linear', labelouter=True)This function is for drawing a 2-D figure from x and y data. You can select xy scale in linear type, log type and so on.Parameters:ax: handle of axisx: 1-D array data of x-axisy: 1-D array data of y-axisstyl: line style (Optional), Default: '-', Select in '-' (solid), '--' (dashed), '.' (dotted), '-.' (dashdot)col: line color (Optional), Default: 'b' (blue)width: line width (Optional), Default: 1.5alpha: transmittance of line, Default: 1.0, set from 0 to 1.0xrange: plot range of x-axis (Optional), Default: None, set as [xmin, xmax]yrange: plot range of y-axis (Optional), Default: None, set as [ymin, ymax]xlabel: label of x-axis (Optional), Default: None, set strings dataylabe: label of y-axis (Optional), Default: None, set strings datalegend: legend of data, Default: None, set a list of strings dataloc: location of the legend, Default: 'best',Detailtitle: title of figure (Optional), Default: None, set strings dataxscale: scale type of x-axis (Optional), Default: 'linear', set in 'linear', 'log', ...labelouter: only display outer label of xy-axes, Default: TrueReturns:NoneExamplesfig1=plot.makefig()ax1=fig1.add_subplot(311)ax2=fig1.add_subplot(312)ax3=fig1.add_subplot(313)plot.plot_xy(ax1,t,chirp,'-','m',0.5,1.0,[0,50],[-3.0,3.0],ylabel='Input [N]',legend=['Chirp'],title='Time response')plot.plot_xy(ax2,tout,u,'-','b',0.5,1.0,[0,50],[-3.0,3.0],ylabel='Input [N]',legend=['Servo Out'])plot.plot_xy(ax3,tout,y*1.0e3,'-','b',0.5,1.0,[0,50],[-0.3,0.3],xlabel='Time [s]',ylabel='Output [mm]',legend=['Position'])fig2=plot.makefig()ax1=fig2.add_subplot(311)ax2=fig2.add_subplot(312)ax3=fig2.add_subplot(313)plot.plot_xy(ax1,fft_axis,chirp_fft,'-','m',1.5,1.0,freqrange,[0,1.0],ylabel='Input [N]',legend=['Chirp'],title='Power spectrum density',xscale='log')plot.plot_xy(ax2,fft_axis,u_fft,'-','b',1.5,1.0,freqrange,[0,0.1],ylabel='Input [N]',legend=['Servo Out'],xscale='log')plot.plot_xy(ax3,fft_axis,y_fft*1.0e6,'-','b',1.5,1.0,freqrange,[0,20],xlabel='Frequency [Hz]',ylabel='Output [um]',legend=['Position'],xscale='log')7.2. plot_tfpylib_sakata.plot.plot_tf(ax_mag, ax_phase, sys, freq, styl='-', col='b', width=1.5, alpha=1.0, freqrange=None, magrange=None, legend=None, loc='best', title=None, labelouter=True)This function is for drawing a Bode diagram from a LTI model.Parameters:ax_mag: handle of magnitude axisax_phase: handle of phase axis, if you set as None, phase axis is skipped.sys: LTI model (StateSpace or TransferFunction)freq: 1-D array frequency data [Hz]styl: line style (Optional), Default: '-', Select in '-' (solid), '--' (dashed), '.' (dotted), '-.' (dashdot)col: line color (Optional), Default: 'b' (blue)width: line width (Optional), Default: 1.5alpha: transmittance of line, Default: 1.0, set from 0 to 1.0freqrange: plot range of frequency-axis (Optional), Default: None, set as [freqmin, freqmax]magrange: plot range of magnitude-axis (Optional), Default: None, set as [magmin, magmax]legend: legend of data, Default: None, set a list of strings dataloc: location of the legend, Default: 'best',Detailtitle: title of figure (Optional), Default: None, set strings datalabelouter: only display outer label of xy-axes, Default: TrueReturns:NoneExamples# Sensitivity functionfig1=plot.makefig()ax_mag=fig1.add_subplot(111)ax_phase=Noneplot.plot_tf(ax_mag,ax_phase,S,freq,'-','m',1.5,1.0,title='Frequency response of sensitivity function')plot.plot_tf(ax_mag,ax_phase,Sn,freq,'--','b',1.5,1.0,[1,1000],[-60,10],legend=['Measurement','Model'])# Complementary sensitivity functionfig2=plot.makefig()ax_mag=fig2.add_subplot(211)ax_phase=fig2.add_subplot(212)plot.plot_tf(ax_mag,ax_phase,T,freq,'-','m',1.5,1.0,title='Frequency response of complementary sensitivity function')plot.plot_tf(ax_mag,ax_phase,Tn,freq,'--','b',1.5,1.0,[1,1000],[-60,10],legend=['Measurement','Model'])7.3. plot_tffrdpylib_sakata.plot.plot_tffrd(ax_mag, ax_phase, freqresp, styl='-', col='b', width=1.5, alpha=1.0, freqrange=None, magrange=None, legend=None, loc='best', title=None, labelouter=True, ax_coh=None, coh=None)This function is for drawing a Bode diagram from a frequency response data.Parameters:ax_mag: handle of magnitude axisax_phase: handle of phase axis, if you set as None, phase axis is skipped.freqresp: instance of FreqResp classstyl: line style (Optional), Default: '-', Select in '-' (solid), '--' (dashed), '.' (dotted), '-.' (dashdot)col: line color (Optional), Default: 'b' (blue)width: line width (Optional), Default: 1.5alpha: transmittance of line, Default: 1.0, set from 0 to 1.0freqrange: plot range of frequency-axis (Optional), Default: None, set as [freqmin, freqmax]magrange: plot range of magnitude-axis (Optional), Default: None, set as [magmin, magmax]legend: legend of data, Default: None, set a list of strings dataloc: location of the legend, Default: 'best',Detailtitle: title of figure (Optional), Default: None, set strings datalabelouter: only display outer label of xy-axes, Default: Trueax_coh: handle of coherence axis, Default: Nonecoh: 1-D array coherence data, Default: NoneReturns:NoneExamples# Plantfig1=plot.makefig()ax_mag=fig.add_subplot(311)ax_phase=fig.add_subplot(312)ax_coh=fig.add_subplot(313)plot.plot_tffrd(ax_mag,ax_phase,Pmeas_frd,'-','m',1.5,1.0,ax_coh=ax_coh,coh=coh,title='Frequency response of plant')plot.plot_tffrd(ax_mag,ax_phase,Pnz_frd,'--','b',1.5,1.0,freqrange,legend=['Measurement','Model'])# Sensitivity functionfig2=plot.makefig()ax_mag=fig1.add_subplot(111)ax_phase=Noneplot.plot_tffrd(ax_mag,ax_phase,S_frd,'-','m',1.5,1.0,title='Frequency response of sensitivity function')plot.plot_tffrd(ax_mag,ax_phase,Sn_frd,'--','b',1.5,1.0,[1,1000],[-60,10],legend=['Measurement','Model'])# Complementary sensitivity functionfig3=plot.makefig()ax_mag=fig2.add_subplot(211)ax_phase=fig2.add_subplot(212)plot.plot_tffrd(ax_mag,ax_phase,T_frd,'-','m',1.5,1.0,title='Frequency response of complementary sensitivity function')plot.plot_tffrd(ax_mag,ax_phase,Tn_frd,'--','b',1.5,1.0,[1,1000],[-60,10],legend=['Measurement','Model'])7.4. plot_nyquistpylib_sakata.plot.plot_nyquist(ax, freqresp, styl='-', col='b', width=1.5, alpha=1.0, xrange=None, yrange=None, legend=None, loc='best', title=None, labelouter=True)This function is for drawing a Nyquist diagram from a frequency response data of a open loop systemParameters:ax: handle of axisfreqresp: instance of FreqResp classstyl: line style (Optional), Default: '-', Select in '-' (solid), '--' (dashed), '.' (dotted), '-.' (dashdot)col: line color (Optional), Default: 'b' (blue)width: line width (Optional), Default: 1.5alpha: transmittance of line, Default: 1.0, set from 0 to 1.0xrange: plot range of real-axis (Optional), Default: None, set as [realmin, realmax]yrange: plot range of imaginary-axis (Optional), Default: None, set as [imagmin, imagmax]legend: legend of data, Default: None, set a list of strings dataloc: location of the legend, Default: 'best',Detailtitle: title of figure (Optional), Default: None, set strings datalabelouter: only display outer label of xy-axes, Default: TrueReturns:NoneExamplesfig=plot.makefig()ax=fig.add_subplot(111)plot.plot_nyquist(ax,G_frd,'-','m',1.5,1.0,title='Nyquist Diagram')plot.plot_nyquist(ax,Gn_frd,'--','b',1.5,1.0,legend=['Measurement','Model'])7.5. plot_nyquist_assistlinepylib_sakata.plot.plot_nyquist_assistline(ax)This function is for drawing assist line of a Nyquist diagram.Parameters:ax: handle of axisReturns:NoneExamplesplot.plot_nyquist_assistline(ax)7.6. makefigpylib_sakata.plot.makefig(dpi=100, figsize=(6, 4), popwin=False)This function will make a new figure handle.Parameters:dpi: dot per inch of figure (Optional), Default: 100figsize: set figure size (Optional), Default: (6, 4) which means 600x400 pixelspopwin: switch to fix the popup window of the figure (Optional), Default: FalseReturns:fig: figure handleExamplesfig=plot.makefig()7.7. savefigpylib_sakata.plot.savefig(figName)This function will save a current figure.Parameters:figName: figure name for saving a current figure, set strings dataReturns:NoneExamplesplot.savefig('freq_P.png')7.8. showfigpylib_sakata.plot.showfig()This function will call matplotlib.pyplot.show()Examplesshowfig()8. pylib_sakata.init8.1. close_allpylib_sakata.init.close_all()This function is for closing current opened figures.Examplesclose_all()8.2. clear_allpylib_sakata.init.clear_all()This function is for deleting all defined variables.Examplesclear_all()