Hey Taylor,
You're likely hitting a bottleneck in how MATLAB handles BLE notifications. By default, MATLAB's BLE communication can be slower due to overhead in event handling. Here are a few things you can try to speed it up:
% Increase buffer size and reduce processing overhead
b = ble(MyDAQAdd, 'Timeout', 10);
c1 = characteristic(b, "0749b706-43ba-4cd9-9ea6-85bf0fc0b87e", "8e34967a-0ad7-4f8b-8b44-276b295eb3fd");
subscribe(c1, "notification", 'BufferSize', 1000);
% Optimize callback function
function saveData(src, ~)
persistent datacount Data Timestamps;
if isempty(datacount)
datacount = 0;
Data = zeros(10000, 16);
Timestamps = datetime.empty(10000, 0)';
end
[data, timestamp] = read(src, 'latest');
datacount = datacount + 1;
Data(datacount, :) = data;
Timestamps(datacount) = timestamp;
if mod(datacount, 100) == 0
disp("Received 100 packets");
end
end
% Start data collection
c1.DataAvailableFcn = @saveData;
pause(10); % Run for a test period
c1.DataAvailableFcn = [];
What This Does
- Increases buffer size to reduce packet loss.
- Minimizes overhead by reducing global variable access.
- Uses mod(datacount, 100) == 0 to display updates without excessive console output.
This should help improve your data rate. Follow me so you can message me anytime with future MATLAB questions.
