summaryrefslogtreecommitdiff
path: root/macros/sos2tf.sci
diff options
context:
space:
mode:
Diffstat (limited to 'macros/sos2tf.sci')
-rw-r--r--macros/sos2tf.sci43
1 files changed, 32 insertions, 11 deletions
diff --git a/macros/sos2tf.sci b/macros/sos2tf.sci
index d38a4f7..f674c85 100644
--- a/macros/sos2tf.sci
+++ b/macros/sos2tf.sci
@@ -1,4 +1,4 @@
-function [B,A] = sos2tf(sos, g)
+function [A,B] = sos2tf(sos, g)
//This function converts series second-order sections to direct H(z) = B(z)/A(z) form.
//Calling Sequence
//[B] = sos2tf(sos)
@@ -8,7 +8,6 @@ function [B,A] = sos2tf(sos, g)
//sos: matrix of real or complex numbers
//g: real or complex value, default value is 1
//Description
-//This is an Octave function.
//This function converts series second-order sections to direct H(z) = B(z)/A(z) form.
//The input is the sos matrix and the second parameter is the overall gain, default value of which is 1.
//The output is a vector.
@@ -19,18 +18,40 @@ function [B,A] = sos2tf(sos, g)
// -2 1 2 4 1
//b =
// 1 10 0 -10 -1
-funcprot(0);
-rhs = argn(2)
-if(rhs<1 | rhs>2)
+if(argn(2)<1 | argn(2)>2)
error("Wrong number of input arguments.")
end
+if argn(2)==1 then
+ g=1;
+end
+
+ [N,M] = size(sos);
+
+ if M~=6
+ error('sos matrix must be N by 6');
+ end
+
+ A = 1;
+ B = 1;
+
+ for i=1:N
+ A = conv(A, sos(i,1:3));
+ B = conv(B, sos(i,4:6));
+ end
+
+ nB = length(A);
+
+ while nB & A(nB)==0
+ A=A(1:nB-1);
+ nB=length(A);
+ end
+ nA = length(B);
+ while nA & B(nA)==0
+ B=B(1:nA-1);
+ nA=length(B);
+ end
+ A = A * g;
- select(rhs)
- case 1 then
- [B,A] = callOctave("sos2tf",sos)
- case 2 then
- [B,A] = callOctave("sos2tf",sos,g)
- end
endfunction