Real time audio data plot from COM/serial port

12 Ansichten (letzte 30 Tage)
Kulbir
Kulbir am 7 Apr. 2023
Kommentiert: Kulbir am 14 Apr. 2023
need to know how i can plot audio data in real-time from serial port. am getting error using this code.
clear; clc;
%create a serial object
s= serialport("COM4", 115200);
%open serial port
fopen(s);
%plotting data
i= 1;
while(1)
data(i)= str2double(fscanf(s));
plot(data);
pause(0.01);
i= i+1;
end
%error i am getting is---
Error using fopen
First input must be a file name or a file identifier.
Error in pltsril (line 5)
fopen(s);

Antworten (1)

Cris LaPierre
Cris LaPierre am 7 Apr. 2023
fopen does not work with a serialport object. See the available methods here:
You likely want read.
  27 Kommentare
Walter Roberson
Walter Roberson am 13 Apr. 2023
Using readline(device) is not going to be useful for you. You need to find out what data format the device is sending, and you need to use read() of the device, probably using one of the commands I showed above.
What model of device are you reading from?
Kulbir
Kulbir am 14 Apr. 2023
hello sir, i am in need your inputs, thank you

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by