summaryrefslogtreecommitdiff
path: root/macros/zp2sos.sci
blob: 6bb9426724ccbbdff2d6643b6b1ce599ac2f6ad9 (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
function [sos,g] = zp2sos(z,p,k)
//This function converts filter poles and zeros to second-order sections.
//Calling Sequence
//[sos] = zp2sos(z)
//[sos] = zp2sos(z, p)
//[sos] = zp2sos(z, p, k)
//[sos, g] = zp2sos(...)
//Parameters 
//z: column vector
//p: column vector
//k: real or complex value, default value is 1
//Description
//This is an Octave function.
//This function converts filter poles and zeros to second-order sections.
//The first and second parameters are column vectors containing zeros and poles. The third parameter is the overall filter gain, the default value of which is 1.
//The output is the sos matrix and the overall gain.
//If there is only one output argument, the overall filter gain is applied to the first second-order section in the sos matrix.
//Examples
//zp2sos([1, 2, 3], 2, 6)
//ans =
//    6  -18   12    1   -2    0
//    1   -3    0    1    0    0


funcprot(0);
rhs = argn(2)
lhs = argn(1)
if(rhs<1 | rhs>3)
error("Wrong number of input arguments.")
end
	select(rhs)
	case 1 then
	if (lhs<2) 
	sos=callOctave("zp2sos",z)
	else
	[sos,g]=callOctave("zp2sos",z)
	end
	case 2 then
	if(lhs<2)
	[sos]=callOctave("zp2sos",z,p)
	else
	[sos,g]=callOctave("zp2sos",z,p)
	end
	case 3 then
	if(lhs<2)
	sos=callOctave("zp2sos",z,p,k)
	else
	[sos,g]=callOctave("zp2sos",z,p,k)
	end
	end
endfunction