How to measure distance between speaker and microphone?
4 views (last 30 days)
Show older comments
I am trying to compare two sounds: one obtained right next to the source of sound and the other at some distance. They are both saved as .fig files but I can't get correct distance and depending on the .fig file ssometimes I get errors in cell2mat function. I found solutions to the similar problem on the internet but I am not sure how to implement them into my code.
Here is my code for recording the sounds:
clc
clear all
load gong.mat;
gong = audioplayer(y, Fs);
t2=0:1/Fs:3-1/Fs;
recObj = audiorecorder(48000,24,1);
disp('Start speaking.');
play(gong);
recordblocking(recObj, 1);
disp('End of Recording.');
myRecording = getaudiodata(recObj);
s_length = length(myRecording);
fs=48000;
sampleTime = ( 1:s_length )/fs;
figure(1)
plot(sampleTime,myRecording);
and code for comparing results:
open sound1.fig
D=get(gca,'Children');
XData=get(D,'XData');
YData=get(D,'YData');
Data=[XData' YData'];
open sound2.fig
D2=get(gca,'Children');
XData2=get(D2,'XData');
YData2=get(D2,'YData');
Data2=[XData2' YData2'];
%%
trshld = 0.3;
pulse1 = find(hf3yd(1,:) < trshld);
pulse2 = find(hf3yd(2,:) < trshld);
Fs = 48000;
pl1 = length(pulse1);
pl2 = length(pulse2);
vlen = min(pl1, pl2);
pulsx = pulse1(1:vlen);
pulsy = pulse2(1:vlen);
pulsxt = pulsx/Fs;
pulsyt = pulsy/Fs;
PulsDt = pulsxt - pulsyt;
PulsDtM = mean(abs(PulsDt));
distance=PulsDtM*340
fprintf(1,'\n\n\tDistance %.3f m\n\n', distance)
0 Comments
Answers (1)
Hamza HEBHOUB
on 26 Nov 2019
can you give the link of the solution that you found in the internet ?
0 Comments
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!