Hello
I use fht code for analysis sound for two microphone real time
I send my code in here
But it didnt correct analysis two microhone and it just analysis once of microphon
Anyone can help me how can i slove this problem
Hello
I use fht code for analysis sound for two microphone real time
I send my code in here
But it didnt correct analysis two microhone and it just analysis once of microphon
Anyone can help me how can i slove this problem
Did you mean FFT code?
I think that you have serious translation problems. Isn't there any forum section for your language?
no fht library
#define LIN_OUT 1 // use the log output function
#define FHT_N 64 // set to 256 point fht
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#include <FHT.h>
int f;
int Rreal[FHT_N];
int Lreal[FHT_N];
int RMAG[FHT_N];
int LMAG[FHT_N];
void setup() {
ADCSRB = 0;
sbi(ADCSRA, ADEN); // Enable ADC
sbi(ADCSRA, ADATE); // Auto trigger
sbi(ADCSRA, ADSC); // Start conversion
// 19.231 kHz
sbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
cbi(ADCSRA, ADPS0);
Serial.begin(115200); // use the serial port
}
void loop() {
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
while (!(ADCSRA & _BV(ADIF))); // wait for adc to be ready
ADMUX = (DEFAULT << 6) |0; // A0
sbi(ADCSRA, ADIF); // Clear interrupt flag
byte m0 = ADCL; // fetch adc data
byte j0 = ADCH;
int k0= (j0 << 8) | m0; // form into an int
k0 -= 0x0200; // form into a signed int
k0 <<= 6; // form into a 16b signed int
Rreal[i] = k0; // put real data into bins
while (!(ADCSRA & _BV(ADIF))); // wait for adc to be ready
ADMUX = (DEFAULT << 6) |2; // A2
sbi(ADCSRA, ADIF); // Clear interrupt flag
byte m2 = ADCL; // fetch adc data
byte j2 = ADCH;
int k2= (j2 << 8) | m2; // form into an int
k2 -= 0x0200; // form into a signed int
k2 <<= 6; // form into a 16b signed int
Lreal[i] = k2; // put real data into bins
}
for (int i = 0 ; i < FHT_N ; i++) {
fht_input[i]=Rreal[i];
delay(1);
}
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_lin(); // take the output of the fht
for (uint8_t i = 2 ; i < FHT_N / 2 ; i++) {
RMAG[i]=fht_lin_out[i];
}
for (int i = 0 ; i < FHT_N ; i++) {
fht_input[i]=Lreal[i];
delay(1);
}
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_lin(); // take the output of the fht
sei();
for (uint8_t i = 2 ; i < FHT_N / 2 ; i++) {
LMAG[i]=fht_lin_out[i];
}
for (uint8_t i = 2 ; i < FHT_N / 2 ; i++) {
f=i * 9600UL / FHT_N;
Serial.print(f);
Serial.print(":");
Serial.print(RMAG[i]);
Serial.print(":");
Serial.println(LMAG[i]);
}
delay(1000);
}
Explain what you expected to happen, and what happened instead. Cut and paste examples of the output into your post.
I want to anlysis sound realtime by two microphone and show analysis sound
I use this code instead analogeRead for 0 and 2 pins
It analysis just once of microphones.
Just A2 pin analysied
How do you know that? Prove it to us.
When run this code show anlysis sound but when disconnected wire of A0 pin , magnitude of frequencyis not decrease , but when disconnect wire of A2 decrease magnitude
A0 = Ground
A2 = 3.3V
Right: -32117 0V
Left: 8832 3.3V
A0 = Ground
A2 = 5V
Right: -32117 0V
Left: 32704 5V
A0 = 3.3V
A2 = Ground
Right: 8183 3.3V
Left: -32768 0V
A0 = 5V
A2 = Ground
Right: 31681 5V
Left: -32768 0V
The ADC seems to be reading the pins correctly so the problem must be elsewhere. Maybe your microphones are not wired correctly? If you use the sketch below, do your inputs average near 'zero' (2.5V).
#define LIN_OUT 1 // use the log output function
#define FHT_N 64 // set to 256 point fht
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
// #include <FHT.h>
int f;
int Rreal[FHT_N];
int Lreal[FHT_N];
int RMAG[FHT_N];
int LMAG[FHT_N];
void setup()
{
ADCSRB = 0;
sbi(ADCSRA, ADEN); // Enable ADC
sbi(ADCSRA, ADATE); // Auto trigger
sbi(ADCSRA, ADSC); // Start conversion
// 19.231 kHz
sbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
cbi(ADCSRA, ADPS0);
Serial.begin(115200); // use the serial port
}
void loop()
{
noInterrupts(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < FHT_N ; i++) // save 256 samples
{
while (!(ADCSRA & _BV(ADIF))); // wait for adc to be ready
ADMUX = (DEFAULT << 6) | 0; // A0
sbi(ADCSRA, ADIF); // Clear interrupt flag
byte m0 = ADCL; // fetch adc data
byte j0 = ADCH;
int k0 = (j0 << 8) | m0; // form into an int
k0 -= 0x0200; // form into a signed int
k0 <<= 6; // form into a 16b signed int
Rreal[i] = k0; // put real data into bins
while (!(ADCSRA & _BV(ADIF))); // wait for adc to be ready
ADMUX = (DEFAULT << 6) | 2; // A2
sbi(ADCSRA, ADIF); // Clear interrupt flag
byte m2 = ADCL; // fetch adc data
byte j2 = ADCH;
int k2 = (j2 << 8) | m2; // form into an int
k2 -= 0x0200; // form into a signed int
k2 <<= 6; // form into a 16b signed int
Lreal[i] = k2; // put real data into bins
}
interrupts();
long TotalRight = 0, TotalLeft = 0;
for (int i = 0; i < FHT_N; i++)
{
TotalRight += Rreal[i];
TotalLeft += Lreal[i];
}
float AverageRight = TotalRight / (float) FHT_N;
float AverageLeft = TotalLeft / (float) FHT_N;
Serial.print("AverageRight = ");
Serial.println(AverageRight);
Serial.print("AverageLeft = ");
Serial.println(AverageLeft);
delay(5000);
}
Sample rate set 19200 but i think due to use two analog reads i decrease to 9600 SPS
Solve it
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.