summaryrefslogtreecommitdiff
path: root/macros/tf2sos.sci
blob: 7570707c3968dafdfdc2cf13731435af97e76e5f (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
function [sos,varargout] = tf2sos (b, a)
//This function converts direct-form filter coefficients to series second-order sections.
//Calling Sequence
//[sos] = tf2sos (b, a)
//[sos, g] = tf2sos (b, a)
//Parameters 
//b: matrix of real numbers
//a: matrix of real numbers 
//Description
//This is an Octave function.
//This function converts direct-form filter coefficients to series second-order sections.
//The input parameters b and a are vectors specifying the digital filter H(z) = B(z)/A(z). 
//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
//tf2sos([1,2,3,4,5,6],2)
//ans =
//   0.50000   0.80579   1.07239   1.00000   0.00000   0.00000
//   1.00000  -1.10337   1.87524   1.00000   0.00000   0.00000
//   1.00000   1.49180  -0.00000   1.00000   0.00000   0.00000

funcprot(0);
rhs = argn(2)
lhs = argn(1)

if(rhs~=2)
error("Wrong number of input arguments.")
end
	select(lhs)
	case 1 then
	sos = callOctave("tf2sos",b,a)
	case 2 then
	[sos,g] = callOctave("tf2sos",b,a)
	end
endfunction