Purpose
To solve the least-squares filtering problem recursively in time. Each subroutine call implements one time update of the solution. The algorithm uses a fast QR-decomposition based approach.Specification
SUBROUTINE FD01AD( JP, L, LAMBDA, XIN, YIN, EFOR, XF, EPSBCK, $ CTETA, STETA, YQ, EPOS, EOUT, SALPH, IWARN, $ INFO ) C .. Scalar Arguments .. CHARACTER JP INTEGER INFO, IWARN, L DOUBLE PRECISION EFOR, EOUT, EPOS, LAMBDA, XIN, YIN C .. Array Arguments .. DOUBLE PRECISION CTETA(*), EPSBCK(*), SALPH(*), STETA(*), XF(*), $ YQ(*)Arguments
Mode Parameters
JP CHARACTER*1 Indicates whether the user wishes to apply both prediction and filtering parts, as follows: = 'B': Both prediction and filtering parts are to be applied; = 'P': Only the prediction section is to be applied.Input/Output Parameters
L (input) INTEGER The length of the impulse response of the equivalent transversal filter model. L >= 1. LAMBDA (input) DOUBLE PRECISION Square root of the forgetting factor. For tracking capabilities and exponentially stable error propagation, LAMBDA < 1.0 (strict inequality) should be used. 0.0 < LAMBDA <= 1.0. XIN (input) DOUBLE PRECISION The input sample at instant n. (The situation just before and just after the call of the routine are denoted by instant (n-1) and instant n, respectively.) YIN (input) DOUBLE PRECISION If JP = 'B', then YIN must contain the reference sample at instant n. Otherwise, YIN is not referenced. EFOR (input/output) DOUBLE PRECISION On entry, this parameter must contain the square root of exponentially weighted forward prediction error energy at instant (n-1). EFOR >= 0.0. On exit, this parameter contains the square root of the exponentially weighted forward prediction error energy at instant n. XF (input/output) DOUBLE PRECISION array, dimension (L) On entry, this array must contain the transformed forward prediction variables at instant (n-1). On exit, this array contains the transformed forward prediction variables at instant n. EPSBCK (input/output) DOUBLE PRECISION array, dimension (L+1) On entry, the leading L elements of this array must contain the normalized a posteriori backward prediction error residuals of orders zero through L-1, respectively, at instant (n-1), and EPSBCK(L+1) must contain the square-root of the so-called "conversion factor" at instant (n-1). On exit, this array contains the normalized a posteriori backward prediction error residuals, plus the square root of the conversion factor at instant n. CTETA (input/output) DOUBLE PRECISION array, dimension (L) On entry, this array must contain the cosines of the rotation angles used in time updates, at instant (n-1). On exit, this array contains the cosines of the rotation angles at instant n. STETA (input/output) DOUBLE PRECISION array, dimension (L) On entry, this array must contain the sines of the rotation angles used in time updates, at instant (n-1). On exit, this array contains the sines of the rotation angles at instant n. YQ (input/output) DOUBLE PRECISION array, dimension (L) On entry, if JP = 'B', then this array must contain the orthogonally transformed reference vector at instant (n-1). These elements are also the tap multipliers of an equivalent normalized lattice least-squares filter. Otherwise, YQ is not referenced and can be supplied as a dummy array (i.e., declare this array to be YQ(1) in the calling program). On exit, if JP = 'B', then this array contains the orthogonally transformed reference vector at instant n. EPOS (output) DOUBLE PRECISION The a posteriori forward prediction error residual. EOUT (output) DOUBLE PRECISION If JP = 'B', then EOUT contains the a posteriori output error residual from the least-squares filter at instant n. SALPH (output) DOUBLE PRECISION array, dimension (L) The element SALPH(i), i=1,...,L, contains the opposite of the i-(th) reflection coefficient for the least-squares normalized lattice predictor (whose value is -SALPH(i)).Warning Indicator
IWARN INTEGER = 0: no warning; = 1: an element to be annihilated by a rotation is less than the machine precision (see LAPACK Library routine DLAMCH).Error Indicator
INFO INTEGER = 0: successful exit; < 0: if INFO = -i, the i-th argument had an illegal value.Method
The output error EOUT at instant n, denoted by EOUT(n), is the reference sample minus a linear combination of L successive input samples: L-1 EOUT(n) = YIN(n) - SUM h_i * XIN(n-i), i=0 where YIN(n) and XIN(n) are the scalar samples at instant n. A least-squares filter uses those h_0,...,h_{L-1} which minimize an exponentially weighted sum of successive output errors squared: n SUM [LAMBDA**(2(n-k)) * EOUT(k)**2]. k=1 Each subroutine call performs a time update of the least-squares filter using a fast least-squares algorithm derived from a QR decomposition, as described in references [1] and [2] (the notation from [2] is followed in the naming of the arrays). The algorithm does not compute the parameters h_0,...,h_{L-1} from the above formula, but instead furnishes the parameters of an equivalent normalized least-squares lattice filter, which are available from the arrays SALPH (reflection coefficients) and YQ (tap multipliers), as well as the exponentially weighted input signal energy n L SUM [LAMBDA**(2(n-k)) * XIN(k)**2] = EFOR**2 + SUM XF(i)**2. k=1 i=1 For more details on reflection coefficients and tap multipliers, references [2] and [4] are recommended.References
[1] Proudler, I. K., McWhirter, J. G., and Shepherd, T. J. Fast QRD based algorithms for least-squares linear prediction. Proceedings IMA Conf. Mathematics in Signal Processing Warwick, UK, December 1988. [2] Regalia, P. A., and Bellanger, M. G. On the duality between QR methods and lattice methods in least-squares adaptive filtering. IEEE Trans. Signal Processing, SP-39, pp. 879-891, April 1991. [3] Regalia, P. A. Numerical stability properties of a QR-based fast least-squares algorithm. IEEE Trans. Signal Processing, SP-41, June 1993. [4] Lev-Ari, H., Kailath, T., and Cioffi, J. Least-squares adaptive lattice and transversal filters: A unified geometric theory. IEEE Trans. Information Theory, IT-30, pp. 222-236, March 1984.Numerical Aspects
The algorithm requires O(L) operations for each subroutine call. It is backward consistent for all input sequences XIN, and backward stable for persistently exciting input sequences, assuming LAMBDA < 1.0 (see [3]). If the condition of the signal is very poor (IWARN = 1), then the results are not guaranteed to be reliable.Further Comments
1. For tracking capabilities and exponentially stable error propagation, LAMBDA < 1.0 should be used. LAMBDA is typically chosen slightly less than 1.0 so that "past" data are exponentially forgotten. 2. Prior to the first subroutine call, the variables must be initialized. The following initial values are recommended: XF(i) = 0.0, i=1,...,L EPSBCK(i) = 0.0 i=1,...,L EPSBCK(L+1) = 1.0 CTETA(i) = 1.0 i=1,...,L STETA(i) = 0.0 i=1,...,L YQ(i) = 0.0 i=1,...,L EFOR = 0.0 (exact start) EFOR = "small positive constant" (soft start). Soft starts are numerically more reliable, but result in a biased least-squares solution during the first few iterations. This bias decays exponentially fast provided LAMBDA < 1.0. If sigma is the standard deviation of the input sequence XIN, then initializing EFOR = sigma*1.0E-02 usually works well.Example
Program Text
* FD01AD EXAMPLE PROGRAM TEXT * Copyright (c) 2002-2017 NICONET e.V. * * .. Parameters .. INTEGER NIN, NOUT, NOUT1 PARAMETER ( NIN = 5, NOUT = 6, NOUT1 = 7 ) DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 ) INTEGER IMAX, LMAX PARAMETER ( IMAX = 500, LMAX = 10 ) DOUBLE PRECISION LAMBDA PARAMETER ( LAMBDA = 0.99D0 ) * .. Local Scalars .. CHARACTER JP INTEGER I, INFO, IWARN, L DOUBLE PRECISION DELTA, EFOR, EOUT, EPOS, XIN, YIN * .. Local Arrays .. DOUBLE PRECISION CTETA(LMAX), EPSBCK(LMAX+1), SALPH(LMAX), $ STETA(LMAX), XF(LMAX), YQ(LMAX) * .. External Functions .. DOUBLE PRECISION XFCN, YFCN EXTERNAL XFCN, YFCN * NOTE: XFCN() generates at each iteration the next sample of the * input sequence. YFCN() generates at each iteration the next * sample of the reference sequence. These functions are user * defined (obtained from data acquisition devices, for * example). * .. External Subroutines .. EXTERNAL FD01AD * * .. File for the output error sequence .. OPEN ( UNIT = NOUT1, FILE = 'ERR.OUT', STATUS = 'REPLACE' ) * .. Executable Statements .. * WRITE ( NOUT, FMT = 99999 ) * Skip the heading in the data file and read the data. READ ( NIN, FMT = '()' ) READ ( NIN, FMT = * ) L, DELTA, JP IF ( L.LE.0 .OR. L.GT.LMAX ) THEN WRITE ( NOUT, FMT = 99992 ) L ELSE IF ( DELTA.LT.ZERO ) THEN WRITE ( NOUT, FMT = 99991 ) ELSE * DO 10 I = 1, L CTETA(I) = ONE STETA(I) = ZERO EPSBCK(I) = ZERO XF(I) = ZERO YQ(I) = ZERO 10 CONTINUE EPSBCK(L+1) = ONE EFOR = DELTA * .. Run least squares filter. DO 20 I = 1, IMAX XIN = XFCN(I) YIN = YFCN(I) CALL FD01AD( JP, L, LAMBDA, XIN, YIN, EFOR, XF, EPSBCK, $ CTETA, STETA, YQ, EPOS, EOUT, SALPH, IWARN, $ INFO) WRITE(NOUT1,*) EOUT 20 CONTINUE CLOSE(NOUT1) * NOTE: File 'ERR.OUT' now contains the output error * sequence. * IF ( INFO.NE.0 ) THEN WRITE ( NOUT, FMT = 99998 ) INFO ELSE WRITE ( NOUT, FMT = 99997 ) DO 30 I = 1, L WRITE ( NOUT, FMT = 99996 ) I, XF(I), YQ(I), EPSBCK(I) 30 CONTINUE WRITE ( NOUT, FMT = 99995 ) L+1, EPSBCK(L+1) WRITE ( NOUT, FMT = 99994 ) EFOR IF ( IWARN.NE.0 ) THEN WRITE ( NOUT, FMT = 99993 ) IWARN END IF END IF END IF END IF STOP * 99999 FORMAT (' FD01AD EXAMPLE PROGRAM RESULTS', /1X) 99998 FORMAT (' INFO on exit from FD01AD = ', I2) 99997 FORMAT (' i', 7X, 'XF(i)', 7X, 'YQ(i)', 6X, 'EPSBCK(i)', /1X) 99996 FORMAT ( I3, 2X, 3(2X, F10.6)) 99995 FORMAT ( I3, 28X, F10.6, /1X) 99994 FORMAT (' EFOR = ', D10.3) 99993 FORMAT (' IWARN on exit from FD01AD = ', I2) 99992 FORMAT (/' L is out of range.',/' L = ',I5) 99991 FORMAT (/' The exponentially weighted forward prediction error', $ ' energy must be non-negative.' ) * END * * .. Example functions .. * DOUBLE PRECISION FUNCTION XFCN( I ) * .. Intrinsic Functions .. INTRINSIC DBLE, SIN * .. Local Scalar .. INTEGER I * .. Executable Statements .. XFCN = SIN( 0.3D0*DBLE( I ) ) * *** Last line of XFCN *** END * DOUBLE PRECISION FUNCTION YFCN( I ) * .. Intrinsic Functions .. INTRINSIC DBLE, SIN * .. Local Scalar .. INTEGER I * .. Executable Statements .. YFCN = 0.5D0 * SIN( 0.3D0*DBLE( I ) ) + $ 2.0D0 * SIN( 0.3D0*DBLE( I-1 ) ) * *** Last line of YFCN *** ENDProgram Data
FD01AD EXAMPLE PROGRAM DATA 2 1.0D-2 BProgram Results
FD01AD EXAMPLE PROGRAM RESULTS i XF(i) YQ(i) EPSBCK(i) 1 4.880088 12.307615 -0.140367 2 -1.456881 2.914057 -0.140367 3 0.980099 EFOR = 0.197D-02