<< 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

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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