signal filtering: why and how - control global · signal filtering: why and how prevent...

13
Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby and Greg McMillan Filtering is the modification of a measured or calculated signal—using an algorithm and/or logic—to remove undesirable aspects of the signal before it is used in a calculation or a controller. Examples in control are the feedback (or controlled) variable to a PID or APC controller, or the input to a feedforward controller. Calculated signal examples include computations based on steady-state material/energy balances or process-oriented relationships, as well as process and control metrics. The main reason to filter a signal is to reduce and smooth out high-frequency noise associated with a measurement such as flow, pressure, level, pH or temperature. A common example is the noise associated with the differential pressure (DP) across an orifice plate used to infer flow rate. High-frequency noise is normally considered to be random and additive to a measured signal, and is usually uncorrelated in time; i.e., the value of the noise at any time does not depend on previous values of the noise. Ideally, we want to estimate the underlying signal without noise, introducing as little distortion as possible. When a noisy signal is used in control, filtering is important for effective derivative action and for avoiding excessive movement in the controller output that causes valve wear or disturbs other control loops. A complicating factor for the control case is that both filtering and controller tuning can be used to reduce movement of the controller output. The downside of filtering is the lag introduced, especially with heavier filtering, which can have a detrimental effect on timely detection of changes in the underlying signal. When used for feedback, the filtered value can result in control that is sluggish or, in the worst case, becomes oscillatory or even unstable. In the authors’ experience, the more typical problem encountered is excessive filtering of a signal, as opposed to under-filtering. The basic idea behind filtering is illustrated in Figure 1, where an underlying unknown signal and the noise-contaminated measured signal are shown. The goal of filtering is to estimate the underlying signal s with as little distortion as possible. Two different filtered signals are shown, 1 and 2 , where 2 is more heavily filtered (smoothed), but has more lag than 1 .

Upload: others

Post on 17-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters.

By Mark Darby and Greg McMillan

Filtering is the modification of a measured or calculated signal—using an algorithm and/or logic—to remove undesirable aspects of the signal before it is used in a calculation or a controller. Examples in control are the feedback (or controlled) variable to a PID or APC controller, or the input to a feedforward controller. Calculated signal examples include computations based on steady-state material/energy balances or process-oriented relationships, as well as process and control metrics.

The main reason to filter a signal is to reduce and smooth out high-frequency noise associated with a measurement such as flow, pressure, level, pH or temperature. A common example is the noise associated with the differential pressure (DP) across an orifice plate used to infer flow rate. High-frequency noise is normally considered to be random and additive to a measured signal, and is usually uncorrelated in time; i.e., the value of the noise at any time 𝑡𝑡 does not depend on previous values of the noise. Ideally, we want to estimate the underlying signal without noise, introducing as little distortion as possible.

When a noisy signal is used in control, filtering is important for effective derivative action and for avoiding excessive movement in the controller output that causes valve wear or disturbs other control loops. A complicating factor for the control case is that both filtering and controller tuning can be used to reduce movement of the controller output.

The downside of filtering is the lag introduced, especially with heavier filtering, which can have a detrimental effect on timely detection of changes in the underlying signal. When used for feedback, the filtered value can result in control that is sluggish or, in the worst case, becomes oscillatory or even unstable. In the authors’ experience, the more typical problem encountered is excessive filtering of a signal, as opposed to under-filtering.

The basic idea behind filtering is illustrated in Figure 1, where an underlying unknown signal 𝑠𝑠 and the noise-contaminated measured signal 𝑠𝑠𝑛𝑛 are shown. The goal of filtering is to estimate the underlying signal s with as little distortion as possible. Two different filtered signals are shown, 𝑦𝑦𝐹𝐹1and𝑦𝑦𝐹𝐹2, where 𝑦𝑦𝐹𝐹2 is more heavily filtered (smoothed), but has more lag than 𝑦𝑦𝐹𝐹1.

Page 2: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

Figure 1. Noise-contaminated signal and filtered values 𝑦𝑦𝐹𝐹1 and 𝑦𝑦𝐹𝐹2; 𝑦𝑦𝐹𝐹2 is more heavily filtered than 𝑦𝑦𝐹𝐹1.

