kalman濾波matlab實(shí)現(xiàn)_第1頁(yè)
kalman濾波matlab實(shí)現(xiàn)_第2頁(yè)
kalman濾波matlab實(shí)現(xiàn)_第3頁(yè)
kalman濾波matlab實(shí)現(xiàn)_第4頁(yè)
kalman濾波matlab實(shí)現(xiàn)_第5頁(yè)
已閱讀5頁(yè),還剩3頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、function S = dosim(T, cda, cdm, cm, sr_scale, sq_scale, stq_C, stq_F, stq_S)global d2r r2d;d2r = pi/180.0; % constant to convert degree to radianr2d = 180.0/pi; % constant to convert radian to degree% temporal parametersstime = T.stime; % length of sim secondmrate = T.mrate; % measurement rate 1/sec

2、onddt = 1/mrate;% water level limitsL_min = T.L_min; % where start filling, etc. meterL_max = T.L_max; % full meter% Measurement device parametersglobal db df ka kl;db = T.db; % Base for angular sensor, just above the max water meterdf = T.df; % Angular sensor arm w/ float, long enough to hit bottom

3、 on empty meterka = T.ka; % Angular/non-linear float scale constantkl = T.kl; % Level/linear float parameters scale constant% Sloshing (sinusoidal) parameterssf = T.sf; % slosh/sin frequency 1/secondsp = T.sp; % slosh phase degree% measurement noise magnitudessrl_m = sr_scale*T.srl_m; % stdev of lev

4、el/linear sensor noise metersra_d = sr_scale*T.sra_d; % stdev of angule/non-linear sensor noise degreeif (nargin = 6) % normal situationstq_C(1) = 5.9609e-05; % Tuned Constant w/ linear measstq_C(2) = 3.5936e-05; % Tuned Constant w/ angular meassq_C = mean(stq_C); % avg of the twostq_F(1) = 1.9638;

5、% Tuned Filling w/ linear measstq_F(2) = 2.027; % Tuned Filling w/ angular meassq_F = mean(stq_F); % avg of the twostq_S(1) = 5.9609e-05; % Tuned Sloshing w/ linear measstq_S(2) = 5.9609e-05; % Tuned Sloshing w/ angular meassq_S = mean(stq_S); % avg of the two% special tune case for filling and slos

6、hingif (cdm = 'FS')stq_F(1) = 0.0028009; % Tuned Filling w/ linear measstq_F(2) = 0.0021271; % Tuned Filling w/ angular meassq_F = mean(stq_F); % avg of the twostq_S(1) = 0.0014462; % Tuned Sloshing w/ linear measstq_S(2) = 0.0010254; % Tuned Sloshing w/ angular meassq_S = mean(stq_S); % avg

7、 of the twoendelseif (nargin = 9) % tuning the filterssq_C = stq_C;sq_F = stq_F;sq_S = stq_S;elseerror('Incorrect number of input arguments for dosim.m.')end% Measurement modelif (cm = 'L')mtype = 1;elseif (cm = 'A')mtype = 2;elseerror('Unkown measurement model.');end

8、% Set up the dynamic model parameters based on the input selector cdmswitch cdmcase 'C' % Constant level% State dimensionsd = 1;% Dynamic/process model% see Section 1.2.1 in document "models"A = zeros(1,1,T.nmeas);A(1,1,:) = 1;qc = (sq_scale*sq_C)2; % scale qc then square for varia

9、nceQ = zeros(1,1,T.nmeas);Q(1,1,:) = qc*dt;% Set aside space for resultsS.Xp = zeros(sd,T.nmeas); % predicted state (X)S.Xc = zeros(sd,T.nmeas); % correctedS.Pp = zeros(sd,sd,T.nmeas); % predicted covariance (P)S.Pc = zeros(sd,sd,T.nmeas); % correctedS.Zp = zeros(1,T.nmeas); % predicted measurement

