Frequency Domain Computations

Todo

Finish this section with examples

To be able to do usable transfer functions, some care should be given to polynomial operations. The least common multiples and greatest common divisors are of the utmost importance.

Thus, harold offers a system-theory inspired method to compute the LCM and GCD with a modified version of [1]. I would appreciate ill-conditioned examples and/or fails or much better methods.

harold.haroldlcm(*args, *, compute_multipliers=True, cleanup_threshold=1e-09)

Takes n-many 1D numpy arrays and computes the numerical least common multiple polynomial. The polynomials are assumed to be in decreasing powers, e.g. s^2 + 5 should be given as numpy.array([1,0,5])

Returns a numpy array holding the polynomial coefficients of LCM and a list, of which entries are the polynomial multipliers to arrive at the LCM of each input element.

For the multiplier computation, a variant of Karcanias, Mitrouli, System theoretic based characterisation and computation of the least common multiple of a set of polynomials, Lin Alg App, 381, 2004, is used.

Parameters:
  • args (1D Numpy array) –
  • compute_multipliers (boolean) – After the computation of the LCM, this switch decides whether the multipliers of the given arguments should be computed or skipped. A multiplier in this context is [1,3] for the argument [1,2] if the LCM turns out to be [1,5,6].
  • cleanup_threshold (float) – The computed polynomials might contain some numerical noise and after finishing everything this value is used to clean up the tiny entries. Set this value to zero to turn off this behavior. The default value is \(10^{-9}\).
Returns:

  • lcmpoly (1D Numpy array) – Resulting polynomial coefficients for the LCM.
  • mults (List of 1D Numpy arrays) – The multipliers for each given argument.

Example

>>>> a , b = haroldlcm(*map(np.array,([1,3,0,-4],[1,-4,-3,18],[1,-4,3],[1,-2,-8])))
>>>> a
    (array([   1.,   -7.,    3.,   59.,  -68., -132.,  144.])

>>>> b
    [array([  1., -10.,  33., -36.]),
     array([  1.,  -3.,  -6.,   8.]),
     array([  1.,  -3., -12.,  20.,  48.]),
     array([  1.,  -5.,   1.,  21., -18.])]

>>>> np.convolve([1,3,0,-4],b[0]) # or haroldpolymul() for poly mult
    (array([   1.,   -7.,    3.,   59.,  -68., -132.,  144.]),
harold.haroldgcd(*args)

Takes 1D numpy arrays and computes the numerical greatest common divisor polynomial. The polynomials are assumed to be in decreasing powers, e.g. \(s^2 + 5\) should be given as numpy.array([1,0,5]).

Returns a numpy array holding the polynomial coefficients of GCD. The GCD does not cancel scalars but returns only monic roots. In other words, the GCD of polynomials \(2\) and \(2s+4\) is still computed as \(1\).

Parameters:args (1D Numpy arrays) –
Returns:gcdpoly
Return type:1D Numpy array

Example

>>>> a = haroldgcd(*map(haroldpoly,([-1,-1,-2,-1j,1j],[-2,-3,-4,-5],[-2]*10)))
>>>> a
     array([ 1.,  2.])

Warning

It uses the LU factorization of the Sylvester matrix. Use responsibly. It does not check any certificate of success by any means (maybe it will in the future). I have played around with ERES method but probably due to my implementation, couldn’t get satisfactory results. Hence I’ve switched to matrix-based methods. I am still interested in better methods though, so please contact me if you have a working implementation that improves over this.

[1]N. Karcanias, M. Mitrouli, System theoretic based characterisation and computation of the least common multiple of a set of polynomials, Linear Algebra and its Applications 381, 2004, DOI