diff options
author | ttt | 2018-12-06 13:02:48 +0530 |
---|---|---|
committer | ttt | 2018-12-06 13:02:48 +0530 |
commit | 3ffa5ac619587eadfdb4ffd3e2fee57fee385e21 (patch) | |
tree | 8ed1a41fc2814d53d60bc4e091a1458350482662 /macros/sos2zp.sci | |
parent | 0ee5488b9c99cdd0d631d97cd1de566a8785ffae (diff) | |
download | FOSSEE-Signal-Processing-Toolbox-3ffa5ac619587eadfdb4ffd3e2fee57fee385e21.tar.gz FOSSEE-Signal-Processing-Toolbox-3ffa5ac619587eadfdb4ffd3e2fee57fee385e21.tar.bz2 FOSSEE-Signal-Processing-Toolbox-3ffa5ac619587eadfdb4ffd3e2fee57fee385e21.zip |
code by jitendra
Diffstat (limited to 'macros/sos2zp.sci')
-rw-r--r-- | macros/sos2zp.sci | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/macros/sos2zp.sci b/macros/sos2zp.sci index 98abc36..1f0f335 100644 --- a/macros/sos2zp.sci +++ b/macros/sos2zp.sci @@ -11,7 +11,6 @@ function [z,p,k] = sos2zp (sos, g) //z: column vector //p: column vector //Description -//This is an Octave function. //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. @@ -24,18 +23,32 @@ function [z,p,k] = sos2zp (sos, g) // -0.6250 + 1.0533i // -0.6250 - 1.0533i //c = 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 + 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]; - select(rhs) - case 1 then - [z,p,k] = callOctave("sos2zp",sos) - case 2 then - [z,p,k] = callOctave("sos2zp",sos,g) - end -endfunction + [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 |