I want to autocorrelate a signal using numpy's correlate
method.
Let us consider a 10 minutes long signal sampled at 2,000SPS:
import numpy as np
import random
import matplotlib.pyplot as plt
import scipy.signal as signal
sampling_rate=2000
duration_in_seconds=600
number_of_samples = sampling_rate*duration_in_seconds
samples = np.arange(number_of_samples)
test_array = np.sin(2*np.pi*samples/float(number_of_samples/1000))+np.sin(2*np.pi*samples/float(number_of_samples/42))+np.random.random(600*sampling_rate)
This synthetic test array is displayed below:
Let us autocorrelate the first second of data using correlate
's default same
mode:
acorr_one_second=np.correlate(test_array[:2000], test_array[:2000], mode='same')
This yields the following plot:
Now, what happens if we upsample our original data by a factor of x1.25, i.e. if we upsample them to 2,500SPS?
upsampled_sampling_rate=2500
upsampled_samples=np.arange(0,sampling_rate*duration_in_seconds, 1/1.25)
upsampled_test_array = signal.resample(test_array,duration_in_seconds*upsampled_sampling_rate)
Running plt.plot(acorr_upsampled_samples,acorr_one_second_upsampled, color='orange',linewidth=2)
yields the following plot:
The amplitude of the autocorrelated upsampled data is exactly 1.25 times greater than that of the original data. Is this the expected behaviour?
I must admit that I have always thought of autocorrelation in terms of the "relative" amplitude variations indicating how well a signal correlates with itself. But what is the meaning of the "absolute" amplitude of the autocorrelated data?