Reputation: 9508
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
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:
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