필터 지우기
필터 지우기

Sound speed measurement (with two microphones)

조회 수: 4 (최근 30일)
Akbar
Akbar 2014년 5월 11일
댓글: Hamza Ashraf 2020년 1월 30일
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
Star Strider
Star Strider 2014년 5월 11일
Thank you! I can get the data from your .fig file.
Akbar
Akbar 2014년 5월 11일
it would be great if MATLAB will calculate delay for me. Below Image Analyst wrote some piece of code. Could you help me with its implementation to code that is above and i will try running it.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2014년 5월 11일
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
Star Strider
Star Strider 2014년 5월 11일
Thank you!
Hamza Ashraf
Hamza Ashraf 2020년 1월 30일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 5월 11일
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
Star Strider
Star Strider 2014년 5월 15일
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
triveni p 2017년 2월 15일
can you just
suggest any code for butterworth in image noise re
moval

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by