Frequency response of initial point least squares polynomial filters

considered the firstpoint in this window in particular and, thus, described the resulting coefficients as an initial point filter. Proctor and Sherwoo...
0 downloads 0 Views 667KB Size
Anal. Chem. 1987, 59, 367-371

367

CORRESPONDENCE Frequency Response of Initial Point Least Squares Polynomial Filters Sir: A great deal has been written regarding the polynomial smoothing filters introduced to analytical chemistry by Savitzky and Golay (I). In recent years there has been a resurgence of interest in digital filtering, as demonstrated by several articles (2-5). The aim of these papers has been to improve and better understand digital filtering methods in use. One useful modification to the original Savitzky-Golay filters, and the subject of this paper, was described by Leach et al. (2) and employed earlier by Proctor and Sherwood (3). These modified filters allow estimation of points other than the central datum in the window being filtered. Leach et al. considered the first point in this window in particular and, thus, described the resulting coefficients as an initial point filter. Proctor and Sherwood used the term extended sliding window filter, which is more general, since points can be estimated anywhere inside or outside of the window. These filters circumvent the problem of lost points at the beginning and end of a data set, a characteristic of symmetric filters such as the original Savitzky-Golay filters. The new filters allow estimation of points not normally accessible to symmetric filters. Since work in our laboratory involves the calculation of initial rates from chemical kinetics data, we were naturally interested in these initial point filters. However, application of the filters to the determination of initial slopes of reaction curves gave results that were poorer than expected. This prompted the investigation that is reported here. One of the most effective ways to describe a filter is by its frequency response ( 4 , 5 ) . While the frequency responses of symmetric nonrecursive filters are commonly described in the literature (6),there is little information regarding those of asymmetric filters. In this paper, we describe how to obtain the frequency response of asymmetric nonrecursive filters and make some general observations regarding initial point Savitzky-Golay filters. Some of the pitfalls associated with the implementation of these filters are discussed.

GENERAL CONSIDERATIONS The general mathematical expression for a nonrecursive filter is m2

y ( n ) = C ck x ( n + k ) k=-m,

(1)

where y ( n ) is the estimate of data point x ( n )and ck is the filter coefficient. It is understood that in order for this equation to be valid, data points must be equally spaced along the abscissa. For symmetric filters, ml = m2 so that an equal number of points on both sides of the point of interest are used in the estimate. This is the class of filters to which traditional Savitzky-Golay polynomial filters belong. Clearly, the first and last m 2points cannot be estimated with this type of filter. Initial point polynomial filters (2,3)are asymmetric with m 1= 0 and, therefore, allow estimation of the initial data point. Alternative values of ml and m2 may be used which allow estimation of other points, such as the second, third, or last. Extrapolation of the data is also possible by this method but is not recommended (see below). The method for calculating the coefficients for these filters is well-defined and described elsewhere ( 2 ) .

To obtain the frequency response of a nonrecursive filter, we first define the complex sinusoid x ( t ) = eiUt,where t is the measurement time ( t n ) and w is the angular frequency of the sinusoid. When this is substituted into eq 1, the result simplifies to

y ( t ) = ZeiQeiwt = Z,i(wt+m)

(2)

+ B sin 4

(3)

where

Z = A cos 4

$ = tan-l @ / A )

(4)

and

m,

B = C ck sin ( k w ) k=-m,

Clearly, the complex sinusoid is an eigenfunction of the filter equation, with eigenvalue Zei+. Therefore, the frequency response of the filter is given by

(5) A consequence of eq 5 is that the frequency response must be represented in terms of two variables, the amplitude response, Z, and the phase shift, 4, as given by eq 3 and 4, respectively. For symmetric smoothing filters, it can be shown that 4 is always zero, so that frequency response can be represented by the amplitude response alone. Strictly speaking, the phase shift for symmetric filters may be 0" or 180°, but the latter is indicated by a negative value in the amplitude response and not by 4. Likewise, for symmetric differentiating filters, the phase shift is always 90" or 270'. These simplifications are not valid for asymmetric filters, such as the initial point polynomial filters, whose phase response can vary widely over the frequency spectrum. Therefore, both the amplitude and phase responses are needed to characterize these filters completely. It should be noted that, in the frequency response equations developed above, units of frequency are normally expressed as fractions of the sampling frequency to ensure generality. With this convention, the Nyquist frequency (half the sampling frequency) provides the upper limit of the frequency response plots, since higher frequencies would simply cause the curve to be reflected about the Nyquist frequency due to aliasing.

