[DEV] add base of delay and sum

This commit is contained in:
Edouard DUPIN 2016-03-18 22:54:53 +01:00
parent ee1e9f8be6
commit 025bb60337
8 changed files with 116 additions and 0 deletions

1
lutinParseSubFolders.txt Normal file
View File

@ -0,0 +1 @@
tools/beamforming

View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <math.h>
// http://www.labbookpages.co.uk/audio/beamforming/delaySum.html
#define ANGLE_RESOLUTION 500 // Number of angle points to calculate
int main(void) {
int numElements = 4; // Number of array elements
double spacing = 0.2; // Element separation in metres
double freq = 1000.0; // Signal frequency in Hz
double speedSound = 343.0; // m/s
// Iterate through arrival angle points
for (int32_t aaa=0; aaa<ANGLE_RESOLUTION; aaa++) {
// Calculate the planewave arrival angle
double angle = -90.0 + 180.0 * double(aaa) / double(ANGLE_RESOLUTION-1.0);
double angleRad = M_PI * double(angle) / 180.0;
double realSum = 0;
double imagSum = 0;
// Iterate through array elements
for (int32_t iii=0; iii<numElements; iii++) {
// Calculate element position and wavefront delay
double position = iii * spacing;
double delay = position * sin(angleRad) / speedSound;
// Add Wave
realSum += cos(2.0 * M_PI * freq * delay);
imagSum += sin(2.0 * M_PI * freq * delay);
}
double output = sqrt(realSum * realSum + imagSum * imagSum) / numElements;
double logOutput = 20 * log10(output);
if (logOutput < -50) {
logOutput = -50;
}
printf("%d %f %f %f %f\n", a, angle, angleRad, output, logOutput);
}
return 0;
}

View File

@ -0,0 +1,6 @@
reset
unset key
set xlabel "Arrival Angle (degrees)" font "arial,12"
set ylabel "Gain (dB)" font "arial,12"
set grid lc rgbcolor "#BBBBBB"
plot 'beamPattern.dat' u 2:5 w l

View File

@ -0,0 +1,42 @@
#include <stdio.h>
#include <math.h>
// http://www.labbookpages.co.uk/audio/beamforming/delaySum.html
// Number of freq points to calculate
#define FREQ_RESOLUTION 500
// Number of angle points to calculate
#define ANGLE_RESOLUTION 500
int main(void) {
int numElements = 4; // Number of array elements
double spacing = 0.2; // Element separation in metre
double speedSound = 343.0; // m/s
// Iterate through arrival angle points
for (int32_t fff=0; fff<FREQ_RESOLUTION; ++fff) {
double freq = 10000.0 * double(fff) / double(FREQ_RESOLUTION-1);
for (int32_t aaa=0; aaa<ANGLE_RESOLUTION; ++aaa) {
// Calculate the planewave arrival angle
double angle = -90.0 + 180.0 * double(aaa) / double(ANGLE_RESOLUTION-1);
double angleRad = M_PI * double(angle) / 180.0;
double realSum = 0;
double imagSum = 0;
// Iterate through array elements
for (iii=0; iii<numElements; ++iii) {
// Calculate element position and wavefront delay
double position = double(iii) * spacing;
double delay = position * sin(angleRad) / speedSound;
// Add Wave
realSum += cos(2.0 * M_PI * freq * delay);
imagSum += sin(2.0 * M_PI * freq * delay);
}
double output = sqrt(realSum * realSum + imagSum * imagSum) / numElements;
double logOutput = 20.0 * log10(output);
if (logOutput < -50.0) {
logOutput = -50.0;
}
printf("%f %f %f\n", angle, freq, logOutput);
}
printf("\n");
}
return 0;
}

View File

@ -0,0 +1,11 @@
reset
set xlabel "Arrival Angle (degrees)" font "arial,8"
set ylabel "Frequency (Hz)" font "arial,8"
set zlabel "Gain (dB)" font "arial,8"
set grid lc rgbcolor "#BBBBBB"
set xrange[-90:90]
set yrange[0:10000]
set zrange[-40:0]
unset key
set view 30,56,0.98
splot 'freqResp.dat' u 1:2:3 with pm3d

View File

@ -0,0 +1,19 @@
reset
set angles degrees
set polar
set grid polar 30 lc rgbcolor "#999999"
unset border
unset param
set size ratio 1 1,1
set xtics axis nomirror -50,10
unset ytics
unset key
set style data line
set xrange[-50:50]
set yrange[-50:50]
set rrange[-50:0]
set label 1 "0°" at graph 1.01,0.5 front
set label 2 "180°" at graph -0.01,0.5 right front
set label 3 "-90°" at graph 0.5,-0.03 center front
set label 4 "90°" at graph 0.5,1.03 center front
plot 'beamPattern.dat' u 2:5