%N lagwt %F $MIR/src/subs/lagwt.for
%P rjs
%: atca
%B
        subroutine LagWt(wts,nwts,fac)

        implicit none
        integer nwts
        real wts(nwts),fac

  This subroutine determines the "optimum" lag re-weighting scheme to
  apply to ATCA continuum data to eliminate the so-called Gibbs problem.

  Inputs:
    nwts       Total number of lag weights. For the 33-channel continuum
               system, nwts will be 64.
    fac        Spectral impulse response width. This gives the half-width
               of the spectral impulse response, in units of normalised
               frequency,i.e. in the range (0,0.5).
  Output:
    wts        The factors to re-weight the lag spectrum by.

  This subroutine finds the lag weights that minimises the absolute
  maximum spectral sidelobe outside the response of the main lobe.
  This is a minimax problem, akin to the filter design procedures
  of McClellan and Parks. The software here reforms the problem
  as a minimax one of finding coefficients a_i of the function

    f(theta) = Sum_i (  a_i * (cos(i*theta) - 1) )

  which make f(theta) approximate -1 in the range of theta
  [2*pi*fac,pi].

  This minimax problem is solved using a Remez exchange algorithm.
  The functions (cos(i*theta)-1) are tabulated in a lookup table.

  The coefficients are then converted back to the appropriate
  lag re-weighting coefficients, and placed in the output array
  in the folded order produced by the FFT routines (the data will
  be in this order after they are FFTed back to the lag domain).

  References
    McClellan J.H., Parks and Rabiner, 1975, "A computer program for
    designing optimum FIR linear phase digital filters", IEEE Transc
    Audio Electroacoustics, vol AU-21, p 506-526.

    Rabiner and Gold, 1975, Theory and Application of Digital Signal
    Processing, Prentice-Hall.

    Cheney, E.W., 1966, Introduction to Approximation Theory, McGraw-Hill,
    NY.
