I am using a noise sensor (ADMP401) along with Arduino Mega. I use openmusiclabs FFT algorithm to convert the noise sensor analog output to frequency domain, then remove the first 30 bins (to remove some board noise), then calculate the rms value of the remaining bins. So, during a period of 10 seconds (which is my polling period), I have a set of 12 rms values from which I take the median value to get the ambient noise equivalent.
Its working fine and I can see the output value responding to noises. I usually get an output of around 7 to 10 for silent conditions. The problem is, for some units, this base value of 7 to 10 shifts to around 2 to 3 after running for some time and then will remain at that lower level. Still the sensor will respond to noises. But since this shifting is happening, I am unable to correlate the output to dB levels.
I set the prescaler to 32 and 38.4kHz sampling rate
ADCSRA = bit (ADEN) | bit (ADSC) | bit (ADIF) | bit (ADPS2) | bit (ADPS0)
256 point FFT
Below is my code:
void Update_ADMPFFT(){
//Setup bit read
ADCSRA = bit (ADEN) | bit (ADSC) |bit (ADPS2) | bit (ADPS0);
ADMUX = 0x42; // Use A2 where ADMP401 is connected to
while(!(ADCSRA & 0x10)); // Wait for ADC to be ready
// Restart adc, clear flag and set the prescaler to 32 and 38.4kHz sampling rate
ADCSRA = bit (ADEN) | bit (ADSC) | bit (ADIF) | bit (ADPS2) | bit (ADPS0);
byte m = ADCL; // Fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // Form into an int
k -= 0x0200; // Form into a signed int
k <<= 6; // Form into a 16b signed int
fft_input[lCounter] = k; // Put real data into even bins
fft_input[lCounter+1] = 0; // Set odd bins to 0
lCounter = lCounter + 2; // Increment counter until 512
if (lCounter == 510){
//Once data is filled in, do FFT
fft_window(); // Window the data for better frequency response
fft_reorder(); // Reorder the data before doing the FFT
fft_run(); // Process the data in the FFT
fft_mag_lin(); // Take the output of the FFT
//Filter out the first 30 bins which includes the board noises
for (byte i = 31; i < FFT_N/2; i++) {
//Use this after using fft_mag_lin() for finding rms of magnitude power
rms = rms + (fft_lin_out[i]* fft_lin_out[i]);
}
//Find rms value of the remaining 97 bins.
rms_sum = sqrt(rms/97);
lCounter = 0;
}
//Reset summation variables
rms = 0;
rms_sum = 0;
}
Has anyone experienced this kind of behavior while working with noise sensors and FFT?