The source of the noise may be electronic or from the process itself. “Process noise” may originate from mixing, flashing, condensation/vaporization or from improper installation of a measurement device, for example, not enough straight-run pipe length upstream or downstream of a flowmeter. Unfortunately, in many cases, filtering is used in an attempt to mask the effect of an unmeasured disturbance or a problem such as valve resolution or dead band in the control loop. In many cases, the filtering makes problems worse. A filter will often be set and then forgotten until the loop is reexamined due to loop troubleshooting of poor performance, or when a control project is executed (e.g., APC).

The literature contains a wide range of approaches to signal filtering, which is a subcategory under the general topic of signal processing. Broadly speaking, filters can be grouped according to the following types:

• Linear filters (constant coefficients), which can be expressed as a linear difference equation and analyzed as a transfer function;

• Nonlinear filters, which depend on the signal value itself or the amplitude of the noise level. Filters based on logic such as the signal rate of change also fall into this category; or

• Model-based schemes that include an underlying process model, and may also include statistics of the noise itself.

Filters used in process control applications are usually linear filters, which will be our focus. The linear filter is a linear combination of current and previous values of the signal and filtered values. The general filter equation is given by

𝑦𝑦𝐹𝐹(𝑘𝑘) = 𝑎𝑎1𝑦𝑦𝐹𝐹(𝑘𝑘 − 1) + ⋯+ 𝑎𝑎𝑛𝑛𝑦𝑦𝐹𝐹(𝑘𝑘 − 𝑛𝑛) + 𝑏𝑏0𝑦𝑦(𝑘𝑘) + 𝑏𝑏1𝑦𝑦(𝑘𝑘 − 1) + ⋯+ 𝑏𝑏𝑛𝑛𝑦𝑦(𝑘𝑘 − 𝑛𝑛)

where 𝑦𝑦(𝑘𝑘) is the signal value and 𝑦𝑦𝐹𝐹(𝑘𝑘) is the filtered value at time step 𝑘𝑘, and 𝑎𝑎𝑛𝑛 and 𝑏𝑏𝑛𝑛are the filter parameters (constants) that must be specified. The time difference or separation between subsequent values (e.g., between 𝑘𝑘 and 𝑘𝑘-1) is denoted as ∆𝑡𝑡 and is, in effect, another parameter to specify. If only measured values appear in the filter equation (i.e., no previous values of 𝑦𝑦𝐹𝐹), the filter is known as a finite impulse response (FIR) filter:

time, sec0 100 200 300 400 500 600

Mag

nitu

de

2

4

6

8

10

12

14

16

18

signal, s

signal+noise, s n

yF1

yF2

Page 3: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

𝑦𝑦𝐹𝐹(𝑘𝑘) = � 𝑏𝑏𝑖𝑖𝑁𝑁−1

𝑖𝑖=0𝑦𝑦(𝑘𝑘 − 𝑖𝑖)

where 𝑁𝑁 is the number of measurement values used. The moving average filter is an example of an FIR filter. The general form of a filter, with both and 𝑦𝑦𝐹𝐹 and 𝑦𝑦 terms, is also known as an infinite impulse response (IIR) filter, since it can be represented as an infinite series of only measured values. The above equations are similar to a discrete process model. The difference is that a filter includes the current 𝑦𝑦(𝑘𝑘) as an input; a change in 𝑦𝑦(𝑘𝑘) therefore has an immediate effect on 𝑦𝑦𝐹𝐹(𝑘𝑘), whereas a process model will usually have at least one ∆𝑡𝑡 of delay, and more if dead time is present. The other notable aspect of a filter is that it has a gain of one, which implies that for a fixed value into the filter, the filtered value 𝑦𝑦𝐹𝐹 will ultimately go to the same value.

Before beginning our discussion of filters, it is useful to look at how a control system produces sampled values of a continuous measurement and where filter(s) can be applied. Figure 1 shows the continuous or analog measurement coming into the analog input (AI) card, where the analog signal is first filtered (the anti-alias filter) before the analog to digital (A/D) converter to remove higher frequencies that would otherwise lead to fictitious frequencies in the sampled values. The A/D converter converts the analog signal to a digital value at a specified scan interval ∆𝑡𝑡. We assume ∆𝑡𝑡 has been appropriately specified for the given signal. The conventional rule of thumb is that the dead time from discontinuous updates should be less than 10% of the total loop dead time (wireless update rates and PID execution rates less than 20% of dead time, assuming zero latency). This is only really true if you are pursing aggressive control where the implied dead time is near the actual dead time. According to Shinskey’s equation for the integrated error for a step load disturbance in terms of PID tuning settings, this corresponds to an execution time that is less than about 5% of the integral time.

