loopback test
This commit is contained in:
parent
d88e9f9955
commit
570149c2ee
2 changed files with 21 additions and 59 deletions
|
@ -27,69 +27,30 @@ def audio_callback(in_data, frame_count, time_info, status):
|
||||||
return (outbytes, pa.paContinue)
|
return (outbytes, pa.paContinue)
|
||||||
|
|
||||||
paudio = pa.PyAudio()
|
paudio = pa.PyAudio()
|
||||||
stream = paudio.open(format=pa.paFloat32,
|
output_strm = paudio.open(format=pa.paFloat32,
|
||||||
channels=1,
|
channels=1,
|
||||||
rate=48000,
|
rate=48000,
|
||||||
output=True,
|
output=True,
|
||||||
stream_callback=audio_callback)
|
stream_callback=audio_callback)
|
||||||
|
output_strm.start_stream()
|
||||||
|
|
||||||
def do_frequency(scaled_f, osci, hscale):
|
input_strm = paudio.open(format=pa.paFloat32,
|
||||||
scaled_frequency = scaled_f
|
channels=1,
|
||||||
time.sleep(0.1)
|
rate=48000,
|
||||||
osci.write("acquire:state run") # Restart acquisition sequence
|
input=True)
|
||||||
time.sleep(10 * hscale)
|
input_strm.stop_stream()
|
||||||
|
|
||||||
osci.write("data:source CH1")
|
def do_frequency(scaled_f):
|
||||||
A_samps = osci.query_binary_values("curve?",datatype='b',container=numpy.array)
|
scaled_frequency = scaled_f
|
||||||
A_samps = A_samps.astype(np.float64)
|
time.sleep(0.2) # Stall for latency/transitory behavior
|
||||||
|
input_strm.start_stream()
|
||||||
|
L = input_strm.read(int(48000 * 0.1)) # We get 1/sqrt(n) noise rejection and 1/n spurious tone rejection
|
||||||
|
input_strm.stop_stream()
|
||||||
|
return np.frombuffer(L, dtype=np.float32)
|
||||||
|
|
||||||
osci.write("data:source CH2") # For now, do not adjust for zeros in the resp.
|
import matplotlib.pyplot as plt
|
||||||
B_samps = osci.query_binary_values("curve?",datatype='b',container=numpy.array)
|
L = do_frequency(440.0/48000)
|
||||||
B_samps = B_samps.astype(np.float64)
|
print(L)
|
||||||
|
plt.plot(L)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
A_samps = np.rfft(A_samps) # No window, because of the precise frequency
|
|
||||||
B_samps = np.rfft(B_samps)
|
|
||||||
|
|
||||||
# We have (10 * hscale)/Tcurv periods
|
|
||||||
return B_samps[np.round((10 * hscale) * (scaled_f * 4800))]
|
|
||||||
/A_samps[np.round((10 * hscale) * (scaled_f * 4800))]
|
|
||||||
|
|
||||||
def find_oscillo():
|
|
||||||
rm = pyvisa.ResourceManager()
|
|
||||||
R = rm.list_resources("USB?*")
|
|
||||||
if R.empty():
|
|
||||||
print("No device found")
|
|
||||||
exit(1)
|
|
||||||
return rm.open_resource(R[0])
|
|
||||||
|
|
||||||
osci = find_oscillo()
|
|
||||||
print(osci.query("*IDN?"))
|
|
||||||
|
|
||||||
osci.write("*RST")
|
|
||||||
time.sleep(5)
|
|
||||||
osci.write("horizontal:main:scale 5.0e-4")
|
|
||||||
|
|
||||||
osci.write("ch1:scale 1.0e-1")
|
|
||||||
osci.write("ch1:bandwidth ON")
|
|
||||||
osci.write("ch1:coupling AC")
|
|
||||||
osci.write("select:ch1 1")
|
|
||||||
|
|
||||||
osci.write("ch2:scale 5.0e-2")
|
|
||||||
osci.write("ch2:bandwidth ON")
|
|
||||||
osci.write("ch2:coupling AC")
|
|
||||||
osci.write("select:ch2 1")
|
|
||||||
|
|
||||||
# 8-bit data
|
|
||||||
osci.write("data:source CH1")
|
|
||||||
osci.write("data:encdg ascii")
|
|
||||||
|
|
||||||
osci.write("trigger:main:edge:source CH1")
|
|
||||||
osci.write("trigger:main:mode NORMAL")
|
|
||||||
osci.write("trigger:main:type EDGE")
|
|
||||||
|
|
||||||
osci.write("acquire:mode average")
|
|
||||||
osci.write("acquire:numavg 128")
|
|
||||||
osci.write("acquire:stopafter sequence")
|
|
||||||
osci.write("acquire:state RUN")
|
|
||||||
|
|
||||||
print(osci.query("curve?"))
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ pkgs.mkShell {
|
||||||
ps.psutil
|
ps.psutil
|
||||||
ps.pyusb
|
ps.pyusb
|
||||||
ps.numpy
|
ps.numpy
|
||||||
ps.pyaudio]))
|
ps.pyaudio
|
||||||
|
ps.matplotlib]))
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue