m b
/
AoA_estimator
Part of a program that estimates the direction of arrival of a signal
Diff: AoA_Est.h
- Revision:
- 8:aaf5cde0aa0a
- Parent:
- 7:25dacf35f4c7
- Child:
- 11:8574bb5b92b0
--- a/AoA_Est.h Wed Apr 27 17:11:16 2016 +0000 +++ b/AoA_Est.h Wed Apr 27 20:12:55 2016 +0000 @@ -2,38 +2,64 @@ #include "mbed.h" #include <cmath> -const int MAX_SENSORS = 10; -const int ITERATIONS = 3; -/** A -* } +/** AoA_Est.h +* Computes the angle of arrival of an audio signal +* EXAMPLE: + @code + //Find the angle of arrival of a 900Hz audio signal using 3 MBEDS equipped with microphones. + //Requires an array of phases, found using Phase_Finder and communication between MBEDs. + //This code begins after phases have been found and communicated to master MBED + //Sensors are located at (0,0), (150,0), and (150,90). Maximum sensors is 10 including master. Can be changed with parameter MAX_SENSORS + float angle = 0; + int x[2] = {150, 150); //Distances from master MBED microphone in milimeters. All distances must be for microphones, not MBED units + int y[2] = {0, 90); //Do not include master MBED, its microphone is assumed to be 0,0. + AoA_Est AoA(3, x, y, 900); + angle = AoA.estimate(phases, phases); * } * @endcode */ +const int MAX_SENSORS = 10; //Maxmimum number of sensors + + + class AoA_Est { public: - /** Create a - * - * @param _pin mbed AnalogIn pin where the analog output of sensor is connected - * - * @note Supported types of sensors: + /** Create an Angle of Arrival Estimator Object + * + * @param numOfSensors Number of sensors including the master + * @param xPassed[] X coordinates of every sensor EXCEPT the master. Master is assumed (0,0). + * @param yPassed[] Y coordinates of every sensor EXCEPT the master + * @param freq frequency of interest in Hz + * @note Maximum number of supported sensors is 10 + */ + AoA_Est(int numOfSensors, int xPassed[], int yPassed[], float freq); + /** Estimate the angle to the sound source + * + * @param phases[] Array of phases, first phase is the master. Must correspond to order of X and Y coordinates. + * @param amp[] Amplitudes. Not currently used. Repeat the phase array here to prevent errors. + * @param yPassed[] Y coordinates of every sensor EXCEPT the master + * @return angle relative to X axis + */ + float estimate(float phases[], float amp[]); + /** Not Used */ - AoA_Est(int numOfSensors, int xPassed[], int yPassed[], float freq); - float estimate(float phases[], float amp[]); bool calibrate(); - - + /** Confidence level of the output + * + * @return number corresponding to the number of angle determinations used in the average + */ int confidence; private: - float estimate_Theoretical(float phases[], float amp[]); - float estimate_Calibrated(float phases[], float amp[]); - void comparative_Phases(float phas[]); + float estimate_Theoretical(float phases[], float amp[]); + float estimate_Calibrated(float phases[], float amp[]); //Unused + void comparative_Phases(float phas[]); //Returns the phases relative to the master float angle_Resolver(); float distanceFinder(float phase); int sensors; - + int ITERATIONS; int x[MAX_SENSORS]; int y[MAX_SENSORS]; float phases[MAX_SENSORS - 1]; @@ -47,6 +73,11 @@ }; AoA_Est::AoA_Est(int numOfSensors, int xPassed[], int yPassed[], float freq) : sensors(numOfSensors) { + int j = sensors - 1; + while (j > 0){ + ITERATIONS += j; + j--; + } wavelength = (338.4 / freq)*1000; for (short i = 0; i < sensors-1; i++) { x[i] = xPassed[i]; @@ -82,7 +113,7 @@ float phas_diff = 0; float relative_angle = 0; float relative_dist = 0; - /*for (int i = 1; i < sensors - 1; i++) { + /*for (int i = 1; i < sensors - 1; i++) { //for(int i = 1; i<ITERATIONS - sensors+1; i++) while (i < sensors - 1) { phas_diff = phases[i - 1] - phases[i]; if (abs(phas_diff) > 180) {