Many control systems provide the option to digitally filter the sampled value (embedded filter) signal before subsequent use in such tasks as alarming, control or calculation, but may not retain the raw sampled value. This can be problematic (think of the problem caused by delaying an alarm). If filtering is required for other applications, such as PID control or in APC, another tag and filter should be configured. The other thing to remember is to not introduce excessive lag by applying the filter at a significantly slower ∆𝑡𝑡 than the scan ∆𝑡𝑡 of the A/D converter. For example, a common mistake is to apply a filter to the value coming through the gateway to an APC application like model predictive control (MPC) that may execute at a slower interval, say, once per minute. Again, this is circumvented by creating additional tags for any required filtered values. This also provides the opportunity to apply a more advanced filter.

Page 4: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

Figure 2. Filtering can be applied at several places and at different ∆𝑡𝑡 values in a controlled system. Filter 1 and Filter 2 illustrate that different filters may be required depending on the application.

The most commonly used filter is the exponential, or first-order filter:

𝑦𝑦𝐹𝐹(𝑘𝑘) = 𝑎𝑎𝑦𝑦𝐹𝐹(𝑘𝑘 − 1) + (1 − 𝑎𝑎)𝑦𝑦(𝑘𝑘)

where 𝑎𝑎 is expressed in terms of ∆𝑡𝑡 and the filter time constant 𝜏𝜏𝐹𝐹 as 𝑎𝑎 = exp (−∆𝑡𝑡/𝜏𝜏𝐹𝐹). Not all control systems implement exponential filters in the same way. It may be that the user must specify a parameter value instead of a time constant, and the user-specified parameter may be on the previously filtered value or on the signal value. It is helpful to think of the exponential filter in terms of “old” and “new” parameter values, corresponding to the previously filtered value and latest signal, respectively:

𝑦𝑦𝐹𝐹(𝑘𝑘) = 𝑓𝑓𝑜𝑜𝑜𝑜𝑜𝑜𝑦𝑦𝐹𝐹(𝑘𝑘 − 1) + 𝑓𝑓 𝑛𝑛𝑛𝑛𝑛𝑛𝑦𝑦(𝑘𝑘)

where 𝑓𝑓𝑜𝑜𝑜𝑜𝑜𝑜 + 𝑓𝑓𝑛𝑛𝑛𝑛𝑛𝑛 = 1, i.e., each parameter is one minus the other. Note that the time constant can be calculated from 𝑓𝑓𝑜𝑜𝑜𝑜𝑜𝑜 as 𝜏𝜏𝐹𝐹 = −∆𝑡𝑡/ln (𝑓𝑓𝑜𝑜𝑜𝑜𝑜𝑜). It’s always good to know the actual filter time 𝜏𝜏𝐹𝐹 used in a filter.

As mentioned, there is a trade-off between removing high-frequency noise and the lag introduced into the filtered signal. To show this, consider a spike (of magnitude 1) to represent a single instance of noise, followed by a pure step of magnitude 1 without noise. Ideally, we would like the filter to ignore the spike, but track the step perfectly. In Figure 3, we see that suppression of noise comes at the price of lag in the filter to the new value. We also see that filtering at a slower ∆𝑡𝑡 relative to the scan ∆𝑡𝑡 has a detrimental effect, similar to increasing 𝜏𝜏𝐹𝐹. However, the effect of a slower filter ∆𝑡𝑡 relative to the scan ∆𝑡𝑡 is actually worse than shown in the figure. In the figure, the step time was synchronized so that all filters “see” the step as the same instance. In reality, the measured value to the filter (and to subsequent applications) may be delayed by as much as the filter ∆𝑡𝑡.

Anti-Aliasing Filter

A/D Converter

I/O Card

SampledSignal

ContinuousSignal

EmbeddedFilter

Alarms

GatewayLevel 2Level 1

Filter 1 PID

Filter 2

Page 5: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

