previous next


The TFit Method: Hyperlinear Quantitative Absorption Spectrophotometry

[background]  [FitM function]  [Simple Demo]  [Demonstration scripts]  [Download ZIP file]  [Have a question? Email me]

This is a Matlab implementation of a computational method for quantitative analysis by multiwavelength absorption spectroscopy, called the transmission-fitting or “TFit” method, based on fitting a model of the instrumentally-broadened transmission spectrum to the observed transmission data, rather than direct calculation of absorbance as log10(Izero/I). The method is described in: T. C. O'Haver and J. Kindervater, J. of Analytical Atomic Spectroscopy 1, 89 (1986); T. C. O'Haver and Jing-Chyi Chang, Spectrochim. Acta 44B, 795-809 (1989); T. C. O'Haver, Anal. Chem. 68, 164-169 (1991). It is included as an application example here because it combines several important concepts: signal-to-noise ratio, Fourier convolution, multcomponent spectroscopy, iterative least-squares fitting, and calibration

Advantages of the TFit method compared to conventional methods are: (a) much wider dynamic range; (b) greatly improved calibration linearity ("hyperlinearily"); (c) ability to operate under conditions that are optimized for signal-to-noise ratio rather than for Beer's Law ideality (e.g. small spectrometers with lower dispersion and larger slit widths).

Just like the multilinear regression (classical least squares) methods conventionally used in absorption spectroscopy, the Tfit method (a) requires an accurate reference spectrum of each analyte, (b) utilizes multi-wavelength data such as would be acquired on diode-array, Fourier transform, or automated scanning spectrometers, and (c) applies both to single-component and multi-component mixture analysis.

The disadvantages of the Tfit method are: (a) it is computationally more intensive than the multilinear regression methods (but, on a typical personal computer, calculations take only a fraction of a second, even for the analysis of a mixture of three components); (b) it requires knowledge of the instrument function, i.e., the slit function or the resolution function of an optical spectrometer (however, this is a fixed characteristic of the instrument and is easily measured beforehand by scanning the spectrum of a narrow atomic line source such as a hollow cathode lamp); and (c) it is an iterative method that can under unfavorable circumstances converge on a local optimum (but this is handled by proper selection of the starting values, based on preliminary approximations calculated by conventional methods).

Click here to download a self-contained demo m-file that works in recent versions of Matlab. (You can also download a ZIP file "TFit.zip" that contains both the newer version and the older one for Matlab 6.5) and you can also download it from the Matlab File Exchange. The following is a description of the main functions and programs:


Background

 In absorption spectroscopy, the intensity I of light passing through an absorbing sample is given (in Matlab notation) by the Beer-Lambert Law:
         I = Izero.*10^-(alpha*L*c)         

where “Izero” is the intensity of the light incident on the sample, “alpha” is the absorption coefficient of the absorber, “L” is the distance that the light travels through the material (the path length), and “c” is the concentration of absorber in the sample. The variables I, Izero, and alpha are all functions of wavelength; L and c are scalar.

In conventional applications, measured values of I and Izero are used to compute the quantity called "absorbance", defined as

            A = log10(Izero./I)           

Absorbance is defined in this way so that, when you combine this definition with the Beer-Lambert law, you get:

            A = alpha*L*c  

So, absorbance is proportional to concentration, ideally, which simplifies analytical calibration. However, any real spectrometer has a finite spectral resolution, meaning that the light beam passing through the sample is not truly monochromatic, with the result that an intensity reading at one wavelength setting is actually an average over a small spectral interval. More exactly, what is actually measured is a convolution of the true spectrum of the absorber and the instrument function. If the absorption coefficient "alpha" varies over that interval, then the calculated absorbance will no longer be linearly proportional to concentration (this is called the “polychromicity” error). The effect is most noticeable at high absorbances. In practice, many instruments will become non-linear starting at an absorbance of 2 (~1% Transmission). As the absorbance increases, the effect of unabsorbed stray light and instrument noise also becomes more significant.

