This is set up as a lab experiment demonstrating the use of cross correlation. The PC sound card is used together with wavplay and wavrecord in MATLAB to generate and measure, using two microphones a fixed distance apart, a noise burst. Wavplay is used in asynchronous mode to play the noise an immediately return control to the command window so that the sound can be recoded using wavrecord.
Fs=44100;
T=1/Fs;
s=.1;
N=s*Fs;
x=idinput(N);%,'prbs');
xx=zeros(N,2);xx(:,2)=x;
t=0:1/Fs:(N-1)/Fs;
wavplay(xx,Fs,'async')
y=wavrecord(s*Fs,Fs,2);
figure(1)
subplot(2,1,1)
plot(t,y);%plot(t,y(:,1))
subplot(2,1,2)
plot(t,y(:,2))
figure(2)
%subplot(2,1,2)
rxx=xcorr(y(:,1),y(:,2),200);
l=-200:200;
plot(l,rxx,'r');grid on
[A,I]=max(rxx);
Tlag=T*(200-I);
v=340;
d=v*Tlag % Display distance in command window
Subscribe to:
Post Comments (Atom)


The speed of sound is variable and depends on the properties of the substance through of which the wave is travelling.
ReplyDeletedistance measurement