<< Chapter < Page Chapter >> Page >
This module gives a summary of the code we wrote to implement multilateration.

Program:

Here is the code for the program that we wrote to record and analyze the data received from the microphones:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Program constants

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

nMics = 4; % The number of microphones

Fs = 44100; % The sample rate

nBits = 8; % The number of bits per sample, either {8,16,24}

nChannels = 1; % The number of channels recorded, either {0,1}

recordLengthSeconds = 3; % The length of each recording in seconds

recordLength = recordLengthSeconds*Fs; % The length of each recording in entries

v = 1130.90551;

maxLags = 0.5*Fs;

% Offset in seconds to add to each mic's tau to account for delay start in recording

mic1TauOffset = 0;

mic2TauOffset = 0.0279;

mic3TauOffset = 0.0596;

mic4TauOffset = 0.1095;

This first part demonstrates the variables that we created and our averages (the offsets) used in calibrating the microphones (we got these values with time delay tests before we tested the entire array). The variable v represents the speed of sound in the area that we tested, and the maxLags represents the maximum lag between the microphones.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Initialization

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

pause on; % Enable pausing, which is used below

ids = zeros(1,nMics); % The device ID for each microphone

ids(1) = 1;

ids(2) = 2;

ids(3) = 3;

ids(4) = 4;

taus = zeros(1,nMics); % The TDOA in seconds between each mic and mic 1

As = zeros(1,nMics-2);

Bs = zeros(1,nMics-2);

Ds = zeros(1,nMics-2);

xs = zeros(1,nMics); % The x-position in feet of each mic relative to mic 1

ys = zeros(1,nMics); % The y-position in feet of each mic relative to mic 1

%{

xs(1) = 0; % Microphone #1 is at (0,0)

ys(1) = 0;

xs(2) = 0; % Microphone #2 is at (0,2)

ys(2) = 2;

xs(3) = 2; % Microphone #3 is at (2,0)

ys(3) = 0;

xs(4) = 2; % Microphone #4 is at (2,2)

ys(4) = 2;

%}

xs(1) = 0; % Microphone #1 is at (0,0)

ys(1) = 0;

xs(2) = -.5; % Microphone #2 is at (-.5,1)

ys(2) = 1;

xs(3) = -1; % Microphone #3 is at (-1,2)

ys(3) = 2;

xs(4) = -1; % Microphone #4 is at (-1,3)

ys(4) = 3;

A = zeros(nMics-2,2); %

B = zeros(nMics-2,1); % The matrices used to solve for point of origin, AX = B

This second part shows how we set up our coordinate grid. We used Matlab to identify each microphone and them input the position of each microphone (both array setups are shown). The last three lines identify the matrices used to find the point of origin, meaning that position was solved with respect to a certain microphone (the microphone at (0,0)).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Record audio data

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

recorder1 = audiorecorder(Fs, nBits, nChannels, ids(1));

recorder2 = audiorecorder(Fs, nBits, nChannels, ids(2));

recorder3 = audiorecorder(Fs, nBits, nChannels, ids(3));

recorder4 = audiorecorder(Fs, nBits, nChannels, ids(4));

record(recorder1, recordLengthSeconds);

record(recorder2, recordLengthSeconds);

record(recorder3, recordLengthSeconds);

record(recorder4, recordLengthSeconds);

pause(recordLengthSeconds*1.5); % Pause for the length of the recording

% plus 50% to ensure recording finishes

temp = getaudiodata(recorder1);

record1 = temp;

temp = getaudiodata(recorder2);

record2 = temp;

temp = getaudiodata(recorder3);

record3 = temp;

temp = getaudiodata(recorder4);

record4 = temp;

%{

figure;

plot(record1);

figure;

plot(record2);

figure;

plot(record3);

figure;

plot(record4);

%}

The third part involves the recording the data from the microphones and then plotting the impulse. The pause function is used to ensure that all of the impulse is recorded and not cut off. The data is then plotted on the same graph. The plots all showed the impulse response of the clap.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Analyze audio data

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Find TDOA for each mic

taus(1) = 0; % No TDOA between mic 1 and itself

crosscorrelation = xcorr(record2,record1,maxLags); % TDOA for mic 2

[maxVal, maxIndex] = max(crosscorrelation);

taus(2) = (maxIndex-maxLags)/Fs + mic2TauOffset;

crosscorrelation = xcorr(record3,record1,maxLags); % TDOA for mic 3

[maxVal, maxIndex] = max(crosscorrelation);

taus(3) = (maxIndex-maxLags)/Fs + mic3TauOffset;

crosscorrelation = xcorr(record4,record1,maxLags); % TDOA for mic 4

[maxVal, maxIndex] = max(crosscorrelation);

taus(4) = (maxIndex-maxLags)/Fs + mic4TauOffset;

% Find A_m, B_m and D_m for each mic m

for i=3:nMics

As(i) = 2*xs(i)/(v*taus(i)) - 2*xs(2)/(v*taus(2));

Bs(i) = 2*ys(i)/(v*taus(i)) - 2*ys(2)/(v*taus(2));

Ds(i) = v*taus(i) - v*taus(2) - (xs(i)^2 + ys(i)^2)/(v*taus(i)) + (xs(2)^2 + ys(2)^2)/(v*taus(2));

end

% Generate matrices A, B to solve for Ax = B

for i=3:nMics

A(i-2,1) = As(i);

A(i-2,2) = Bs(i);

B(i-2,1) = -Ds(i);

end

X = linsolve(A,B);

A

B

X

taus

The final part involved finding the actual time differences between the sound recordings of the microphones. As seen at the top, the known data of the different time arrivals of the sound to each individual microphone was cross-correlated in order to find the time differences in arrival of the sound for any two microphones. This information was then used to create matrix points for each of the microphones. The matrix was then solved to find the position of the person clapping using the equation Ax = B. The values were then printed out.

Questions & Answers

what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Elec 301 projects fall 2011. OpenStax CNX. Jun 18, 2012 Download for free at http://cnx.org/content/col11431/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Elec 301 projects fall 2011' conversation and receive update notifications?

Ask