[Table of Contents] [Previous section] [Next section]

Differentiation

The symbolic differentiation of functions is a topic that is introduced in all elementary Calculus courses. The numerical differentiation of digitized signals is an application of this concept that has many uses in analytical signal processing. The first derivative of a signal is the rate of change of y with x, that is, dy/dx, which is interpreted as the slope of the tangent to the signal at each point. Assuming that the x-interval between adjacent points is constant, the simplest algorithm for computing a first derivative is:

(for 1< j <n-1).

where X'j and Y'j are the X and Y values of the jth point of the derivative, n = number of points in the signal, and X is the difference between the X values of adjacent data points. A commonly used variation of this algorithm computes the average slope between three adjacent points:

(for 2 < j <n-1).

The second derivative is the derivative of the derivative: it is a measure of the curvature of the signal, that is, the rate of change of the slope of the signal. It can be calculated by applying the first derivative calculation twice in succession. The simplest algorithm for direct computation of the second derivative in one step is

(for 2 < j <n-1).

Basic Properties of Derivative Signals

Click to view enlarged figure The figure on the left shows the results of the successive differentiation of a computer-generated signal (click to see the full-sized figure). The signal in each of the four windows is the first derivative of the one before it; that is, Window 2 is the first derivative of Window 1, Window 3 is the first derivative of Window 2, Window 3 is the second derivative of Window 1, and so on. You can predict the shape of each signal by recalling that the derivative is simply the slope of the original signal: where a signal slopes up, its derivative is positive; where a signal slopes down, its derivative is negative; and where a signal has zero slope, its derivative is zero.

The sigmiodal signal shown in Window 1 has an inflection point (point where where the slope is maximum) at the center of the x axis range. This corresponds to the maximum in its first derivative (Window 2) and to the zero-crossing (point where the signal crosses the x-axis going either from positive to negative or vice versa) in the second derivative in Window 3. This behavior can be useful for precisely locating the inflection point in a sigmoid signal, by computing the location of the zero-crossing in its second derivative. Similarly, the location of maximum in a peak-type signal can be computed precisely by computing the location of the zero-crossing in its first derivative.

Click to view enlarged figureAnother important property of the differentiation of peak-type signals is the effect of the peak width on the amplitude of derivatives. The figure on the left shows the results of the successive differentiation of two computer-generated Gaussian bands (click to see the full-sized figure). The two bands have the same amplitude (peak height) but one of them is exactly twice the width of the other. As you can see, the wider peak has the smaller derivative amplitude, and the effect becomes more noticeable at higher derivative orders. In general, it is found that that the amplitude of the nth derivative of a peak is inversely proportional to the nth power of its width. Thus differentiation in effect discriminates against wider peaks and the higher the order of differentiation the greater the discrimination. This behavior can be useful in quantitative analytical applications for detecting peaks that are superimposed on and obscured by stronger but broader background peaks.

Applications of Differentiation

A simple example of the application of differentiation of experimental signals is shown in Figure 5. This signal is typical of the type of signal recorded in amperometric titrations and some kinds of thermal analysis and kinetic experiments: a series of straight line segments of different slope. The objective is to determine how many segments there are, where the breaks between then fall, and the slopes of each segment. This is difficult to do from the raw data, because the slope differences are small and the resolution of the computer screen display is limiting. The task is much simpler if the first derivative (slope) of the signal is calculated (Figure 5, right). Each segment is now clearly seen as a separate step whose height (y-axis value) is the slope. The y-axis now takes on the units of dy/dx. Note that in this example the steps in the derivative signal are not completely flat, indicating that the line segments in the original signal were not perfectly straight. This is most likely due to random noise in the original signal. Although this noise was not particularly evident in the original signal, it is more noticeable in the derivative.

It is commonly observed that differentiation degrades signal-to-noise ratio, unless the differentiation algorithm includes smoothing that is carefully optimized for each application. Numerical algorithms for differentiation are as numerous as for smoothing and must be carefully chosen to control signal-to-noise degradation.

A classic use of second differentiation in chemical analysis is in the location of endpoints in potentiometric titration. In most titrations, the titration curve has a sigmoidal shape and the endpoint is indicated by the inflection point, the point where the slope is maximum and the curvature is zero. The first derivative of the titration curve will therefore exhibit a maximum at the inflection point, and the second derivative will exhibit a zero-crossing at that point. Maxima and zero crossings are usually much easier to locate precisely than inflection points.

Figure 6 shows a pH titration curve of a very weak acid with a strong base, with volume in mL on the X-axis and pH on the Y-axis. The volumetric equivalence point (the "theoretical" endpoint) is 20 mL. The endpoint is the point of greatest slope; this is also an inflection point, where the curvature of the signal is zero. With a weak acid such as this, it is difficult to locate this point precisely from the original titration curve. The second derivative of the curve is shown in Window 2 on the right. The zero crossing of the second derivative corresponds to the endpoint and is much more precisely measurable. Note that in the second derivative plot, both the x-axis and the y-axis scales have been expanded to show the zero crossing point more clearly. The dotten lines show that the zero crossing falls at about 19.4 mL, close to the theoretical value of 20 mL.

