diff options
Diffstat (limited to 'macros/sftrans.sci')
-rw-r--r-- | macros/sftrans.sci | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/macros/sftrans.sci b/macros/sftrans.sci index 2dfd2bb..9a59e61 100644 --- a/macros/sftrans.sci +++ b/macros/sftrans.sci @@ -1,33 +1,28 @@ // Copyright (C) 2018 - IIT Bombay - FOSSEE -// // This file must be used under the terms of the CeCILL. // This source file is licensed as described in the file COPYING, which // you should have received as part of this distribution. The terms // are also available at // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt // Original Source : https://octave.sourceforge.io/signal/ -// Modifieded by:Sonu Sharma, RGIT Mumbai +// Modifieded by: Abinash Singh Under FOSSEE Internship +// Date of Modification: 3 Feb 2024 // Organization: FOSSEE, IIT Bombay // Email: toolbox@scilab.in - function [Sz, Sp, Sg] = sftrans (Sz, Sp, Sg, W, stop) //Transform band edges of a prototype filter (cutoff at W=1) represented in s-plane zero-pole-gain form (Frequency Transformation in Analog domain). - //Calling Sequence //[Sz, Sp, Sg] = sftrans (Sz, Sp, Sg, W, stop) //[Sz, Sp] = sftrans (Sz, Sp, Sg, W, stop) //[Sz] = sftrans (Sz, Sp, Sg, W, stop) - //Parameters //Sz: Zeros. //Sp: Poles. //Sg: Gain. //W: Edge freuency of target filter. //stop: True(%T or 1) for high pass and band stop filters or false (%F or 0) for low pass and band pass filters. - //Description //Theory: Given a low pass filter represented by poles and zeros in the splane, you can convert it to a low pass, high pass, band pass or band stop by transforming each of the poles and zeros individually. The following table summarizes the transformation: - // Transform Zero at x Pole at x // ---------------- ------------------------- ------------------------ // Low Pass zero: Fc x/C pole: Fc x/C @@ -57,8 +52,6 @@ function [Sz, Sp, Sg] = sftrans (Sz, Sp, Sg, W, stop) //algebra, you can derive the above formulae yourself by substituting the transform for S into H(S)=S-x for a zero at x or H(S)=1/(S-x) for a pole at x, and converting the result into the form: // // H(S)=g prod(S-Xi)/prod(S-Xj) - - //Examples //[Sz, Sp, Sg] = sftrans([1 2 3], [4 5 6], 15, 20, %T) // Output @@ -71,6 +64,8 @@ function [Sz, Sp, Sg] = sftrans (Sz, Sp, Sg, W, stop) // Sz = // // 20. 10. 6.6666667 + // dependencies + // funcprot(0); [nargout nargin]= argn(); @@ -115,12 +110,12 @@ function [Sz, Sp, Sg] = sftrans (Sz, Sp, Sg, W, stop) Sp = [b+sqrt(b.^2-Fh*Fl), b-sqrt(b.^2-Fh*Fl)]; extend = [sqrt(-Fh*Fl), -sqrt(-Fh*Fl)]; if isempty(Sz) - Sz = [extend(1+rem([1:2*p],2))]; + Sz = [extend(1+modulo([1:2*p],2))]; else b = (C*(Fh-Fl)/2)./Sz; Sz = [b+sqrt(b.^2-Fh*Fl), b-sqrt(b.^2-Fh*Fl)]; if (p > z) - Sz = [Sz, extend(1+rem([1:2*(p-z)],2))]; + Sz = [Sz, extend(1+modulo([1:2*(p-z)],2))]; end end else @@ -178,3 +173,13 @@ function [Sz, Sp, Sg] = sftrans (Sz, Sp, Sg, W, stop) end end endfunction +/** +Note : This function is tested with Octave's outputs as a reference. + +[Sz_new , Sp_new , Sg_new ] = sftrans([0.5;-0.5],[0.3 ; -0.3],2,0.5,0) // passed +[Sz_new , Sp_new , Sg_new ] = sftrans([0.5;-0.5],[0.3 ; -0.3],2,0.5,1) // passed +[Sz_new, Sp_new, Sg_new] = sftrans([0.5], [0.3], 1, [1.0, 2.0], 0) //passed +[Sz_new, Sp_new, Sg_new] = sftrans([0.5], [0.3], 1, [1.0, 2.0], 1) //passed +[Sz_new, Sp_new, Sg_new] = sftrans([], [], 1, 1.0, 0) //error passed +[Sz_new, Sp_new, Sg_new] = sftrans([0], [], 1, 1.0, 0)//error passed +*/
\ No newline at end of file |