10、(Z)S.K = zeros(sd,T.nmeas); % Kalman gain% Initialize filterL_init = L_max/2.0; % initial guessS.Xp(1,1) = L_init;S.Xc(1,1) = L_init;S.Pp(1:1,1:1,1) = L_max2;S.Pc(1:1,1:1,1) = L_max2;case 'F' % Filling% State dimensionsd = 2;% Dynamic/process model% see Section 1.2.2 and equations (4) and (5

11、) in document "models"A = zeros(sd,sd,T.nmeas);for m=1:T.nmeasA(1,1,m) = 1;A(2,2,m) = 1;A(1,2,m) = dt;endQ = zeros(sd,sd,T.nmeas);qc = (sq_scale*sq_F)2; % scale qc then square for variancefor m=1:T.nmeasQ(1,1,m) = qc*dt3/3.0;Q(1,2,m) = qc*dt2/2.0;Q(2,1,m) = Q(1,2,m);Q(2,2,m) = qc*dt;end% S

12、et aside space for resultsS.Xp = zeros(sd,T.nmeas); % predicted state (X)S.Xc = zeros(sd,T.nmeas); % correctedS.Pp = zeros(sd,sd,T.nmeas); % predicted covariance (P)S.Pc = zeros(sd,sd,T.nmeas); % correctedS.Zp = zeros(1,T.nmeas); % predicted measurement (Z)S.K = zeros(sd,T.nmeas); % Kalman gain% Ini

13、tialize filterL_init = L_max/2.0; % initial guessS.Xp(1,1) = L_init;S.Xc(1,1) = L_init;S.Pp(:,:,1) = L_max2,0;0,(L_max/stime)2;S.Pc(:,:,1) = L_max2,0;0,(L_max/stime)2;case 'S' % Sloshing% State dimensionsd = 2;% Dynamic/process model% see Section 1.2.3 and equations (6) and (7) in document &

14、quot;models"A = zeros(sd,sd,T.nmeas);w = 2*pi*sf; % omegafor m=1:T.nmeasA(1,1,m) = 1;A(2,2,m) = 1;A(1,2,m) = w*cos(w*T.ts(m)+sp*d2r);endQ = zeros(sd,sd,T.nmeas);qc = (sq_scale*sq_S)2; % scale qc then square for variancefor m=1:T.nmeasQ(1,1,m) = qc*w2*cos(w*T.ts(m)2*dt*(3*T.ts(m)2+3*T.ts(m)*dt+d

