• PUDN用户
  • matlab
  • 5KB
  • zip
  • 0
  • 1 积分
  • 3
  • 2013-07-28 17:31
1. Transfer function to state space model transfer function to state space A=[1 1 1] B=[1 6 11 6] [A,B,C,D]=tf2ss(num,den)
  • programs txt.txt
1. Transfer function to state space model %transfer function to state space A=[1 1 1]; B=[1 6 11 6]; [A,B,C,D]=tf2ss(num,den) 2. State apace to transfer function model %state space to transfer function% a=[0 1 0;0 0 1;-6 -11 -6] b=[0;0;1] c=[1 1 1] d=[0] [num,den]=ss2tf(a,b,c,d) 3. Continuous time to discrete time %continuous time to discerete time num=[1 0 1] den=[1 3 2] ts=2 c=tf(num,den) g=c2d(c,ts,'tustin') 4. Discrete time to continuous time %discrete time to continuous time num=[1 3 2]; den=[1 -4 5]; a=tf(num,den,2) t=d2c(a,'tustin') 5. Controllability %verify controllable A=[0 1 0;0 0 1;-6 -11 -6] B=[0;0;1] co=ctrb(A,B) r=rank(co) L=length(A) if r==L disp('system is controllable') else disp('system is not controllable') end 6. Observability %verify observability A=[0 1 0;0 0 1;-6 -11 -6] C=[1 1 1] op=obsv(A,C) r=rank(op) L=length(A) if r==L disp('system is observable') else disp('system is not observable') end 7. Linear convolution %Linear convolution close all; clear all; %input sequence% x=[1 2 3]; %starting index of input% xs=0; %time vector for x(n)% xt=xs:xs+length(x)-1; %display the input sequence% subplot(3,1,1) stem(xt,x) xlabel('sample number -n'); ylabel('amplitude'); title('input sequence'); h=[1 2 -2 -1]; hs=-1; ht=hs:hs+length(h)-1; subplot(3,1,2) stem(ht,h) xlabel('sample number-n'); ylabel('amplitude'); title('input response sequence h(n)'); subplot(3,1,1) axis([-5 10 -10 10]) subplot(3,1,2) axis([-5 10 -10 10]) %convolve x(n) and h(n)% y=conv(x,h) %starting position of y(n)% ys=min(xs,hs) %length of the convolved signal% yl=length(x)+length(h)-1 yt=ys:ys+length(y)-1 subplot(3,1,3) stem(yt,y) xlabel('sample number') ylabel('amplitude') title('output sequence response') axis([-5 10 -10 10]) grid on; 8. Circular convolution % circular convolution for equal length sequences% x=[1 2 2 3]; y=[4 3 2 1]; %length of two sequences% nx=length(x) ny=length(y) if(nx~=ny) error('vector is must be the same length for this version') end [n m]=size(x) if((n<n*m)&&(m<n*n)) error('x must be the vector') end [n m]=size(y) if((n<n*m)&&(m<n*m)) error('y must be the vector') end %cyclic convolution% for n=1:10*nx ref_seq=x(1:nx); circ_shift=y(mod(n-1:-1:n-ny,ny)+1); %circularly shifted sequence% dot_prod=ref_seq.*circ_shift op(n)=sum(dot_prod) end stem(0:10*nx-1,op) %output as a column vector% op=op' %verification% op_verify=ifft(fft(x).*fft(y)) 9. Bode plot using MATLAB %bode plot clc; num=[80]; den=[1 22 40 0]; sys=tf(num,den) bode(sys) [pm gm wp wg]=margin(sys) if(gm>0&&pm>0) disp('system is stable') else disp('system is unstable') end 10. Stability using Liapunov approach %liapunov stability analysis clc; a=input('enter matrix a '); eig(a) q=input('enter matrix q '); p=lyap(a',q); eig(p) dp=det(p) if dp>0 disp('system is asymptotically stable') else disp('system is unstable') end 11. Root locus using MATLAB %root locus clc; num=input('enter the numarator') den=input('enter the denaminator') c=input('enter the no of values of p:') p=input('enter the values of p[]:') g=tf(num,den) rlocus(g) k=rlocfind(g) for i=1:c if(p(i)>k) fprintf('system is unstable') else fprintf('system is stable') end end 12. Design of PID controller %PID controller clc; g=tf([100],[1 13 32 20]) w=4 ess=0.1 pmd=45 kv=1/ess; k=100; a=1; b=13; c=32; d=20; [a1,f1]=bode(g,w); pmu=180+f1; t1=pmd-pmu tr=deg2rad(t1); ki=(kv*d)/k; kd=(sin(tr)/(w*a1))+(ki/w^2) kp=cos(tr)/a1 gc=tf([kd kp ki],[1 0]) g0=series(g,gc) [a0,f0]=bode(g0,w); pm0=180+f0 13. Back propagation algorithm %Back propagation algorithm clc; close all; clear all; tic; inp=[0 0;0 1;1 0;1 1]; targ=[0;1;1;0]; wi=[0.1 0.2;0.3 0.4]; wo=[-0.4 0.5]'; bi=[0.5 -1]; bo=-1; eta=0.1; i=1; xo=inp(1,:); l=wi*xo'+bi'; o=tansig(1); m=wo'*o+bo; op_hid=tansig(m); tp=targ(1); for s=1:4 l=wi*xo'+bi'; o=tansig(l); m=wo'*o+bo; op_hid=tansig(m); del_o=(1+op_hid)*(1-op_hid)*(tp-op_hid); del_j=(1+0).*(1-0).*(del_o*wo); wo=wo+(eta*del_o)*o; wi=wi+(eta)*(del_j*xo); i=mod(i,4)+1; xo=inp(i,:); tp=targ(i); end disp('results') final_input_weights=wi final_output_weights=wo 14. Minimum order observer %Minimum order observer clc; A=[0 1 0;0 0 1;-6 -11 -6]; B=[0;0;1]; C=[1 0 0]; D=[0]; aaa=[0]; aab=[1 0]; aba=[0;-6]; abb=[0 1;-11 -6]; ba=[0]; bb=[0;1]; p=poly(abb); a1=p(2); b2=p(3); w=[a1 1;1 0]; n=[aab' abb'*aab']; i=sqrt(-1); j=[-2+i*2*sqrt(3) 0;0 -2-i*2*sqrt(3)] jj=poly(j) aa1=jj(2) aa2=jj(3) ke=inv(w*n')*[aa2-b2;aa1-a1] 15. Full order observer %Full order observer clc; A=[0 1; 20.6 0]; B=[0 ;1]; C=[1 0 ]; D=[0]; m=[B A*B]; rank(m); i=sqrt(-1); j=[-1.8+i*2.4 0;0 -1.8-i*2.4] poly(j); ph1=polyvalm(poly(j),A); k=[0 1]*inv(m)*ph1; n=[C' A'*C']; rank(n); jo=[-8 0; 0 -8]; poly(jo); ph=polyvalm(poly(jo),A); ke=ph*inv(n')*[0;1]; [np,dp]=ss2tf(A,B,C,D); gp=tf(np,dp) [no,do]=ss2tf((A-B*k-ke*C),ke,k,D) gob=tf(no,do) H=tf([0 1],[0 1]) goltf=series(gp,gob) gcltf=feedback(goltf,H) 16. Continuous time Kalman filter %Continuous time Kalman filter clear clc close all %This script implements the linear filter and shows its performance %On a second order under-damped LTI systems %In the first part, a noisy model with two state variables is simulated and %in the second part, kalman filtering is applied to estimate the real %observations %Model Characteristics %x(t)=A*x(t-1)+v(t) StateDim=2; %number of states(size(A,1)) obsdim=1; %number of observations (size(C,1)) A = [1.9223 -0.9604 1.0000 0] C = zeros(obsdim,StateDim); C(:,1)=1; N = 100; x = zeros(StateDim,N); y=zeros(obsdim,N); %%Generate process noise(Noise of the state equation) var_PNoise = .1; Mu_PNoise = 0; Std_Pnoise = sqrt(var_PNoise)'; PNoise = Std_Pnoise*randn(StateDim,N)+Mu_PNoise*ones(StateDim,N); Q = cov(PNoise'); %Generate observation Noise(Noise of the output equation) Var_ONoise = 2; Mu_ONoise = 0; Std_ONoise = sqrt(Var_ONoise)'; ONoise = Std_ONoise*randn(obsdim,N)+Mu_ONoise*ones(obsdim,N); R = cov(ONoise'); %%Initial values for the model x(:,1) = [1 0]'; y(1) = C*x(:,1)+ONoise(:,1); %% Simulate stetes and observation %B and D matrices have been ignored in the model for i=2:N x(:,i) = A*x(:,i-1)+PNoise(:,i); y(:,i) = C*x(:,i)+ONoise(:,i); end %%Kalman Filtering xh(:,1) = 0.01*randn(StateDim,1); Px = eye(StateDim); for i = 1:size(y,2) %------Time Updated------ %A priori estimate of the current state(x(t/t-1)=A*x(t-1/t-1) xh_(:,i) = A*xh(:,i); %A Priori estimate of the state covariance matrix(P(t/t-1)=A*P(t-1/t-1)A'+Q Px_ = A*Px*A'+Q; %--------Measurement Updated-------- %kalman Filter Coeeficient(k(t)=P(t/t-1)*C'*inv(C*P(t/t-1)*C'+R) k = Px_*C'*inv(C*Px_*C'+R); %Estimated Observation(y(t/t-1)=C*x(t/t-1)+R) yh_(:,i)=C*xh_(:,i)+R; %Measure residual error or innovation error(y(t)-y(t/t-1)) inov(:,i) = y(:,i)-yh_(:,i); %A posteriori(Updated) estimate of the current State(x(t/t))= x(t/t-1)+k(t)*y(t)-y(t/t-1) xh(:,i+1) = xh_(:,i)+k*inov(:,i); %A posteriori(updated) state covariance %matrix(P(t/t)=(I-k(t)*C)*P(t/t-1) Px=Px_-k*C*Px_; end %%Plot the estimation results plot(y) hold on, plot(yh_,'r') grid on legend('Real Observation','Estimated Observation') 17. Discrete time Kalman filter %Discrete time Kalman filter %estimating the constant value x(k)=x(k+1)=0.12345 using the measuremrnt %z(k)=x(k)+w(k) where w is a white noise w~n(0,0.01). We will implement %Kalman's filter algorithm for discrete time. clc; r=0.01; noise=randn(1,150) w=sqrt(r)*noise; zmeasure=
    • spaceinvaders
      太空侵略者 GNU / Linux上基于C的基于文本的游戏。 使用CODL库编写 建造 运行make命令 如果还没有安装СODL库,则还需要安装它 游戏控制 向左/向右箭头-移动航天飞机 太空—射击 Q —退出 ...此游戏也有盲文字体版本
    • Space_Invaders
      Space Invaders是由日本工程师和游戏设计师Nishikado Tomohiro于1978年创建并由日本电子游戏制造商Taito Corp生产的街机游戏。SpaceInvaders的目标是在屏幕上平移拍摄,这是最早发行的视频游戏之一。下降的外星群,...
    • SpaceShooter
    • SpaceInvaders
      太空侵略者 :从在TDD中实施太空侵略者项目
    • SpaceInvaders
      太空侵略者 我在高中的时候就意识到了这个项目,我使用Java和JUnit Test
    • yourSpace
      yourSpace 这是一个使用Node.Js,MongoDB和Express进行公共博客的简单应用程序。 有关实时版本,请参见此处: :
    • ORACLE space
      管理的ORACLE数据库越来越多,统计不是很方便,ORACLE space诞生了, 它实现定时统计ORACLE数据库表空间大小、使用、空闲比例等。
    • space
      我的个人页面 HTML,CSS,Bootstrap和JQuery
    • Space Sniffer
      Windows 下的磁盘空间占用查看工具,磁盘空间 分析,清除垃圾 大文件。
    • colorspace
      This is matlab code for colorspace.