Figure 3. The effect of 𝜏𝜏𝐹𝐹 and filter ∆𝑡𝑡 on a noise spike and step response with an exponential filter. Left: Increasing 𝜏𝜏𝐹𝐹 suppresses noise, but adds lag to the step response. Right: Increasing filter ∆𝑡𝑡 relative to scan

∆𝑡𝑡 adds lag and also introduces delay (not shown).

A natural question is whether a higher-order filter offers significant advantage over the first-order or exponential filter. Higher-order filters result in more terms and more constants that must be stored, but this doesn’t pose a problem for today’s control systems. Here, we consider 2nd- and 3rd-order overdamped filters, with a repeated time constant 𝜏𝜏𝐹𝐹. It is derived from the corresponding continuous filter using a technique called Pole- Zero Mapping (Yang, 2009). Other higher-order filters, such as the Butterworth, exhibit an underdamped step response.

Table 1. Digital Filter Equations

1st-order filter 𝑦𝑦𝐹𝐹(𝑘𝑘) = 𝑎𝑎𝑦𝑦𝐹𝐹(𝑘𝑘 − 1) + (1 − 𝑎𝑎)𝑦𝑦(𝑘𝑘)

𝑎𝑎 = exp (−∆𝑡𝑡/𝜏𝜏𝐹𝐹) (𝑎𝑎 used in all filters)

2nd-order Filter 𝑦𝑦𝐹𝐹(𝑘𝑘) = 𝑎𝑎1𝑦𝑦𝐹𝐹(𝑘𝑘 − 1)+𝑎𝑎2𝑦𝑦𝐹𝐹(𝑘𝑘 − 2) + (1 − 𝑎𝑎1 − 𝑎𝑎2)𝑦𝑦(𝑘𝑘)

𝑎𝑎1 = 2𝑎𝑎 𝑎𝑎2 = −𝑎𝑎2

3rd-order filter 𝑦𝑦𝐹𝐹(𝑘𝑘) = 𝑎𝑎1𝑦𝑦𝐹𝐹(𝑘𝑘 − 1)+𝑎𝑎2𝑦𝑦𝐹𝐹(𝑘𝑘 − 2) + +𝑎𝑎3𝑦𝑦𝐹𝐹(𝑘𝑘 − 3) + (1 − 𝑎𝑎1 − 𝑎𝑎2 − 𝑎𝑎3)𝑦𝑦(𝑘𝑘)

𝑎𝑎1 = 3𝑎𝑎 𝑎𝑎2 = −3𝑎𝑎2 𝑎𝑎3 = 𝑎𝑎3

Note: It’s important to carry enough decimal places in the 𝑎𝑎 coefficients as the 𝑦𝑦(𝑘𝑘) coefficient (1 – sum of 𝑎𝑎 coefficients) can be small, especially for larger 𝜏𝜏𝐹𝐹.

Page 6: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

We will first evaluate filters based on 1) reduction in standard deviation of random noise and 2) lag in the step response. The desire is to obtain the lowest lag for the same amount of noise reduction. The reduction in standard deviation of random noise can be directly calculated using the Yule-Walker equations (Box,

Jenkins and Reinsel, 1994). The noise attenuation for the 1st-order filter is given by �(1 − 𝑎𝑎)/(1 + 𝑎𝑎); higher-order filters require a simultaneous solution. The lag is evaluated by direct calculation of the filter to a step input. Figure 4 shows the comparisons of the filters. We see that the higher-order filters provide less lag for a given time constant 𝜏𝜏𝐹𝐹. A better way to compare the filters is the time to achieve a given response time to a step input, and here we select the 98% response time. For example, at levels of 0.30 and 0.20 attenuation of noise, the corresponding 98% response times are:

98% response time, sec Attenuation 1st-order 2nd-order 3rd-order

0.30 20.68 15.07 14.08 0.20 47.90 35.13 33.42

We see noticeable improvement of the higher-order filters over the 1st-order filter. The 2nd-order filter achieves a 27% faster and the 3rd-order filter 32% faster time response compared to the first-order. At 0.3 attenuation, the relative improvement is similar, but with slightly less percentage improvement. The relative improvement of the 3rd-order filter over the 2nd-order is less than the improvement of the 2nd-order over the 1st-order, suggesting a dimensioning improvement of higher-ordered filters of this type. It should be noted that at smaller percentage response times—as the percentage response moves away from near steady-state (e.g., at 80%)—the advantage of the higher-order filters continue to hold true although with less relative improvement.

