<< Chapter < Page Chapter >> Page >
This section contains a few important links, the code that we used for the project, and the project executable files.

Matlab code

  • new_sim2: function new_sim2(theta_true) % Values, Vectors, and a Matrix%theta_true = pi./2; degree = 32;c = 346.287; % speed of sound in air N = 150; % length of the sample bufferFs = 48000; % sampling frequency f = 500; % frequency of sine waveM = 2; % number of microphones dist = .1;t = [0:N-1]./Fs; % time axism = (M-1)./2; % array center x = dist.*[-m:m]; % microphone location on the x axis omega = 2*pi*f; % commonly used valuetheta_test = [1:2:2*degree-1]*pi/(2*degree); % test vector of theta values%theta_test = pi./2; divisor = degree/8; % region divisorlength_t = length(theta_test); % length of the delay vector A = zeros(1,length_t); % initialize A vectordelay_true = x.*cos(theta_true)./c; % actual delay delay_test = x'*cos(theta_test)./c; % test matrix of delay valuessamples = round(2.*delay_test*Fs)./2; % number of samples to shift in testing index = samples - ones(M,1)*min(samples) + 1;% Signal Simulation for j = 1:My(j,:) = sin(omega*(t-delay_true(j))); end% Region Approximation for i = [1:length_t]for j = [1:M] y_delay(j,:) = y(j,[index(j,i)+50:index(j,i)+100]); %delay y1 by the 1,i value using index endz = sum(y_delay); A(i) = sum(z.^2);end aa = find(A == max(A));region = floor(aa(1)./divisor) theta_range = [region-1 region]*pi/8; if(0)figure plot(theta_test/pi,A)end
  • sim_input3: function [region,theta_range] = sim_input3(theta_true,degree)% Values, Vectors, and a Matrix c = 346.287; % speed of sound in airN = 150; % length of the sample buffer Fs = 44100; % sampling frequencyf = 500; % frequency of sine wave M = 2; % number of microphones%dist = .32; % distance between microphones dist = .5;t = [0:N-1]./Fs; % time axism = (M-1)./2; % array center x = dist.*[-m:m]; % microphone location on the x axis cutoff = 50; % cutoff frequency of filteromega = 2*pi*f; % commonly used value theta_test = [1:2:2*degree-1]*pi/(2*degree); % test vector of theta values divisor = degree/8; % region divisorlength_t = length(theta_test); % length of the delay vector A = zeros(1,length_t); % initialize A vectorB = fir1(40,cutoff/Fs,'low'); % lowpass filter delay_true = x.*cos(theta_true)./c; % actual delaydelay_test = x'*cos(theta_test)./c; % test matrix of delay values samples = round(2.*delay_test*Fs)./2; % number of samples to shift in testingindex = samples - ones(M,1)*min(samples) + 1; cos_base = cos(omega*t(1:N));sin_base = sin(omega*t(1:N)); SNR = 1000;noise1 = randn(1,N)/SNR; noise2 = randn(1,N)/SNR;% Signal Simulation y1 = sin(omega*(t-delay_true(1))) + noise1;y2 = sin(omega*(t-delay_true(2))) + noise2; % Region Approximationfor i = [1:length_t] y1_sample = y1(index(1,i):index(1,i)+40); %delay y1 by the 1,i value using indexy2_sample = y2(index(2,i):index(2,i)+40); z = y1_sample + y2_sample;z_cos = z.*cos_base(1:41); z_sin = z.*sin_base(1:41);z_cos_filter = sum(fliplr(z_cos).*B);z_sin_filter = sum(fliplr(z_sin).*B);A(i) = z_sin_filter^2 + z_cos_filter^2; end% figure % plot(theta_test,A);% title(theta_true) aa = find(A == max(A));region = floor(aa(1)./divisor); if(0)theta_range = [region-1 region]*pi/8;figure plot(theta_test/pi,A)end

C code

  • index.h: short index[2][32]= { {0x0001, 0x0001, 0x0001,0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0008, 0x0009, 0x000A, 0x000A, 0x000B, 0x000C, 0x000D, 0x000D, 0x000D, 0x000E, 0x000E},{0x000E, 0x000E, 0x000D,0x000D, 0x000D, 0x000C, 0x000B, 0x000A, 0x000A, 0x0009, 0x0008, 0x0006, 0x0005, 0x0004, 0x0003, 0x0002, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001} };
  • loop_intr_pcm2.c: #include "index.h" #define N 100 //sample buffer length #define N2 128 //averaging buffer length #define DEGREE 32 //number of theta test values to try #define SUMSAMP 70 //number of theta test values to try float Fs = 16000.0; //irrelevant since jumper in 3-4 int* lights = (int*)0x90080000; short buffer1[N] = {0}; short buffer2[N] = {0}; int buffer3[N2] = {0}; int buf_full = 0; int buf_index = 0; interrupt void c_int12() //McBSP1 receive ISR { int sample = input_leftright_sample(); buffer1[buf_index] = (short)(sample >> 16); buffer2[buf_index] = (short)sample; buf_index++; if(buf_index == N) { buf_index = 0; buf_full = 1; } return; //return from interrupt } void main() { int i; int j; int k = 0; int z, test_amp; int region; int out; int sum = 0; int max_theta_index = 0; int max_amplitude = -1; for(k=0;k<N2;k++) buffer3[k] = 0; k = 0; comm_intr(); //init DSK, codec, McBSP while(1) { if(buf_full) { buf_full = 0; max_amplitude = -1; for(i=0; i<DEGREE; i++) { test_amp = 0; for(j=0; j<SUMSAMP; j++) { z = buffer1[index[0][i]+j] + buffer2[index[1][i]+j]; test_amp += (z * z) >> 15; } if(test_amp > max_amplitude) { max_amplitude = test_amp; max_theta_index = i; } } region = max_theta_index >> 2; sum -= buffer3[k]; buffer3[k++] = region; sum += region; if(k == N2) { k = 0; out = sum >> 7; /*if(out > 3) out = 0; else out = 7;*/ *lights = out << 24; } } } }
  • vectors_11.asm: *Vectors_11.asm Vector file for interrupt-driven program .ref _c_int12 ;ISR used in C program.ref _c_int00 ;entry address .sect "vectors" ;section for vectorsRESET_RST: mvkl .S2 _c_int00,B0 ;lower 16 bits --> B0 mvkh .S2 _c_int00,B0 ;upper 16 bits --> B0B .S2 B0 ;branch to entry address NOP ;NOPs for remainder of FPNOP ;to fill 0x20 Bytes NOPNOP NOPNMI_RST: .loop 8 NOP ;fill with 8 NOPs.endloop RESV1: .loop 8NOP .endloopRESV2: .loop 8 NOP.endloop INT4: .loop 8NOP .endloopINT5: .loop 8 NOP.endloop INT6: .loop 8NOP .endloopINT7: .loop 8 NOP.endloop INT8: .loop 8NOP .endloopINT9: .loop 8 NOP.endloop INT10: .loop 8NOP .endloopINT11: .loop 8 NOP.endloop INT12: b _c_int12 ;branch to ISR.loop 7 NOP.endloopINT13: .loop 8 NOP.endloop INT14: .loop 8NOP .endloopINT15: .loop 8 NOP.endloop

Project executable files

Questions & Answers

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
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, Audio localization. OpenStax CNX. Jun 06, 2011 Download for free at http://cnx.org/content/col10250/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Audio localization' conversation and receive update notifications?

Ask