function out = rate(data,range,half)
% 発火率の推定
%
% [t-half, t+half] の区間(幅 2*half+1)で発火率 r(t) の推定を行う
%

trial=size(range,1);		%%% 試行数
len=range(1,2)-range(1,1);	%%% 切り出す長さ

out=zeros(len,1);	%%% 発火率 r(t) の推定値 

for i=1:trial
  train=data(range(i,1)-half<data & data<=range(i,1)+len+half)-range(i,1);
			%%% 試行ごとに±halfだけ余分に切り出す．
  for t=1:len
    out(t)=out(t)+length(train(t-half <= train & train <= t+half));
  end
end

out = out/trial/(2*half+1);