RESULTS AND DISCUSSION Filter Characterization. In accordance with eq 3 and 4, Figures 1 and 2 show the amplitude and phase response of a typical initial point filter, in this case an 11-point quadratic smoothing filter. Also shown in the figures are the responses of a symmetric Savitzky-Golay 11-point quadratic smooth. Considering first the amplitude response shown in Figure 1, general similarities will be noted between the symmetric and asymmetric (initial point) filters. Both functions decrease

0003-2700/87/0359-0367$0 1.50/0 0 1987 American Chemical Society

368

ANALYTICAL CHEMISTRY, VOL. 59, NO. 2, JANUARY 1987 1

6

-0

2$-

-0

4G C

,

,

I

,

,

,

,

0 2

,

,

0 3

Frequency

,

30 5

9 4

Ratic

Figure 1. Amplitude response of initial point (top curve) and symmetric (lower curve) smoothing filters. Both are 11-point quadratic filters. B

O

,

,

,

,

,

,

I

,

I

,

,

f\ V

-10 - 2 0 , 0 0

~

; 0 1

;

i

0 2

F-equency

~

0 3

I 0 4

~

0 5

Ra’io

Figure 2. Phase response of initial point and symmetric smoothing filters (quadratic, 11 point). The symmetric filter gives the flat phase shift extending from 0’.

with increasing frequency, a feature that is indicative of high-frequency noise attenuation, and exhibit the oscillatory patterns characteristic of these types of f-ters. The differences are even more striking, however. Although both responses start at unity, as expected, the response of the symmetric filter steadily decreases, while that for the asymmetric filter first reaches a maximum of approximately 1.46 before it begins to fall. This implies that certain frequencies in the power spectrum of the signal are actually amplified by application of the initial point filter. These frequencies may correspond to components of the pure signal, the noise, or both. In the case of pure signal, distortions are introduced which are of a different nature from those caused by symmetric polynomial filters, since the latter always attenuate frequency components above dc. In the case of noise, certain frequencies in the noise spectrum will be amplified, possibly leading to erroneous results. Another characteristic of the initial point filter is that the amplitude response is always greater than that of the symmetric least-squares filter, suggesting that noise attenuation will be less for the former. This observation is corroborated from another perspective later. The phase response of the initial point filter, as shown in Figure 2, is completely different from that of the traditional Savitzky-Golay filter. The latter exhibits zero phase shift for all frequencies, so positional integrity in the time domain will be retained. This is not so for the initial point filter, which shows a wide variation in phase shifts. If the pure signal contains primarily low frequency components (less than about 0.07 of the sampling frequency for this filter), this is of little significance, since the phase shift remains close to zero at the

beginning, and only the higher frequency noise will be affected. The greater the high-frequency content of the pure signal, however, the greater will be the distortion in the time domain. This, coupled with the greater than unity amplitude response, suggests that these filters may distort data excessively and should be applied with care. Several factors will affect the frequency response of asymmetric least-squares filters, including the order of the polynomial, the number of points used, and the position of the point being estimated. Since the general frequency response equations have been given, the effects of these parameters will be discussed qualitatively in lieu of presenting an extensive set of graphs. The effect on filter order is considered first. In terms of the amplitude response, the effect of increasing the order of the polynomial fit is to move the first maximum to higher frequencies and generally raise the response curve to higher values. The latter effect means a reduction in the noise attenuation capabilities of the filter. The magnitude of the first maximum is also affected by the order of the filter, but the direction of the variation depends on the number of coefficients. The trend for low orders is for the height of the first maximum to increase with increasing order. In the limit of high orders, the amplitude response should become flat. The effect of increasing filter order on the phase response is to increase the frequency range for which the phase shift remains close to zero and to decrease the maximum phase shift observed. For example, the maximum phase shift for the while that for the quartic 11-point linear smooth is close to No, is around 25’. This would be a favorable sign were it not for the degradation of the amplitude response for higher orders. Another factor affecting the frequency response of the intial point polynomial filters is the number of coefficients used in the smooth. The effects of increasing the number of coefficients on the amplitude response are (1)to decrease the frequency at which the first maximum occurs and to increase its magnitude, (2) to increase the number of maxima/minima occurring and decrease their amplitude, and (3) to decrease values at higher frequencies. These observations correlate well with the behavior of symmetric polynomial filters. With respect to the phase response, the effects of increasing the number of coefficients are (1)to move the position of the maximum phase shift to lower frequencies (decreasing the range spent near 0’) and increase its magnitude and (2) to increase the number of maxima/minima observed. As previously mentioned, the asymmetric polynomial filter coefficients can be generated not only for the initial point but also for points not accessible with symmetric filters, such as the second or last point in a data set. Extrapolation can also be performed to estimate, for example, the “zeroth point, the point prior to the first datum acquired. The effect of these modifications on the frequency response is complex, but in general the frequency response is degraded as the point being estimated moves further from the center of the filter window. For example, the maximum amplitude response for the “zeroth” point quadratic smoothing filter with 11 coefficients is approximately 2.3, which is undesirably large. Because of such degradation in filter performance, extrapolations are not recommended, especially when higher order filters and relatively few points are employed. Estimation of points within the filter window is considerably more reliable but still may introduce distortions in the data. In addition to the initial point polynomial smoothing filters, a brief examination of the frequency response of initial slope (derivative) filters was also carried out. Similar effects are apparent in this case as for the smoothing filters, with undesirable features present in both the amplitude and phase spectra. Since derivative filters are more sensitive to highfrequency noise than smoothing filters (6, 7), it is likely that

