2
$\begingroup$

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.enter image description here

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

$\endgroup$
7
  • $\begingroup$ 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. $\endgroup$
    – mark leeds
    Jun 16, 2020 at 9:09
  • $\begingroup$ @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). $\endgroup$ Jun 16, 2020 at 10:16
  • $\begingroup$ 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? $\endgroup$ Jun 16, 2020 at 10:24
  • $\begingroup$ @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. $\endgroup$
    – mark leeds
    Jun 16, 2020 at 15:01
  • $\begingroup$ Yes I can! I ran "print(correlation[0], ' ', max(abs(correlation)))" and it shows "5.6644 13.0998" $\endgroup$
    – Mornet
    Jun 16, 2020 at 15:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.