function CRLB=DSF2DLocFoUnkwnMtTm_CRLB(u,u_dot,S,fo,c,T,Qn,Qs,Qfo)
% CRLB=DSF2DLocFoUnkwnMtTm_CRLB(u,u_dot,S,fo,c,T,Qn,Qs,Qfo)
%
% CRLB for the object location (position and velocity) in 2-D by using
% frequency measurements at multiple time instants, source frequency unknown.
%
% Input:
%   u:      (2 x 1), object position
%   u_dot:  (2 x 1), object velocity
%   S:      (2 x M), sensor positions, M=number of sensors
%   fo:     scalar, center frequency
%   c:      scalar, signal propagation speed
%   T:      time interval between two consecutive measurements
%   Qn:     (MN x MN), measurement noise covariance matrix, N=number of instants
%   Qs:     (2M x 2M), sensor position error covariance matrix
%   Qfo:    scalar, variance of available center frequency
%
% Output:
%   CRLB:  (4 x 4), CRLB for object location ([position; velocity])
%
% Reference:
% M. Ahmed, K. C. Ho, and G. Wang, "Localization of a moving source by
% frequency measurements," IEEE Trans. Signal Process., vol. 68,
% pp. 4839-4854, 2020.
%
% Musaab Ahmed, K. C. Ho	08-18-2021
%
%       Copyright (C) 2021
%       Computational Intelligence Signal Processing Laboratory
%       University of Missouri
%       Columbia, MO 65211, USA
%       hod@missouri.edu
%

M=length(S);        % number of sensors
N=length(Qn)/M;     % number of instants

u_all=u*ones(1,N)+u_dot*(0:N-1)*T;
r=sqrt(sum((kron(u_all,ones(1,M))-repmat(S,1,N)).^2,1));

a=zeros(M*N,2);b=a;C=zeros(M*N,2*M);de_fo=zeros(M*N,1);

for k=1:M*N
    i=mod(k+M-1,M)+1;
    n=fix((k-1)/M);
    ums=u+n*T*u_dot-S(:,i);
    a(k,:)=fo/c/r(k)*(u_dot-(ums'*u_dot*ums)/r(k)^2)';
    b(k,:)=fo/c/r(k)*(ums+n*T*u_dot-n*T*ums'*u_dot*ums/r(k)^2)';
    de_fo(k)=1+1/c*ums'*u_dot/r(k);
    C(k,:)=[zeros(1,2*(i-1)) -a(k,:) zeros(1,2*(M-i))];
end

de_s_alpha=[zeros(M*2,1) eye(2*M)];
de_fo_alpha=[1 zeros(1,2*M)];
f_beta=[a b];
f_alpha=[de_fo C];

X=f_beta'/Qn*f_beta;
Y=f_beta'/Qn*f_alpha;

Z=f_alpha'/Qn*f_alpha+de_s_alpha'/Qs*de_s_alpha+de_fo_alpha'/Qfo*de_fo_alpha;

CRLB= diag(inv(X)+X\Y/(Z-Y'/X*Y)*Y'/X);

% --------------------------------------------------------------


