Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 8:aaf5cde0aa0a, committed 2016-04-27
- Comitter:
- mikeb
- Date:
- Wed Apr 27 20:12:55 2016 +0000
- Parent:
- 7:25dacf35f4c7
- Child:
- 9:d86d73964999
- Commit message:
- Smoothing Function
Changed in this revision
| AoA_Est.h | Show annotated file Show diff for this revision Revisions of this file |
| Phase_Finder.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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) {
--- a/Phase_Finder.h Wed Apr 27 17:11:16 2016 +0000
+++ b/Phase_Finder.h Wed Apr 27 20:12:55 2016 +0000
@@ -40,7 +40,13 @@
}
void Phase_Finder::est_Max(float samples1[]) {
-
+ float change = 0;
+
+ for (int i = 2; i < length - 1; i++) {
+ change = abs(samples1[i - 2] - samples1[i - 1]);
+ if (abs(samples1[i] - samples1[i-1]) > change*4.5)
+ samples1[i] = (samples1[i - 1] + samples1[i + 1]) / 2;
+ }
for (int j = 0; j<peaks; j++) {
float max = 0;