I'm trying to FFT the live input sound and filter it to have only 350 to 500 HZ. So, my goal is to turn the LED light on only when some sound has frequency between 350-500. I looked at FFT codes, but don't know how to filter it and send the output signal out.

I'm very new to arduino board. You can assume I know nothing about the arduino board or C programming.. Please be specific as possible.. Thanks.

  • 1
    \$\begingroup\$ Why not a bandpass filter? \$\endgroup\$ – Ignacio Vazquez-Abrams Dec 14 '13 at 4:38
  • \$\begingroup\$ Oh! that's what I used on MATLAB! Well If I explain what I did so far.. because me and my professor did not know how to program arduino board, we started with MATLAB and I used FFT and bandpass filter to get the frequency spectrum. However.... I don't know how to implement MATLAB code to arduino code.. n on top of that, I don't know how to trigger the output signal :( so anyway, there's code called bandpass filter for arduino as well?? ah.. I wish somebody can translate my MATLAB code into arduino code.. \$\endgroup\$ – Bri Dec 14 '13 at 5:12
  • \$\begingroup\$ No, I mean a bandpass filter from passives. Then you put a frequency-to-voltage converter at the end and trigger on that. \$\endgroup\$ – Ignacio Vazquez-Abrams Dec 14 '13 at 5:18
  • \$\begingroup\$ Um.. Thanks for your info. I still don't understand but I'll research on 'bandpass filter from passives' and 'frequency-to-voltage converter' and see what I can do :D but these are something I can do with arduino board right? I meant the code for arduino board \$\endgroup\$ – Bri Dec 14 '13 at 5:45
  • \$\begingroup\$ Maybe. But FFT might need a bit more oomph than you can get from an Arduino other than the Due. \$\endgroup\$ – Ignacio Vazquez-Abrams Dec 14 '13 at 5:47

I would suggest building some sort of bandpass filter followed by a peak detector and a comparator. You can build an RLC bandpass filter or perhaps an active bandpass filter with a couple of op amps and some passive components. How steep does the cutoff on the filter need to be? If you need a very steep cutoff, then you probably need an active filter.

Alternatively, you can run the signal through an RC low pass filter, sample it with the Arduino ADC, and the filter it with a DSP bandpass filter. I know Matlab has a toolbox for building FIR and IIR filters; I would suggest using that to calculate the correct filter coefficients. I don't think the Arduino will give you enough cycles to do an FFT in real time, and you'd still have to do the low pass filtering and sampling with an FFT.

  • \$\begingroup\$ Hey, first, thank you for the comment :D What's the difference between RLC and DSP? I was trying to download ADC and FFT libraries and I downloaded FFT library. I don't know where it's going to take me to but at least I found something but no luck with ADC. Is there ADC library that I can download? Since I don't really understand the program well, I was hoping that I can down load those two libraries and start coding from there. And yes, when I used MATLAB, I used bandpass toolbox to filter my sound. \$\endgroup\$ – Bri Dec 15 '13 at 5:35
  • \$\begingroup\$ RLC = resistor, inductor, capacitor. A filter built with passive components. You can find calculators online for determining the proper component values. I think TI might have some filter calculation software as well that you can try out. And if you want to do signal processing on an Arduino, you're probably going to have to throw out the ADC library and work on bare metal. Most of the Arduino libraries I have looked at are horribly inefficient. \$\endgroup\$ – alex.forencich Dec 15 '13 at 6:39

"Only 350Hz to 500Hz" is a practical impossibility. Any filter that totally eradicates frequencies below and above a certain limit will take infinite time to process the signal so given that you haven't specified the out of band parameters this makes it a little hard to advise on. What digital filtering knowledge I have might help a bit: -

enter image description here

Because I'm an electronics guy, the digital LP filter emulates a simple RC filter. This filter can be set for a low pass limit of 500Hz and if the sampling frequency (the rate which you are collecting ADC samples) is (say) 10kHz, T = 100 x 10\$^{-6}\$, and CR will be \$\dfrac{1}{2\pi F}\$ = 318 x 10\$^{-6}\$.

That gives you a first order low pass filter and you can improve on this by cascading a few more to give you a steeper roll-off. To get a high pass filter use the same topology and note that the high pass output is available as shown below: -

enter image description here

There are a few other bells and whistles that can be applied to make the steepness of the filter tighter but I won't go into those here because it's probably not needed or too deep. Note that "sample time" and "delay time" are exactly the same in the two diagrams - I wasn't very consistent in naming these!

Once you have adequately filtered the signal you need to calculate RMS of the resulting signal and set a threshold for triggering. This can feed an Arduino (or any MCU) output to drive a signal to the outside world.

For completeness, a lot of digital filter books will show the filter like this: -

enter image description here

It's mathematically the same but is re-arranged to how it is shown in a lot of articles on digital IIC (infinite impulse response) filters. I prefer the pictures earlier on because they are more directly relatable to the simple analogue CR filter. Good luck.

  • \$\begingroup\$ Thank you for kind and well explained answer. Since I'm not an electrical engineer.. I didn't understand it fully, but I'll let my friend look at it and hopefully, he will be able to implement this :D \$\endgroup\$ – Bri Dec 15 '13 at 20:31
  • \$\begingroup\$ @Bri - glad to be of help. \$\endgroup\$ – Andy aka Dec 15 '13 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.