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
Thursday, November 25, 2010
Sunday, November 14, 2010
Demonstration of Ensemble Stochastic Process
% Demonstrate ensemble stochastic processM=4000;N=50;Nsub=6;
x=randn(M,N);
% Uncomment next two lines when we filter the process
% b=1;a=[1 -1.5 .85];
% x=filter(b,a,x')';
n=0:N-1;
nn=20;mm=21; % nn and mm are the positions of the markers
for i=1:Nsub
subplot(Nsub,1,i);
stem(n,x(i,:),'MarkerSize',3);%axis([0 N -2.5 2.5]);
hold on
plot(nn,x(i,nn+1),'o','MarkerSize',6,'MarkerFaceColor','r','MarkerEdgeColor','k')
plot(mm,x(i,mm+1),'^','MarkerSize',6,'MarkerFaceColor','g','MarkerEdgeColor','k')
hold off
end
ac=mean(x(:,nn).*x(:,mm))
subplot(Nsub,1,1)
Subscribe to:
Comments (Atom)