The theoretical best signal-to-noise ratio and absorbance precision for a photon-noise limited optical absorption instrument can be shown to be close to an absorbance of 1.0 (see #8 on http://terpconnect.umd.edu/~toh/models/AbsSlitWidth.html#BestAbsorbance). However, if one attempts to arrange sample dilutions and absorption cell path lengths to obtain a working range centered on an absorbance of 1.0, for example over the range .1 – 10, or 0.01 – 100, the measurements will obviously fail at the high end. (Clearly, the direct measurement of an absorbance of 100 is unthinkable, as it implies the measurement of light attenuation of 100 powers of ten - no real measurement system has a dynamic range even close to that). In practice, it is difficult to achieve an dynamic range even as high as 5 or 6 absorbance, so that much of the theoretically optimum absorbance range is actually unusable. (c.f. http://en.wikipedia.org/wiki/Absorbance). So, in conventional practice, greater sample dilutions and shorter path lengths are required to force the absorbance range to lower values, even if this means poorer signal-to-noise ratio and measurement precision at the low end. 

It is true that the non-linearity caused by polychromicity can be reduced by operating the instrument at the highest resolution setting (reducing the instrumental slit width). However, this has a serious undesired side effect: in dispersive instruments, reducing the slit width to increase the spectral resolution degrades the signal-to-noise substantially. The optimum signal-to-noise ratio is often achieved when the resolution of the instrument approximately matches the width of the analyte absorption, but operating the instrument in that way would result in very substantial non-linearity over most of the absorbance range because of the “polychromicity” error. This non-linearity has its origin in the spectral domain (intensity vs wavelength), not in the calibration domain (absorbance vs concentration). Therefore it should be no surprise that curve fitting in the calibration domain, for example fitting the calibration data with a quadratic or cubic fit, might not be the best solution. Perhaps a better approach is to perform the curve fitting in the spectral domain. This is possible with modern absorption spectrophotometers that use array detectors that have many tiny detector elements that slice up the spectrum of the transmitted beam into many small wavelength segments, rather than detecting the sum of all those segments with one big photo-tube detector as older instruments do.

The TFit method sidesteps the above problems by calculating the absorbance in a completely different way: it starts with the reference spectra (an accurate absorption spectrum for each analyte, also required by the multilinear regression methods), normalizes them to unit height, multiplies each by an adjustable coefficient, adds them up, computes the antilog, and convolutes it with the previously-measured slit function. The result, representing the instrumentally broadened transmission spectrum, is compared to the observed transmission spectrum. The coefficients (one for each unknown component in the mixture) are adjusted by the program until the computed transmission model is a least-squares best fit to the observed transmission spectrum. The best-fit coefficients are then equal to the absorbances determined under ideal optical conditions. Provision is also made to compensate for unabsorbed stray light and changes in background intensity (background absorption). These calculations are performed by the function fitM, which is used as a fitting function for Matlab's iterative non-linear fitting function fminsearch. The TFit method gives measurements of absorbance that are much closer to the "true" peak absorbance (in the absence of stray light and polychromatic light errors) and it allows linear and wide dynamic range measurements to be made, even if the slit width of the instrument is increased to optimize the signal-to-noise ratio.

Note: It's important to understand that the use of the TFit method does not guarantee a perfectly linear analytical curve at all absorbances, despite the impression given by these simulations. The TFit method simply compensates for the non-linearity caused by unabsorbed stray light and the polychromatic light effect. Other sources of non-linearity remain, in particular chemical effects, such as photolysis, equilibrium shifts, temperature effects, pH effects, binding, dimerization, polymerization, molecular phototropism, fluorescence, etc.

Bottom line: The TFit method is based on the Beer-Lambert Law, but it calculates the absorbance in a different way that does not require the assumption that stray light and polychromatic radiation effects are zero. Because it allows larger slit widths to be used, it is possible to obtain greater signal-to-noise ratios, while still achieving a much wider linear dynamic range than previous methods. 


The fitM.m function

function err = fitM(lam,yobsd,Spectra,InstFun,StrayLight)

fitM is a fitting function for the Tfit method, for use with Matlab's or Octave's fminsearch function. The input arguments of fitM are:

absorbance= vector of absorbances that are calculated to give the best fit to the transmission spectrum.
yobsd = observed transmission spectrum of the mixture sample over the spectral range (column vector)
Spectra = reference spectra for each component, over the same spectral range, one column/component, normalized to 1.00.
InstFun = Zero-centered instrument function or slit function (column vector)
StrayLight = fractional stray light (scalar or column vector, if it varies with wavelength)
Note: yobsd, Spectra, and InstFun must have the same number of rows (wavelengths). Spectra must have one column for each absorbing component.

Typical use:

absorbance=fminsearch(@(lambda)(fitM(lambda,yobsd,TrueSpectrum,InstFunction,straylight)),start); 

where start is the first guess (or guesses) of the absorbance(s) of the analyte(s); it's convenient to use the conventional log10(Izero/I) estimate of absorbance for start. The other arguments (described above) are passed on to FitM. In this example, fminsearch returns the value of absorbance that would have been measured in the absence of stray light and polychromatic light errors (which is either a single value or a vector of absorbances, if it is a multi-component analysis). The absorbance can then be converted into concentration by any of the usual calibration procedures (Beer's Law, external standards, standard addition, etc.)

