# Autocorrelation not as expected

I am trying to find the autocorrelation function on the intensity of a pixel over time stored in an array "Intensity". Usually one would expect the highest point to be at t = 0 and then decay. I am getting a random mess.

I checked my code with multiple posts on here regarding autocorrelation such as Autocorrelation: numpy versus FFT I am working in python

correlation = np.correlate(Intensity, Intensity, mode='full')/Intensity.size
correlation = correlation[correlation.size//2:]
plt.plot(range(0,len(correlation)),correlation)
plt.show()


You might say well maybe your data looks very similar all around, but then either way why would the highest value not be at t = 0? its not even close. I feel like I must be doing something wrong

• Hi: At $t=0$, you have the lag zero autocorrelation which is the standard deviation of the process ( so not really an autocorrelation). It can be shown that the sd of any process is always greater than all of its other autocorrelations. Jun 16 '20 at 9:09
• @markleeds that's exactly Mornet's question: why isn't the graph showing that. (also, lag zero is really an autocorrelation, just like any other lag, if you ask me; treating it special just complicates a lot of math). Jun 16 '20 at 10:16
• Mornet, I'd agree with you mathematically. However, I can't run your code to verify this is being a bug in numpy or just a visualization problem. Could you either supply a complete example that we can run, or check the value of correlation[0] and max(abs(correllation)) manually? Jun 16 '20 at 10:24
• @Marcus Muller: Thanks. My bad. I didn't realize that the plot shown was that of the autocorrelations. Definitely something is wrong because correlations should of course be between -1.0 and 1.0. Jun 16 '20 at 15:01
• Yes I can! I ran "print(correlation[0], ' ', max(abs(correlation)))" and it shows "5.6644 13.0998" Jun 16 '20 at 15:55