2
0
forked from awendt/pyrelacs

adding calbi for different db

This commit is contained in:
wendtalexander 2024-09-26 14:29:47 +02:00
parent 66ea22fb4a
commit 43e0d4b75a

View File

@ -82,78 +82,128 @@ class Calibration(MccDac):
t = np.arange(0, DURATION, 1 / SAMPLERATE) t = np.arange(0, DURATION, 1 / SAMPLERATE)
data = AMPLITUDE * np.sin(2 * np.pi * SINFREQ * t) data = AMPLITUDE * np.sin(2 * np.pi * SINFREQ * t)
# data = np.concatenate((data, data)) # data = np.concatenate((data, data))
db_values = [0.0, -5.0, -8.5, -10.0]
stim = self.write_analog( colors = ["red", "blue", "black", "green"]
data, colors_in = ["lightcoral", "lightblue", "grey", "lightgreen"]
[0, 0],
SAMPLERATE,
ScanOption=uldaq.ScanOption.EXTTRIGGER,
)
readout = self.read_analog(
[0, 1],
DURATION,
SAMPLERATE,
ScanOption=uldaq.ScanOption.EXTTRIGGER,
)
self.diggital_trigger()
signal.signal(signal.SIGSEGV, self.segfault_handler)
log.info(self.ao_device)
ai_status = uldaq.ScanStatus.RUNNING
ao_status = uldaq.ScanStatus.RUNNING
log.debug(
f"Status Analog_output {ao_status}\n, Status Analog_input {ai_status}"
)
while (ai_status != uldaq.ScanStatus.IDLE) and (
ao_status != uldaq.ScanStatus.IDLE
):
log.debug("Scanning")
time.sleep(0.5)
ai_status = self.ai_device.get_scan_status()[0]
ao_status = self.ao_device.get_scan_status()[0]
log.debug(
f"Status Analog_output {ao_status}\n, Status Analog_input {ai_status}"
)
fig, axes = plt.subplots(2, 2, sharex="col") fig, axes = plt.subplots(2, 2, sharex="col")
channel1 = np.array(readout[::2]) for i, db_value in enumerate(db_values):
channel2 = np.array(readout[1::2]) self.set_attenuation_level(db_channel1=db_value)
beat = channel1 + channel2 stim = self.write_analog(
beat_square = beat**2 data,
[0, 0],
f, powerspec = welch(beat, fs=SAMPLERATE) SAMPLERATE,
powerspec = decibel(powerspec) ScanOption=uldaq.ScanOption.EXTTRIGGER,
)
f_sq, powerspec_sq = welch(beat_square, fs=SAMPLERATE) readout = self.read_analog(
powerspec_sq = decibel(powerspec_sq) [0, 1],
peaks = find_peaks(powerspec_sq, prominence=20)[0] DURATION,
SAMPLERATE,
f_stim, powerspec_stim = welch(channel1, fs=SAMPLERATE) ScanOption=uldaq.ScanOption.EXTTRIGGER,
powerspec_stim = decibel(powerspec_stim) )
self.diggital_trigger()
f_in, powerspec_in = welch(channel2, fs=SAMPLERATE) signal.signal(signal.SIGSEGV, self.segfault_handler)
powerspec_in = decibel(powerspec_in) log.info(self.ao_device)
ai_status = uldaq.ScanStatus.RUNNING
axes[0, 0].plot(t, channel1, label="Readout Channel0") ao_status = uldaq.ScanStatus.RUNNING
axes[0, 0].plot(t, channel2, label="Readout Channel1")
log.debug(
axes[0, 1].plot(f_stim, powerspec_stim, label="powerspec Channel0") f"Status Analog_output {ao_status}\n, Status Analog_input {ai_status}"
axes[0, 1].plot(f_in, powerspec_in, label="powerspec Channel2") )
axes[0, 1].set_xlabel("Freq [HZ]") while (ai_status != uldaq.ScanStatus.IDLE) and (
axes[0, 1].set_ylabel("dB") ao_status != uldaq.ScanStatus.IDLE
):
axes[1, 0].plot(t, beat, label="Beat") # log.debug("Scanning")
axes[1, 0].plot(t, beat**2, label="Beat squared") time.time_ns()
axes[1, 0].legend() ai_status = self.ai_device.get_scan_status()[0]
ao_status = self.ao_device.get_scan_status()[0]
axes[1, 1].plot(f, powerspec)
axes[1, 1].plot(f_sq, powerspec_sq) self.write_bit(channel=0, bit=0)
axes[1, 1].scatter(f_sq[peaks], powerspec_sq[peaks]) log.debug(
axes[1, 1].set_xlabel("Freq [HZ]") f"Status Analog_output {ao_status}\n, Status Analog_input {ai_status}"
axes[1, 1].set_ylabel("dB") )
axes[0, 0].legend() channel1 = np.array(readout[::2])
embed() channel2 = np.array(readout[1::2])
exit() beat = channel1 + channel2
beat_square = beat**2
f, powerspec = welch(beat, fs=SAMPLERATE)
powerspec = decibel(powerspec)
f_sq, powerspec_sq = welch(beat_square, fs=SAMPLERATE)
powerspec_sq = decibel(powerspec_sq)
peaks = find_peaks(powerspec_sq, prominence=20)[0]
f_stim, powerspec_stim = welch(channel1, fs=SAMPLERATE)
powerspec_stim = decibel(powerspec_stim)
f_in, powerspec_in = welch(channel2, fs=SAMPLERATE)
powerspec_in = decibel(powerspec_in)
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=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",
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,
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()
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): def decibel(power, ref_power=1.0, min_power=1e-20):