Iterative least-squares methods are ordinarily considered to be more difficult and less reliable than multilinear regression methods, and this can be true if there are more than one nonlinear variable that must be iterated, especially if those variables are correlated.  However, in the TFit method, there is only one iterated variable (absorbance) per measured component, and reasonable first guesses are readily available from the conventional single-wavelength absorbance calculation or multiwavelength regression methods. As a result, an iterative least-squares method works very well in this case.  Comparing the expression for absorbance given above for the TFit method to that for the weighted regression method:

 absorbance=([weight weight].*[Background ReferenceSpectra])\(-log10(yobsd).*weight)
you can see that, in addition to the ReferenceSpectra and observed transmission spectrum (yobsd), the TFit method also requires a measurement of the Instrument function (spectral bandpass) and the stray light (which the linear regression methods assume to be zero), but these are characteristics of the spectrometer and need be done only once for a given spectrometer.  Finally, although the TFit method does make the computer work harder, the computation time on a typical laboratory personal computer is only a fraction of a second (roughly 25 µsec per spectral data point per component analyzed), using Matlab as the computational environment.  

The tfit.m demonstration function for Matlab or Octave.

The tfit.m function is a self-contained command-line demonstration function that compares the TFit method to the single-wavelength, simple regression, and weighted regression methods. The syntax is tfit(absorbance), where 'absorbance' is the true peak absorbance of an absorber with a Lorentzian spectral profile of width 'width' (line 29), measured with a spectrometer with a Gaussian spectral bandpass of width 'InstWidth' (line 30), fractional unabsorbed stray light level of 'straylight' (line 32), photon noise level of 'noise' (line 31) and a random Izero shift of 'IzeroShift' (line 33).  Plots the spectral profiles and prints the measured absorbances of each method in the command window.  Examples:

>> tfit(1)

width = 10
InstWidth = 20
noise = 0.01
straylight = 0.01
IzeroShift = 0.01
 
          True A    SingleW    SimpleR      WeightR      TFit
            1      0.38292     0.54536      0.86839      1.0002

>> tfit(10)
            10     1.4858       2.2244       9.5123      9.9979

>> tfit(100)
           100      2.0011      3.6962       57.123     99.951

TFitDemo.m: Interactive explorer for the Tfit method for Matlab, version 2.1

Click to view enlarged figure
Slider-operated version, for Matlab 6.5



