wavrecord() replacement and sound speed measurement
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Michal Rocinski
am 27 Apr. 2020
Kommentiert: Walter Roberson
am 21 Sep. 2023
I would like to try to measure sound speed with Matlab. I have two microphones recording sound at the same time. They are both connected to my laptop through stereo input. I have tried to use code from this topic: https://www.mathworks.com/matlabcentral/answers/129171-sound-speed-measurement-with-two-microphones
I replaced 'wavrecord()' to an audiorecorder function but it gives an error. I have no idea what I can change to make the program work properly and start recording a sound.
Here is the code and the error below:
if true
clear; figure; grid on; hold on;
Fs = 22050;
r = audiorecorder(22050,16,2);
record(r,5);
mySpeech = getaudiodata(r, 'int16');
tmax = length(mySpeech)/Fs;
t = linspace(0, tmax, 5*Fs);
plot(t*1000,mySpeech);
axis([0 tmax*1000 -2 2]);
xlabel('time (ms)');
j = 1;
for i=1:length(mySpeech)
if mySpeech(i)>0.15
pick(j) = 1000*i/Fs;
fprintf('%3d --> %8.1f ms\n',j, pick(j));
j=j+1;
end
end
end
Error using audiorecorder/getaudiodata (line 765)
Recorder is empty.
Error in program (line 7)
mySpeech = getaudiodata(r, 'int16');
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Dian
am 21 Sep. 2023
Bearbeitet: Walter Roberson
am 21 Sep. 2023
clear all;
Fs = 8000;
y = wavrecord(5.0*Fs, Fs, 'double');
wavwrite(y,Fs,'aiueo.wav')
y1=wavread('aiueo.wav');
t=length(y1);
y2=y1(1:10000);
plot(y2)
1 Kommentar
Walter Roberson
am 21 Sep. 2023
Unfortunately, that will not solve @Michal Rocinski's problem, which was happening in R2019b. By R2019b, wavrecord() had been completely removed from MATLAB; wavwrite() had also been removed https://www.mathworks.com/matlabcentral/answers/647743-is-wavwrite-still-used#answer_544418 and probably wavread() had been removed too.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!