14.1 状态空间
输入是u,输出是y
多输入,u是标量还是向量都可以,只要调整B、D即可。 多输出,C、D决定了y是标量还是向量。
?(t)?AX(t)?BU(t)?X ??Y(t)?CX(t)?DU(t)系统系数矩阵 A,系统输入矩阵 B 系统输出矩阵 C,直接传输矩阵 D 简记为(A,B,C,D)形式。
[A,B,C,D] = TF2SS(NUM,DEN)
14.2 从传函得到微分方程
从传函得到微分方程,可以通过tf2ss得到对应的状态空间表达式之后,再写出对应的y/u,即可。
31
14.3 LTI models(线性时不变系统 linear time invariable)
1.1 Linear Model Representations
The Control System Toolbox supports the following model representations: (1) State-space models (SS) of the form sys_dc = ss(A,B,C,D) (2)Transfer functions (TF) sys_tf =tf(num,den) (3) Zero-pole-gain (ZPK) models sys_zpk =zpk(zeros, poles)
(4) Frequency response data (FRD) models, which consist of sampled measurements of a system's frequency response. sys_rf =frd(response,frequencies) Type TF2SS TF2ZP SS2TF ZP2SS ZP2TF Conversion of LTI models [A,B,C,D] = TF2SS(NUM,DEN) [Z,P,K] = TF2ZP(NUM,DEN) [NUM,DEN] = SS2TF(A,B,C,D,iu) [A,B,C,D] = ZP2SS(Z,P,K) [NUM,DEN] = ZP2TF(Z,P,K) Remark 1.1.1 Discrete Time Systems
For example, sys_disc = tf(num, den, Ts);
1.1.2 Adding Delays to Linear Models
You can add time delays to linear models by specifying an input or output delay when building a model. sys_delay = tf(num, den, 'outputdelay', delayTime);
1.2 Model Characteristics
size(model_name) ndims(model_name) pole(model_name) zero(model_name) dcgain(model_name) norm(model_name) Number of inputs and outputs Number of dimensions System poles System (transmission) zeros DC gain System norms (H2 and L) 1.3 Interconnecting Linear Models
Equivalent Ways to Interconnect Systems Operator sys1 + sys2 sys1 * sys2 Function parallel(sys1,sys2) series(sys2,sys1) Resulting Transfer Function Systems in parallel Cascaded systems You can use the feedback and lft functions to derive closed-loop models. For example, sys_f = feedback (plantSys, feedSys)
1.4 Continuous/Discrete Conversions
The commands c2d, d2c, and d2d perform continuous to discrete, discrete to continuous, and discrete to discrete (resampling) conversions, respectively.
32
sysd = c2d(sysc,Ts) % Discretization w/ sample period Ts sysc = d2c(sysd) % Equivalent continuous-time model sysd1= d2d(sysd,Ts) % Resampling at the period Ts 1.5 Model Order Reduction balreal minreal modred sminreal Input/output balancing Minimal realization (pole/zero cancellation) State deletion in I/O balanced realization Structurally minimal realization 14.4 Analyzing Models
2.1 LTI Viewer
2.2 Simulink LTI Viewer
2.3 Functions for Time and Frequency Response
Time responses investigate the time-domain transient behavior of linear models for particular classes of inputs and disturbances. You can determine such system characteristics as rise time, settling time, overshoot, and steady-state error from the time response. State Time Domain initial gensig lsim impulse step Frequency Domain freqresp bode nichols nyquist margin Initial condition response plot Input signal generator (for lsim) Simulation of response to arbitrary inputs Impulse response plot Step response plot Computes the frequency response for a set of frequencies Bode plot Nichols plot Nyquist plot Computes and plots gain and phase margins 2.3.1 Plotting MIMO Model Responses
example: bode([sys1, sys2]);
2.3.2 Plotting and Comparing Multiple Systems
Example : bode(sys1,'r',sys2,'y--',sys3,'gx')
15 文件及文件夹操作
mkdir(strcat('10_figures\\fig_k',num2str(5)));% 在当前目录下的子目录‘10_figures’中产生fig_k5文件夹
批处理文件
d = dir('*.jpg'); % or *.xxx ,当前文件夹下文件,后缀不区分大小写 str = {d.name}; % get the name list
33
for i = 1: size(str,2) ...
filename = str(i); ...
do what you want... .... end
保持图像
saveas(gcf,fignameTemp,'emf');% fignameTemp可以包含一些路径信息
16 其他
16.1 如何生成A1, A2, A3, A4...这样的变量?
for i=1:5
eval(strcat(strcat('A',num2str(i)),'=',num2str(i^2))) end
16.2 如何写一个分段函数
res=fun1*(a1 16.3 排序 sort(x) 如果是向量,直接增序排列;如果是矩阵,按列增序排列; 系统数学模型是系统的一次近似模型,而仿真数学模型则是系统的二次近似模型。 符号运算 clear syms t k t=2*k-1; 34 f=(t+1)^4+6*(t+1)^3-16-(8*t^4-8*t^2+1)/8 collect(f) % 合并同类项 expand % 展开 积分:int syms k k=t a=-1; b=1; int(k^2,a,b) 数值积分: trapz syms x diff('ln(x)') % 微分 diff('tan(x)') % 符号积分 int('sqrt(1+x^2)') 17 滤波 17.1 小波滤波 小波滤波:一种频域滤波,对ay这种信号效果不错,压力信号也不错。这个滤波要求输入值的幅值较小。 Lev = 5; P_FL_f_2 = wden(P_FL,'sqtwolog','s','one',Lev,'sym8'); 特点: 1、 对已经操作过的数据,比如上面的P_FL_f_2,再用同样的Lev操作一次无效果。 2、 Lev只能是整数; 3、 Lev这个值越大,滤波越狠。 4、 如果某一段的值和中间部分的值有阶跃,那么会直接丢掉边上的值,这样滤波后的数据没有边儿上的部分。 对于1kHz的压力数据,这个值取4-6比较合适。如果不是在分析压力从给出指令,多长时间开始建立压力的话。 17.2 filter,matlab自带的,可以通过参数,设置成多种形式 % Y = FILTER(B,A,X) filters the data in vector X with the % filter described by vectors A and B to create the filtered 35