diff options
Diffstat (limited to 'macros/ellip.sci')
-rw-r--r-- | macros/ellip.sci | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/macros/ellip.sci b/macros/ellip.sci index ab34458..69463f2 100644 --- a/macros/ellip.sci +++ b/macros/ellip.sci @@ -1,18 +1,16 @@ // 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 +// Last Modified on : 3 Feb 2024 // Organization: FOSSEE, IIT Bombay // Email: toolbox@scilab.in - function [a, b, c, d] = ellip (n, rp, rs, w, varargin) //Elliptic or Cauer filter design with rp dB of passband ripple and rs dB of stopband attenuation. - //Calling Sequence //[b, a] = ellip (n, rp, rs, wp) //[b, a] = ellip (n, rp, rs, wp, "high") @@ -20,7 +18,6 @@ function [a, b, c, d] = ellip (n, rp, rs, w, varargin) //[b, a] = ellip (n, rp, rs, [wl, wh], "stop") //[z, p, g] = ellip (…) //[…] = ellip (…, "s") - //Parameters //n: positive integer value (order of filter) //rp: non negative scalar value (passband ripple) @@ -28,14 +25,12 @@ function [a, b, c, d] = ellip (n, rp, rs, w, varargin) //wp: positive real value, // 1).Normalised digital passband edge(s) for digital filter, in the range [0, 1] {dimensionless} // 2).Analog passband edge(s) for analog filter, in the range [0, Inf] {rad/sec} - //Description //This function generates an elliptic or Cauer filter with rp dB of passband ripple and rs dB of stopband attenuation. //[b, a] = ellip(n, Rp, Rs, Wp) indicates low pass filter with order n, Rp decibels of ripple in the passband and a stopband Rs decibels down and cutoff of pi*Wp radians. If the fifth argument is high, then the filter is a high pass filter. //[b, a] = ellip(n, Rp, Rs, [Wl, Wh]) indictaes band pass filter with band pass edges pi*Wl and pi*Wh. If the fifth argument is stop, the filter is a band reject filter. //[z, p, g] = ellip(...) returns filter as zero-pole-gain. //[...] = ellip(...,’s’) returns a Laplace space filter, wp can be larger than 1. - //Examples //[b, a]=ellip(2, 3, 40, [0.3,0.4]) //Output : @@ -59,7 +54,9 @@ function [a, b, c, d] = ellip (n, rp, rs, w, varargin) // column 5 // // 0.0202774 - + // Dependencies + // ellipap sftrans bilinear zp2tf + funcprot(0); [nargout nargin] = argn(); @@ -85,7 +82,7 @@ function [a, b, c, d] = ellip (n, rp, rs, w, varargin) case "stop" stop = %T; case "low" - stop = %T; + stop = %F; case "pass" stop = %F; else @@ -93,7 +90,7 @@ function [a, b, c, d] = ellip (n, rp, rs, w, varargin) end end - [rows_w colums_w] = size(w); + [rows_w columns_w] = size(w); if (~ ((length (w) <= 2) & (rows_w == 1 | columns_w == 1))) error ("ellip: frequency must be given as WP or [WL, WH]"); @@ -119,7 +116,7 @@ function [a, b, c, d] = ellip (n, rp, rs, w, varargin) // Prewarp the digital frequencies if (digital) T = 2; // sampling frequency of 2 Hz - w = 2 / T * tan (%pi * w / T); + w = (2 / T )* tan (%pi * w / T); end // Generate s-plane poles, zeros and gain @@ -139,8 +136,8 @@ function [a, b, c, d] = ellip (n, rp, rs, w, varargin) if (nargout == 2) [a b] = zp2tf(zero, pole, gain); elseif (nargout == 3) - a = zero; - b = pole; + a = conj(zero'); + b = conj(pole'); c = gain; else // output ss results @@ -148,3 +145,49 @@ function [a, b, c, d] = ellip (n, rp, rs, w, varargin) error("ellip: yet not implemented in state-space form OR invalid number of o/p arguments") end endfunction + +/* +%% Test input validation // all passed +error [a, b] = ellip () +error [a, b] = ellip (1) +error [a, b] = ellip (1, 2) +error [a, b] = ellip (1, 2, 3) +error [a, b] = ellip (1, 2, 3, 4, 5, 6, 7) +error [a, b] = ellip (.5, 2, 40, .2) +error [a, b] = ellip (3, 2, 40, .2, "invalid") + +test + +//[b, a] = ellip (n, rp, rs, [wl, wh]) +[b, a] = ellip (5, 1, 90, [.1 .2]); // passed + +//[b, a] = ellip (n, rp, rs, wp) +[A, B] = ellip (6, 3, 50, .6); //passed + +//[b, a] = ellip (n, rp, rs, [wl, wh], "stop") +[b, a] = ellip (5, 1, 90, [.1 .2],"stop"); // passed + +//[b, a] = ellip (n, rp, rs, wp, "high") +[A, B] = ellip (6, 3, 50, .6,"high"); // passed + +//[b, a] = ellip (n, rp, rs, [wl, wh]) +[b, a] = ellip (5, 1, 90, [.1 .2],"s"); // passed + +//[b, a] = ellip (n, rp, rs, wp) +[A, B] = ellip (6, 3, 50, .6,"z"); // passed + +//[b, a] = ellip (n, rp, rs, [wl, wh], "stop") +[b, a] = ellip (5, 1, 90, [.1 .2],"pass"); // passed + +//[b, a] = ellip (n, rp, rs, wp, "high") +[A, B] = ellip (6, 3, 50, .6,"low"); // passed + + +//[z, p, g] = ellip (…) +[z, p, g] = ellip (6, 3, 50, .6); // passed + +[z,p,g] = ellip( 10,15,4,.9,"s") // passed + +test + [a, b, c, d] = ellip (6, 3, 50, .6); // not implemented yet + */
\ No newline at end of file |