Keyboard-operated version (for Matlab)
Keypress-operated interactive explorer for the Tfit method (for Matlab only), applied to the measurement of a single component with a Lorentzian (or Gaussian) absorption peak, with controls that allow you to adjust the true absorbance (Peak A), spectral width of the absorption peak (AbsWidth), spectral width of the instrument function (InstWidth), stray light, and the noise level (Noise) continuously while observing the effects graphically and numerically. Simulates the effect of photon noise, unabsorbed stray light, and random background intensity shifts (light source flicker). Compares observed absorbances by the single-wavelength, weighted multilinear regression (sometimes called Classical Least Squares in the chemometrics literature), and the TFit methods. To run this file, right-click TFitDemo.m click "Save link as...", save it in a folder in the Matlab path, then type "TFitDemo" at the Matlab command prompt.  With the figure window topmost on the screen, press K to get a list of the keypress functions.  Version 2.1, November 2011, adds SNR calculation; W key to Switch between Transmission and Absorbance display.

In the example shown on the left, the true peak absorbance is exactly 1.000, the absorption widths and instrument function widths are equal, the unabsorbed stray light is 0.5%., and the photon noise is 5%.  The results below the graphs show that the TFit method gives a much more accurate measurement (1.0046) than the single-wavelength method (0.617) or weighted multilinear regression method (0.954).

Note: The original version of this demo, which uses sliders, works only on Matlab 6.5, but I recommend that you use TFitDemo.m instead, as it is more up-to-date and includes the statistics and calibration curve. 

KEYBOARD COMMANDS

Peak shape....Q     Toggles between Gaussian and Lorentzian absorption peak shape
True peak A...A/Z   True absorbance of analyte at peak center, without
                    instrumental broadening, stray light, or noise.
AbsWidth......S/X   Width of absorption peak
SlitWidth.....D/C   Width of instrument function (spectral bandpass)
Straylight....F/V   Fractional unabsorbed stray light.
Noise.........G/B   Random noise level
Re-measure....Spacebar   Re-measure signal
Switch mode...W     Switch between Transmission and Absorbance display
Statistics....Tab   Prints table of statistics of 50 repeats
Cal. Curve....M     Displays analytical calibration curve in Figure 2
Keys..........K     Print this list of keyboard commands


Why does the noise on the graph change if I change the instrument function (slit width or InstWidth)? In the most common type of absorption spectrometer, using a continuum light source and a dispersive spectrometer, the spectrometer's spectral bandwidth ("InstWidth") is changed by changing the monochromator slit width, which also effects the light intensity transmitted through the monochromator and thus the signal-to-noise ratio. Therefore, in all these programs, when you change InstWidth, the photon noise is automatically changed accordingly just as it would in a real spectrophotometer.

TFitStats.m: Statistics of methods compared (Matlab or Octave)

    True A    SingleW   SimpleR   WeightR   TFit 
MeanResult =
0.0010 0.0004 0.0005 0.0006 0.0010
PercentRelativeStandardDeviation =
1.0e+003 *
0.0000 1.0318 1.4230 0.0152 0.0140
PercentAccuracy =
0.0000 -60.1090 -45.1035 -38.6300 0.4898

MeanResult =
100.0000 2.0038 3.7013 57.1530 99.9967
PercentRelativeStandardDeviation =
0 0.2252 0.2318 0.0784 0.0682
PercentAccuracy =
0 -97.9962 -96.2987 -42.8470 -0.0033
Simple script that computes the statistics of the TFit method compared to single- wavelength (SingleW), simple regression (SimpleR), and weighted regression (WeightR) methods. Simulates photon noise, unabsorbed stray light and random background intensity shifts. Estimates the precision and accuracy of the four methods by repeating the calculations 50 times with different random noise samples. Computes the mean, relative percent standard deviation, and relative percent deviation from true absorbance. Parameters are easily changed in lines 19 - 26. Results are displayed in the MATLAB command window.

In the sample output shown on the left, results for true absorbances of 0.001 and 100 are computed, demonstrating that the accuracy and the precision of the TFit method is superior to the other methods over a 10,000-fold range.

This statistics function is included as a keypress command (Tab key) in TFitDemo.m.

TFitCalDemo.m: Comparison of analytical curves (Matlab or Octave)

Click to view enlarged
                figure
Click to view enlarged figure
Function that compares the analytical curves for single-wavelength, simple regression, weighted regression, and the TFit method over any specified absorbance range (specified by the vector “absorbancelist” in line 20). Simulates photon noise, unabsorbed stray light and random background intensity shifts. Plots a log-log scatter plot with each repeat measurement plotted as a separate point (so you can see the scatter of points at low absorbances). The parameters can be changed in lines 20 - 27.

