필터 지우기
필터 지우기

Why can't Matlab save the acceleration data higher than 8.67KSPS

조회 수: 3 (최근 30일)
tje_b
tje_b 2023년 10월 15일
댓글: Walter Roberson 2023년 10월 16일
I used the following codes to save my acceleration data from my Teensy4.1 board connected to my Macbook comport. I find out that It cant save data greater than 8.67KHz sampling frequency. I am doing something wrong?
% Setup a connection to the USB port
portName = '/dev/cu.usbmodem131678501'; % Adjust to your port name
s = serialport(portName, 2000000);
configureTerminator(s, 'LF');
s.Timeout = 20;
fopen(s);
% Create a file for writing
fileID = fopen('accelerometertest.txt', 'w');
% Read data from the serial port and write to the file
try
while true
dataLine = fgets(s); % Read a line from the serial port
fprintf(fileID, '%s', dataLine); % Write the data to the file
end
catch ME
% If any error occurs or you stop the script, close the connections
fclose(fileID);
fclose(s);
delete(s);
disp('Serial connection and file closed.');
rethrow(ME);
end
  댓글 수: 2
dpb
dpb 2023년 10월 15일
You can try buffering to memory instead of writing each record--that should speed it up at least some, but the high-level overhead of MATLAB itself is problably going to be limiting as compared to running directly at a lower level coding protocol.
Walter Roberson
Walter Roberson 2023년 10월 15일
You can do better if you can send the data in binary instead of as text.

댓글을 달려면 로그인하십시오.

답변 (1개)

Pratyush
Pratyush 2023년 10월 16일
Hi tje_b,
I understand that you have written a script for reading data from the serial port and writing it to a file, but you cannot save data greater than 8.67KHz sampling frequency. The issue you're experiencing might be related to the limitations of the serial communication between your Teensy4.1 board and your MacBook.
In your code, you set the baud rate to 2,000,000 (2 Mbps). However, the maximum baud rate supported by the Teensy4.1 board is 12 Mbps.
To increase the sampling frequency, you can try increasing the baud rate in your code to its maximum value of 12,000,000. Modify the line s = serialport(portName, 2000000); to s = serialport(portName, 12000000);.
Make sure that both the Teensy4.1 board and your MacBook's serial port need to support the chosen baud rate for successful communication.
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 10월 16일
It doesn't matter. The /dev name shows it is a USB device rather than a true serial port. Baud rate is irrelevant for USB: transfer speed is according to the protocol version negotiated between the host and the peripheral.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by