Tf2zp.java

/*
 * $Id: Tf2zp.java,v 1.25 2008/03/24 14:57:16 koga Exp $
 *
 * Copyright (C) 2004 Koga Laboratory. All rights reserved.
 */
package org.mklab.tool.control;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.mklab.nfc.matrix.DoubleComplexMatrix;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.scalar.DoubleNumber;
import org.mklab.nfc.scalar.DoublePolynomial;


/**
 * 伝達関数(係数からなる行列)から極とゼロ点の集合に変換するクラスです。
 * 
 * <p>Transfer function to zero-pole conversion
 * 
 * @author koga
 * @version $Revision: 1.25 $
 * @see org.mklab.tool.control.Tf2tfn
 * @see org.mklab.tool.control.Tf2ss
 * @see org.mklab.tool.control.Tf2tfm
 * @see org.mklab.tool.control.Zp2tf
 */
public class Tf2zp {

  /**
   * 1入力多出力システム
   * 
   * <pre><code> NUM(s) (s-z1)(s-z2)...(s-zn) G(s) = ------- = K --------------------- den(s) (s-p1)(s-p2)...(s-pn) </code></pre>
   * 
   * のゼロ点<code>z</code>、極<code>p</code>、ゲイン<code>k</code>を求めます。
   * 
   * @param numerator 伝達関数の分子多項式の係数 (coefficients of the numerator)
   * @param deniminator 伝達関数の分母多項式の係数 (coefficients of the denominator)
   * @return {z, po, k} (ゼロ点, 極, ゲイン) (zeros, poles, gains)
   */
  public static List<DoubleComplexMatrix> tf2zp(DoubleMatrix numerator, DoubleMatrix deniminator) {
    DoubleComplexMatrix p = new DoublePolynomial(deniminator).getRoots();
    int np = numerator.getRowSize();
    int nn = numerator.getColumnSize();

    DoubleMatrix k = numerator.createOnes(np, 1);
    DoubleNumber unit = k.getElement(1, 1);
    DoubleComplexMatrix z = new DoubleComplexMatrix(numerator.createOnes(nn, np).multiply(unit.getInfinity()));

    for (int i = 1; i <= np; i++) {
      DoublePolynomial num = new DoublePolynomial(numerator.getRowVector(i));
      int deg = num.getDegree();
      if (1 <= deg) {
        z.setSubMatrix(1, deg, i, i, num.getRoots());
      }
      k.setElement(i, num.getCoefficient(num.getDegree()));
    }

    return new ArrayList<>(Arrays.asList(new DoubleComplexMatrix[] {z, p, new DoubleComplexMatrix(k)}));
    //return new MatxList(new Object[] {z, p, k});
  }

}