The output from MeasurementFcn must have the same size and data type as the given measurement.

7 views (last 30 days)
I have Simulink model for feed axis driving system with an Intermediary Extended Kalman Filter (EKF) block, i have used mymeasurementfunc and myStateTransitionFcn as follows
x_hat = myStateTransitionFcn(x,u)
Ts = 0.001;
x_hat = x+[x(2); x(2)*((-K2-c)/P)+((K1*u)/P)]*Ts; %state equation
end
function y =mymeasurementfunc(x)
y = x(1);
end
while executing this i am getting error as The output from MeasurementFcn must have the same size and data type as the given measurement.

Answers (1)

Pooja Kumari
Pooja Kumari on 11 Oct 2024
I understand you are facing an error with the compatibility of the state you are trying to use with the models. The state you are trying to use is incompatible with the models you are using for state transition and measurement.
Both of these models are designed to work with a 3-D constant velocity state [x; vx; y; vy; z; vz], and mymeasurementfunc provides a 3-D position measurement [x; y; z] with the default MeasurementParameters value.
If you want to use the "trackingEKF" function with the models as described above, you will have to write your own state transition function, measurement function, and corresponding Jacobian functions.
You can refer below for reference implementation:
% State transition function:
function state = myStateTransitionFcn(state, dt, varargin)
% Validate that state is 4-elements long and that there are two inputs
A1d = [1 dt; 0 1];
A = blkdiag(A1d,A1d);
state(:) = A*state(:);
end
% Measurement function:
function meas = mymeasurementfunc(state, varargin)
% Validate that state is 4-elements long
H = [1 0 0 0; 0 0 1 0; 0 1 0 0; 0 0 0 1];
meas = H*state(:);
end

Community Treasure Hunt

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

Start Hunting!