how to implement kalman filter function?

5 次查看(过去 30 天)
we are working on a code that requires to merge the measured value with the true value of the dataset using kalman filter. Below is the code that we are working on and having errors in T.
A = [1.1269 -0.4940 0.1129;
1.0000 0 0;
0 1.0000 0];
B = [-0.3832;
0.5919;
0.5191];
C = [1 0 0];
Plant = ss(A,[B B],C,0,-1,'inputname',{'u' 'w'},'outputname','y');
Q = 1;
R = 1;
[kalmf,L,P,M] = kalman(Plant,Q,R);
M;
kalmf = kalmf(1,:);
a = A;
b = [B B 0*B B B 0*B B B 0*B B B 0*B B B 0*B B B 0*B B B 0*B B B 0*B B B 0*B 0*B];
c = [C;C];
d = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1];
P = ss(a,b,c,d,-1,'inputname',{'u' 'w' 'v' 'a1' 'a2' 'a3' 'a4' 'a5' 'a6' 'a7' 'a8' 'a9' 'b1' 'b2' 'b3' 'b4' 'b5' 'b6' 'b7' 'b8' 'b9' 'c1' 'c2' 'c3' 'c4' 'c5' 'c6' 'c7'},'outputname',{'y' 'yv'});
sys = parallel(P,kalmf,1,1,[],[]);
SimModel = feedback(sys,1,4,2,1); % Close loop around input #4 and output #2
SimModel = SimModel([1 2],[28 1 2]); % Delete yv from I/O list
SimModel.InputName;
SimModel.OutputName;
m = cell(1,28);
t=zeros(size(m,1),size(m,2));
t=str2double(m);
src = dsp.SignalSource('SamplesPerFrame',1);
src.Signal = xlsread('D:\ieee14\trainingset.xlsx',1,'A1:AB1');
w = src.Signal;
src1 = dsp.SignalSource('SamplesPerFrame',5600);
src1.Signal = xlsread('D:\ieee14\faultset.xlsx',1,'A1:AB5601');
u = src1.Signal;
src2 = dsp.SignalSource('SamplesPerFrame',5600);
src2.Signal = xlsread('D:\ieee14\faultset.xlsx',1,'A5601:AB11201');
v = src2.Signal;
[out,x] = lsim(SimModel,[u;v;w]);
the error is
Error using DynamicSystem/lsim (line 84)
When simulating the response to a specific input signal, the input data U must be a matrix with as many rows as samples in the time
vector T, and as many columns as input channels.
Error in kalman16thapril (line 42)
[out,x] = lsim(SimModel,[w;v;u]);
size of u is 5601x28
v is 5601x28
w is 1x28
t is 1x28
sys is 3x29 %i ddnt set this one it came on its own
  1 个评论
John D'Errico
John D'Errico 2017-4-19
First, read this. Learn how to format your code so it is readable, instead of the mess you have given us.
https://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup#answer_18099
Next, what errors? If you have an error, then show it.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 State-Space Control Design and Estimation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by