forked from awendt/pyrelacs
adding calbi for different db
This commit is contained in:
parent
66ea22fb4a
commit
43e0d4b75a
@ -82,7 +82,12 @@ class Calibration(MccDac):
|
||||
t = np.arange(0, DURATION, 1 / SAMPLERATE)
|
||||
data = AMPLITUDE * np.sin(2 * np.pi * SINFREQ * t)
|
||||
# data = np.concatenate((data, data))
|
||||
|
||||
db_values = [0.0, -5.0, -8.5, -10.0]
|
||||
colors = ["red", "blue", "black", "green"]
|
||||
colors_in = ["lightcoral", "lightblue", "grey", "lightgreen"]
|
||||
fig, axes = plt.subplots(2, 2, sharex="col")
|
||||
for i, db_value in enumerate(db_values):
|
||||
self.set_attenuation_level(db_channel1=db_value)
|
||||
stim = self.write_analog(
|
||||
data,
|
||||
[0, 0],
|
||||
@ -107,15 +112,15 @@ class Calibration(MccDac):
|
||||
while (ai_status != uldaq.ScanStatus.IDLE) and (
|
||||
ao_status != uldaq.ScanStatus.IDLE
|
||||
):
|
||||
log.debug("Scanning")
|
||||
time.sleep(0.5)
|
||||
# log.debug("Scanning")
|
||||
time.time_ns()
|
||||
ai_status = self.ai_device.get_scan_status()[0]
|
||||
ao_status = self.ao_device.get_scan_status()[0]
|
||||
|
||||
self.write_bit(channel=0, bit=0)
|
||||
log.debug(
|
||||
f"Status Analog_output {ao_status}\n, Status Analog_input {ai_status}"
|
||||
)
|
||||
fig, axes = plt.subplots(2, 2, sharex="col")
|
||||
channel1 = np.array(readout[::2])
|
||||
channel2 = np.array(readout[1::2])
|
||||
beat = channel1 + channel2
|
||||
@ -134,26 +139,71 @@ class Calibration(MccDac):
|
||||
f_in, powerspec_in = welch(channel2, fs=SAMPLERATE)
|
||||
powerspec_in = decibel(powerspec_in)
|
||||
|
||||
axes[0, 0].plot(t, channel1, label="Readout Channel0")
|
||||
axes[0, 0].plot(t, channel2, label="Readout Channel1")
|
||||
axes[0, 0].plot(
|
||||
t,
|
||||
channel1,
|
||||
label=f"{db_value} Readout Channel0",
|
||||
color=colors[i],
|
||||
)
|
||||
axes[0, 0].plot(
|
||||
t,
|
||||
channel2,
|
||||
label=f"{db_value} Readout Channel1",
|
||||
color=colors_in[i],
|
||||
)
|
||||
|
||||
axes[0, 1].plot(f_stim, powerspec_stim, label="powerspec Channel0")
|
||||
axes[0, 1].plot(f_in, powerspec_in, label="powerspec Channel2")
|
||||
axes[0, 1].plot(
|
||||
f_stim,
|
||||
powerspec_stim,
|
||||
label=f"{db_value} powerspec Channel0",
|
||||
color=colors[i],
|
||||
)
|
||||
axes[0, 1].plot(
|
||||
f_in,
|
||||
powerspec_in,
|
||||
label=f"{db_value} powerspec Channel2",
|
||||
color=colors_in[i],
|
||||
)
|
||||
axes[0, 1].set_xlabel("Freq [HZ]")
|
||||
axes[0, 1].set_ylabel("dB")
|
||||
|
||||
axes[1, 0].plot(t, beat, label="Beat")
|
||||
axes[1, 0].plot(t, beat**2, label="Beat squared")
|
||||
axes[1, 0].plot(
|
||||
t,
|
||||
beat,
|
||||
label="Beat",
|
||||
color=colors[i],
|
||||
)
|
||||
axes[1, 0].plot(
|
||||
t,
|
||||
beat**2,
|
||||
label="Beat squared",
|
||||
color=colors_in[i],
|
||||
)
|
||||
axes[1, 0].legend()
|
||||
|
||||
axes[1, 1].plot(f, powerspec)
|
||||
axes[1, 1].plot(f_sq, powerspec_sq)
|
||||
axes[1, 1].scatter(f_sq[peaks], powerspec_sq[peaks])
|
||||
axes[1, 1].plot(
|
||||
f,
|
||||
powerspec,
|
||||
color=colors[i],
|
||||
)
|
||||
axes[1, 1].plot(
|
||||
f_sq,
|
||||
powerspec_sq,
|
||||
color=colors_in[i],
|
||||
label=f"dB {db_value}, first peak {np.min(f_sq[peaks])}",
|
||||
)
|
||||
axes[1, 1].scatter(
|
||||
f_sq[peaks],
|
||||
powerspec_sq[peaks],
|
||||
color="maroon",
|
||||
)
|
||||
axes[1, 1].set_xlabel("Freq [HZ]")
|
||||
axes[1, 1].set_ylabel("dB")
|
||||
axes[0, 0].legend()
|
||||
embed()
|
||||
exit()
|
||||
axes[1, 1].legend()
|
||||
plt.show()
|
||||
self.set_analog_to_zero()
|
||||
self.disconnect_dac()
|
||||
|
||||
|
||||
def decibel(power, ref_power=1.0, min_power=1e-20):
|
||||
|
Loading…
Reference in New Issue
Block a user