0
\$\begingroup\$

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.

JYelton
35.7k34 gold badges149 silver badges282 bronze badges
asked Jun 24, 2014 at 17:05
\$\endgroup\$
1
  • \$\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\$ Commented Jun 24, 2014 at 23:02

2 Answers 2

1
\$\begingroup\$

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.

answered Jun 24, 2014 at 18:15
\$\endgroup\$
1
  • \$\begingroup\$ Excellent! (I've never done a digital filter) I like step 2-3. \$\endgroup\$ Commented Jul 25, 2014 at 0:08
0
\$\begingroup\$

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

FILT <-- FILT + FF(NEW - FILT)

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.

answered Jul 24, 2014 at 20:55
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.