forked from harry/creotech-sayma-testsuite
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
|
import numpy as np
|
||
|
import matplotlib.pyplot as plot
|
||
|
from scipy import signal, constants
|
||
|
|
||
|
def rp_raw_to_numpy(rp_raw):
|
||
|
# Convert raw buffer strings to numpy arrays
|
||
|
buff_string = rp_raw.split(',')
|
||
|
return np.array(list(map(float, buff_string)))
|
||
|
|
||
|
def main():
|
||
|
y1_raw = None
|
||
|
y2_raw = None
|
||
|
|
||
|
with open('rp_y1_raw.bin', 'rb') as f:
|
||
|
y1_raw = f.read().decode('utf-8')
|
||
|
with open('rp_y2_raw.bin', 'rb') as f:
|
||
|
y2_raw = f.read().decode('utf-8')
|
||
|
if None in [y1_raw, y2_raw]:
|
||
|
raise IOError("Raw RP string files cannot be opened.")
|
||
|
|
||
|
y1 = rp_raw_to_numpy(y1_raw)
|
||
|
y2 = rp_raw_to_numpy(y2_raw)
|
||
|
|
||
|
t = np.arange(y1.shape[0])/125e6
|
||
|
y = np.c_[y1, y2].T
|
||
|
z = signal.decimate(y*np.exp(1j*2*np.pi*9e6*t), q=10, ftype="fir", zero_phase=True)[:, 10:]
|
||
|
z = signal.decimate(z, q=10, ftype="fir", zero_phase=True)[:, 10:]
|
||
|
angle = np.angle(np.mean(z[0]*z[1].conj()))
|
||
|
|
||
|
print(angle)
|
||
|
|
||
|
plot.plot(y1)
|
||
|
plot.plot(y2)
|
||
|
plot.show()
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|