Why does the convolution/cross correlation truncate to 0?
Why does the convolution/cross correlation truncate to 0?
Cross-correlation for uniformly sampled signals is defined as [1]
Convolution for uniformly sampled signals is defined as [2]
I am trying to cross-correlate or convolve two arrays of similar input data. These arrays are two similar time series voltage events that I am trying to align. However, the correlation and convolution only give back arrays full of 0. This seems strange to me, because the input arrays are observations of the same phenomena and should have some sort of overlap. I can clearly plot the input data:
Whole Time Series:
Zoomed in:
This is the code I am running:
def get_cross_corr(files):
datalist =
# open required files for correlation
try:
for f in files:
fp = open(f, "rb")
data = np.fromfile(fp,dtype=np.int16)
datalist.append(data[0:int(len(data)/4)])
fp.close()
except:
print("could not open one of %s"%(files))
return
# cross correlation on specified files
a = np.convolve(datalist[0], datalist[1])
b = np.correlate(datalist[0], datalist[1])
print(a)
print(b)
plt.plot(datalist[0])
plt.plot(datalist[1])
plt.show()
plt.plot(a)
plt.plot(b)
plt.show()
When doing small calculations by hand, they are non-zero. What could be the issue?
If possible, please include some example data in your code so it shows the issue you are talking about.
– Joe
1 hour ago
The data is int16 binary data, how can I post that?
– Mir
6 mins ago
try explicitly converting to float after reading it in
– Mohammad Athar
1 min ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Plz indent your code properly so that others can directly copy it and run it. It would be helpful to have some small files so as to reproduce the error.
– Bazingaa
2 hours ago