Maestro
Maestro

Reputation: 9508

Which DSP filter-algorithms are simple to implement?

I have a datalogger with very little memory, and I want to implement support for filters in the firmware.

Which types of filters can I implement easily without the need for buffers or huge functions?

One that comes to mind is an exponential moving average, something like:

sample = (alpha * new_sample) + (1.0 - alpha) * sample

Are there any other well-known DSP-filters that could be accomplished in a few lines?

Upvotes: 2

Views: 1127

Answers (1)

Bjorn Roche
Bjorn Roche

Reputation: 11469

It is impossible to implement frequency selective filtering without some buffering. Even the example you give requires a buffer of one sample. First off, forget about FFT filtering for most realtime data. For most filtering applications, and certainly applications where you are concerned about memory, you will want to use a time-domain filter.

Time-domain filters generally come in two favors, IIR and FIR. Filters are also distinguished based on their "order". The example you gave above is a first order IIR filter. The relevant facts are:

  • Broadly speaking, IIR filters require a lower order than FIR for a given response.
  • A filter can be implemented with a number of memory locations equal to the order of the filter. This is not always the best way to implement a filter, but it can be done using something called Direct Form II.

For a broad range of applications, second order IIR filters (sometimes called "biquads") are an excellent choice. I have a tutorial on second order biquads here. It is oriented towards audio applications, but you will probably find it useful. Keep in mind this tutorial uses Direct Form I which is more numerically stable, but requires more memory locations. At four locations, though, I don't think it's much to fret about even for a highly memory starved application.

Upvotes: 2

Related Questions