Figure 4. Comparison of 1st-, 2nd- and 3rd-order filters. Left: noise attenuation as a function of 𝜏𝜏𝐹𝐹. Right: noise attenuation expressed in terms of 98% response time.

The other filter we consider is the moving average filter. It is an FIR filter with all coefficients equal; 𝑏𝑖𝑖 = 1/N. This filter is simply the arithmetic average based on the most recent N measured values. Notice that the calculation can be simplified to 𝑦F(𝑘) = (𝑦(𝑘) + 𝑁𝑦F(𝑘− 1) − 𝑦(𝑘−𝑁))/𝑁. The noise attenuation

Time constant , sec0 5 10 15 20 25 30 35 40 45 50

Noi

se s

td. d

ev. a

ttenu

atio

n, fr

actio

n

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

1st order

2nd order

3rd order

Page 7: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

for the moving average filter is directly calculated as 1/√𝑁𝑁. Figure 5 shows the attenuation of noise of the moving average filter as a function of the number of measurement values N, and compares the moving average filter with the 1st- and 2nd-order filters. We see that the moving average filter provides better noise attenuation at the cost of significantly more filter coefficients and storage of previous signal values. Again, this should not pose a problem for today’s control systems, particularly if large N moving average filters are not applied widely (i.e., only to selected applications).

Figure 5. Moving average filter. Left: noise attenuation as a function of 𝑁𝑁. Right: noise attenuation expressed in terms of 98% response time, showing the improvement compared to 1st- and 2nd-order filters.

The step response of a moving average filter is a ramp starting at value 1/N and achieving steady state at 𝑁𝑁 − 1 time steps, corresponding to a time equal to N-1 times the filter ∆𝑡𝑡. This is illustrated in Figure 6 for a moving average filter with N = 10. A benefit of the moving average filter is that it can completely eliminate a constant, periodic disturbance imposed on a signal if the filter values N and ∆𝑡𝑡 are set such that their product N∆𝑡𝑡 equals the period of the periodic disturbance. Figure 7 illustrates the case of a periodic disturbance with period equal to 30 sec.

Figure 6. Moving average filter with N = 10 applied to a step at time 0.

Number of terms, N0 10 20 30 40 50 60 70 80 90 100

Noi

se s

td. d

ev. a

ttenu

atio

n, fr

actio

n

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

98% resonse time, sec0 10 20 30 40 50 60 70 80 90 100

Noi

se s

td. d

ev. a

ttenu

atio

n, fr

actio

n0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

1st order

2nd order

Moving average

Time (sec)0 5 10 15 20 25 30 35 40 45 50

Step

resp

onse

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 8: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

Peak error: Maximum error following an unmeasured step in load disturbance on process input. Peak error is important to prevent relief, alarm and SIS activation, and environmental violation.

IAE: Integrated absolute error over time is a common criterion for measuring loop performance. It directly relates to economics as it provides a measure of the amount of process material that is off-setpoint.

Time, sec

Figure 7. Moving average filter applied to a constant signal followed by a unit step. Notice that the cycle is eliminated after the initial transient or start-up of the filter.

We’ll now consider the impact of filtering on PID loop performance. An important reason to filter the feedback variable (PV) is to ensure effective derivative action. Derivative action is important when aggressive control is required, particularly for integrating and near-integrating (lag-dominant) systems with additional lag(s) and significant dead time. If not properly filtered, noisy signals will cause derivative action to be ineffective due to erratic movement of the PID controller output. Fortunately, most industrial PID controllers include a filter on just the derivative term, expressed as a fraction, or divisor, of the specified derivative time. The fraction is usually in the range of 0.10 to 0.20 of the derivative time.

The other reason to filter the PV is to temper the controller output (CO) so the noise does not lead to excessive movement (and wear) of the valve, or cause disturbances to other control loops. In the past, another reason to filter the PV was due to resolution limits caused by the A/D converter, which would show up as noticeable steps in the measurement value; however, with 16 bit I/O cards, this is no longer an issue.

