Sound speed measurement (with two microphones)
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Akbar
am 11 Mai 2014
Kommentiert: Hamza Ashraf
am 30 Jan. 2020
I have two microphones connected to my laptop through one microphone port. The microphones are separated by some distance (about 1.5 meters). My aim is to measure the delay of sound between microphones to measure sound speed. (v_sound=x/delay). Below is my program:
if true
clear; figure; grid on; hold on;
Fs = 4000; % sampling rate in Hz
dt = 8; % duration in seconds
% get data
y = wavrecord(dt*Fs, Fs, 2);
% convert to time (sec)
tmax = length(y)/Fs;
t = linspace(0, tmax, dt*Fs);
% plot
plot(t*1000,y);
axis([0 tmax*1000 -2 2]);
xlabel('time (ms)');
% --- Analysis ---
j = 1;
for i=1:length(y)
if y(i)>0.15
pick(j) = 1000*i/Fs;
fprintf('%3d --> %8.1f ms\n',j, pick(j));
j=j+1;
end
end
end
This program runs 8 seconds, during that time i did two claps with my hands close to one microphone (so one microphone receives sound before the other, i need that delay). And here is an output:
Blue color is a microphone close to my hands and green is a microphone that is abou 1.5m. away. I zoom in and try to find the delay manually using data cursor but there are too many peaks there, i don't know which pair of peaks to take.
Do you have any suggestions? Ideas?
4 Kommentare
Akzeptierte Antwort
Star Strider
am 11 Mai 2014
Success!
It took a few minutes to get the data out of the figure, and then some experimenting. I thought about low-pass filtering your signal (I still believe that would be a good idea if you intend to repeat this experiment), but decided in the interests of time to go with simple thresholding (while I watched Manchester City and West Ham).
I include all the code, including that to acquire the data from your .fig file (even though you don’t need that part).
The code:
% Get figure and data, convert to numeric from cell:
ssf = openfig('sound_speed.fig')
hf2 = get(gca, 'Children')
hf3xc = get(hf2, 'XData')
hf3yc = get(hf2, 'YData')
hf3xd = cell2mat(hf3xc);
hf3yd = cell2mat(hf3yc);
trshld = -0.6; % Threshold arbitrary, estimated from plot
% Threshold first:
pulse1 = find(hf3yd(1,:) < trshld);
pulse2 = find(hf3yd(2,:) < trshld);
Fs = 4000; % Sampling frequency (Hz)
% Equalise vector lengths:
pl1 = length(pulse1);
pl2 = length(pulse2);
vlen = min(pl1, pl2);
pulsx = pulse1(1:vlen); % Lengths in samples
pulsy = pulse2(1:vlen);
pulsxt = pulsx/Fs; % Lengths in seconds
pulsyt = pulsy/Fs;
% Subtract:
PulsDs = pulsx - pulsy; % Difference in microphones arrival times (samples)
PulsDt = pulsxt - pulsyt; % Difference in microphones arrival times (seconds)
% Take mean:
PulsDsM = mean(abs(PulsDs));
PulsDtM = mean(abs(PulsDt));
MicDist = 1.66; % Distance between microphones (m)
Csc = MicDist/PulsDtM % Calculated speed of sound (m/s)
fprintf(1,'\n\n\tSpeed of sound = %.3f m/s\n\n', Csc)
The result:
Speed of sound = 390.588 m/s
If you intend to repeat this experiment over time, I suggest:
- Develop an appropriate low-pass filter
- Develop an adaptive threshold or other peak- or pulse-detection algorithm
- Record everything that can affect the air density and therefore the speed of sound (temperature °K, barometric pressure, relative humidity, etc.)
- Collect data over time and do regressions (and plots if the function space permits) of the various variables and how they affect the speed of sound over time
- This sounds like a cool advanced secondary or undergraduate university physics experiment!
8 Kommentare
Hamza Ashraf
am 30 Jan. 2020
i want to do the same thing but my problem is i have recorded sound as wav format how can i find speed of that sound at differnt mircophones seperated by a distance. please help me out
Weitere Antworten (1)
Image Analyst
am 11 Mai 2014
Can't you just threshold?
sound1TimeIndex = find(abs(sound1) > 0.2, 1, 'first');
sound2TimeIndex = find(abs(sound2) > 0.2, 1, 'first');
deltaTimeIndex = abs(sound1TimeIndex - sound2TimeIndex);
Did you try that?
22 Kommentare
Star Strider
am 15 Mai 2014
I assigned the name of each of your files figfile. That made it easier to load them, and then to write out the speed of sound for the appropriate figure. (See my previous posts for examples of that output.) You can either rewrite the line, or name figfile as any string variable.
One option:
figfile = datestr(now, 'yyyy-mm-dd HH.MM.SS');
That way, it prints out the date and time of the experiment, as well as the calculated speed of sound.
triveni p
am 15 Feb. 2017
can you just
suggest any code for butterworth in image noise re
moval
Siehe auch
Kategorien
Mehr zu Measurements and Spatial Audio 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!