Reading an Array Data from the Serial Port

6 次查看(过去 30 天)
How can I read the ARRAY data with 256 samples Array[256] from the Serial Port in matlab and show as a plot. I was using
s=serialport('COM13',19200);
i=1;
% out1 = instrfind('Port','COM3')
%open serial port
while(true)
data=readline(s);
deta(i)=str2double(data)
y=deta
drawnow;
% d = designfilt ('bandstopiir','FilterOrder',2,'HalfPowerFrequency1',46,'HalfPowerFrequency2',65,'SampleRate',1000); y = filter (d,deta);
if i<600
TF = isnan(deta)
deta(TF)=0;
end
h=[h;y(i)]
plot(y, 'r-');
i=i+1
end
But I am getting every values one by one, this makes my sampling rate really slow, normally I am using 13 kHz in MSP430, but I am taking 60 Hz sampling Rate. Can you help me? How can I Read and Plot an ARRAY with 256samples from the Serial Port. Thank you.

回答(1 个)

VBBV
VBBV 2023-7-22
data=read(s);

Try using read function which has option to read how many data samples you want at a time. It also allows to read all data input at once, which is something you want.

类别

Help CenterFile Exchange 中查找有关 Digital Filter Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by