diff --git a/doc/crosstalk/img/.gitkeep b/doc/crosstalk/img/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/doc/crosstalk/img/Graph - 230 Ohm - Far end.png b/doc/crosstalk/img/Graph - 230 Ohm - Far end.png new file mode 100644 index 0000000..957aced Binary files /dev/null and b/doc/crosstalk/img/Graph - 230 Ohm - Far end.png differ diff --git a/doc/crosstalk/img/Graph - 230 Ohm - Near end.png b/doc/crosstalk/img/Graph - 230 Ohm - Near end.png new file mode 100644 index 0000000..7573215 Binary files /dev/null and b/doc/crosstalk/img/Graph - 230 Ohm - Near end.png differ diff --git a/doc/crosstalk/img/Graph - 50 Ohm - Far end.png b/doc/crosstalk/img/Graph - 50 Ohm - Far end.png new file mode 100644 index 0000000..6cc69de Binary files /dev/null and b/doc/crosstalk/img/Graph - 50 Ohm - Far end.png differ diff --git a/doc/crosstalk/img/Graph - 50 Ohm - Near end.png b/doc/crosstalk/img/Graph - 50 Ohm - Near end.png new file mode 100644 index 0000000..4d51edf Binary files /dev/null and b/doc/crosstalk/img/Graph - 50 Ohm - Near end.png differ diff --git a/doc/crosstalk/img/Graph - Capacative - Far end.png b/doc/crosstalk/img/Graph - Capacative - Far end.png new file mode 100644 index 0000000..fabcd37 Binary files /dev/null and b/doc/crosstalk/img/Graph - Capacative - Far end.png differ diff --git a/doc/crosstalk/img/Graph - Capacative - Near end.png b/doc/crosstalk/img/Graph - Capacative - Near end.png new file mode 100644 index 0000000..a6fecf0 Binary files /dev/null and b/doc/crosstalk/img/Graph - Capacative - Near end.png differ diff --git a/doc/crosstalk/img/Graph - Inductive - Far end.png b/doc/crosstalk/img/Graph - Inductive - Far end.png new file mode 100644 index 0000000..34f0082 Binary files /dev/null and b/doc/crosstalk/img/Graph - Inductive - Far end.png differ diff --git a/doc/crosstalk/img/Graph - Inductive - Near end.png b/doc/crosstalk/img/Graph - Inductive - Near end.png new file mode 100644 index 0000000..045da9f Binary files /dev/null and b/doc/crosstalk/img/Graph - Inductive - Near end.png differ diff --git a/scripts/crosstalk.py b/scripts/crosstalk.py new file mode 100644 index 0000000..1ee2b07 --- /dev/null +++ b/scripts/crosstalk.py @@ -0,0 +1,60 @@ +from matplotlib import pyplot as plt +from matplotlib import patches as pat +import numpy as np +import reader + +# load data +data_reader = reader.Reader() +num = 14 +data = data_reader.read_file(f".\data\T00{num}ALL.csv") +str_end = 'Near end' if num % 2 == 0 else 'Far end' +str_desc = '230 Ohm' + +# FFT +np_data1 = np.array(data['CH1']) +np_data2 = np.array(data['CH2']) +np_time = np.array(data['TIME']) +X1 = np.fft.rfft(np_data1) +X2 = np.fft.rfft(np_data2) +N = np.fft.rfftfreq(len(np_data1), (np_time[1]-np_time[0])) + +phi1 = np.angle(X1, True) +phi2 = np.angle(X2, True) +diff_phi = phi1[np.argmax(abs(X1))]-phi2[np.argmax(abs(X2))] + +fig, ax = plt.subplots() +plt.plot(data['TIME'], data['CH1'], label='CH1') +plt.plot(data['TIME'], data['CH2'], label='CH2') + +handles, labels = ax.get_legend_handles_labels() +patch = pat.Patch( + color='C0', + label='pk-pk = ${:.2f}\ V$'.format(max(data['CH1'])-min(data['CH1']))) +handles.append(patch) +patch = pat.Patch( + color='C1', + label='pk-pk = ${:.2f}\ V$'.format(max(data['CH2'])-min(data['CH2']))) +handles.append(patch) +patch = pat.Patch( + color='C0', + label='F = ${:.1f}\ MHz$'.format(N[np.argmax(abs(X1))]/1e6)) +handles.append(patch) +patch = pat.Patch( + color='C1', + label='F = ${:.1f}\ MHz$'.format(N[np.argmax(abs(X2))]/1e6)) +handles.append(patch) +patch = pat.Patch( + color='grey', + label='$\Delta \phi$ = ${:.1f} \degree$'.format(diff_phi)) +handles.append(patch) + +plt.title('Voltage vs Time, ' + str_desc + ', ' + str_end) +plt.legend(loc='upper right', handles=handles) +plt.grid() +plt.xlabel('Time [s]') +plt.ylabel('Voltage [V]') +plt.xlim(data['TIME'][0], data['TIME'][-1]) +name = f'Graph - {str_desc} - {str_end}.png' +plt.savefig(f'./doc/crosstalk/img/{name}') +print('Saved:', name) +# plt.show() \ No newline at end of file diff --git a/scripts/helper.py b/scripts/helper.py index 18334da..794ecd2 100644 --- a/scripts/helper.py +++ b/scripts/helper.py @@ -14,4 +14,4 @@ def cut_time(data : dict, start : float, end : float) -> dict: if idx_end != 0 and idx_start != 0: return {key: value[idx_start:idx_end] for key, value in data.items()} else: - return None + raise Exception("Start or end out of range") diff --git a/scripts/reader.py b/scripts/reader.py index 1f9e2bc..47d5cc8 100644 --- a/scripts/reader.py +++ b/scripts/reader.py @@ -7,7 +7,8 @@ class Reader(): def read_file(self, filename) -> dict: with open(filename, 'r') as file: data = list(csv.reader(file, delimiter=',')) - + + # Delete metadata for now for i in range(15): data.pop(0) diff --git a/scripts/reflection.py b/scripts/reflection.py index c412a0d..076c29e 100644 --- a/scripts/reflection.py +++ b/scripts/reflection.py @@ -6,7 +6,7 @@ import helper # load data data_reader = reader.Reader() -data = data_reader.read_file(r".\data\T0004CH1.csv") +data = data_reader.read_file(r".\data\T0001CH1.csv") # slice empty space, start and end time is in seconds data = helper.cut_time(data, -1e-7, 5e-7) @@ -41,5 +41,11 @@ if len(peaks) > 0: peak*step+data['TIME'][0], min(data['CH1']), max(data['CH1']), 'red', 'dashed') +plt.xlabel('Time [s]') +plt.ylabel('Voltage [V]') +plt.title('Voltage vs Time, $75 \Omega$ cable') +plt.tight_layout() +txt="$\Delta t\ =\ {:.2f}\ ns $".format(tim_diff*1e9) +plt.figtext(0.54, 0.01, txt, wrap=True, horizontalalignment='center', fontsize=9) plt.grid() plt.show()