In the sample result shown on the left, analytical curves for the four methods are computed over a 10,000-fold range, up to a peak absorbance of 100, demonstrating that the TFit method (shown by the green circles) is much more nearly linear over the whole range than the single-wavelength, simple regression, or weighted regression methods.

This calibration curve function is included as a keypress command (M key) in TFitDemo.m.

TFit3.m: Application to a three-component mixture for Matlab/Octave (and TFit3Demo.m, for Matlab only)

Click to view enlarged
                figure
Figure No. 1 window: Click to enlarge
Click to view enlarged figure
Figure No. 2 window: Click to enlarge

Demo of the T-Fit method applied to the multi-component absorption spectroscopy of a mixture of three absorbers. The adjustable parameters are: the absorbances of the three components (A1, A2, and A3), spectral overlap between the component spectra ("Sepn"), width of the instrument function ("InstWidth"), and the noise level ("Noise"). Compares quantitative measurement by weighted regression and TFit methods. Simulates photon noise, unabsorbed stray light and random background intensity shifts. Note: After executing this m-file, slide the "Figure No. 1" and "Figure No.2" windows side-by-side so that they don't overlap. Figure 1 shows a log-log scatter plot of the true vs. measured absorbances, with the three absorbers plotted in different colors and symbols. Figure 2 shows the transmission spectra of the three absorbers plotted in the corresponding colors. As you use the keyboard commands (below) in Figure No. 1, both graphs change accordingly.

In the sample calculation shown above, component 2 (shown in blue) is almost completely buried by the stronger absorption bands of components 1 and 3 on either side, giving a much weaker absorbance (0.1) that the other two components (3 and 5, respectively). Even in this case, the TFit method gives a result (T2=0.101) within 1% of the correct value (A2=0.1).  In fact, over most combinations of the three concentrations, the TFit methods works better (although of course nothing works if the spectral differences between the components is too small). Note: in this program, as in all of the above, when you change InstWidth, the photon noise is automatically changed accordingly just as it would in a real variable-slit dispersive spectrophotometer.

The original version of this demo, which uses sliders, works only on Matlab 6.5, but you can also download the newer self-contained keyboard-operated version that works in recent versions of Matlab:

KEYBOARD COMMANDS
A1           A/Z   Increase/decrease true absorbance of component 1
A2           S/X   Increase/decrease true absorbance of component 2
A3           D/C   Increase/decrease true absorbance of component 3
Sepn         F/V   Increase/decrease spectral separation of the components
InstWidth    G/B   Increase/decrease width of instrument function (spectral bandpass)
Noise        H/N   Increase/decrease random noise level when InstWidth = 1
Peak shape   Q     Toggles between Gaussian and Lorentzian absorption peak shape
Table        Tab   Print table of results
             K     Print this list of keyboard commands

Sample table of results (by pressing the Tab key):
---------------------------------------------------------------
                 True        Weighted        TFit
              Absorbance    Regression      method
Component 1      3             2.06          3.001            
Component 2      0.1           0.4316        0.09829        
Component 3      5             2.464         4.998 


Note for Octave users: the current versions (October, 2012 or later) of fitM.m, TFit3.m, TFitStats.m and TFitCalDemo.m work in Octave as well as in Matlab. However, the interactive features of TfitDemo.m and Tfit3Demo.m work only in Matlab; Octave users can use the command-line function tfit.m (single absorbing component) or TFit3.m (mixture of 3 absorbing components) instead. See http://terpconnect.umd.edu/~toh/spectrum/functions.html for a list of and links to these and other Matlab and Octave functions.

Created October 03, 2006.  Revised Auigust, 2014.
© Tom O'Haver
Professor Emeritus
Department of Chemistry and Biochemistry
The University of Maryland at College Park
toh@umd.edu
http://terpconnect.umd.edu/~toh/


index previous next

Number of unique visits since May 17, 2008:

counter create hit