To evaluate the above filters in a closed loop, we simulate an integrating process with a noisy disturbance signal and an aggressively tuned PID controller. The loop and simulation details are shown in Figure 8. The tuning formulas used are the Lambda tuning rules modified by McMillan (2015) to provide better load disturbance rejection for a Standard Form PID, shown in Table 2 for an integrating process, where seemingly insignificant noise is amplified by a high PID gain. A value of 𝜆𝜆 = 2 sec. (twice the loop dead time) was used as the arrest time (time to stop excursion) for the tuning as it produced a non-oscillatory response in both the PV and CO provided the system is linear and the dynamics are fixed and well known. The following loop criteria are evaluated for each of the above filters.

0 100 200 300 400 500 600 700 800 900 1000

Mag

nitu

de

-1

-0.5

0

0.5

1

1.5

2

Signal

Moving average

Page 9: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

Setpoint overshoot: The maximum error overshoot for a setpoint change. Excessive overshoot can have economic or safety implications.

IAD: Integrated absolute difference of the controller output. For the case that the PID directly manipulates a valve, this is total valve travel distance and directly relates to valve wear.

Figure 8. Simulated closed-loop system.

Table 2. McMillan Lambda Tuning Formulas 𝐾𝐾𝑐𝑐 = Gain, 𝑇𝑇𝑖𝑖 = integral (reset) time, 𝑇𝑇𝑜𝑜 = derivative (rate) time. 𝜆𝜆 ≥ 𝜃𝜃𝑜𝑜 recommended.

Algorithm 𝑲𝑲𝒄𝒄 𝑻𝑻𝒊𝒊 𝑻𝑻𝒅𝒅

PID 2𝜆𝜆 + 𝜃𝜃𝑜𝑜

𝐾𝐾𝑖𝑖(𝜆𝜆 + 𝜃𝜃𝑜𝑜)22𝜆𝜆 + 𝜃𝜃𝑜𝑜 min �1

4𝑇𝑇𝑖𝑖 , max(1

2𝜃𝜃𝑜𝑜, 𝜏𝜏𝑜𝑜)�

PI 2𝜆𝜆 + 𝜃𝜃𝑜𝑜

𝐾𝐾𝑖𝑖(𝜆𝜆 + 𝜃𝜃𝑜𝑜)2max � 𝜃𝜃𝑜𝑜, 2𝜆𝜆 + 𝜃𝜃𝑜𝑜� −

For closed-loop evaluation of the filters, we decided to keep the PID tuning the same and not increase the filtering to an extent that causes cycling. Heavy filtering of the PV contributes lag and changes the process response, which would necessitate retuning. Since our objective is aggressive control, we want to minimize the impact of filtering on control, but reduce CO movement. Figure 9 shows the response in 𝑦𝑦 and 𝑢𝑢 (the CO) to a 20% step in load (𝑑𝑑𝑜𝑜) at time = 10 sec. for PID control without filtering. The effect of the noise on 𝑢𝑢 is clearly seen. Table 3 shows the results for PID control and, for comparison, also includes the results for PI control. While the PID achieves noticeably better PV results compared to PI, it does so at the expense of significantly more movement in 𝑢𝑢.

Process:Open-loop integrating gain = 0.01 %/% sec Open-loop time constant = 0.5 sec Open-loop dead time = 1.0 sec

Integrating Process

FilterRandom Noise

PID

PID: Standard form with proportional and derivative on PV

Derivative filter = 0.20

Filters:1st, 2nd, 3rd order, or Moving Average

𝑲𝑲𝒄𝒄 𝑻𝑻𝒊𝒊 𝑻𝑻𝒅𝒅

PID (𝜆𝜆 = 2) 55.57 5.0 0.5

PI (𝜆𝜆 = 2) 55.57 5.0 0

4

Page 10: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

Figure 9. PID closed-loop response to step in load. No filtering.

Table 3. PID vs. PI results with load disturbance, no filtering. Peak Error

(%PV) IAE

(%PV·sec) IAD

(%CO·sec) PID 0.373 1.974 280.7 PI 0.444 2.436 32.538

