summaryrefslogtreecommitdiff
path: root/macros/polystab.sci
diff options
context:
space:
mode:
authorRashpat932024-08-09 11:47:07 +0530
committerGitHub2024-08-09 11:47:07 +0530
commitb10cff2c07747b039e3c3ee83a34d437e958356b (patch)
tree094aee26fc70ca50e7fc61a96f0e30ea3924eb17 /macros/polystab.sci
parentf8ae45ed71b709b3308a472ca00d641d6ba0fda3 (diff)
parent08f31efcfe59cfe8403b0dd4fe1329b090bcbf79 (diff)
downloadFOSSEE-Signal-Processing-Toolbox-b10cff2c07747b039e3c3ee83a34d437e958356b.tar.gz
FOSSEE-Signal-Processing-Toolbox-b10cff2c07747b039e3c3ee83a34d437e958356b.tar.bz2
FOSSEE-Signal-Processing-Toolbox-b10cff2c07747b039e3c3ee83a34d437e958356b.zip
Merge pull request #16 from Chand-ra/master
Re-write functions in native Scilab
Diffstat (limited to 'macros/polystab.sci')
-rw-r--r--macros/polystab.sci53
1 files changed, 35 insertions, 18 deletions
diff --git a/macros/polystab.sci b/macros/polystab.sci
index 84e42d4..c9da6f0 100644
--- a/macros/polystab.sci
+++ b/macros/polystab.sci
@@ -1,21 +1,38 @@
-function b = polystab(a)
-//This function stabilizes the polynomial transfer function.
-//Calling Sequence
-//b = polystab(a)
-//Parameters
-//a:
-//Description
-//This is an Octave function.
-//This function stabilizes the polynomial transfer function by replacing all roots outside the unit circle with their reflection inside the unit circle.
-//Examples
+function y = polystab(x)
+//Stabilize the polynomial transfer function.
+//Calling Sequence:
+//y = polystab(x)
+//Parameters:
+//x: real or complex valued vector
+//Description:
+//This function stabilizes the polynomial transfer function by replacing all
+//roots outside the unit circle with their reflection inside the unit circle.
+//Example:
//polystab([1,3,5])
-//ans =
-// 1. 0.6 0.2
+//ans=
+//[1, 0.6, 0.2]
+
+ funcprot(0);
+ if (argn(2) ~= 1)
+ error("polystab: wrong number of input arguments");
+ end
+ root = roots(x);
+ vals = find(abs(root) > 1);
+ root(vals) = 1 ./ conj(root(vals));
+ b = x(1) * poly(root, 'x');
+ y = flipdim(coeff(b), 2);
+ if (isreal(x))
+ y = real(y);
+ end
-funcprot(0);
-rhs = argn(2)
-if(rhs~=1)
-error("Wrong number of input arguments.")
-end
-b = callOctave("polystab",a)
endfunction
+
+//input validation:
+//assert_checkerror("polystab()", "polystab: wrong number of input arguments");
+//assert_checkerror("polystab(1, 2)", "Wrong number of input arguments.")
+
+//tests:
+//assert_checkalmostequal(polystab([1, 3, 5]), [1, 0.6, 0.2], %eps);
+//assert_checkequal(polystab([1; 3; 5]), polystab([1, 3, 5]));
+//assert_checkalmostequal(polystab([1+3*%i, 4+2*%i, 2+2*%i]), [1 + 3*%i, 1.35664 + 1.84888*%i, 0.88566 + 0.88566*%i], 5*10^-5);
+//assert_checkalmostequal(polystab([-1; 3+%i; -2-6*%i]), [-1, 0.3 + 0.4*%i, -0.05-0.15*%i], 5*10^-5);