ANALYTICAL CHEMISTRY, VOL. 59, NO. 2, JANUARY 1987

no. of coefficients 11

9

order of filter 2

2

13

2

11

1

offset from center

0 11

3

11

4

-5 0 -5 0

I

I

I I

I

Original

I I

I I

I

I

I

Data

-.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bout/ uin

1.098 0.762 0.528 0.455 0.813 0.505 0.719 0.418 0.564 0.302 0.889 0.455 0.958 0.577

-6 -5 -4 0 -4 0 -6 0 -5

I

I

Table I. Comparison of White Noise Attentuation for Various Types of Polynomial Smoothing Filters

369

h v)

.-c C

3

x

-. -

L

0 L

.-

4-

-

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . .S m . o. o .t h.e d. .1 . T .i m.e . . . . . . . . . . . . . . . . . . . . . . . .

.a L

0 v

Q 0 3

.-+s

-.

. . . . . . . . . . . . . . . . . . . _

.. .. .. .. .. .. .. .. .. . . . . . . . . . . . .. .. .. . .

-

S m o o t h e d 5 Times

- .. . ... ...... ... .... .. ... .... .. .... ..... .... ........ .... ........... .. .... ......... ... . ....

n

E

4

these changes in frequency response will have a greater effect on the results. This is demonstrated later with experimental data. A characteristic of asymmetric polynomial filters that should be pointed out is that they generally do not exhibit the redundancy with respect to order that is observed with their symmetric counterparts. For example, it is known that quadratic and cubic smoothing fiiters give identical frequency responses for the symmetric case, but this is not true for the asymmetric case. Another perspective from which filter performance can be evaluated is the extent to which white noise is attenuated when passed through the filter. If white noise of unit variance is passed through the filter, the variance of the output will be equal to the area of the square of the amplitude response curve (8). The variance of the output can also be shown to be equal to the sum of the squares of the filter coefficients (6); that is a2(output)/a2(input) =

Cck2 k

Thus, this ratio can be used as a criterion for judging the performance of the filter. While this should not be the sole means of evaluation (signal distortion is also important), it is a useful and rapid way to determine the extent of white noise removal by a filter. Table I shows the theoretical white noise gain of various smoothing filters, expressed in terms of the standard deviation of the output with a white noise input of unit variance. This is given as a function of the number of coefficients, the order of the filter, and the position of the point being estimated. The last value is given in terms of the offset from the central point. For example, when 11coefficients are used, the central point number is 6, so an offset of -5 refers to an initial point filter. The entries in Table I support the general observationsthat have already been made. Noise rejection capabilities of the filter are diminished by a number of factors, such as (1)increasing the distance of the point being estimated from the center of the window, (2) decreasing the number of coefficients, and (3) increasing the order of the filter. It will be noted that noise attenuation by the initial point filters is significantly poorer than for the symmetric counterparts. This means that the same signal-to-noise ratio (S/N) improvement should be the expected with and initial point filter as for a symmetric filter of the same type. Some initial point filters, such as the quartic 11-point smooth exhibit virtually no noise rejection. Also,extrapolation of the data to points before the initial point can even result in noise amplification. Effects on Data. Some conclusions can be drawn re-

1 I

I

I

I

1

Time

I

I

I

I

I

(arbitrary

I

I

I

t I

units)

Flgwe 3. Effect of repetitively smoothing a pure sinusoid. Asymmetric least-squares filters were employed near the edges of the data. A quadratic 11-point smoothing filter was used.

