Reading about the I2S MEMS sensor, I see that this needs a specific I2S HW. I don't know about it.. is this I2S supported by the Arduino Nano Every? And, in case, can you share the possible pins connections?
Do you think that this could be a valid solution? Any ideas about pros and cons?
Begin at the beginning! Is the"sound" a single frequency? Does the frequency change? If so , how often? IS the sound accompanied by other sound, making a noisy environment? Does the sound contain harmonics of the primary frequency?
This is much, much more difficult to achieve than you are imagining, for the reasons outlined by @Paul_KD7HB .
Before you waste time and money researching and buying components, explain your project in more detail. It is possible that Nano Every, or other Arduino, will not be able to do what is needed. It could be that the computing power of a PC, or at least a Raspberry Pi, would be required.
Sure!
I'm implementing a remote hive monitoring system.
Currently, I studied and implemented a system in order to retrieve other bees' life parameters like the temperature, the humidity and the weight.
Reading this article about a similar system, I'm curious to understand the feasibility of sound hive monitoring. There are also some papers about the hive sound frequency study. Basically, using the sound frequency it's possible to know and prevent some scenarios about the healthy bees conditions.
Here I'm also reporting a copy and paste from the link shared above about the sound analysis.
For the frequency analysis, we focused on a low-frequency range of about 500 Hz total: 98 Hz to 583 Hz, split over ten intervals of about 48 Hz each. We chose this specific range as it would allow us to distinguish different situations at different frequencies such as:
High spectral density at approx. 350 Hz could indicate quacking, which is a phenomenon in which multiple queens are present and would fight to become the queen of the colony.
High spectral density at approx. 450 Hz could indicate tooting which happens when a bee signals that she is the future queen to be born (allowing other potential queens not to be released by workers).
High spectral density at 510 Hz could indicate that the colony is in bad health.
The frequency analysis would require the Arduino to perform a Fourier Transform. This is a complex mathematical process, but since frequencies above ~600Hz can be ignored and only 10 frequency bands need to be analysed, maybe a Nano Every could do it.
The microphone probably doesn't need to be as fancy as some of the models you have been looking at, and the Nano's internal ADCs may be fast enough.
Someone on the forum will know far more than me about FFT, necessary sample rates etc.
What you need is not the frequency, but the frequency spectrum.
The FFT function calculates that for a given sound sample (typically a power of 2 number of data points -- 256, 512, etc. -- collected over some fraction of a second).
The sound sample rate must be at least twice the highest frequency in the input, or the spectrum will have severe artifacts due to "aliasing".
With a digital (I2S) microphone, you may have to implement a low pass filter and pass the data through it, before the FFT can be calculated.
So I think we can answer some of your original questions now.
The MEMS sensor is digital, so would not need to use the Nano's internal ADCs, while the one you already have is analog and would need to use the Nano's ADCs.
The MEMS microphone also has a high data rate, much faster than its required for your project. It probably provides a sample rate of several tens of KHz, and you only need a couple of KHz, so as @jremington mentioned, your code would need to apply a low pass filter to the data to reduce the data rate and keep the sample data size small enough for the Every to perform the FFT on it.
I2S is supported by some of the more advanced Nano models like Nano33IoT which run at 3.3V and have 32-bit processors, but not the 5V 8-bit models like the Every.
EDIT: according to Adafruit:
It's a 1.6-3.3V device only, so not for use with 5V logic (its really unlikely you'd have a 5V-logic device with I2S anyways).
The Nano Every can use "classic" microphone, sampling with the built in ADC, but not the digital microphone. You may still need to implement a low pass filter, to avoid artifacts in the spectrum.
Guys,
thanks a lot for your suggestions!
As I said above, honestly, I'm not an Arduino expert.. even more about the sound components analysis... I'm sorry for this!
I would like just to add one point that, maybe, I assumed and I did not explain: I can't put inside the hive the entire system: What I mean about it? I can't put inside the hive the Arduino Every. This should be applied outside and only the humidity and temperature sensor will be inside the hive. For this reason I'll need a microphone that will have a small size..this, in case, should be inserted inside the hive also.
Keeping to googling about this, I also found this article that's, in my opinion, seems a good point:
Here the used sensor has been a MAX4466 based module.
In your opinion, could this be a good starting point for me to reach out some first results?
That looks like an OK starting point, but do not use Strings with Arduino, as the author recommends. They are never needed, and cause memory problems and program crashes.
Convert statements like this Serial.print("Time: "+ String(millis() - t0)); Serial.print(" Min: "+ String(signalMin));
error: 'TIMSK0' was not declared in this scope
error: 'ADCSRA' was not declared in this scope
error: 'ADCSRA' was not declared in this scope
note: suggested alternative: 'ADC_t'
error: 'DIDR0' was not declared in this scope
note: suggested alternative: 'DDRD'
....
If I understand correctly, it seems that the processor on the Arduino Nano Every it's not supported. Is this correct? Is there any different way to use the FHT lib on the Nano Every or, is there any different way to retrieve the sound frequency using the Arduino Nano Every?
The symbols TIMSK0, ADCSRA, etc. are specific to the peripherals on ATmega328 and similar processors.
You would need to replace those lines of code with equivalents that are supported by the Nano Every, which uses different timers and ADCs.
Again, getting the sound frequency (using FFT, FHT, etc.) has nothing to do with the details of collecting the sound data.
For now, focus on collecting sampled analog data using your Every. Or, buy an Uno, Pro Mini, etc. so that these older tutorials apply directly, then learn how the actual analysis works.
I would like to highlight again that I'm not an Audio analyst expert... or maybe It's better to say that I don't know anything about audio analysis.
Do you see any problem using this?
The first three steps of the procedure are part of the preprocessing of the raw audio data. First, the data are
downsampled from the initial 44.11 kHz sampling rate down
Fig. 1. Picture of the acquisition system installed on a dedicated chamber
on top of the beehive.
to 4096 Hz, resulting in a measurable frequency range up to
2048 Hz. Since most of the spectral content of the bees’ sound
is documented below 1 kHz, this new sampling rate is
sufficient. As a result, a large portion of the external noise in
frequencies outside that range is removed and, also, the
complexity of the spectral calculations is reduced.
The signal is, then, pre-emphasized, which is a typical step
of the MFCC extraction process that flattens the amplitudes of
the spectrum by amplifying the higher frequency components.
A value of 0.97 was chosen for the pre-emphasis coefficient,
which is a typical value used in literature. After that, a Finite
Impulse Response (FIR) band-pass filter is applied with a
frequency range of 80 - 2000 Hz. This filter is used to
attenuate the noise components generated by the supply circuit
(60 Hz) and any residual higher frequencies.
The next step is calculating the spectrogram of the audio
time series. This is done by performing the Short Time Fourier
Transform (STFT), which is a process that involves framing
and windowing the time series into small segments and
calculating the Discrete Fourier Transform (DFT) on each
segment. The result is the spectrogram, which is a twodimensional array with amplitudes, with one axis
corresponding to the N frequency bins that the N-point Fourier
transform produced, and the other axis corresponding to the
multiple frames of the overall signal. By examining the
frequency content of the spectrogram, the most dominant
frequencies of each time segment are derived.
The processing steps that follow are used for the feature
extraction. The spectrogram is transformed through the MelFrequency Transform and is divided into N mel bands. This is
accomplished by applying a series of triangular filters at
certain frequencies. The resulting spectrum, called cepstrum,
is customized in a way that it is more discriminative at lower
frequencies and less discriminative at higher frequencies. By
calculating the Discrete Cosine Transform (DCT), a set of
coefficients are derived that correspond to the N different mel
bands.
If, by "the first step", you mean the initial audio sampling, the downsampling, the preemphasis followed by the low pass filter, that is a large and complex task for a beginner. Do you have the authors code and circuitry to examine?
Those actions also depend on a number of choices that the project authors made, and there are other ways to approach the problem.
From what I understand, you want to analyze audio frequencies in the range of 0-2 kHz, which (without the downsampling) requires a 4 kHz sample rate and a GOOD (fourth order or better) 2 kHz low pass filter between the microphone and the ADC input. There is plenty of material on low pass filter design.