15、t2)/3.0;Q(1,2,m) = w*cos(w*T.ts(m)*qc*dt*(2*T.ts(m) + dt)/2.0;Q(2,1,m) = Q(1,2,m);Q(2,2,m) = qc*dt;end% Set aside space for resultsS.Xp = zeros(sd,T.nmeas); % predicted state (X)S.Xc = zeros(sd,T.nmeas); % correctedS.Pp = zeros(sd,sd,T.nmeas); % predicted covariance (P)S.Pc = zeros(sd,sd,T.nmeas); %

16、 correctedS.Zp = zeros(1,T.nmeas); % predicted measurement (Z)S.K = zeros(sd,T.nmeas); % Kalman gain% Initialize filterL_init = L_max/2.0; % initial guessS.Xp(1,1) = L_init;S.Xc(1,1) = L_init;S.Xp(2,1) = T.sm; % temp - cheatS.Xc(2,1) = T.sm;S.Pp(:,:,1) = L_max2,0;0,(L_max/2)2;S.Pc(:,:,1) = L_max2,0;

17、0,(L_max/2)2;case 'FS' % Filling and Sloshing% State dimensionsd = 3;% Dynamic/process model% see Section 1.2.4 and equations (8) and (9) in document "models"A = zeros(sd,sd,T.nmeas);w = 2*pi*sf; % omegafor m=1:T.nmeasA(1,1,m) = 1;A(2,2,m) = 1;A(3,3,m) = 1;A(1,2,m) = dt;A(1,2,m) =

18、w*cos(w*T.ts(m)+sp*d2r);endQ = zeros(sd,sd,T.nmeas);qcs = (sq_scale*sq_S)2; % scale qc then square for varianceqcf = (sq_scale*sq_F)2; % scale qc then square for variancefor m=1:T.nmeasQ(1,1,m) = dt*(dt2+3*T.ts(m)2+3*T.ts(m)*dt)*(qcf+w2*cos(w*T.ts(m)2*qcs)/3.0;Q(1,2,m) = qcf*dt*(2*T.ts(m) + dt)/2.0;

19、Q(2,1,m) = Q(1,2,m);Q(1,3,m) = w*cos(w*T.ts(m)*qcs*dt*(2*T.ts(m)+dt)/2.0;Q(3,1,m) = Q(1,3,m);Q(2,2,m) = qcf*dt;Q(3,3,m) = qcs*dt;end% Set aside space for resultsS.Xp = zeros(sd,T.nmeas); % predicted state (X)S.Xc = zeros(sd,T.nmeas); % correctedS.Pp = zeros(sd,sd,T.nmeas); % predicted covariance (P)

20、S.Pc = zeros(sd,sd,T.nmeas); % correctedS.Zp = zeros(1,T.nmeas); % predicted measurement (Z)S.K = zeros(sd,T.nmeas); % Kalman gain% Initialize filterL_init = L_max/2.0; % initial guessS.Xp(1,1) = L_init;S.Xc(1,1) = L_init;S.Xp(3,1) = T.sm; % temp - cheatS.Xc(3,1) = T.sm;S.Pp(:,:,1) = L_max2,0,0; 0,(

21、L_max/stime)2,0; 0,0,(L_max/2)2;S.Pc(:,:,1) = L_max2,0,0; 0,(L_max/stime)2,0; 0,0,(L_max/2)2;otherwiseerror('Unknown dynamic model type.');end% Choose the set of measurements based on the input selector cda (actual dynamics)switch cdacase 'C' % Constant level% Measurement modelif (mt

22、ype = 1)Za = T.m.l.C; % actual measurementselseZa = T.m.a.C; % actual measurementsendcase 'F' % Filling level% Measurement modelif (mtype = 1)Za = T.m.l.F; % actual measurementselseZa = T.m.a.F; % actual measurementsendcase 'S' % Sloshing level% Measurement modelif (mtype = 1)Za = T.

23、m.l.S; % actual measurementselseZa = T.m.a.S; % actual measurementsendcase 'FS' % Filling and Sloshing level% Measurement modelif (mtype = 1)Za = T.m.l.FS; % actual measurementselseZa = T.m.a.FS; % actual measurementsendotherwiseerror('Unknown dynamic model type.');end% Measurement n

24、oise modelif (mtype = 1)% see Section 2.1 in document "models"R = (srl_m * kl)2;else% see Section 2.2 in document "models"R = (sra_d * ka)2;end% Loop through all measurementsfor k = 2:T.nmeas% predictS.Xp(:,k) = A(:,:,k)*S.Xc(:,k-1);S.Pp(:,:,k) = A(:,:,k)*S.Pc(:,:,k-1)*A(:,:,k)&#

25、39; + Q(:,:,k);% measurement prediction and JacobianS.Zp(k) = meas(S.Xp(:,k),mtype,sd);H = measJacobian(S.Xp(:,k),mtype,sd);% correctS.K(:,k) = S.Pp(:,:,k)*H'*inv(H*S.Pp(:,:,k)*H' + R); % Kalman gainS.Xc(:,k) = S.Xp(:,k) + S.K(:,k)*(Za(k)-S.Zp(k);S.Pc(:,:,k) = (eye(sd) - S.K(:,k)*H)*S.Pp(:,:,k

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論