The “MACD Approach” to Derivative (Rate of Change) Estimation
This page describes the “MACD approach” for filtering to estimate derivatives (rate of change of variables over time), and second derivatives as well. This page is part of the section on Filtering that is part of A Guide to Fault Detection and Diagnosis.
An overview of the MACD (dual filter difference) approach
The central idea is to subtract a heavily filtered value from a lightly filtered value, as shown in the following block diagram. (A scaling factor must be applied, not shown here.) In this diagram, the filters are exponential filters, with time constants < :
The extreme case with = 0 (no light filter at all) is also included, as discussed in a special section later. That is, just subtract a heavily filtered value from the current value.
This is intuitively appealing: roughly speaking, the lightly filtered value approximates a recent value, and the heavily filtered value approximates an older value. Derivatives are the difference between a recent value and an old value, after dividing by a scale factor representing a time interval.
The original “MACD” acronym stands for “Moving Average Convergence Divergence”. This terminology describes a particular calculation used for trend analysis for investments. In that case, the heart of the calculation involves exponential filters with 12week and 26week time constants. That specific MACD calculation also throws in another 9week exponential filter in series, to filter the derivative estimate even more, and also enable estimation of the second derivative. Here, we use the terminology “MACD approach” to mean the idea of taking the difference of two filter outputs to estimate a derivative.
This “moving average” part of the MACD acronym abuses the ARMA “moving average” terminology, since there is no input history that is used  just the current input. This naming continued the unfortunate practice (used in stock analysis and some other places) of calling an exponential filter an “exponentially weighted moving average” (EWMA or EMA), even though it is not a moving average using traditional time series terminology.
Effects of the time constants for exponential filters in an MACD approach
This approach with two exponential filters generates an estimate of the filtered value of the derivative. The calculation is the equivalent of those same two filters in series, in series with a differentiator, with an overall gain of the difference in the two time constants (  ). That is, to estimate the derivative, take the output and divide it by (  ).
When using exponential filters with a fixed sample time interval, the time scale is based on the sample time. To convert to the time derivative, divide the output by the sampling interval time.
One important special case is when = 0. That is, you take a variable with no filtering, and subtract a filtered value using a filter with time constant . In this case, you get an estimate of the derivative filtered by a filter with time constant , and gain . The full version with both filters is usually preferred to reduce the impact of noise.
As an approximation at low frequencies, the MACD approach can be seen to roughly approximate a differentiator in series with a single filter. The approximate filter time constant for that single equivalent filter is roughly the sum of the two time constants ( + ). The output has the same gain, equal to (  ).
Why does MACD estimate the time derivative?
You can skip the explanation of this approximation and just use the results above. The analysis that follows is for the continuous time (analog) equivalent of these digital filters. We do some “hand waving” that the filter outputs for the analog and digital first order lags are the same at the sampling times, when the digital “smoothing” constant (a number between 0 and 1) is set based on the time constant. This is explained in the section on the exponential filter. By looking at the continuous time equivalent, we can use Laplace transforms, which are probably more commonly known than the z transforms of discrete time systems. The equivalent to the MACD diagram above can then be represented by the following block diagram, where the exponential filters are replaced by the corresponding firstorder lags:
We can then write the gain G(s) of this system as
That is, the MACD calculation is the equivalent of the same two filters in series, in series with a differentiator. The gain term for the overall block is the difference of the time constants. In block diagram form, this is:
