1

I'm trying to generate some basic thumping stereo sound using Arduino's PWM pins along with low-pass filters.

This is the frequency spectrum for the sound I want to play using Arduino UNO's PWM pins:

enter image description here

Based on this, I think (from what I understand) the cut-off frequency for the low-pass filter should be around 8900Hz. But, wouldn't the PWM function operate at a much higher frequency to generate the same wave? If that's how it'll be, how should I decide the cut-off frequency for my low-pass filter?

I understand that the fastest frequency one can get for 8-bit PWM on an UNO is 62.5 kHz. So, I might not be able to generate this wave using the UNO itself. Unfortunately, I won’t be able to use another microcontroller for this project. However, what I can do to solve this issue is - generate a different sound wave of lower frequency. If someone can help me with finding out by how much will the frequency of the wave increase if I use PWM to generate it, I’ll be able to generate an appropriate wave.

5
  • Yes, you would need a PWM frequency much higher than the frequency you want, but the PWM frequency of the UNO is fixed at 490Hz (see arduino.cc/reference/en/language/functions/analog-io/…). Doesn't look like that's going to work.
    – PMF
    Mar 25 at 8:11
  • 1
    @PMF I think it is possible to increase the default frequency. Found some tutorials online, but here’s a similar question on this forum: arduino.stackexchange.com/questions/25609/… Mar 25 at 8:14
  • 1
    If you have an Uno or some similar AVR-based board, the fastest frequency you can get for 8-bit PWM is 62.5 kHz. You could go faster at the expense of resolution. Mar 25 at 8:29
  • You'll probably want a Teensy for this.
    – towe
    Mar 25 at 9:03
  • @towe Unfortunately, I won’t be able to use a Teensy for this project. However, what I can do to solve this issue is- generate a different sound wave. If someone can help me with finding out by how much will the frequency of the wave increase if I use PWM to generate it, I’ll be able to generate an appropriate wave. Mar 25 at 9:10
1

That looks like the spectrum of an 8-bit sound that is playing low bass notes only. Most everything above that looks like noise floor. (You can only get about 6 dB range per bit of resolution, so 8 bits gives about 48 dB max.) If this is the case, you definitely don't want to reproduce the upper frequencies. If you want to stick to your original PWM scheme, use pins 5 or 6 because they use 980 Hz PWM instead of 490. I suggest you determine the filter by trial and error, since it comes down to how much PWM carrier you can tolerate. You can make a simple RC filter using the formula F = 1 / (2 * pi * R * C) where F is the cutoff frequency in Hz, R is ohms, and C is farads (that's 10^6 microfarads per farad). This type of simple filter will have a very soft cutoff frequency, about 6 dB per octave, so if you set it for 123 Hz (3 octaves below 980 Hz) the 980 Hz PWM will be reduced by 18 dB. The R connects to the PWM pin, and the C goes from the other end of R to ground, as does the signal output. The formula assumes that there is no output load, so you should connect an amplifier there. If you are like most folks, you probably have fewer capacitor values on hand than resistor values, so pick the C value first. Let's say it's 1 uFd. Then if you use R=1K the cutoff will be 159 Hz. Change R while listening to the output

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.