garding the manner in which asymmetric polynomial filters will affect data in the time domain. There are essentially two effects observed (1)distortions introduced by the greater than unity amplitude response and varying phase shift and (2) an increase in the noise level when compared to data processed with a symmetric filter of the same type. The distortions introduced by the asymmetric filters primarily affect the edges (beginning and end) of a set of data, since that is where these filters are applied. These distortions, henceforth referred to as “edge effects”, manifest themselves when correlated noise and/or actual signal components are present at the edges of the data in the frequency range which is adversely affected by the filter. Since phase relationships are of relatively little importance where pure noise is concerned, distortions in this case are introduced in the frequency range where the gain of the filter is greater than unity. For the pure signal present at the edges, distortions can arise from both amplitude and phase effects. The distortions introduced mean that data near the edges cannot be regarded as reliable in many circumstances. One use of the asymmetric polynomial filters that has been reported by Proctor and Sherwood (3) is in the repetitive filtering of data to improve noise rejection. The advantage of applying asymmetric filters at the edges of the data is that points are not lost after each repeated application of the filter. The result, however, is that distortions introduced by the asymmetric filters on the first pass are used by the normal symmetric filter on subsequent passes, so the distortions are “pulled” toward the center of the data set. The net affect is that the frequency attenuation characteristics of the symmetric filter work against the distortions introduced by the filters used at the edges. We have found that the effects of the symmetric filter predominate and the integrity of the central portion of data is maintained, at least to the extent that filtered data is reliable. Repetitive application of the filter continues to smooth distortions near the edges, but it is virtually impossible to remove the edge effects completely. The effects of repetitive filtering are illustrated in Figures 3 and 4. Figure 3 shows the effect of repetitively filtering a sine wave with a quadratic 11-point filter, with application

370

ANALYTICAL CHEMISTRY, VOL. 59, NO. 2, JANUARY 1987 3.

I

I

I

I

0.5

t 2

-

1

t

a,

1

I

i

i

‘I-

c

4

3 4

v

0

0.3

2 C

0

n 0.2 Q

-’ -2

tt t

-3

0 L1

n

< 0.1

I

I

I

I

20

40

60

80

1

0.0

~

0

Point

1

GO

Ndrnoer

Flgure 4. Results of repetitively smoothing white noise. The points shown are the original data, the s o l i line is the result of smoothing 20 times with a quadratic 1l-point filter, and the dashed line is the result of 100 passes with the same filter.

a!

Initial Doint Filter ( o f f s e t 0.1 AU/sec)

VI

\ 3 4

v

of the asymmetric versions at the edges. The frequency of the sine wave is one-tenth of the sampling frequency, which is near the maximum amplitude response of the initial point filter. After one pass of the filter, the phase and amplitude distortions a t the edges are clearly evident. Note that the amplitude of the filtered signal at the right-hand edge is even greater than the amplitude of the original sine wave. The figure also shows that repetitive smoothing does not efficiently remove these edge effects. Figure 4 demonstrates that the edge effects observed in Figure 3 can also arise from short range correlations in white noise. The points in Figure 4 are 100 computer-generated samples of Gaussian white noise with unit variance. Repetitive smoothing of these points was undertaken with a quadratic 11-point polynomial filter. The smoothed data after 20 and 100 passes are shown. Note that while the major portion of the data becomes increasingly flat as the number of passes increases, there is very little effect close to the edges. This is the same effect that was observed by Proctor and Sherwood (3)and is expected to occur in all cases of such repetitive filter application. The effect of asymmetric filters on the attenuation of white noise has already been noted (see Table I) and it has been shown that the variance of the output is greater than for the comparable symmetric filter. In terms of the effect on real data, this means that points near the edges will have a greater variance than the points in the middle. This may be of little importance with smoothing applications, but it should be noted that the effects become more pronounced as higher order derivatives are taken. This is illustrated in Figure 5 . Figure 5a shows an experimental reaction curve obtained on an automated stopped-flow spectrophotometer (9). Four hundred data points were acquired at 10-ms intervals during the course of the experiment. Figure 5b shows the derivative of these data as calculated with two 21-point quadratic filters, a symmetric Savitzky-Golay filter and an initial point Savitzky-Golay filter. The distortion introduced by these filters is negligible, since the filter window is quite small relative to the time constant, but it is clear that the noise level for the initial point filter is much greater. A nonlinear least-squares fit of the original data provided parameters for the curve. This allowed calculation of the standard deviation (SD) for both derivative curves. The theoretical ratio (SD(initia1 pt)/SD(symmetric)) is 3.8, while the experimental value is 2.4. The difference is probably because the noise in the original signal was not white. In any case, it is apparent that the performance

0.3

0

0.2

I

U

\ 4

0.1

0.0 0

2

1

Time

3

4

(sec)