To evaluate the various filters for PID control, we tuned the filter parameter (𝜏𝜏𝐹𝐹 or N) to achieve the same load IAD result (0.5423) as for PI control. Because the moving average parameter N is an integer value, it’s not possible to exactly match the same IAD value, so results are shown for filter N values above and below the PID value of 0.5423. Results are shown in Table 4 for both load and setpoint responses. We see that the first-order filter with PID control achieves worse results across all metrics than PI control with no filtering. Notably, the higher-order and moving average filters all perform better than PI control. The 2nd-order filter is the best performing filter across all metrics. Compared to the 1st-order filter, the 2nd-order filter achieves 7.3% smaller peak error and 19% smaller IAE for the load response, and 60% and 5.4% smaller peak error and IAE for the setpoint response. Compared to PID control with no filtering, the 2nd-order filter has 12% worse peak error and 3.9% worse IAE error for load response.

Table 5. PID results with filtering, same load IAD as PI.

Load Response Setpoint Response PID with Filter Peak Error

(%PV) IAE

(%PV·sec) IAD

(%CO·sec) Peak Error

(%PV) IAE

(%PV·sec) IAD

(%CO·sec) 1st Order, 𝜏𝜏𝐹𝐹 = 0.5439 0.453 2.538 32.538 0.116 5.301 32.526 2nd Order, 𝜏𝜏𝐹𝐹 = 0.1771 0.420 2.051 32.538 0.046 5.013 32.268 3rd Order, 𝜏𝜏𝐹𝐹 = 0.1180 0.433 2.122 32.538 0.057 5.014 32.346 Moving Average, N=7 0.428 2.087 37.158 0.052 5.006 36.678 Moving Average, N=8 0.437 2.169 31.992 0.064 5.035 31.800

0 5 10 15 20 25 30 35 40 45 50

u

-30

-20

-10

0

10

t, sec

0 5 10 15 20 25 30 35 40 45 50

y

-0.2

0

0.2

0.4

Page 11: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

To compare all filters on exactly the same basis, we first select a moving average filter to achieve at least a 90% reduction in IAD compared to PID control without a filter; and then tune 𝜏𝜏𝐹𝐹 for the higher-order filters to achieve the same IAD. These results are shown in Table 6. Again, we see that the second-order filter yields better results across all metrics. Compared to the 1st-order filter, the 2nd-order filter yields 11% smaller peak error and 40% better IAE for load response, and 71% and 21% better results for the setpoint response. Figure 10 shows the time responses for the 1st-order filter, and Figure 11 shows the time responses for the 2nd-order filter. The improvement from the 2nd-order filter over the 1st-order filter is clearly seen. Also seen in Figure 12 is that the response with the 1st-order filter is starting to become oscillatory. Note that at 𝜏𝜏𝐹𝐹 = 1.875 for the first-order filter, the loop becomes unstable. For the other filters, loop instability occurs at 𝜏𝜏𝐹𝐹 = 0.73 for the 2nd-order, 𝜏𝜏𝐹𝐹 = 0.45 for the 3rd-order filter, and N = 26 for the moving average filter. Thus, it does not take much filtering to cause loop instability.

Table 6. PID results with filtering, 91.5% reduction in load IAD. Load Response Setpoint Response

PID with Filter Peak Error (%PV)

IAE (%PV·sec)

IAD (%CO·sec)

Peak Error (%PV)

IAE (%PV·sec)

IAD (%CO·sec)

1st Order, 𝜏𝜏𝐹𝐹 = 0.8161 0.488 3.597 23.886 0.222 6.372 24.174 2nd Order, 𝜏𝜏𝐹𝐹 = 0.2177 0.434 2.167 23.886 0.064 5.045 23.676 3rd Order, 𝜏𝜏𝐹𝐹 = 0.1388 0.443 2.235 23.886 0.073 5.066 23.748 Moving Average, N=11 0.464 2.555 23.886 0.114 5.285 23.892

Figure 10. PID closed-loop responses with 1st order filter. Left: load response. Right: setpoint response.

0 5 10 15 20 25 30 35 40 45 50

u

-40

-20

0

20

t, sec

0 5 10 15 20 25 30 35 40 45 50

y

-0.2

0

0.2

0.4

0.6

0 5 10 15 20 25 30 35 40 45 50

u

-20

0

20

40

t, sec

0 5 10 15 20 25 30 35 40 45 50

y

-0.5

0

0.5

1

1.5

Page 12: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

Figure 11. PID closed-loop responses with 2nd order filter. Left: load response. Right: setpoint response.

