You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the ADC in continuous sampling mode at a fixed frequency > 2x as fast as the fastest frequency I'd like to detect, per the Nyquist Frequency Theorem. We want continuous samples with zero missed time intervals. Use "ADC ready" interrupts to run an ISR each time a sample is ready.
In the ISR, store the latest sample into a ring buffer 2x as long as the number of samples we need for each FFT calculation. Once a full FFT sample count is stored, set a volatile, atomic-access-guard-protected (bare-metal-mutex-protected) flag to indicate "time to run FFT analysis."
In the main loop, read that flag and run the FFT once per data set, ensuring it runs fast enough that the full calculation can complete before that data set starts to get overwritten again in the ISR. In other words, the full calculation per data set should complete in the time it takes to store a single data set.
Once FFT analysis is complete and an array of peaks is stored, send out the FFT results data over serial for plotting and logging to a PC. Also, reset the flag that was set in the ISR.
Also, output a beep at a fixed tone through a speaker to indicate which frequency is detected. Ex: for a 1 KHz frequency detected, play a 1 KHz tone for a 1/4 sec beep. For a 1.5KHz frequency detected, play that freq for 1/4 sec beep. Dual drive the speaker by using an H-bridge and 2 pins at 50% PWM duty cycle, offset by 180 deg to dual drive the speaker in 2 directions, like Arduino's toneac() library does.
The text was updated successfully, but these errors were encountered:
ElectricRCAircraftGuy
changed the title
Add full Arduino FFT frequency detection algorithm example
Add full Arduino or STM32 mcu FFT frequency detection algorithm example
Apr 16, 2023
Use the ADC in continuous sampling mode at a fixed frequency > 2x as fast as the fastest frequency I'd like to detect, per the Nyquist Frequency Theorem. We want continuous samples with zero missed time intervals. Use "ADC ready" interrupts to run an ISR each time a sample is ready.
In the ISR, store the latest sample into a ring buffer 2x as long as the number of samples we need for each FFT calculation. Once a full FFT sample count is stored, set a volatile, atomic-access-guard-protected (bare-metal-mutex-protected) flag to indicate "time to run FFT analysis."
In the main loop, read that flag and run the FFT once per data set, ensuring it runs fast enough that the full calculation can complete before that data set starts to get overwritten again in the ISR. In other words, the full calculation per data set should complete in the time it takes to store a single data set.
Once FFT analysis is complete and an array of peaks is stored, send out the FFT results data over serial for plotting and logging to a PC. Also, reset the flag that was set in the ISR.
Also, output a beep at a fixed tone through a speaker to indicate which frequency is detected. Ex: for a 1 KHz frequency detected, play a 1 KHz tone for a 1/4 sec beep. For a 1.5KHz frequency detected, play that freq for 1/4 sec beep. Dual drive the speaker by using an H-bridge and 2 pins at 50% PWM duty cycle, offset by 180 deg to dual drive the speaker in 2 directions, like Arduino's
toneac()
library does.Here's the gist of the H-bridge wiring. The motor in the diagram would be a speaker in our case: https://www.google.com/amp/s/hackersgrid.com/2017/03/the-h-bridge.html
The text was updated successfully, but these errors were encountered: