I am new to embedded systems. I done a bit of analogue circuit design but nothing connecting analogue circuits to a STM32 via ADC. I am using STM32F4 microcontroller and had couple of questions.
- I know that you need an antialiasing filter for analog signals to an ADC, but can't workout what sampling rate is needed? Like can I pick it? Can someone please explain it to me?
-
\$\begingroup\$ What signal are you sampling? Sample rate and AA filter depend on the information in the signal that you want to access. Thermocouple or battery level, seconds. Load cell, hundreds of Hz to kHz. Audio, tens of kHz. \$\endgroup\$Neil_UK– Neil_UK2023年08月13日 12:35:27 +00:00Commented Aug 13, 2023 at 12:35
-
\$\begingroup\$ A audio signal from an auduo sensor, so from 0 to 10khz. I don't know how to based the AA filter and how much it has to attenuate by using a stm32F4. Thanks for your help \$\endgroup\$CircuitFreak– CircuitFreak2023年08月13日 13:06:49 +00:00Commented Aug 13, 2023 at 13:06
-
\$\begingroup\$ @CircuitFreak - Hi, Your request for a buying recommending is off-topic - see here. That's because such requests can attract spam answers, any answers would quickly become out-of-date as old products leave the market and new ones are introduced, and recommendations are often localised (e.g. may not be available in your area), or insufficiently specified (e.g. may not fit targets for longevity of supply, price, power budget or other constraints). To avoid these and other issues, buying recommendations are off-topic on many SE sites. Therefore I removed it from your question. \$\endgroup\$SamGibson– SamGibson ♦2023年08月25日 16:13:39 +00:00Commented Aug 25, 2023 at 16:13
1 Answer 1
If you need to sample frequencies up to 10 kHz, you need a sampling rate above double that, so more than 20 kHz. This is the Nyquist sampling theorem.
If you sample at 20 kHz, the sampled data must not have any frequencies above 10 kHz. So you need a filter that passes everything below 10 kHz and nothing above 10 kHz. In real life this kind of ideal brick wall filter is unrealizable so you need to decide how good/expensive/narrow you want your filter to be, how much aliasing is allowed, and how much higher you want your sampling rate to go to allow simpler filter and less aliasing.
So there is not really possible to say what numbers/values/filters you should use as you don't know your requirements.
-
\$\begingroup\$ Thanks for the reply, that's is helpful. My main problem is knowing the sample rate of a board such as stm32f4. Is there a way to know what sampling rate does stm32f4 sample at? \$\endgroup\$CircuitFreak– CircuitFreak2023年08月13日 13:47:57 +00:00Commented Aug 13, 2023 at 13:47
-
\$\begingroup\$ @CircuitFreak You read the data sheet and see the maximum sampling rate it can achieve, and you can sample as fast or slow as you want as long as you sample below the maximun rate. \$\endgroup\$Justme– Justme2023年08月13日 13:57:51 +00:00Commented Aug 13, 2023 at 13:57
-
\$\begingroup\$ Thanks so much. I didn't think that adc on stm32f4 can sample at 42Mhz. I thought that would be way to fast. \$\endgroup\$CircuitFreak– CircuitFreak2023年08月13日 14:12:41 +00:00Commented Aug 13, 2023 at 14:12
-
1\$\begingroup\$ Thanks so much. I think I understand now. So MSPS is the maximum sampling frequency of the board. Depending on the application you chose the sampling frequency. In my case with 10kHz AA filter, and let's say that I want the signal to fully attenuate by 20kHz I have to used Nyquist theory and set the sampling frequency at 40kHz. Is this correct ? And of course depending on the filter order causes a steeper rolloff of the signal. \$\endgroup\$CircuitFreak– CircuitFreak2023年08月13日 15:24:05 +00:00Commented Aug 13, 2023 at 15:24
-
1\$\begingroup\$ That is spot on, if you want to sample something. Now in real life, if you want to sample audio, you would just connect an audio ADC chip that inegrates everything to the STM32 via I2S audio interface, which will be light years easier and better compared to be limited to using the internal 12-bit ADC and making the analog filters yourself. But that's another topic. \$\endgroup\$Justme– Justme2023年08月13日 15:58:05 +00:00Commented Aug 13, 2023 at 15:58