I am trying to do acoustic direction finder , I am using correlation method with 2 mic to find the degree of sound source location . I am searching only front of the mic. (180*) .
I want to find the difference of time by multiplying the i'th value by sample rate, whichever step I can read
the value of 490 000 . I have faced with this error (invalid operands of types 'int*' and 'int' to binary 'operator/')
how can I transfer the results of correlation operations to the array system , I think I can do linear search in this way .
int n=100;
int read1=A0;
int read2=A1;
float a;
float b;
int sum_xy[100];
int sum_xy2[99];
int X;
int Y;
int ch1[100];
int ch2[100];
int i=100;
void setup() {
pinMode(read1,INPUT);
pinMode(read2,INPUT);
Serial.begin(9600);
}
void loop() {
for(i=0; i < n; i++) {
int X= analogRead(read1); // 1. mic
ch1[i]=X;
int Y = analogRead(read2); // 2. mic
ch2[i]=Y;
Serial.print(read1);
Serial.print(read2);
}
}
float correlation(int ch1[], int ch2[], int n){ // burada int X diye tanıttığım değer int X[] şeklindeki sisteme giriyor mu ?
for(i=0; i < n; i++) // n sample
{
for(
sum_xy = (sum_xy + ch1[i] * ch2[i])/n; // first corr
for(j=1; i < n+1 ; j++){
sum_xy2 = (sum_xy2 + ch1[i] * ch2[j+1])/n-1; // second iterated corr
}
if(sum_xy[i]>= 490000) // This value comes from microphones , i make treshold as 700 to understand there is a sound
{
return i; // i want to find in which step (i'th) I catch the 490000 value
}
else if(sum_xy2[i]>=490000){
return i;
}
}
}
Someone with three posts should know to read the locked posts at the top of this forum and learn to post properly. Mobile devices used by some helpers (and me) cannot read attached ino files. Sad but true.
The sampling rate should be constant so the time difference should be constant. The time difference should NOT involve the value of a sample.
Sampling rate and time difference should also have units, such as thousands of samples per second, and microseconds.
I thought, if I saw the value that I wanted, which iteration was in correlation result. I'm taking that step, for example in 4th step i catch the max correlation result. if I multiply that value with sampling rate, I can find the time it takes to catch it . The sampling rate of Arduino is constant , and I need to find out in which step that i can found Max correlation results.
I add new things in my code;
#define constant 15
int n=100;
int read1=A0;
int read2=A1;
int sum_xy;
int sum_xy2;
int X;
int Y;
int ch1[100];
int ch2[100];
int sum1[100];
int sum2[100];
long int i=100;
int k=100;
int j=100;
void setup() {
pinMode(read1,INPUT);
pinMode(read2,INPUT);
Serial.begin(9600);
}
void loop() {
for(i=0; i < n; i++) {
int X= analogRead(read1); // 1. mic
ch1[i]=X;
Serial.println(ch1[i]);
Serial.println(" ");
int Y = analogRead(read2); // 2. mic
ch2[i]=Y;
return ch1[i];
}
}
float correlation(int ch1[], int ch2[], int n){ // burada int X diye tanıttığım değer int X[] şeklindeki sisteme giriyor mu ?
for(i=0; i < n; i++) // n sample
{
for(i=0; i < n; i++) {
sum_xy = (sum_xy + ch1[i] * ch2[i])/n; // first corr
sum1[i]=sum_xy;
Serial.print("sum");
Serial.println(sum1[i]);
for(i=1; i < n ; i++){
sum_xy2 = (sum_xy2 + ch1[i] * ch2[i+1]) /n-1; // second iterated corr
sum2[i]=sum_xy2;
}
}
if(sum1[i]>= 490000) // This value comes from microphones , i make treshold as 700 to understand there is a sound
{
return i; // i want to find in which step (i'th) I catch the 490000 value
}
else if(sum2[i]>=490000){
return i;
}
}
float timedelay = i * 1/9600;
Serial.print(timedelay);
float distance = timedelay*340;
float radian= acos(distance /constant);
}
That give you a phase difference between two signals of sound source , is it on front of both microphones then phase will be 0 deg.....
Probably you need convert received signals to rectangles
I don't know how to call funtion, is there any paper about for this?
#define constant 15
int n=100;
int read1=A0;
int read2=A1;
int sum_xy;
int sum_xy2;
int X;
int Y;
int ch1[100];
int ch2[100];
int sum1[100];
int sum2[100];
long int i=100;
int k=100;
int j=100;
void setup() {
pinMode(read1,INPUT);
pinMode(read2,INPUT);
Serial.begin(9600);
}
void loop() {
for(i=0; i < n; i++) {
int X= analogRead(read1); // 1. mic
ch1[i]=X;
Serial.println(ch1[i]);
Serial.println(" ");
int Y = analogRead(read2); // 2. mic
ch2[i]=Y;
}
}
float correlation(int ch1[], int ch2[], int n){ // burada int X diye tanıttığım değer int X[] şeklindeki sisteme giriyor mu ?
for(i=0; i < n; i++) // n sample
{
for(k=0; k < n; k++) {
sum_xy = (sum_xy + ch1[k] * ch2[k])/n; // first corr
sum1[k]=sum_xy;
Serial.print("sum");
Serial.println(sum1[i]);
for(j=1; j < n ; j++){
sum_xy2 = (sum_xy2 + ch1[j] * ch2[j+1]) /n-1; // second iterated corr
sum2[j]=sum_xy2;
}
}
if(sum1[i]>= 490000) // This value comes from microphones , i make treshold as 700 to understand there is a sound
{
return i; // i want to find in which step (i'th) I catch the 490000 value
}
else if(sum2[i]>=490000){
return i;
}
}
float timedelay = i * 1/9600;
Serial.print(timedelay);
float distance = timedelay*340;
float radian= acos(distance /constant);
}
I want to take values from analogRead and connect them to correlation function ?
#define constant 15
int n=100;
int read1=A0;
int read2=A1;
int sum_xy;
int sum_xy2;
int X;
int Y;
int ch1[100];
int ch2[100];
long int sum1[100];
long int sum2[100];
long int i=100;
int k=100;
int j=100;
void setup() {
pinMode(read1,INPUT);
pinMode(read2,INPUT);
Serial.begin(9600);
}
void loop() {
for(i=0; i < n; i++) {
int X= analogRead(read1); // 1. mic
ch1[i]=X;
Serial.println(ch1[i]);
Serial.println(" ");
int Y = analogRead(read2); // 2. mic
ch2[i]=Y;
}
}
float correlation(int ch1[], int ch2[], int n){ // burada int X diye tanıttığım değer int X[] şeklindeki sisteme giriyor mu ?
for(i=0; i < n; i++) // n sample
{
for(k=0; k < n; k++) {
sum_xy = (sum_xy + ch1[k] * ch2[k])/n; // first corr
sum1[k]=sum_xy;
Serial.print("sum");
Serial.println(sum1[i]);
for(j=1; j < n ; j++){
sum_xy2 = (sum_xy2 + ch1[j] * ch2[j+1]) /n-1; // second iterated corr
sum2[j]=sum_xy2;
}
}
if(sum1[i]>= 490000) // This value comes from microphones , i make treshold as 700 to understand there is a sound
{
return i; // i want to find in which step (i'th) I catch the 490000 value
}
else if(sum2[i]>=490000){
return i;
}
}
float timedelay = i * 1/9600;
Serial.print(timedelay);
float distance = timedelay*340;
float radian= acos(distance /constant);
}