summaryrefslogtreecommitdiff
path: root/macros/sos2zp.sci
blob: 1f0f33521be9ebe49baa32c1669da197a2a9150a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [z,p,k] = sos2zp (sos, g)
//This function converts series second-order sections to zeros, poles, and gains (pole residues).
//Calling Sequence
//z = sos2zp (sos)
//z = sos2zp (sos, g)
//[z, p] = sos2zp (...)
//[z, p, k] = sos2zp (...)
//Parameters 
//sos: matrix of real or complex numbers
//g: real or complex value, default value is 1
//z: column vector
//p: column vector
//Description
//This function converts series second-order sections to zeros, poles, and gains (pole residues).
//The input is the sos matrix and the second parameter is the overall gain, default value of which is 1.
//The outputs are z, p, k. z and p are column vectors containing zeros and poles respectively, and k is the overall gain. 
//Examples
//[a,b,c]=sos2zp([1,2,3,4,5,6])
//a =
//  -1.0000 + 1.4142i
//  -1.0000 - 1.4142i
//b =
//  -0.6250 + 1.0533i
//  -0.6250 - 1.0533i
//c =  1
if(argn(2)<1 | argn(2)>2)
error("Wrong number of input arguments.")
end
if argn(2)==1 then
    g=1;
end
  gns = sos(:,1); 
  k = prod(gns)*g; 
  if k==0 then
     error('one or more section gains is zero'); 
     end
  sos(:,1:3) = sos(:,1:3)./ [gns gns gns];

  [N,m] = size(sos);
  if m~=6 then
      error('sos matrix should be N by 6'); 
      end

  z = zeros(2*N,1);
  p = zeros(2*N,1);
  for i=1:N
    ndx = [2*i-1:2*i];
    zi = roots(sos(i,1:3));
    z(ndx) = zi;
    pi = roots(sos(i,4:6));
    p(ndx) = pi;
  end

endfunction