Based on the above results, the closed-loop simulations show that significant improvement over the 1st-order filter is possible when significant noise is present, and aggressive control and significant reduction in IAD is needed. These results also show that a 2nd-order filter provides the best metrics, although not always by a large margin.

Conclusions: What have we learned, what are the lessons? Be careful to not overly filter. What’s good to the eye is usually too much filtering, especially for control. Excessive suppression of noise and the consequential instability or reduced response to disturbances can be costly. The more attenuation, the slower the filtered signal approaches a new average value—i.e., the more time lag. For the same amount of noise attenuation, higher-order filters (2nd- and 3rd-order) and the moving average filter approach a new average value quicker than the often-used exponential or 1st-order filter. The moving average filter can achieve higher levels of noise attenuation than the 2nd- and 3rd-order filters at the added cost of more coefficients and storage of previous signal values, but this should not pose a problem with today’s control systems. An advantage of the moving average filter is that it can eliminate a periodic cycle if the filter ∆𝑡𝑡 and N are selected appropriately.

When a noisy PV is used in control, the deciding issue to filter is unacceptable movement in the manipulated variable (controller output) caused by the noise. In this case, if aggressive control is required (higher gain with derivative action), higher-order and moving average filters allow tighter control with improved metrics (peak error and IAE) compared to the exponential or 1st-order filter.

Before retuning a loop, make sure to note what the filter parameters are: time constant or filter factor and ∆𝑡𝑡. Only use filtering to temper movement in the manipulated variable (controller output) caused by the noise. If aggressive control is required (higher gain and derivative action), higher-order and moving average filters allow tighter control with improved metrics (peak error and IAE) compared to the exponential or 1st-order filter. One should be careful to not cause loop instability with filtering. Although not extensive, these simulation results, plus others we have performed, generally show that of the filters considered, the 2nd-order filter provides the best metrics when targeting reduced levels of IAD.

0 5 10 15 20 25 30 35 40 45 50

u

-40

-20

0

20plot

t, sec

0 5 10 15 20 25 30 35 40 45 50

y

-0.2

0

0.2

0.4

0.6

0 5 10 15 20 25 30 35 40 45 50

u

-10

0

10

20

30plot

t, sec

0 5 10 15 20 25 30 35 40 45 50

y

-0.5

0

0.5

1

1.5

Page 13: Signal filtering: Why and how - Control Global · Signal filtering: Why and how Prevent over-filtering by simultaneously optimizing loop tuning and filter parameters. By Mark Darby

We took the simple approach of keeping the tuning the same to show the improvement possible with more sophisticated filters. Ideally, the tuning and the selection of filter parameters should be jointly optimized, e.g., using a loop tuning optimizer.

We have focused on linear filters. However, the following additional suggestions are offered:

• When a process variable (PV) cannot respond faster than by an amount X/sec., a PV rate limit with this setting can be used to screen out noise without adding a lag. Alternatively, a setpoint rate limit to reduce CO movement can be put on the analog output block or secondary loop manipulated by the PID and external-reset feedback (e.g., dynamic reset limit) turned on to prevent the PID output from changing faster than the imposed setpoint rate limit. However, upon download or during tests for checkout and maintenance, the rate limit must be turned off.

• For pH measurements, the use of middle signal selection of three electrodes can reduce noise and eliminate spikes that commonly occur due to imperfect mixing and ground potentials without adding a lag, in addition to ignoring slower responding electrodes due to aging or fouling.

• For electrodes and temperature sensors, increasing back mixing and minimizing phase changes, and for pipeline installations, ensuring the tip is in the middle of the pipe at least 25 pipe diameters downstream of a pump discharge or equipment outlet can greatly reduce the source of process noise for these critical primary loops.

References 1. Yang, W.Y. (2009). Signals and Systems with MATLAB. Elsevier, Inc., Oxford.2. Box, G.E.P., Jenkins, G.M., and Reinsel, G.C. (1994). Time Series Analysis, 3rd Ed. Prentice-Hall.,Englewood, NJ.3. McMillan, G.K. (2015). Tuning and Control Loop Performance, 4th Ed. Momentum Press, New York.

About the authors Mark Darby, principal consultant, CMiD Solutions, Houston, can be reached at [email protected]. Greg McMillan, senior principal software engineer, Emerson Process Solutions; Control columnist and Process Automation Hall of Fame member, can be reached at [email protected].