I'm trying to implement two cascaded low pass filters in a software application so that I can smooth out a potentially volatile data set. Based on the incoming data, I want a signal to be turned on/off at a certain threshold (i.e. the filtered data drops below x). But I want this signal to turned on and off smoothly, so that its not affected by big spikes, but is affected by consistent samples below x (or above in the opposite case). From what I remember from my DSP class, low pass filters are what I want. The exact equation I'm using, with two cascaded, is:

Signal at time T = (sample at time T) * gamma + (signal at time T-1) * (1-gamma)

My question is, could anyone demonstrate the exact mathematical calculation to determine the sensitivity of my filter, based on my values for gamma. I.e. a gamma value of x will ensure a single sample does not move the overall signal by more than y%, or a similar calculation so that I can have a numeric value on this.

  • \$\begingroup\$ "a gamma value of x will ensure a single sample does not move the overall signal by more than y%". This is a meaningless spec. If the previous signal value is 0, any non-zero input moves the signal infinitely in percentage terms. \$\endgroup\$ – The Photon Jun 24 '14 at 23:02

Here's what I use when I want to implement a software low pass filter. The picture shows how to derive it. All you've got to do is plug in the numbers representative of the C and R values and the sample time period: -

enter image description here

The digital filter I've shown is of the form: -

OUT(n) = OUT(n-1) * (1 - T/CR) + IN(n-1) * (-T/CR)

If you want a more rigorous proof read this. It's called digital filter design for analogue engineers.

  • \$\begingroup\$ Excellent! (I've never done a digital filter) I like step 2-3. \$\endgroup\$ – George Herold Jul 25 '14 at 0:08

The equation you show is correct for a single pole low pass filter, but I usually implement it this way in the actual computation:


Where FF is the "filter fraction", which is similar to your gamma. On a small system, you try to arrange FF to be 1/2N, so that the multiply by FF can be realized as a right shift by N bits.

What this means in frequency space has to do with how fast you are sampling. I have figured out the equations in the past, but I don't remember exactly what they are without looking in source code. My PIC assembler pre-processor has a built in function to compute FF from a sample rate and desired rolloff frequency.

However, most of the time in a small system the time domain is more relevant. Generally you want to know how much the filter will delay things. For that I have my FILTBITS program, that I usually run from the PLOTFILT wrapper. This shows you the step and inpulse responses. I go into more details on the filter above, PLOTFILT, and show a example plot, in my answer here.


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.