function timeMap = findTimeMap(posang,post,bins,bin_ang)

% Duration of trial
duration = post(end)-post(1);
% Average duration of each position sample
sampDur = duration/length(posang);

% angle for current bin position
pcx = -bin_ang/2;  % [0.2pi]
timeMap = zeros(bins,1);
% Find number of position samples in each bin
for ii = 1:bins
    % Increment the angle
    pcx = pcx + bin_ang;
    I = find(posang >= pcx & posang < pcx+bin_ang);
    % Number of position samples in the current bin
    timeMap(ii) = length(I);
end
% Convert to time spent in bin
timeMap = timeMap * sampDur;
