3
\$\begingroup\$

I'm looking for a little direction or recommendations in how to select and implement a low-pass filter in software as my background in signals and systems is quite weak. In particular, I'm interfacing to an analog input that accepts either a standard 0-10 V or 4-20 mA signal (circuit can be physically switched) and am concerned about noise that can be expected from running the signal wires over 100 ft adjacent to wiring for lighting systems and other power electronics. The initial idea was to simply have an adjustable window size for averaging samples, but it appears that the time period needed to effectively combat noise in some scenarios also introduces significant lag as well.

Ideally, I would simulate the scenario above with a physical setup and take extensive measurements before starting this, but time constraints make it difficult. I did a quick search for a web tool that generates coefficients and the first thing that Google brings up is http://t-filter.engineerjs.com/. Is this a good place to start or is guess and test a waste of my time without doing more research? Is there a particular type of digital filtering topic that I should direct efforts to researching?

\$\endgroup\$
6
  • \$\begingroup\$ Have a look at my answer and the comment discussion to When to use an active filter instead of a passive filter. It may be of help, if I understand this question correctly. \$\endgroup\$
    – Transistor
    Commented Aug 5, 2016 at 22:15
  • \$\begingroup\$ What I understand by the term 'digital filter' is one which uses sampled discrete data from an analog to digital converter which is operated on mathematically by a processor of some description. In the case of an finite impulse response (FIR), this would be the convolution of the data samples with the filter's impulse response. Is this really what you're looking for, or do you want some form of analog filter to remove noise picked up? Could you clarify exactly what you're trying to achieve and I might be able to answer. \$\endgroup\$
    – N.G. near
    Commented Aug 6, 2016 at 1:01
  • \$\begingroup\$ Apropos filter co-efficients, they are just a quantised representation of the desired impulse response, which you get from the frequency response via the inverse Fourier transform (FIR filter) \$\endgroup\$
    – N.G. near
    Commented Aug 6, 2016 at 1:22
  • \$\begingroup\$ First of all, the 4-20 will (supposedly) have greater noise immunity than the 0-10V. Second, you can probably just use a biquad low pass filter if you still need filtering. But with digital filters, you need to be sure that all noise above Fs/2 has been removed prior to sampling. Fs is the sampling frequency. So if you sample at 20kHz, you need to use an analog low-pass filter before sampling with a cutoff of less than 10 kHz. earlevel.com/main/2013/10/13/biquad-calculator-v2 \$\endgroup\$
    – user57037
    Commented Aug 6, 2016 at 4:43
  • 2
    \$\begingroup\$ I wrote a kind of beginners guide here: jamesoakwood.co.uk/… but, I would advise you that if you alias noise you could be creating a bigger problem. So, consider trying to remove noise above the nyquist sampling rate using analogue means. \$\endgroup\$
    – Andy aka
    Commented Aug 6, 2016 at 9:43

2 Answers 2

2
\$\begingroup\$

Better late than never, but I feel that you're fighting the wrong fight. My understanding here is that you're creating the signal for some sort of industrial PLC. A 4-20 mA signal in a shielded twisted-pair cable is already fairly noise resistant.

[...] concerned about noise that can be expected from running the signal wires over 100 ft adjacent to wiring for lighting systems and other power electronics.

If there's concern about running the signal cable 100 ft beside power, then move the data collection point closer. Either the main panel or a remote panel could work. Seeing as this is an industrial setting though, there are codes in place for how close you can run instrumentation cabling to power cabling. You should, and can, run it in its own conduit, or if you're in cable tray, make sure that there is adequate separation. A barrier might be necessary.

100 ft in and of itself should not be an issue. If you're seeing substantial voltage drop then you'd fix it like any other voltage drop and up the size of your cabling.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ A shielded cable should help, but what seems even more important is a twisted pair, which can also be shielded. \$\endgroup\$
    – PStechPaul
    Commented Aug 21, 2022 at 7:28
2
\$\begingroup\$

You don't really want a lowpass if you also want a fast response. Fast responses are only possible if you leave in the high-frequency components.

Of course, then the question becomes, "How fast do you really need?" Convert that to a frequency, add some margin, and see where the noise sits relative to that cutoff. If there's enough of a difference, then yes, a filter can work. But if the noise and signal are (close to) the same frequency, then you can't filter that.

In that case, there are practically two options left:

  1. Eliminate the noise itself, so that the filter isn't needed.
  2. Characterize the noise and the intended signal, so that you can more-or-less subtract a recording of noise without damaging the signal too much.

Option #1 is usually more effective, and a current loop on a twisted pair usually does a good job of that, which is what the 4-20mA signal is.*

(*or at least should be! I'm sure some uneducated sparky somewhere has make the mistake of pulling two separate spools of single wire, possibly alongside many more, and calling that a 4-20mA sensor run.)


If you must use a lowpass (or if you just want to put one on as a matter of course), then I think the easiest one to implement would be an exponential average, which is in DSP terms, a 1st order lowpass, and exactly equivalent to an analog R-C lowpass.**

(**provided that you haven't run afoul of some other DSP gotchas, like too-low sample rate causing what should have been filtered out to instead combine with the intended signal, which is normally known as "aliasing" and can only be eliminated by using a higher sample rate or an analog lowpass before the converter)

Anyway, a quick and easy way to do it is:

#define LOWPASS_SHIFT    9   //~10Hz cutoff, bigger number gives lower frequency
//1st-order IIR lowpass
//2^(-SHIFT) = 1 - e^(-2*pi * Fc/Fs)
//Fc = Fs * (-ln(1 - 2^(-SHIFT)) / (2*pi))
//Fs = 31.25kHz, Fc = -3dB cutoff frequency

#if LOWPASS_SHIFT < 0
    #error LOWPASS_SHIFT must be positive
#endif

void process_sample(void)
{
    output -= (output >> LOWPASS_SHIFT);
    output += ( input >> LOWPASS_SHIFT);
}

That's copied (almost) directly from one of my projects, on a processor that can only add, subtract, and shift. (shifting is thus an easy way to divide, but limited to powers of 2) A bit of algebraic rearranging should show that this is equivalent to the canonical representation.

If you need a steeper rolloff, then you can cascade 2 of these to make a 2nd order lowpass, or you can use a different DSP algorithm to do it all at once.

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.