Figure 5. (a)Experimentally obtained exponential reaction curve. (b) Numerically obtained derivatives of curve a. Initial point and symmetric filters were used (quadratic, 21 point).

of the initial slope filter is worse than one would anticipate on the basis of the symmetric derivative filter. It also explains why our attempts to use the initial slope filter for the estimation of initial reaction rates was not entirely successful. In order to obtain the same signal-to-noise ratio for the initial slope filter as for the symmetric derivative filter, either the number of coefficients would have to be increased or the order of the filter would have to be decreased. Both of these methods would be more likely to distort the data. There are two general circumstances under which it is useful to employ the asymmetric polynomial filters discussed here. The first is where the content of the edges of the data is relatively unimportant with regard to the central points, but it is desired to retain these data nevertheless. This was the case with the results obtained by Proctor and Sherwood ( 3 ) , who applied the filters to X-ray photoelectron spectra. As long as the edges of the data are not considered very reliable, this is a reasonably safe application. The other situation to which the asymmetric filters may be applied is where the value obtained from the filter is of primary importance. This is the case in our work, where we wish t o estimate the initial slope of a reaction curve. Because of the importance of the initial data in these circumstances, the potential distortions and poorer noise rejection of asymmetric polynomial filters are of special concern. To summarize, the findings of this study are (1)asymmetric polynomial filters can distort data where they are applied and should be used with caution, (2) the edge effects introduced by the application of asymmetric polynomial filters are only slightly affected by repetitive filtering, (3) noise attenuation by these filters is generally poorer than for their symmetric counterparts and is especially bad for derivative filters, and (4) extrapolation of the data with these filters, especially beyond one point, is not recommended. In short, asymmetric

Anal. Chem. 1907,5 9 , 371-373

polynomial filters are useful if no other option, such as ensemble averaging, exists but should be applied with care and will not generally perform as well as symmetric polynomial filters.

LITERATURE CITED (1) Savitzky, A.; Golay, M. J. E. Anal. Chem. 1864, 36, 1627-1639. (2) . . Leach, R. A.; Carter, C. A.; Harris, J. M. Anal. Chem. 1984, 56, 2304-2307. (3) Proctor, A,; Sherwood, P. M. A. Anal. Chem. 1980, 52,2315-2321. (4) Nevlus, T. A.; Pardue, H. L. Anal. Chem. 1084, 56,2249-2251. (5) Jagannathan, S.; Patel, R. C. Anal. Chem. 1866, 58,421-427. (6) Harnrnlng, R. W. Dgfial Filters; Prentlce-Hall: Englewood Cliffs NJ, 1983. (7) Horlick, G. Anal. Chem. 1972, 4 4 , 943-947. (8) Otnes, R. K.; Enochson, L. Digfial Time Series Analysis; Wiley: New York, 1972.

37 1

(9) Beckwlth, P. M.; Crouch, S. R. Anal. Chem. 1972, 4 4 , 221-227.

Peter D. Wentzell Thomas P. Doherty S. R. Crouch* Department of Chemistry Michigan State University East Lansing, Michigan 48824 RECEIVED for review July 29, 1986. Accepted September 23, 1986. The authors gratefully acknowledge the financial support of the National Science Foundation through NSF Grant No. CHE 8320620 and the Natural Sciences and Engineering Research Council of Canada through an NSERC Graduate Fellowship (P.D.W.).

Polymer Investigations with the Laser Microprobe Sir: The laser microprobe is gaining a place in organic microspot analysis. It has been used with good results where it has been necessary to identify low molecular weight substances with high spatial resolution ( I , 2). In contrast, the investigation of polymers by this method is just beginning. The reason for this is that too few systematic investigations of the fragmentation behavior of polymers under laser bombardment have been undertaken. Most of the published investigations have been restricted to comparing spectra by the fingerprint method or have merely attempted to interpret the spectra in the mass range mle 400. Sometimes, we found that the mass differences corresponded to the monomer unit. The effects were not reproducible, however. It could be that the investigated polymers contained a certain amount of oligomers in the mass range concerned. This was undoubtedly the case with the aforementioned polyamide 6 sample. A methanol extract was prepared and

washed with water to remove most of the lactam and the dimer and to enrich the higher oligomers. The residual white powder constituted about 0.05% of the original material. The molecular weight distribution as determined by HPLC is given in Figure 1. The laser microprobe spectrum (Figure 2) shows reproducibly multiples of the monomer unit (up to 7-fold) cationized with Na. The intensities even reflect approximately the quantities from the molecular weight distribution. We therefore started to investigate spectra of other oligomers. In each case it was found that two types of ions are formed: (a) fragment ions of mle