% 04/25/2016
% have different setting for different recording room
% use [xc,yc,R] = cirfit(x,y) to find the center and the diameter of the track
% let the headstage go around the track

% beep at the beginning of the tracking
fs_sin=8000;
fs0=800;
t=0 : 1/fs_sin : 0.1;
beep0 = sin(fs0*2*pi*t);

fprintf('Start tracking: ');
pause(15);
% drop the old data
[~, ~, locationArray, ~, VTRecsReturned, ~] = NlxGetNewVTData(vt_acq_ent);
sound(beep0,fs_sin);
pause(30);
[~, ~, locationArray1, ~, VTRecsReturned, ~] = NlxGetNewVTData(vt_acq_ent);
pause(20);
[~, ~, locationArray2, ~, VTRecsReturned, ~] = NlxGetNewVTData(vt_acq_ent);
locationArray = [locationArray1,locationArray2];
sound(beep0,fs_sin);

x_array=locationArray(1:2:end-1);
y_array=locationArray(2:2:end);
ind=find(x_array~=0 & y_array~=0); % exclude missing data
x_circle=x_sign*x_array(ind)*scale_x;
y_circle=y_sign*y_array(ind)*scale_y;

[x_center,y_center,R_inner] = cirfit(x_circle,y_circle);
diam_inner=R_inner*2;

fprintf('center: %s , %s, \r',num2str(x_center),num2str(y_center));