MATLAB Answers

Would like to measure the speed of sound in Windows MatLab by timed sounds from the speaker with simultaneous recording. Run measurements continuously for days

1 view (last 30 days)
Richard K Collins
Richard K Collins on 13 Mar 2021
I have a 24 bit, 96000 sps, single channel microphone. I can record it with
  • Mic1 = audiorecorder(96000,24,1)
  • recordblocking(Mic1,1)
  • S1 = getaudiodata(Mic1,'int16')
but using record(Mic1,1) goes immediately to getaudiodata. It needs a delay or wait or schedule
  • Mic1 = audiorecorder(96000,24,1)
  • record(Mic1,1)
  • play sound after 50 milliseconds (the recorder will probably be slow to start
  • wait to almost one second so I can store results at exactly one sample per second. Yes it takes fiddling
  • S1 = getaudiodata(Mic1,'int16')
I want to start the recorder and then at a precisely known moment generate a short pulse sound (tick or click or chirp or pulse) to the speaker. After one second total Stop the recorder and then look at the recorded signal and see if I can calibrate somehow.
Once I can get it to make one measurement, I want to just let it run continuously and store the raw data and summary data.
T = timer( some stuff )
T.StartFcn = MyStart;
T.StopFcn = MyStop;
T.start();
function MyStart()
Start recording with record(Mi1, 1)
-- I have a small room The distance is about 3 meters at 340 m/s so time = distance/speed = 8823.5 microSecs
-- in sample units I would expect the first bit of sound to come at (3/340)*96000 = 847 samples into the recording
Play the sound -- how do I build a 96000 Hz sound with 100 amplitudes?
end
function MyStop()
Process the recorded sound, mark down the exact times, save everything, and then do it again
T.Start(); -- this is not the current syntax but it is a good object practice to put the methods inside and just refer to one object name
end
  2 Comments
Richard K Collins
Richard K Collins on 13 Mar 2021
There does not seem to be an 'int32' for "record()". You can set it for 24 bit digital recording, but it will only store 16 bit digital.
"single" is 4 byte floating point. Please, someone be consistent.
Is there any way to get MatLab to use the real capabilities of devices, not arbitrary settings?
If you ever save days of data for millions of users, you cannot waste time converting to floating point. and you NEVER use a lossy format or transform.
Record() should be generic to all sensors.
Record.audio(Mic1, 5 ms) should not kill you compiler/parser
Mic1.record(5 ms) would be better
If the compiler writers and data compilers cooperate, you can get a clean and mean language that is concise, easy to learn and use. If the compiler/parser group is smart they can allow aliases and different languages for people coming from different backgrounds.
mic1 at 1.236 632 337 for 5.012 us
All my global Internet projects require global submicrosecond coordination, working to nanosecond and sub for special projects.

Sign in to comment.

Answers (1)

Andrei Ursache
Andrei Ursache on 30 Apr 2021
Richard, you might find the following example useful. It's using functions in Data Acquisition Toolbox (rather than audiorecorder) and Signal Processing Toolbox.
Andrei
  1 Comment
Richard K Collins
Richard K Collins on 1 May 2021
Thank you for taking the time to answer. I read over that example. It requires specialized hardware, renting two more modules, and lots of time to figure out. Plus the distraction of having still more things that almost work, and have to be sorted through.
The MathWorks design concept always requires purchasing more modules. It benefits the company, not the users. They have programmed into every solution, every product - how can we make people more dependent, how can we extract more money and rent. The core product is not being refined and improved to reduce cost and time, but every new features gets stuffed into yet another module. They cannot seem to help themselves.
That sounds pretty cynical early in the morning, on a dark and rainy and gloomy day. But every example I tried on my own with MatLab. Every example like this - user-contributed time is being used to sell more modules, to support them, to find new markets. It is not a sustainable strategy, even if it lets the company grow to large size in the short term. (20 years is the short term)
Thanks for thinking of this. What really bothers me, is that none of the functions show which library they come from, and all the functions require human readers for their explanation.
The core system should be constantly aware of all sensors and devices, their capabilities and behaviors. In the 1960's the software was this poorly integrated, the documentation on paper that required massive amounts of reading and memorization or page turning. It has not changed at all.
site:mathworks.com ("audio" OR "sound" OR "ultrasound") has 51,200 entry points. MathWorks and its community has not learned how to consolidate, simplify, organize, save time of users, save time for society as a whole.
I guess I will have to find a way to buy the pieces to run https://www.mathworks.com/help/audio/ref/impulseresponsemeasurer-app.html if I could just find out what hardware and software it requires. And what that requires. And what that requires.
Richard Collins, Director, The Internet Foundation

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!