Fluorescence correlation spectroscopy (FCS) is a common technique used by physicists, chemists, and biologists to experimentally characterize the dynamics of fluorescent species.

The key of the technique is the auto correlation function. The (temporal) autocorrelation function is the correlation of a time series with itself shifted by time τ, as a function of τ:

The formula is given by $$ G(\tau) = \frac{\langle \delta I(t) \delta I (t+\tau)\rangle}{\langle I(t)\rangle^2} = \frac{\langle I(t)I(t+\tau)\rangle}{\langle I(t)\rangle^2} - 1$$

where $$ \delta I(t) = I(t)-\langle I(t)\rangle $$ is the deviation from the mean intensity.

My question is:

Given a row vector of finite elements, what is the right way to calculate G(tau).

The matlab code below shows two methods giving two different result. Which one is the correct one?

```
rawdata = [1 2 3 4 5 6 7 8];
%the regular method.Result shown in the next line
%0.259259259 0.2 0.151515152 0.111111111 0.076923077 0.047619048 0.022222222
count = rawdata;
Ntime = length(count);
G = [];
for t = 0:Ntime-1
top = [];
bottom = [];
ai = [];
bi = [];
ai = count(1:end-t);
bi = count(t+1:end);
top = mean( (ai-mean(ai)) .* (bi-mean(bi)) );
bottom = mean(ai) * mean(bi);
%bottom = mean(count)^2;
G = [G, top/bottom];
end
%The typical FFT method. Results shown in the next line
%0.259259259 0.086419753 -0.037037037 -0.111111111 -0.135802469 -0.111111111 -0.037037037 0.086419753
%NFFT euqals to the length of the input.
count = rawdata;
NFFT = 8;
tmpGfft = length(count) * ifft( fft(count,NFFT).*conj(fft(count,NFFT)))/sum(count)^2 - 1;
plot(G,'*');hold on; plot(tmpGfft,'o')
```

More reference on the technique itself, http://en.wikipedia.org/wiki/Fluorescence_correlation_spectroscopy