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)
|
||||
|
||||
paudio = pa.PyAudio()
|
||||
stream = paudio.open(format=pa.paFloat32,
|
||||
output_strm = paudio.open(format=pa.paFloat32,
|
||||
channels=1,
|
||||
rate=48000,
|
||||
output=True,
|
||||
stream_callback=audio_callback)
|
||||
output_strm.start_stream()
|
||||
|
||||
def do_frequency(scaled_f, osci, hscale):
|
||||
scaled_frequency = scaled_f
|
||||
time.sleep(0.1)
|
||||
osci.write("acquire:state run") # Restart acquisition sequence
|
||||
time.sleep(10 * hscale)
|
||||
input_strm = paudio.open(format=pa.paFloat32,
|
||||
channels=1,
|
||||
rate=48000,
|
||||
input=True)
|
||||
input_strm.stop_stream()
|
||||
|
||||
osci.write("data:source CH1")
|
||||
A_samps = osci.query_binary_values("curve?",datatype='b',container=numpy.array)
|
||||
A_samps = A_samps.astype(np.float64)
|
||||
def do_frequency(scaled_f):
|
||||
scaled_frequency = scaled_f
|
||||
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.
|
||||
B_samps = osci.query_binary_values("curve?",datatype='b',container=numpy.array)
|
||||
B_samps = B_samps.astype(np.float64)
|
||||
import matplotlib.pyplot as plt
|
||||
L = do_frequency(440.0/48000)
|
||||
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.pyusb
|
||||
ps.numpy
|
||||
ps.pyaudio]))
|
||||
ps.pyaudio
|
||||
ps.matplotlib]))
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue