equal
deleted
inserted
replaced
|
1 #!/usr/bin/python |
|
2 # 10.3 |
|
3 |
|
4 import scipy as sp |
|
5 |
|
6 def imcsplit(B, polynomial): |
|
7 """ Splits a polynomial B into good, nonminimum with |
|
8 positive real & with negative real parts. |
|
9 All are returned in polynomial form. |
|
10 Gain is returned in Kp and delay in k.""" |
|
11 k = 0 |
|
12 Kp = 1 |
|
13 if polynomial: |
|
14 roots = sp.roots(B) |
|
15 Kp = sum(B)/sum(sp.poly(roots)) |
|
16 else: |
|
17 roots = B |
|
18 Bg, Bnmp, Bm = sp.array([1]), sp.array([1]), sp.array([1]) |
|
19 for root in roots: |
|
20 if root == 0: |
|
21 k += 1 |
|
22 elif abs(root)<1 and root.real>=0: |
|
23 Bg = sp.convolve(Bg, [1, -root]) |
|
24 elif abs(root)>=1 and root.real>=0: |
|
25 Bnmp = sp.convolve(Bnmp, [1, -root]) |
|
26 else: |
|
27 Bm = sp.convolve(Bm, [1, -root]) |
|
28 return Kp, k, Bg, Bnmp, Bm |