Find time offset that best lines up two position curves using appdesigner
Show older comments
% I have time histories of position (time, X, Y) from two different sources (KTM and RNET). Both sources have the target goin over about the same path, but % % there appears to be a time offset. I want to find the time offset to that best lines up the data for comparison.
properties (Access = private)
RNETTable
KTMTable
end
methods (Access = public)
% time histories from two sources
% are stored in tables
% SSDelta applies a time shift (dTime) to one time history of position
% (time, X, Y) and computes the sum of the square of the
% differences of the X and Y components
function SSD = SSDelta(app,dTime)
% apply time shift to one source
RSOD=app.RNETTable{:,'SOD'}+dTime;
% interpolate the X and Y data from RNET to times of the KTM
% since they are not synchronized and compute the sum of the
% squares of the differences
DX=interp1(RSOD(:),app.RNETTable{:,'Xnb'},app.KTMTable{:,'SOD'})-app.KTMTable{:,'x_m_'};
DX=DX.*DX;
DY=interp1(RSOD,app.RNETTable{:,'Ynb'},app.KTMTable{:,'SOD'})-app.KTMTable{:,'y_m_'};
DY=DY.^2;
%return the sum of the squares of the differences
SSD=sum(DX)+sum(DY);
end
end
% From a push button function callback, I use fminbnd to determine the time offset that results in the
% minimum sum of the squares of the differences
dTime=fminbnd(@SSDelta,-20.0,20.0);
% I get the error
Undefined function 'SSDelta' for input arguments of type 'double'.
fx = funfcn(x,varargin{:});
% I am open to an alternate approach, although I have a number of these, so I would like to use appdesigner
Accepted Answer
More Answers (0)
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!