My goal is to specify a custom measurement function in the tracking particle filter (trackingPF) from the Sensor Fusion and Tracking Toolkit. I can do it by direct reference to a custom function, but I'm getting an error when trying to do the same with a function handle returned from another function.
Here is the direct approach that works.
pf_direct = trackingPF(@constvel, @customMeasurementFcn, priorState)
prediction = predict(pf_direct)
posterior = correct(pf_direct, 45)
Fine so far. Now attempt the same with a function handle returned from another function.
customMeasurementFcn_returnedHandle = generateMeasurementFunction
pf_handle = trackingPF(@constvel, @customMeasurementFcn_returnedHandle, priorState)
prediction = predict(pf_handle)
posterior = correct(pf_handle, 45)
The correct() call fails with...
In contradiction with the error, the measurement function handle in the filter looks right...
And I can use the handle on its own...
But the same call using the handle stored within the particle filter object fails.
Here are the function definitions.
function predictedParticles = customMeasurementFcn(particles, varargin)
fullMeasurement = cvmeas(particles, 'spherical');
predictedParticles = fullMeasurement(1,:) + randn(1, size(particles,2));
function generatedMeasurementFunction = generateMeasurementFunction()
generatedMeasurementFunction = @customMeasurementFcn;
Could you please show me how to use a function handle returned from generateMeasurementFunction() as the MeasurementFcn in the trackingPF?