Derivative Spectroscopy

In spectroscopy, particularly in infra-red, u.v.-visible absorption, fluorescence, and reflectance spectrophotometry, differentiation of spectra is a widely used technique, referred to as derivative spectroscopy. Derivative methods have been used in analytical spectroscopy for three main purposes: (a) spectral discrimination, as a qualitative fingerprinting technique to accentuate small structural differences between nearly identical spectra; (b) spectral resolution enhancement, as a technique for increasing the apparent resolution of overlapping spectral bands in order to more easily determine the number of bands and their wavelengths; (c) quantitative analysis, as a technique for the correction for irrelevant background absorption and as a way to facilitate multicomponent analysis.

Because of the fact that the amplitude of the nth derivative of a peak-shaped signal is inversely proportional to the nth power of the width of the peak, differentiation may be employed as a general way to discriminate against broad spectral features in favor of narrow components. This is the basis for the application of differentiation as a method of correction for background signals in quantitative spectrophotometric analysis. Very often in the practical applications of spectrophotometry to the analysis of complex samples, the spectral bands of the analyte (i.e. the compound to be measured) are superimposed on a broad, gradually curved background. Background of this type can be reduced by differentiation.

Click to view enlarged figure Click to view enlarged figure

Click to enlarge

This is illustrated by the figure on the left, which shows a simulated UV spectrum (absorbance vs wavelength in nm), with the green curve representing the spectrum of the pure analyte and the red line representing the spectrum of a mixture containing the analyte plus other compounds that give rise to the large sloping background absorption. The first derivatives of these two signals are shown in the center; you can see that the difference between the pure analyte spectrum (green) and the mixture spectrum (red) is reduced. This effect is considerably enhanced in the second derivative, shown on the right. In this case the spectra of the pure analyte and of the mixture are almost identical. In order for this technique to work, it is necessary that the background absorption be broader (that is, have lower curvature) than the analyte spectral peak, but this turns out to be a rather common situation. Because of their greater discrimination against broad background, second (and sometimes even higher-order) derivatives are often used for such purposes.

It is sometimes (mistakenly) said that differentiation "increases the sensitivity" of analysis. You can see how it would be tempting to say something like that by inspecting the three figures above; it does seems that the signal amplitude of the derivatives is greater (at least graphically) than that of the original analyte signal. However, it is not valid to compare the amplitudes of signals and their derivatives because they have different units. The units of the original spectrum are absorbance; the units of the first derivative are absorbance per nm, and the the units of the second derivative are absorbance per nm2. You can't compare absorbance to absorbance per nm any more than you can compare miles to miles per hour. (It's meaningless, for instance, to say that 30 miles per hour is greater than 20 miles.) You can, however, compare the signal-to-background ratio and the signal-to-noise ratio. For example, in the above example, it would be valid to say that the signal-to-background ratio is increased in the derivatives.

Trace Analysis

One of the widest uses of the derivative signal processing technique in practical analytical work is in the measurement of small amounts of substances in the presence of large amounts of potentially interfering materials. In such applications it is common that the analytical signals are weak, noisy, and superimposed on large background signals. Measurement precision is often degraded by sample-to-sample baseline shifts due to non-specific broadband interfering absorption, non-reproducible cuvette positioning, dirt or fingerprints on the cuvette walls, imperfect cuvette transmission matching, and solution turbidity. Baseline shifts from these sources are usually either wavelength-independent (light blockage caused by bubbles or large suspended particles) or exhibit a weak wavelength dependence (small-particle turbidity). Therefore it can be expected that differentiation will in general help to discriminate relevant absorption from these sources of baseline shift. An obvious benefit of the suppression of broad background by differentiation is that variations in the background amplitude from sample to sample are also reduced. This can result in improved precision or measurement in many instances, especially when the analyte signal is small compared to the background and if there is a lot of uncontrolled variability in the background. An example of the improved ability to detect trace component in the presence of strong background interference is shown in Figure 7.

The spectrum on the left shows a weak shoulder near the center due to the analyte. The signal-to-noise ratio is very good in this spectrum, but in spite of that the broad, sloping background obscures the peak and makes quantitative measurement very difficult. The fourth derivative of this spectrum is shown on the right. The background has been almost completely suppressed and the analyte peak now stands out clearly, facilitating measurement. An even more dramatic case is shown in Figure 8. This is essentially the same spectrum as in Figure 7, except that the concentration of the analyte is lower. The question is: is there a detectable amount of analyte in this spectrum? This is quite impossible to say from the normal spectrum, but inspection of the fourth derivative (right) shows that the answer is yes. Some noise is clearly evident here, but nevertheless the signal-to-noise ratio is sufficiently good for a reasonable quantitative measurement.

