pico-radio/test/sync/sync.py

32 lines
1.2 KiB
Python

# this script helps to verify if the 2 channels of
# the picoscope are sampled synchronously (as stated in the datasheet)
import numpy as np
import matplotlib.pyplot as plt
# the input is the same square wave on both channels
# stored as an array of pairs of float32-s
data = np.fromfile("sync_test.bin", dtype=np.float32)
# if the i and q channels are perfectly indetical and in sync
# their difference should be const 0
diff = data[0::2] - data[1::2]
plt.plot(diff[:10000], label="I - Q")
plt.title("Difference of channels")
plt.legend()
plt.show()
# this is not exactly the case, channel b seems to be
# a higher value at the changes in the signal
# maybe the two channels are sampled synchronously
# but with a small delay (less than a sample length)
# if the signals are sampled with
plt.figure()
corr = np.correlate(data[0::2][:10000], data[1::2][:10000], mode="full")
print(f"Index of maximum (starting from 0, to 10000):", np.argmax(corr))
# 9999 -> index of last element in the array -> complete overlap without offset
plt.plot(corr)
plt.title("Correlation")
plt.show()
# the maximum of the correlation is when the two signals perfectly overlap without
# and offset, this means that they are sampled at the same time