Sleepico: a pleasant noise-generator for the #raspberrypi #rp2040

On this blog I’ve described a few “sleep” noise-generators in the past. White noise is too hash, and needs to be “softened” by attenuating the higher frequencies. I had described pseudo Brown noise generators in a previous post using an RC (resistor-capacitor) low-pass filter. RC filters are not “true” Brownian noise , but they are eminently sufficient for their intended purpose.

Brown noise reduces output at all frequencies, whereas an RC filter is a low-pass filter.

RC filters are usually implemented electronically. Ostensibly they use just a resistor and a capacitor, but I think things are more complicated than that. They assume that the output from the RC circuit has high impedance, i.e. that there is a large resistance in the output circuit to ground.

But this is not necessarily the case. You can’t just attach a speaker at the output of the circuit, because speakers generally have a low resistance. You therefore won’t get the output you expect. You could put an opamp to configured in as a buffer between the RC circuit and the speaker. This introduces extra problems, because with something like a 714 opamp you need to supply an negative voltage owing to its limitations.

What a palaver!

An alternative is to use a uC (microcontroller) to process signals digitally, and then just spit out the result. No electronics (although of course you’ll still need a speaker), just code.

Arduino Unos are unlikely to have enough grunt to handle the processing requirements. Fortunately, I found the Raspberry Pi Pico to be up to the job, at least for use as an RC filter.

The differential equation to determine the voltage across a capacitor is given by:

vc(t+dt) = vc(t) + 2*pi*fc*dt*(va(t)-vc(t))

where vc is the voltage output, fc is the cut-off frequency ( parameter), dt is the time interval, t is time and va is the input voltage.

va can vary over time, if you like. In my implementation I use a random number generator to generate white noise for va.

Normally, one would choose va to be uniformly distributed over some range. What I did in my code is to make it either fully on (value of 1), or fully off (value of 0). I calculate vc from that, and set the pin high if vc>=0.5, low otherwise.

Connect a speaker to GP19. You can use an audio jack if you like, or just use a simple small speaker.

As an added bonus, GP20 acts as a switch between white noise and the filtered noise. Under normal mode of operation, the filtered noise is produced. Press down GP20 to hear the underlying white noise.

Sweet dreams.

About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s