This use of signal differentiation has become widely used in quantitative spectroscopy, particularly for quality control in the pharmaceutical industry. In that application the analyte would typically be the active ingredient in a pharmaceutical preparation and the background interferences might arise from the presence of fillers, emulsifiers, flavoring or coloring agents, buffers, stabilizers, or other excipients.

The Importance of Smoothing Derivatives

For the successful application of differentiation in quantitative analytical applications, it is essential to use differentiation in combination with sufficient smoothing, in order to optimize the signal-to-noise ratio. Click to view enlarged figureClick to view enlarged figure This is illustrated in the figure on the left. Window 1 shows a Gaussian band with a small amount of added noise. Windows 2, 3, and 4, show the first derivative of that signal with increasing smooth widths. As you can see, without sufficient smoothing, the signal-to-noise ratio of the derivative can be substantially poorer than the original signal. However, with adequate amounts of smoothing, the signal-to-noise ratio of the smoothed derivative can be better than that of the unsmoothed original. This effect is even more striking in the second derivative, as shown on the right. In this case, the signal-to-noise ratio of the unsmoothed second derivative (Window 2) is so poor you can not even see the signal visually. It makes no difference whether the smooth operation is applied before or after the differentiation. What is important, however, is the nature of the smooth, its smooth ratio (ratio of the smooth width to the width of the original peak), and the number of times the signal is smoothed. The optimum values of smooth ratio for derivative signals is approximately 0.5 to 1.0. For a first derivative, two applications of a simple rectangular smooth or one application of a triangular smooth is adequate. For a second derivative, three applications of a simple rectangular smooth or two applications of a triangular smooth is adequate. The general rule is: for the nth derivative, use at least n+1 applications of rectangular smooth (or half that number of triangular smooths). Such heavy amounts of smoothing result in substantial attenuation of the derivative amplitude; in the figure on the right above, the amplitude of the most heavily smoothed derivative (in Window 4) is much less than its less-smoothed version (Window 3). However, this won't be a problem, as long as the standard (analytical) curve is prepared using the exact same derivative, smoothing, and measurement procedure as is applied to the unknown samples.

Video Demonstrations

The first 13-second, 1.5 MByte video (SmoothDerivative2.wmv ) demonstrates the huge signal-to-noise ratio improvements that are possible when smoothing derivative signals, in this case a 4th derivative.

The second video, 17-second, 1.1 MByte, (DerivativeBackground2.wmv ) demonstrates the measurement of a weak peak buried in a strong sloping background. The amplitude (Amp) of the peak is varied between 0 and 0.14, but the background is so strong that the peak, located at x = 500, is hardly visible. Then the 4th derivative (Order=4) is computed and the scale expansion (Scale) is increased, with a smooth width (Smooth) of 88. Finally, the amplitude (Amp) of the peak is varied again, but now the changes in the signal are now quite noticeable and easily measured. (These demonstrations were created in Matlab 6.5. If you have access to that software, you may download a set of Matlab Interactive Derivative m-files (15 Kbytes), InteractiveDerivative.zip so that you can experiment with the variables at will and try out this technique on your own signals).


SPECTRUM, the freeware signal-processing application that accompanies this tutorial, includes first and second derivative functions, which can be applied successively to compute derivatives of any order.

Differentiation in Matlab

Click to view enlarged figure
Differentiation functions such as described above can easily be created in Matlab. Some simple examples that you can download include: deriv, a first derivative using the 2-point central-difference method, deriv2, a simple second derivative using the 3-point central-difference method, a third derivative deriv3 using a 4-point formula, and deriv4, a 4th derivative using a 5-point formula. Each of these is a simple Matlab function of the form d=deriv(a); the input argument is a signal vector "a", and the differentiated signal is returned as the vector "d". Click on these links to inspect the code, or right-click to download for use within Matlab.

Interactive Derivative for Matlab is a collection of Matlab functions and scripts for interactive differentiation of time-series signals, with sliders that allow you to adjust the derivative order, smooth width, and scale expansion continuously while observing the effect on your signal dynamically. Requires Matlab 6.5. Click here to download the ZIP file "InteractiveDerivative.zip" that also includes supporting functions, self-contained demos to show how it works. Run InteractiveDerivativeTest to see how it works. Also includes DerivativeDemo.m, which demonstrates the application of differentiation to the detection of peaks superimposed on a strong, variable background. Generates a signal peak, adds random noise and a variable background, then differentiates and smooths it, and measures the signal range and signal-to-noise ratio (SNR). Interactive sliders allow you to control all the parameters. This was used to create the video demonstration DerivativeBackground2.wmv.

[Table of Contents] [Previous section] [Next section]


Last updated April, 2008. This page is maintained by Prof. Tom O'Haver , Department of Chemistry and Biochemistry, The University of Maryland at College Park. Comments, suggestions and questions should be directed to Prof. O'Haver at toh@umd.edu.