APIStreamer
APIStreamer is a class that reads directly from buffers on the hardware without waiting for it to go to the tank. Because it is essentially competing with Synapse for access to the hardware, it has lower bandwidth than SynapseLive, but it has much faster access.
You can download the latest MATLAB SDK files here. The MATLAB APIStreamer class installs into:
C:\TDT\TDTMatlabSDK\TDTSDK\APIStreamer
Examples install into:
C:\TDT\TDTMatlabSDK\Examples\OnlineAnalysis
The Python APIStreamer installs with pypi:
pip install tdt
Release v96 of Synapse and above includes the custom gizmos that APIStreamer can read from, in the Gizmo List under Custom > TDT > API.
-
Attach one of the APIStreamer gizmos (e.g. APIStreamMC for multi-channel signals) to your data source.
-
Use one of the examples to read from the buffer inside the APIStream gizmo during the recording.
The data rate limit for APIStreamer is ~8 channels of 32-bit floats at ~25 kHz or the equivalent data rate (e.g. 32 channels at ~6 kHz). Beyond that we recommend a PO8e Streaming Interface card, which is a direct connection from the RZ to a separate PCI card, bypassing Synapse altogether.
Matlab Examples
Python Examples
Online Data Processing
APIStreamer is collecting data in the background. Reads the data buffer every 1 second.
import time
import tdt
s = tdt.APIStreamer(gizmo='APIStreamerMC1', history_seconds=10)
while 1:
print(s.get_data())
time.sleep(1)
Online Data Processing Callback
Runs the do_something
function every time new data is read from the hardware
import tdt
def do_something(result):
print('process data', result.data.shape)
s = tdt.APIStreamer(gizmo='APIStreamerMC1', history_seconds=10, callback=do_something)
Online Streaming Data
Plots the data from the APIStreamer
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import tdt
s = tdt.APIStreamer(gizmo='APIStreamerMC1', history_seconds=10)
fig = plt.figure(figsize=(10,5))
ax1 = fig.add_subplot(111)
def animate(i):
result = s.get_data()
if result is None:
return
xs, ys = result
if len(xs) == len(ys) == 1:
return
ax1.clear()
ax1.plot(xs, ys.T + np.arange(ys.shape[0]).T)
ax1.set_xlabel('time, s')
ax1.set_ylabel('V')
ani = animation.FuncAnimation(fig, animate, interval=100, cache_frame_data=False)
plt.show()
Plotting Multiple Streams
Reads from two APIStreamer gizmos and plots them
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import tdt
s = tdt.APIStreamer(gizmo='APIStreamer1Ch1', history_seconds=10)
s2 = tdt.APIStreamer(gizmo='APIStreamer2Ch1', history_seconds=10)
fig = plt.figure(figsize=(10,5))
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
def animate(i):
result = s.get_data()
if result is None:
return
result2 = s2.get_data()
if result2 is None:
return
xs, ys = result
ax1.clear()
ax1.plot(xs, ys.T + 1*np.arange(ys.shape[0]).T)
ax1.set_xlabel('time, s')
ax1.set_ylabel('V')
xs2, ys2 = result2
ax2.clear()
ax2.plot(xs2, ys2.T + 1*np.arange(ys2.shape[0]).T)
ax2.set_xlabel('time, s')
ax2.set_ylabel('V')
ani = animation.FuncAnimation(fig, animate, interval=100, cache_frame_data=False)
plt.show()