diff options
113 files changed, 7240 insertions, 3004 deletions
diff --git a/help/en_US/arburg.xml b/help/en_US/arburg.xml index 6aa017e..775d9c1 100644 --- a/help/en_US/arburg.xml +++ b/help/en_US/arburg.xml @@ -40,34 +40,32 @@ <listitem><para> positive integer value < length(x) - 2</para></listitem></varlistentry> <varlistentry><term>criterion:</term> <listitem><para> string value, takes in "AKICc", "KIC", "AICc", "AIC" and "FPE", default it not using a model-selection criterion</para></listitem></varlistentry> - <varlistentry><term>a, v, k:</term> - <listitem><para> Output variables</para></listitem></varlistentry> + <varlistentry><term>a:</term> + <listitem><para> list of autoregression coefficients.</para></listitem></varlistentry> + <varlistentry><term>v:</term> + <listitem><para> mean square of residual noise from the whitening operation of the Burg lattice filter</para></listitem></varlistentry> + <varlistentry><term>k:</term> + <listitem><para> reflection coefficients defining the lattice-filter embodiment of the model</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. - </para> - <para> This function calculates coefficients of an autoregressive (AR) model of complex data x using the whitening lattice-filter method of Burg. </para> <para> The first argument is the data sampled. The second argument is the number of poles in the model (or limit in case a criterion is supplied). The third parameter takes in the criterion to limit the number of poles. The acceptable values are "AIC", "AKICc", "KIC", "AICc" which are based on information theory. -Output variable a is a list of P+1 autoregression coefficients. -Output variable v is the mean square of residual noise from the whitening operation of the Burg lattice filter. -Output variable k corresponds to the reflection coefficients defining the lattice-filter embodiment of the model. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -arburg([1,2,3,4,5],2) -ans = -1.00000 -1.86391 0.95710 +x = [1,2,3,4,5] ; +poles = 2 ; +arburg(x,poles) ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/arch_rnd.xml b/help/en_US/arch_rnd.xml index 4692e05..fe24c5c 100644 --- a/help/en_US/arch_rnd.xml +++ b/help/en_US/arch_rnd.xml @@ -43,16 +43,25 @@ <refsection> <title>Description</title> <para> -This is an Octave function. It Simulates an ARCH sequence of length t with AR coefficients b and CH coefficients a. The result y(t) follows the model </para> <para> -y(t) = b(1) + b(2) * y(t-1) + … + b(lb) * y(t-lb+1) + e(t), + <latex> + \begin{eqnarray} +y(t) = b(1) + b(2) * y(t-1) + … + b(lb) * y(t-lb+1) + e(t) + \end{eqnarray} + </latex> +<para> where e(t), given y up to time t-1, is N(0, h(t)), with +</para> </para> <para> + <latex> + \begin{eqnarray} h(t) = a(1) + a(2) * e(t-1)^2 + … + a(la) * e(t-la+1)^2 + \end{eqnarray} + </latex> </para> </refsection> @@ -61,14 +70,9 @@ h(t) = a(1) + a(2) * e(t-1)^2 + … + a(la) * e(t-la+1)^2 <programlisting role="example"><![CDATA[ a = [1 2 3 4 5]; b = [7 8 9 10]; +t = 5 ; arch_rnd (a, b, t) -ans = -6.1037e+00 -5.7294e+01 -5.7390e+02 -6.3063e+03 -6.8695e+04 ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/arma_rnd.xml b/help/en_US/arma_rnd.xml index fdf1c26..922bfb3 100644 --- a/help/en_US/arma_rnd.xml +++ b/help/en_US/arma_rnd.xml @@ -48,12 +48,16 @@ <refsection> <title>Description</title> <para> -This is an Octave function. The ARMA model is defined by </para> <para> -x(n) = a(1) * x(n-1) + … + a(k) * x(n-k) -+ e(n) + b(1) * e(n-1) + … + b(l) * e(n-l) + <latex> + \begin{eqnarray} +x(n) = a(1) * x(n-1) + … + a(k) * x(n-k) + e(n) + b(1) * e(n-1) + … + b(l) * e(n-l) + \end{eqnarray} + </latex> +</para> +<para> in which k is the length of vector a, l is the length of vector b and e is Gaussian white noise with variance v. The function returns a vector of length t. </para> <para> @@ -70,13 +74,7 @@ v = 10; t = 5; n = 100; arma_rnd (a, b, v, t, n) -ans = --1.6176e+05 --4.1663e+05 --1.0732e+06 --2.7648e+06 --7.1221e+06 ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/aryule.xml b/help/en_US/aryule.xml index 7d706fd..6ad7b46 100644 --- a/help/en_US/aryule.xml +++ b/help/en_US/aryule.xml @@ -37,29 +37,29 @@ <listitem><para> vector of real or complex numbers, length > 2</para></listitem></varlistentry> <varlistentry><term>p:</term> <listitem><para> positive integer value < length(x) - 1</para></listitem></varlistentry> - <varlistentry><term>a, v, k:</term> - <listitem><para> Output variables</para></listitem></varlistentry> + <varlistentry><term>a:</term> + <listitem><para> gives the AR coefficients </para></listitem></varlistentry> + <varlistentry><term>v:</term> + <listitem><para> gives the variance of the white noise, </para></listitem></varlistentry> + <varlistentry><term>k:</term> + <listitem><para> gives the reflection coefficients to be used in the lattice filter</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. - </para> - <para> This function fits an AR (p)-model with Yule-Walker estimates. The first argument is the data vector which is to be estimated. -Output variable a gives the AR coefficients, v gives the variance of the white noise and k gives the reflection coefficients to be used in the lattice filter. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -aryule([1,2,3,4,5],2) -ans = -1. - 0.8140351 0.1192982 +x = [1,2,3,4,5] ; +poles = 2 ; +arburg(x,poles) ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/autoreg_matrix.xml b/help/en_US/autoreg_matrix.xml index 61fefef..217a151 100644 --- a/help/en_US/autoreg_matrix.xml +++ b/help/en_US/autoreg_matrix.xml @@ -54,11 +54,11 @@ The resulting matrix may be used as a regressor matrix in autoregressions. <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -autoreg_matrix([1,2,3],2) -ans = -1. 0. 0. -1. 1. 0. -1. 2. 1. + +Y = [1,2,3] ; +K = 2 ; +autoreg_matrix(Y,K) + ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/besselap.xml b/help/en_US/besselap.xml index f3236d7..1704b68 100644 --- a/help/en_US/besselap.xml +++ b/help/en_US/besselap.xml @@ -17,7 +17,7 @@ <refnamediv> <refname>besselap</refname> - <refpurpose>Return bessel analog filter prototype.</refpurpose> + <refpurpose>Bessel analog filter prototype.</refpurpose> </refnamediv> @@ -25,7 +25,6 @@ <title>Calling Sequence</title> <synopsis> [zero, pole, gain] = besselap (n) - [zero, pole] = besselap (n) zero = besselap (n) </synopsis> </refsynopsisdiv> @@ -36,36 +35,34 @@ <varlistentry><term>n:</term> <listitem><para> Filter Order</para></listitem></varlistentry> <varlistentry><term>zero:</term> - <listitem><para> Zeros</para></listitem></varlistentry> + <listitem><para> Zeros of filter</para></listitem></varlistentry> <varlistentry><term>pole:</term> - <listitem><para> Poles</para></listitem></varlistentry> + <listitem><para> Poles of filter</para></listitem></varlistentry> <varlistentry><term>gain:</term> - <listitem><para> Gain</para></listitem></varlistentry> + <listitem><para> Gain of filter</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -It Return bessel analog filter prototype of nth order. +It Return Bessel analog filter prototype of nth order. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[zero, pole, gain] = besselap (5) -zero = [](0x0) -pole = - --0.59058 + 0.90721i --0.59058 - 0.90721i --0.92644 + 0.00000i --0.85155 + 0.44272i --0.85155 - 0.44272i - -gain = 1 +n = 5; +[zero, pole, gain] = besselap (n) ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/besself.xml b/help/en_US/besself.xml index b792eaf..f7456d9 100644 --- a/help/en_US/besself.xml +++ b/help/en_US/besself.xml @@ -17,18 +17,19 @@ <refnamediv> <refname>besself</refname> - <refpurpose>This function generates a Bessel filter.</refpurpose> + <refpurpose>Bessel filter design.</refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [a, b] = besself(n, w) - [a, b] = besself (n, w, "high") - [a, b, c] = besself (…) - [a, b, c, d] = besself (…) - […] = besself (…, "z") +[b, a] = besself(n, Wc) +[b, a] = besself (n, Wc, "high") +[b, a] = besself (n, [Wl, Wh]) +[b, a] = besself (n, [Wl, Wh], "stop") +[z, p, g] = besself (…) +[…] = besself (…, "z") </synopsis> </refsynopsisdiv> @@ -36,31 +37,30 @@ <title>Parameters</title> <variablelist> <varlistentry><term>n:</term> - <listitem><para> positive integer value</para></listitem></varlistentry> - <varlistentry><term>w:</term> - <listitem><para> positive real value</para></listitem></varlistentry> + <listitem><para> positive integer value (order of filter)</para></listitem></varlistentry> + <varlistentry><term>W:</term> + <listitem><para> positive real value</para><para> 1).Analog 3dB cutoff frequency/frequencies for analog filter, in the range [0, Inf] {rad/sec}</para><para> 2).Normalised digital 3dB cutoff frequency/frequencies for digital filter, in the range [0, 1] {dimensionless}</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function generates a Bessel filter. The default is a Laplace space (s) filter. -The third parameter takes in high or low, the default value being low. The cutoff is pi*Wc radians. -[z,p,g] = besself(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. -[...] = besself(...,’z’) returns a discrete space (Z) filter. w must be less than 1. -[a,b,c,d] = besself(...) returns state-space matrices. +This function generates a Bessel filter. The default is a Laplace space (s) or analog filter.</para> +<para>If second argument is scalar the third parameter takes in high or low, the default value being low. The cutoff is Wc rad/sec.</para> +<para>If second argument is vector of length 2 ie [Wl Wh] then third parameter may be pass or stop default is pass for bandpass and band reject filter respectively</para> +<para>[z,p,g] = besself(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.</para> +<para>[...] = besself(...,’z’) returns a discrete space (Z) filter. Wc must be less than 1 {dimensionless}. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[a,b]=besself(2,3,"low") -a = 9.0000 -b = -1.0000 5.1962 9.0000 +n = 2; +wc = 0.3; +[b, a]=besself(n, wc, "high", "z") + ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/bilinear.xml b/help/en_US/bilinear.xml index 0361759..e6a2e46 100644 --- a/help/en_US/bilinear.xml +++ b/help/en_US/bilinear.xml @@ -17,36 +17,82 @@ <refnamediv> <refname>bilinear</refname> - <refpurpose>Transform a s-plane filter specification into a z-plane specification</refpurpose> + <refpurpose>Transforms a s-plane filter (Analog) into a z-plane filter (Digital) using Bilinear transformation</refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [ZB, ZA] = bilinear (SB, SA, T) - [ZB, ZA] = bilinear (SZ, SP, SG, T) - [ZZ, ZP, ZG] = bilinear (...) + [Zb, Za] = bilinear(Sb, Sa, T) + [Zb, Zb] = bilinear(Sz, Sp, Sg, T) + [Zz, Zp, Zg] = bilinear(...) </synopsis> </refsynopsisdiv> <refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>Sb:</term> + <listitem><para> Numerator coefficient vector in s-domain. </para></listitem></varlistentry> + <varlistentry><term>Sa:</term> + <listitem><para> Denumerator coefficient vector s-domain.</para></listitem></varlistentry> + <varlistentry><term>Sz:</term> + <listitem><para> zeros in s-plane.</para></listitem></varlistentry> + <varlistentry><term>Sp:</term> + <listitem><para> poles in s-plane.</para></listitem></varlistentry> + <varlistentry><term>Sg:</term> + <listitem><para> gain in s-domain.</para></listitem></varlistentry> + <varlistentry><term>T:</term> + <listitem><para> Sampling period (double).</para></listitem></varlistentry> + <varlistentry><term>Zb:</term> + <listitem><para> Numerator coefficient vector in z-domain.</para></listitem></varlistentry> + <varlistentry><term>Za:</term> + <listitem><para> Denumerator coefficient vector z-domain.</para></listitem></varlistentry> + <varlistentry><term>Zz:</term> + <listitem><para> zeros in z-plane.</para></listitem></varlistentry> + <varlistentry><term>Zp:</term> + <listitem><para> poles in z-plane.</para></listitem></varlistentry> + <varlistentry><term>Zg:</term> + <listitem><para> gain in z-domain.</para></listitem></varlistentry> + </variablelist> +</refsection> + +<refsection> <title>Description</title> <para> -Transform a s-plane filter specification into a z-plane specification. Filters can be specified in either zero-pole-gain or transfer function form. The input form does not have to match the output form. 1/T is the sampling frequency represented in the z plane. +a filter design can be transformed from the s-plane to the z-plane while maintaining the band edges by means of the bilinear transform. This maps the left hand side of the s-plane into the interior of the unit circle in z-plane. The mapping is highly non-linear, so you must design your filter with band edges in the s-plane positioned at 2/T tan(w*T/2) so that they will be positioned at w after the bilinear transform is complete. </para> <para> -Note: this differs from the bilinear function in the signal processing toolbox, which uses 1/T rather than T. +It does following transformation from s-plane to z-plane </para> + <para> -Theory: Given a piecewise flat filter design, you can transform it from the s-plane to the z-plane while maintaining the band edges by means of the bilinear transform. This maps the left hand side of the s-plane into the interior of the unit circle. The mapping is highly non-linear, so you must design your filter with band edges in the s-plane positioned at 2/T tan(w*T/2) so that they will be positioned at w after the bilinear transform is complete. -</para> + <latex> + \begin{eqnarray} + s --> \frac{2} {T} \frac {z - 1} {z + 1} + \end{eqnarray} + </latex> + </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[ZB,ZA]=bilinear([1],[2,3],3) +Sz = [1 2 3] +Sp = [4 5 6] +Sg = 1; +T = 1; +[Zb,Za] = bilinear (Sz, Sp, Sg, T) + ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/bitrevorder.xml b/help/en_US/bitrevorder.xml index 996ed26..35ca8f4 100644 --- a/help/en_US/bitrevorder.xml +++ b/help/en_US/bitrevorder.xml @@ -17,15 +17,18 @@ <refnamediv> <refname>bitrevorder</refname> - <refpurpose></refpurpose> + <refpurpose> Returns input data in bit-reversed order </refpurpose> + <para> </para> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [y,i]=bitrevorder(x) + [y,i] = bitrevorder(x) + y = bitrevorder(x) </synopsis> + <para> </para> </refsynopsisdiv> <refsection> @@ -33,13 +36,17 @@ <variablelist> <varlistentry><term>x:</term> <listitem><para> Vector of real or complex values</para></listitem></varlistentry> + <varlistentry><term>y:</term> + <listitem><para> input vector in bit reverse order</para></listitem></varlistentry> + <varlistentry><term>i:</term> + <listitem><para> indices after bit reversing </para></listitem></varlistentry> + <para> </para> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. This function returns the input data after reversing the bits of the indices and reordering the elements of the input array. </para> </refsection> @@ -47,11 +54,8 @@ This function returns the input data after reversing the bits of the indices and <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -1. [y]=bitrevorder ([i,1,3,6i]) -y = [0 + 1i 3 + 0i 1 + 0i 0 + 6i] -2. [y,i]=bitrevorder (['a','b','c','d']) -y = acbd -i = [1 3 2 4] +x = [%i,1,3,6*%i] ; +[y i]=bitrevorder(x) ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/buttap.xml b/help/en_US/buttap.xml index d891af5..9a7a948 100644 --- a/help/en_US/buttap.xml +++ b/help/en_US/buttap.xml @@ -17,15 +17,13 @@ <refnamediv> <refname>buttap</refname> - <refpurpose>Design a lowpass analog Butterworth filter.</refpurpose> + <refpurpose>Produces a lowpass analog prototype Butterworth filter.</refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - z = buttap (n) - [z, p] = buttap (n) [z, p, g] = buttap (n) </synopsis> </refsynopsisdiv> @@ -47,21 +45,23 @@ <refsection> <title>Description</title> <para> -This is an Octave function. -It designs a lowpass analog Butterworth filter of nth order. +It gives a lowpass analog prototype Butterworth filter of nth order. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[z, p, g] = buttap (5) -z = [](0x0) -p = - --0.30902 + 0.95106i -0.80902 + 0.58779i -1.00000 + 0.00000i -0.80902 - 0.58779i -0.30902 - 0.95106i - -g = 1 +n = 5 ; +[z, p, g] = buttap (n) ]]></programlisting> </refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> + </refsection> + </refentry> diff --git a/help/en_US/butter.xml b/help/en_US/butter.xml index bacacaf..8137c23 100644 --- a/help/en_US/butter.xml +++ b/help/en_US/butter.xml @@ -17,20 +17,19 @@ <refnamediv> <refname>butter</refname> - <refpurpose>This function generates a Butterworth filter.</refpurpose> + <refpurpose>Butterworth filter design..</refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [a, b] = butter (n, w) - [a, b] = butter (n, w, "high") - [a, b] = butter (n, [wl, wh]) - [b, a] = butter (n, [wl, wh], "stop") - [a, b, c] = butter (…) - [a, b, c, d] = butter (…) - […] = butter (…, "s") + [b, a] = butter (n, wc) + [b, a] = butter (n, wc, "high") + [b, a] = butter (n, [wl, wh]) + [b, a] = butter (n, [wl, wh], "stop") + [z, p, g] = butter (…) + […] = butter (…, "s") </synopsis> </refsynopsisdiv> @@ -38,34 +37,39 @@ <title>Parameters</title> <variablelist> <varlistentry><term>n:</term> - <listitem><para> positive integer value</para></listitem></varlistentry> - <varlistentry><term>w:</term> - <listitem><para> positive real value, w in the range [0,1]</para></listitem></varlistentry> + <listitem><para> positive integer value (order of filter).</para></listitem></varlistentry> + <varlistentry><term>wc:</term> + <listitem><para> positive real value,</para><para> 1).Normalised digital 3dB cutoff frequency/frequencies for digital filter, in the range [0, 1] {dimensionless}</para><para> 2).Analog 3dB cutoff frequency/frequencies for analog filter, in the range [0, Inf] {rad/sec}</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function generates a Butterworth filter. Default is a discrete space (Z) filter. -The third parameter takes in low or high, default value is low. The cutoff is pi*Wc radians. -[b,a] = butter(n, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians. -[b,a] = butter(n, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians. -[z,p,g] = butter(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. -[...] = butter(...,’s’) returns a Laplace space filter, w can be larger than 1. -[a,b,c,d] = butter(...) returns state-space matrices. +This function generates a Butterworth filter. Default is a discrete space (z) or digital filter using Bilinear transformation from s to z plane.</para> + <para>If second argument is scalar the third parameter takes in low or high, default value is low. The cutoff is pi*wc radians.</para> + <para>[b,a] = butter(n, [wl, wh]) indicates a band pass filter with cutoffs pi*Wl and pi*wh radians. </para> + <para>[b,a] = butter(n, [wl, wh], ’stop’) indicates a band reject filter with cutoffs pi*wl and pi*wh radians.</para> + <para>[z,p,g] = butter(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.</para> + <para>[...] = butter(...,’s’) returns a Laplace space filter,here cutoff(s) wc can be larger than 1 (rad/sec). </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[a,b]=butter(3, 0.7) -a = -0.37445 1.12336 1.12336 0.37445 -b = -1.00000 1.16192 0.69594 0.13776 +n = 4; +wc = 0.3; +[b a] = butter(n, wc, "high") + ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/buttord.xml b/help/en_US/buttord.xml index da92712..32b7f21 100644 --- a/help/en_US/buttord.xml +++ b/help/en_US/buttord.xml @@ -17,7 +17,7 @@ <refnamediv> <refname>buttord</refname> - <refpurpose>/This function computes the minimum filter order of a Butterworth filter with the desired response characteristics.</refpurpose> + <refpurpose>Minimum filter order and 3dB cutoff frequency of a digital Butterworth filter with the desired response characteristics. </refpurpose> </refnamediv> @@ -33,38 +33,47 @@ <title>Parameters</title> <variablelist> <varlistentry><term>Wp:</term> - <listitem><para> scalar or vector of length 2</para></listitem></varlistentry> + <listitem><para> scalar or vector of length 2 (passband edge(s)), elements must be in the range [0,1]</para></listitem></varlistentry> <varlistentry><term>Ws:</term> - <listitem><para> scalar or vector of length 2, elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> scalar or vector of length 2 (stopband edge(s)), elements must be in the range [0,1]</para></listitem></varlistentry> <varlistentry><term>Rp:</term> - <listitem><para> real or complex value</para></listitem></varlistentry> + <listitem><para> passband ripple in dB.</para></listitem></varlistentry> <varlistentry><term>Rs:</term> - <listitem><para> real or complex value</para></listitem></varlistentry> + <listitem><para> stopband attenuation in dB.</para></listitem></varlistentry> + <varlistentry><term>n:</term> + <listitem><para> Minimum filter order satisfying specs.</para></listitem></varlistentry> + <varlistentry><term>Wc:</term> + <listitem><para> 3dB cutoff frequency/frequencies.</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function computes the minimum filter order of a Butterworth filter with the desired response characteristics. -The filter frequency band edges are specified by the passband frequency wp and stopband frequency ws. -Frequencies are normalized to the Nyquist frequency in the range [0,1]. -Rp is measured in decibels and is the allowable passband ripple, and Rs is also in decibels and is the minimum attenuation in the stop band. -If ws>wp, the filter is a low pass filter. If wp>ws, the filter is a high pass filter. -If wp and ws are vectors of length 2, then the passband interval is defined by wp the stopband interval is defined by ws. -If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp the filter is a band-stop or band-reject filter. +This function computes the minimum filter order of a Butterworth filter with the desired response characteristics. </para> +<para>The filter frequency band edges are specified by the passband frequency wp and stopband frequency ws.</para> +<para>Frequencies are normalized to the Nyquist frequency in the range [0,1]. </para> +<para>Rp is measured in decibels and is the allowable passband ripple, and Rs is also in decibels and is the minimum attenuation in the stop band.</para> +<para>If ws>wp, the filter is a low pass filter. If wp>ws, the filter is a high pass filter.</para> +<para>If wp and ws are vectors of length 2, then the passband interval is defined by wp the stopband interval is defined by ws. </para> +<para>If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp the filter is a band-stop or band-reject filter. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -Wp = 40/500 -Ws = 150/500 -[n, Wn] = buttord(Wp, Ws, 3, 60) -n = 5 -Wn = 0.080038 + Wp = 40/500 ; + Ws = 150/500 ; + [n, Wc] = buttord(Wp, Ws, 3, 60) ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/cheb1ap.xml b/help/en_US/cheb1ap.xml index dbd541a..beae9a2 100644 --- a/help/en_US/cheb1ap.xml +++ b/help/en_US/cheb1ap.xml @@ -17,7 +17,7 @@ <refnamediv> <refname>cheb1ap</refname> - <refpurpose>This function designs a lowpass analog Chebyshev type I filter.</refpurpose> + <refpurpose>Produces a lowpass analog Chebyshev type I prototype filter.</refpurpose> </refnamediv> @@ -25,8 +25,6 @@ <title>Calling Sequence</title> <synopsis> [z, p, g] = cheb1ap (n, Rp) - [z, p] = cheb1ap (n, Rp) - p = cheb1ap (n, Rp) </synopsis> </refsynopsisdiv> @@ -36,7 +34,7 @@ <varlistentry><term>n:</term> <listitem><para> Filter Order</para></listitem></varlistentry> <varlistentry><term>Rp:</term> - <listitem><para> Peak-to-peak passband ripple</para></listitem></varlistentry> + <listitem><para> Peak-to-peak passband ripple in dB</para></listitem></varlistentry> <varlistentry><term>z:</term> <listitem><para> Zeros</para></listitem></varlistentry> <varlistentry><term>p:</term> @@ -49,27 +47,25 @@ <refsection> <title>Description</title> <para> -This is an Octave function. -It designs a lowpass analog Chebyshev type I filter of nth order and with a Peak-to-peak passband ripple of Rp. +It gives a lowpass analog Chebyshev type I prototype filter of nth order and with a Peak-to-peak passband ripple of Rp. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[z, p, g] = cheb1ap (10, 20) -z = [](0x0) -p = - -Columns 1 through 6: - --0.00157 - 0.98774i -0.00456 - 0.89105i -0.00709 - 0.70714i -0.00894 - 0.45401i -0.00991 - 0.15644i -0.00991 + 0.15644i - -Columns 7 through 10: - --0.00894 + 0.45401i -0.00709 + 0.70714i -0.00456 + 0.89105i -0.00157 + 0.98774i - -g = 1.9630e-04 - 6.3527e-22i +n = 10 ; +Rp = 3 ; +[z, p, g] = cheb1ap (n, Rp) ]]></programlisting> </refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Sonu Sharma, RGIT Mumbai</member> + <member>FOSSEE, IIT Bombay</member> + </simplelist> + </refsection> + </refentry> diff --git a/help/en_US/cheb1ord.xml b/help/en_US/cheb1ord.xml index e60a114..843753c 100644 --- a/help/en_US/cheb1ord.xml +++ b/help/en_US/cheb1ord.xml @@ -17,7 +17,7 @@ <refnamediv> <refname>cheb1ord</refname> - <refpurpose>This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics.</refpurpose> + <refpurpose>Minimum filter order of a digital Chebyshev type I filter with the desired response characteristics.</refpurpose> </refnamediv> @@ -25,7 +25,7 @@ <title>Calling Sequence</title> <synopsis> n = cheb1ord(Wp, Ws, Rp, Rs) - [n, Wc] = cheb1ord(Wp, Ws, Rp, Rs) + [n, Wp] = cheb1ord(Wp, Ws, Rp, Rs) </synopsis> </refsynopsisdiv> @@ -33,35 +33,48 @@ <title>Parameters</title> <variablelist> <varlistentry><term>Wp:</term> - <listitem><para> scalar or vector of length 2, all elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> scalar or vector of length 2 (passband edge(s)), all elements must be in the range [0,1]</para></listitem></varlistentry> <varlistentry><term>Ws:</term> - <listitem><para> scalar or vector of length 2, all elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> scalar or vector of length 2 (stopband edge(s)), all elements must be in the range [0,1]</para></listitem></varlistentry> <varlistentry><term>Rp:</term> - <listitem><para> real value</para></listitem></varlistentry> + <listitem><para> passband ripple in dB.</para></listitem></varlistentry> <varlistentry><term>Rs:</term> - <listitem><para> real value</para></listitem></varlistentry> + <listitem><para> stopband attenuation in dB.</para></listitem></varlistentry> + <varlistentry><term>n:</term> + <listitem><para> Minimum filter order satisfying specs.</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics. -Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. -Frequencies are normalized to the Nyquist frequency in the range [0,1]. -Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. -If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. -If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. -If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. +This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics. </para> +<para>Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. </para> +<para>Frequencies are normalized to the Nyquist frequency in the range [0,1]. </para> +<para>Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.</para> +<para>If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.</para> +<para>If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. </para> +<para>If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -cheb1ord(0.1,0.2,-0.3,4) -ans = 2 +wp = [0.25 0.3]; +ws = [0.24 0.31]; +Rp = 3; +Rs = 10; +[n, wp]=cheb1ord(wp, ws, Rp, Rs) + ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/cheb2ap.xml b/help/en_US/cheb2ap.xml index 0fcdd8f..7035925 100644 --- a/help/en_US/cheb2ap.xml +++ b/help/en_US/cheb2ap.xml @@ -17,7 +17,7 @@ <refnamediv> <refname>cheb2ap</refname> - <refpurpose>This function designs a lowpass analog Chebyshev type II filter.</refpurpose> + <refpurpose>Produces a lowpass analog Chebyshev type II prototype filter.</refpurpose> </refnamediv> @@ -25,8 +25,6 @@ <title>Calling Sequence</title> <synopsis> [z, p, g] = cheb2ap (n, Rs) - [z, p] = cheb2ap (n, Rs) - p = cheb2ap (n, Rs) </synopsis> </refsynopsisdiv> @@ -36,7 +34,7 @@ <varlistentry><term>n:</term> <listitem><para> Filter Order</para></listitem></varlistentry> <varlistentry><term>Rs:</term> - <listitem><para> Stopband attenuation</para></listitem></varlistentry> + <listitem><para> Stopband attenuation in dB</para></listitem></varlistentry> <varlistentry><term>z:</term> <listitem><para> Zeros</para></listitem></varlistentry> <varlistentry><term>p:</term> @@ -49,15 +47,25 @@ <refsection> <title>Description</title> <para> -This is an Octave function. -This function designs a lowpass analog Chebyshev type II filter of nth order and with a stopband attenuation of Rs. +This function gives a lowpass analog Chebyshev type II prototpye filter of nth order and with a stopband attenuation of Rs. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ - +n = 4; +Rs = 10; +[z, p, g] = cheb2ap (n, Rs) ]]></programlisting> </refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Sonu Sharma, RGIT Mumbai</member> + <member>FOSSEE, IIT Bombay</member> + </simplelist> + </refsection> + </refentry> diff --git a/help/en_US/cheb2ord.xml b/help/en_US/cheb2ord.xml index 199c595..279e258 100644 --- a/help/en_US/cheb2ord.xml +++ b/help/en_US/cheb2ord.xml @@ -17,7 +17,7 @@ <refnamediv> <refname>cheb2ord</refname> - <refpurpose>This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics.</refpurpose> + <refpurpose>Minimum filter order of a digital Chebyshev type II filter with the desired response characteristics. </refpurpose> </refnamediv> @@ -25,7 +25,7 @@ <title>Calling Sequence</title> <synopsis> n = cheb2ord(Wp, Ws, Rp, Rs) - [n, Wc] = cheb2ord(Wp, Ws, Rp, Rs) + [n, Ws] = cheb2ord(Wp, Ws, Rp, Rs) </synopsis> </refsynopsisdiv> @@ -33,35 +33,47 @@ <title>Parameters</title> <variablelist> <varlistentry><term>Wp:</term> - <listitem><para> scalar or vector of length 2, all elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> scalar or vector of length 2 (passband edge(s)), all elements must be in the range [0,1]</para></listitem></varlistentry> <varlistentry><term>Ws:</term> - <listitem><para> scalar or vector of length 2, all elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> scalar or vector of length 2 (stopband edge(s)), all elements must be in the range [0,1]</para></listitem></varlistentry> <varlistentry><term>Rp:</term> - <listitem><para> real value</para></listitem></varlistentry> + <listitem><para> passband ripple in dB.</para></listitem></varlistentry> <varlistentry><term>Rs:</term> - <listitem><para> real value</para></listitem></varlistentry> + <listitem><para> stopband attenuation in dB.</para></listitem></varlistentry> + <varlistentry><term>n:</term> + <listitem><para> Minimum order of filter satisfying given specs.</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics. -Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. -Frequencies are normalized to the Nyquist frequency in the range [0,1]. -Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. -If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. -If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. -If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. +This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics.</para> +<para>Stopband frequency ws and passband frequency wp specify the the filter frequency band edges.</para> +<para>Frequencies are normalized to the Nyquist frequency in the range [0,1].</para> +<para>Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.</para> +<para>If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.</para> +<para>If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws.</para> +<para>If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -cheb2ord([0.25,0.3],[0.2,0.8],0.3,0.4) -ans = 1 + Wp = 40/500; + Ws = 150/500; + Rp = 3; + Rs = 60; + [n,Ws] = cheb2ord(Wp,Ws,Rp,Rs) ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/cheby1.xml b/help/en_US/cheby1.xml index 92a7848..e33a506 100644 --- a/help/en_US/cheby1.xml +++ b/help/en_US/cheby1.xml @@ -17,20 +17,19 @@ <refnamediv> <refname>cheby1</refname> - <refpurpose>This function generates a Chebyshev type I filter with rp dB of passband ripple.</refpurpose> + <refpurpose>Chebyshev type I filter design with rp dB of passband ripple.</refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [a, b] = cheby1 (n, rp, w) - [a, b] = cheby1 (n, rp, w, "high") - [a, b] = cheby1 (n, rp, [wl, wh]) - [a, b] = cheby1 (n, rp, [wl, wh], "stop") - [a, b, c] = cheby1 (…) - [a, b, c, d] = cheby1 (…) - […] = cheby1 (…, "s") + [b, a] = cheby1 (n, rp, wp) + [b, a] = cheby1 (n, rp, wp, "high") + [b, a] = cheby1 (n, rp, [wl, wh]) + [b, a] = cheby1 (n, rp, [wl, wh], "stop") + [z, p, g] = cheby1 (…) + […] = cheby1 (…, "s") </synopsis> </refsynopsisdiv> @@ -38,37 +37,41 @@ <title>Parameters</title> <variablelist> <varlistentry><term>n:</term> - <listitem><para> positive integer value</para></listitem></varlistentry> + <listitem><para> positive integer value (order of filter)</para></listitem></varlistentry> <varlistentry><term>rp:</term> - <listitem><para> non negative scalar value</para></listitem></varlistentry> - <varlistentry><term>w:</term> - <listitem><para> vector, all elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> non negative scalar value (passband ripple)</para></listitem></varlistentry> + <varlistentry><term>wp:</term> + <listitem><para> vector, all elements must be in the range [0,1]</para><para> 1).Normalised digital passband edge(s) for digital filter, in the range [0, 1] {dimensionless}</para><para> 2).Analog passband edge(s) for analog filter, in the range [0, Inf] {rad/sec}</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function generates a Chebyshev type I filter with rp dB of passband ripple. -The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians. -[b, a] = cheby1(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians. -[b, a] = cheby1(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians. -[z, p, g] = cheby1(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. -[...] = cheby1(...,’s’) returns a Laplace space filter, w can be larger than 1. -[a,b,c,d] = cheby1(...) returns state-space matrices. +This function generates a Chebyshev type I filter with rp dB of passband ripple.</para> +<para>if third parameter is scalar the fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians.</para> +<para>[b, a] = cheby1(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.</para> +<para>[b, a] = cheby1(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.</para> +<para>[z, p, g] = cheby1(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.</para> +<para>[...] = cheby1(...,’s’) returns a Laplace space filter, w can be larger than 1 rad/sec. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[a,b,c]=cheby1(2,6,0.7,"high") -a = -1 1 -b = --0.62915 + 0.55372i -0.62915 - 0.55372i -c = 0.055649 +n = 2; +rp = 6; +wp = 0.7; +[z, p, k]=cheby1(n, rp, wp, "high") ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/cheby2.xml b/help/en_US/cheby2.xml index 24cef7d..7eb4fea 100644 --- a/help/en_US/cheby2.xml +++ b/help/en_US/cheby2.xml @@ -17,20 +17,19 @@ <refnamediv> <refname>cheby2</refname> - <refpurpose>This function generates a Chebyshev type II filter with rs dB of stopband attenuation.</refpurpose> + <refpurpose>Chebyshev type II filter design with rs dB of stopband attenuation.</refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [a, b] = cheby2 (n, rs, wc) - [a, b] = cheby2 (n, rs, wc, "high") - [a, b] = cheby2 (n, rs, [wl, wh]) - [a, b] = cheby2 (n, rs, [wl, wh], "stop") - [a, b, c] = cheby2 (…) - [a, b, c, d] = cheby2 (…) - […] = cheby2 (…, "s") + [b, a] = cheby2 (n, rs, ws) + [b, a] = cheby2 (n, rs, ws, "high") + [b, a] = cheby2 (n, rs, [wl, wh]) + [b, a] = cheby2 (n, rs, [wl, wh], "stop") + [z, p, g] = cheby2 (…) + […] = cheby2 (…, "s") </synopsis> </refsynopsisdiv> @@ -38,37 +37,42 @@ <title>Parameters</title> <variablelist> <varlistentry><term>n:</term> - <listitem><para> positive integer value</para></listitem></varlistentry> - <varlistentry><term>rp:</term> - <listitem><para> non negative scalar value</para></listitem></varlistentry> - <varlistentry><term>w:</term> - <listitem><para> vector, all elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> positive integer value (order of filter)</para></listitem></varlistentry> + <varlistentry><term>rs:</term> + <listitem><para> non negative scalar value (stopband attenuation in dB)</para></listitem></varlistentry> + <varlistentry><term>ws:</term> + <listitem><para> vector, all elements must be in the range [0,1]</para><para> 1).Normalised digital stopband edge(s) for digital filter, in the range [0, 1] {dimensionless}</para><para> 2).Analog stopband edge(s) for analog filter, in the range [0, Inf] {rad/sec}</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function generates a Chebyshev type II filter with rs dB of stopband attenuation. -The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians. -[b, a] = cheby2(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians. -[b, a] = cheby2(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians. -[z, p, g] = cheby2(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. -[...] = cheby2(...,’s’) returns a Laplace space filter, w can be larger than 1. -[a,b,c,d] = cheby2(...) returns state-space matrices. +This function generates a Chebyshev type II filter with rs dB of stopband attenuation.</para> +<para>If third parameter is scalar then,the fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians.</para> +<para>[b, a] = cheby2(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.</para> +<para>[b, a] = cheby2(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.</para> +<para>[z, p, g] = cheby2(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.</para> +<para>[...] = cheby2(...,’s’) returns a Laplace space filter, wp can be larger than 1 rad/sec. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[a,b,c]=cheby2(2,5,0.7,"high") -a = --0.31645 - 0.94861i -0.31645 + 0.94861i -b = --0.39388 + 0.53138i -0.39388 - 0.53138i -c = 0.47528 +n = 2; +rs = 5; +ws = 0.7; +[z, p, g]=cheby2(n, rs, ws, "high") + ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/chirp.xml b/help/en_US/chirp.xml index 31ccb71..60fc279 100644 --- a/help/en_US/chirp.xml +++ b/help/en_US/chirp.xml @@ -17,10 +17,9 @@ <refnamediv> <refname>chirp</refname> - <refpurpose>This function evaluates a chirp signal at time t.</refpurpose> + <refpurpose>Chirp signal at time t.</refpurpose> </refnamediv> - <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> @@ -28,8 +27,8 @@ y = chirp(t, f0) y = chirp(t, f0, t1) y = chirp(t, f0, t1, f1) - y = chirp(t, f0, t1, f1, frm) - y = chirp(t, f0, t1, f1, frm, phse) + y = chirp(t, f0, t1, f1, form) + y = chirp(t, f0, t1, f1, form, phase) </synopsis> </refsynopsisdiv> @@ -37,26 +36,27 @@ <title>Parameters</title> <variablelist> <varlistentry><term>t:</term> - <listitem><para> vector</para></listitem></varlistentry> + <listitem><para> a vector of times to evaluate the chirp signal.</para></listitem></varlistentry> <varlistentry><term>f0:</term> - <listitem><para> </para></listitem></varlistentry> + <listitem><para> the frequency at t=0. [default value = 0 Hz]</para></listitem></varlistentry> <varlistentry><term>t1:</term> - <listitem><para> </para></listitem></varlistentry> + <listitem><para> some intermediate time. [default value = 1 sec] </para></listitem></varlistentry> <varlistentry><term>f1:</term> - <listitem><para> </para></listitem></varlistentry> - <varlistentry><term>frm:</term> - <listitem><para> string value, takes in "linear", "quadratic", "logarithmic"</para></listitem></varlistentry> - <varlistentry><term>phse:</term> - <listitem><para> </para></listitem></varlistentry> + <listitem><para> frequency at t=t1. [default value = 100 Hz]</para></listitem></varlistentry> + <varlistentry><term>form:</term> + <listitem><para> string value, takes in "linear", "quadratic", "logarithmic". [default value = "linear"]</para></listitem></varlistentry> + <varlistentry><term>phase:</term> + <listitem><para> phase shift at t=0. [default value = 0]</para></listitem></varlistentry> + <varlistentry><term>y:</term> + <listitem><para> chirp signal value corresponding to t. </para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function evaluates a chirp signal at time t. A chirp signal is a frequency swept cosine wave. -The first argument is a vector of times to evaluate the chirp signal, second argument is the frequency at t=0, third argument is time t1 and fourth argument is frequency at t1. +This function evaluates a chirp signal at time t. A chirp signal is a frequency swept cosine wave.</para> +<para>The first argument is a vector of times to evaluate the chirp signal, second argument is the frequency at t=0, third argument is time t1 and fourth argument is frequency at t1. The fifth argument is the form which takes in values "linear", "quadratic" and "logarithmic", the sixth argument gives the phase shift at t=0. </para> </refsection> @@ -64,12 +64,20 @@ The fifth argument is the form which takes in values "linear", "quadratic" and " <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -chirp([4,3,2,1],4,5,0.9) -ans = -column 1 to 3 -0.9685832 0.2486899 0.0627905 -column 4 -- 0.3681246 + t = [4,3,2,1]; + f0 = 4; + t1 = 5; + f1 = 0.9; + form = "quadratic"; + y = chirp(t, f0, t1, f1, form) ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/circshift.xml b/help/en_US/circshift.xml new file mode 100644 index 0000000..d457205 --- /dev/null +++ b/help/en_US/circshift.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + * + * This help file was generated from circshift.sci using help_from_sci(). + * + --> + +<refentry version="5.0-subset Scilab" xml:id="circshift" xml:lang="en" + xmlns="http://docbook.org/ns/docbook" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:ns3="http://www.w3.org/1999/xhtml" + xmlns:mml="http://www.w3.org/1998/Math/MathML" + xmlns:scilab="http://www.scilab.org" + xmlns:db="http://docbook.org/ns/docbook"> + + <refnamediv> + <refname>circshift</refname> + <refpurpose>Shifts array/matrix circularly</refpurpose> + <para> </para> + </refnamediv> + +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> +R = circshift(M, d) + </synopsis> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>M , R :</term> + <listitem><para> vector or matrix of any data type</para></listitem></varlistentry> + <varlistentry><term>d :</term> + <listitem><para> vector of integers. d(i) is the shift to be applied to the M's components along its ith dimension.</para>for example d = [0 n] will shift element n position along column<para></para></listitem></varlistentry> + </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Description</title> + <para> +circularly shifts by d(i) positions components of M along its ith dimensions +</para> + <para> </para> +</refsection> + +<refsection> + <title>Example : 1</title> + <programlisting role="example"><![CDATA[ + M = [1 2 3 4]; + circshift(M, [0 1]) + ]]></programlisting> +</refsection> + +</refentry> diff --git a/help/en_US/dctmtx.xml b/help/en_US/dctmtx.xml index 0b05453..2594b48 100644 --- a/help/en_US/dctmtx.xml +++ b/help/en_US/dctmtx.xml @@ -17,14 +17,14 @@ <refnamediv> <refname>dctmtx</refname> - <refpurpose></refpurpose> + <refpurpose>Return the DCT transformation matrix of size N-by-N.</refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [y]=dctmtx(n) + T = dctmtx(n) </synopsis> </refsynopsisdiv> @@ -39,7 +39,6 @@ <refsection> <title>Description</title> <para> -This is an Octave function dctmtx(n) returns a Discrete cosine transform matrix of order n-by-n. It is useful for jpeg image compression. D*A is the DCT of the columns of A and D'*A is the inverse DCT of the columns of A (when A is n-by-n). </para> </refsection> @@ -47,12 +46,16 @@ dctmtx(n) returns a Discrete cosine transform matrix of order n-by-n. It is usef <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -1. dctmtx(2) -ans = [0.70711 0.70711; 0.70711 -0.70711] -2. dctmtx(3) -ans = [5.7735e-01 5.7735e-01 5.7735e-01; -7.0711e-01 4.9996e-17 -7.0711e-01; -4.0825e-01 -8.1650e-01 4.0825e-01] + n= 3; + T = dctmtx(n) ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/dftmtx.xml b/help/en_US/dftmtx.xml index ed6ecf7..4197d98 100644 --- a/help/en_US/dftmtx.xml +++ b/help/en_US/dftmtx.xml @@ -17,14 +17,14 @@ <refnamediv> <refname>dftmtx</refname> - <refpurpose></refpurpose> + <refpurpose>Computes n-by-n Discrete Fourier transformation matrix. </refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [d]=dftmtx(n) + d = dftmtx(n) </synopsis> </refsynopsisdiv> @@ -39,7 +39,6 @@ <refsection> <title>Description</title> <para> -This is an Octave function This fuction gives a complex matrix of values whose product with a vector produces the discrete Fourier transform. This can also be achieved by directly using the fft function i.e. y=fft(x) is same as y=A*x where A=dftmtx(n). </para> </refsection> @@ -47,10 +46,15 @@ This fuction gives a complex matrix of values whose product with a vector produc <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -1. dftmtx(3) -ans = 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i -1.00000 + 0.00000i -0.50000 - 0.86603i -0.50000 + 0.86603i -1.00000 - 0.00000i -0.50000 + 0.86603i -0.50000 - 0.86603i +d = dftmtx(4) ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/digitrevorder.xml b/help/en_US/digitrevorder.xml new file mode 100644 index 0000000..988f372 --- /dev/null +++ b/help/en_US/digitrevorder.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + * + * This help file was generated from digitrevorder.sci using help_from_sci(). + * + --> + +<refentry version="5.0-subset Scilab" xml:id="digitrevorder" xml:lang="en" + xmlns="http://docbook.org/ns/docbook" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:ns3="http://www.w3.org/1999/xhtml" + xmlns:mml="http://www.w3.org/1998/Math/MathML" + xmlns:scilab="http://www.scilab.org" + xmlns:db="http://docbook.org/ns/docbook"> + + <refnamediv> + <refname>digitrevorder</refname> + <refpurpose></refpurpose> + </refnamediv> + +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> + [y,i] = digitrevorder(x,r) + y = digitrevorder(x,r) + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>x:</term> + <listitem><para> Vector of real or complex values</para></listitem></varlistentry> + <varlistentry><term>r:</term> + <listitem><para> radix / base </para></listitem></varlistentry> + <varlistentry><term>y:</term> + <listitem><para> input vector in bit reverse order</para></listitem></varlistentry> + <varlistentry><term>i:</term> + <listitem><para> indices after bit reversing </para></listitem></varlistentry> + <para> </para> + </variablelist> +</refsection> + +<refsection> + <title>Description</title> + <para> +This function returns the input data after reversing the digits of the indices and reordering the elements of the input array. +</para> +</refsection> + +<refsection> + <title>Examples</title> + <programlisting role="example"><![CDATA[ +x = [%i,1,3,6*%i] ; +r = 2 ; +[y i]=digitrevorder(x, r) + ]]></programlisting> +</refsection> + +</refentry> diff --git a/help/en_US/ellip.xml b/help/en_US/ellip.xml index 847f91e..66ec6fc 100644 --- a/help/en_US/ellip.xml +++ b/help/en_US/ellip.xml @@ -17,20 +17,19 @@ <refnamediv> <refname>ellip</refname> - <refpurpose>This function generates an elliptic or Cauer filter with rp dB of passband ripple and rs dB of stopband attenuation.</refpurpose> + <refpurpose>Elliptic/Cauer filter design with rp dB of passband ripple and rs dB of stopband attenuation.</refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [a, b] = ellip (n, rp, rs, wp) - [a, b] = ellip (n, rp, rs, wp, "high") - [a, b] = ellip (n, rp, rs, [wl, wh]) - [a, b] = ellip (n, rp, rs, [wl, wh], "stop") - [a, b, c] = ellip (…) - [a, b, c, d] = ellip (…) - […] = ellip (…, "s") + [b, a] = ellip (n, rp, rs, wp) + [b, a] = ellip (n, rp, rs, wp, "high") + [b, a] = ellip (n, rp, rs, [wl, wh]) + [b, a] = ellip (n, rp, rs, [wl, wh], "stop") + [z, p, g] = ellip (…) + […] = ellip (…, "s") </synopsis> </refsynopsisdiv> @@ -38,37 +37,36 @@ <title>Parameters</title> <variablelist> <varlistentry><term>n:</term> - <listitem><para> positive integer value</para></listitem></varlistentry> + <listitem><para> positive integer value (order of filter)</para></listitem></varlistentry> <varlistentry><term>rp:</term> - <listitem><para> non negative scalar value</para></listitem></varlistentry> + <listitem><para> non negative scalar value (passband ripple)</para></listitem></varlistentry> <varlistentry><term>rs:</term> - <listitem><para> non negative scalar value</para></listitem></varlistentry> - <varlistentry><term>w:</term> - <listitem><para> scalar or vector, all elements should be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> non negative scalar value (stopband attenuation)</para></listitem></varlistentry> + <varlistentry><term>ws:</term> + <listitem><para> scalar or vector of length 2, all elements should be in the range [0,1]</para><para> 1).Normalised digital passband edge(s) for digital filter, in the range [0, 1] {dimensionless}</para><para> 2).Analog passband edge(s) for analog filter, in the range [0, Inf] {rad/sec}</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -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, w can be larger than 1. -[a, b, c, d] = ellip(...) returns state-space matrices. +This function generates an elliptic or Cauer filter with rp dB of passband ripple and rs dB of stopband attenuation.</para> +<para>[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.</para> +<para>[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.</para> +<para>[b,a] = ellip(n, Rp, Rs, [Wl, Wh], 'stop') band reject filter with edges pi*Wl and pi*Wh</para> +<para>[z, p, g] = ellip(...) returns filter as zero-pole-gain.</para> +<para>[...] = ellip(...,’s’) returns a Laplace space filter, wp can be larger than 1 rad/sec. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[a,b]=ellip(2, 0.5, 0.7, [0.3,0.4]) -a = -0.88532 -1.58410 2.40380 -1.58410 0.88532 -b = -1.00000 -1.78065 2.68703 -1.75725 0.97454 +n = 2; +rp = 3; +rs = 40; +wp = [0.3 0.4]; +[b, a]=ellip(n, rp, rs, wp) ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/ellipap.xml b/help/en_US/ellipap.xml index 597a4c1..b0cc2fb 100644 --- a/help/en_US/ellipap.xml +++ b/help/en_US/ellipap.xml @@ -17,7 +17,7 @@ <refnamediv> <refname>ellipap</refname> - <refpurpose>Designs a lowpass analog elliptic filter.</refpurpose> + <refpurpose>Produces a lowpass analog elliptic prototype filter.</refpurpose> </refnamediv> @@ -25,8 +25,6 @@ <title>Calling Sequence</title> <synopsis> [z, p, g] = ellipap (n, Rp, Rs) - [z, p] = ellipap (n, Rp, Rs) - z = ellipap (n, Rp, Rs) </synopsis> </refsynopsisdiv> @@ -36,33 +34,41 @@ <varlistentry><term>n:</term> <listitem><para> Filter Order</para></listitem></varlistentry> <varlistentry><term>Rp:</term> - <listitem><para> Peak-to-peak passband ripple</para></listitem></varlistentry> + <listitem><para> Peak-to-peak passband ripple in dB</para></listitem></varlistentry> <varlistentry><term>Rs:</term> - <listitem><para> Stopband attenuation</para></listitem></varlistentry> + <listitem><para> Stopband attenuation in dB</para></listitem></varlistentry> + <varlistentry><term>z:</term> + <listitem><para> Zeros</para></listitem></varlistentry> + <varlistentry><term>p:</term> + <listitem><para> Poles</para></listitem></varlistentry> + <varlistentry><term>g:</term> + <listitem><para> Gain</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -It designs a lowpass analog elliptic filter of nth order, with a Peak-to-peak passband ripple of Rp and a stopband attenuation of Rs. +It gives a lowpass analog elliptic prototype filter of nth order, with a Peak-to-peak passband ripple of Rp dB and a stopband attenuation of Rs dB. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[z, p, g] = ellipap (5, 10, 10) -z = - -0.0000 + 2.5546i 0.0000 + 1.6835i -0.0000 - 2.5546i -0.0000 - 1.6835i - -p = - --0.05243 + 0.63524i -0.01633 + 0.96289i -0.05243 - 0.63524i -0.01633 - 0.96289i -0.07369 + 0.00000i - -g = 0.0015012 +n = 4; +Rp = 3; +Rs = 10; +[z, p, g] = ellipap (n, Rp, Rs) ]]></programlisting> </refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Sonu Sharma, RGIT Mumbai</member> + <member>FOSSEE, IIT Bombay</member> + </simplelist> + </refsection> + </refentry> diff --git a/help/en_US/ellipord.xml b/help/en_US/ellipord.xml index 0f562c8..2a3dbe2 100644 --- a/help/en_US/ellipord.xml +++ b/help/en_US/ellipord.xml @@ -17,14 +17,14 @@ <refnamediv> <refname>ellipord</refname> - <refpurpose>This function computes the minimum filter order of an elliptic filter with the desired response characteristics.</refpurpose> + <refpurpose>Minimum filter order of a digital elliptic/Cauer filter with the desired response characteristics. </refpurpose> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [n] = ellipord(Wp, Ws, Rp, Rs) + n = ellipord(Wp, Ws, Rp, Rs) [n, Wp] = ellipord(Wp, Ws, Rp, Rs) </synopsis> </refsynopsisdiv> @@ -33,36 +33,39 @@ <title>Parameters</title> <variablelist> <varlistentry><term>Wp:</term> - <listitem><para> scalar or vector of length 2, all elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> scalar or vector of length 2 (passband edge(s)), all elements must be in the range [0,1]</para></listitem></varlistentry> <varlistentry><term>Ws:</term> - <listitem><para> scalar or vector of length 2, all elements must be in the range [0,1]</para></listitem></varlistentry> + <listitem><para> scalar or vector of length 2 (stopband edge(s)), all elements must be in the range [0,1]</para></listitem></varlistentry> <varlistentry><term>Rp:</term> - <listitem><para> real or complex value</para></listitem></varlistentry> + <listitem><para> passband ripple in dB.</para></listitem></varlistentry> <varlistentry><term>Rs:</term> - <listitem><para> real or complex value</para></listitem></varlistentry> + <listitem><para> stopband attenuation in dB.</para></listitem></varlistentry> + <varlistentry><term>n:</term> + <listitem><para> Minimum order of filter satisfying given specs.</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -This function computes the minimum filter order of an elliptic filter with the desired response characteristics. -Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. -Frequencies are normalized to the Nyquist frequency in the range [0,1]. -Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. -If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. -If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. -If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. +This function computes the minimum filter order of an elliptic filter with the desired response characteristics.</para> +<para>Stopband frequency ws and passband frequency wp specify the the filter frequency band edges.</para> +<para>Frequencies are normalized to the Nyquist frequency in the range [0,1].</para> +<para>Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.</para> +<para>If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.</para> +<para>If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws.</para> +<para>If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[a,b]=ellipord(0.2, 0.5, 0.7, 0.4) -a = 1 -b = 0.20000 + Wp = [60 200]/500; + Ws = [50 250]/500; + Rp = 3; + Rs = 40; + [n,Wp] = ellipord(Wp,Ws,Rp,Rs) ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/isfir.xml b/help/en_US/isfir.xml index 7aa7e0d..5974df7 100644 --- a/help/en_US/isfir.xml +++ b/help/en_US/isfir.xml @@ -17,7 +17,60 @@ <refnamediv> <refname>isfir</refname> - <refpurpose>[nargout,nargin]=argn();</refpurpose> + <refpurpose> Determines whether given system function is FIR or not</refpurpose> + <para> </para> </refnamediv> + +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> + fir = isfir(b,a) + fir = isfir(sos) + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>b</term> + <listitem><para> Coefficients of numerator polynomial of system function </para></listitem></varlistentry> + <varlistentry><term>a</term> + <listitem><para> Coefficients of denumerator polynomial of system function</para></listitem></varlistentry> + <varlistentry><term>sos</term> + <listitem><para> Second order section matrix of order Kx6 </para></listitem></varlistentry> + <varlistentry><term>fir</term> + <listitem><para> This function returns logical 1 if system is FIR (fir = 1) </para> <para> Otherwise it returns logical 0 (fir = 0)</para></listitem></varlistentry> + </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Description</title> + <para> This function takes input a System function in terms of numerator and denumerator coefficients or in second order section (sos) matrix and checks for system having Finite Impulse Response (FIR) or not </para> +<para> </para> +</refsection> + +<refsection> + <title>Examples</title> + <para>Checking given system function is FIR or not</para> + <para> + <latex> + \begin{eqnarray} + H(z) = 1 - z^{-1} + z^{-2} + \end{eqnarray} + </latex> + </para> + <para> </para> + + <programlisting role="example"><![CDATA[ +b = [1 -1 1] ; +a = 1 ; +f = isfir(b,a) //This is an example of FIR system function, hence output will be f = 1 +]]></programlisting> +</refsection> + + + </refentry> diff --git a/help/en_US/islinphase.xml b/help/en_US/islinphase.xml index 54ba2d7..47e4407 100644 --- a/help/en_US/islinphase.xml +++ b/help/en_US/islinphase.xml @@ -17,7 +17,62 @@ <refnamediv> <refname>islinphase</refname> - <refpurpose>[nargout,nargin]=argn();</refpurpose> + <refpurpose>Checks given system function is linearphase or not</refpurpose> + <para> </para> </refnamediv> +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> + flag = islinphase(b,a) + flag = islinphase(sos) + flag = islinphase(...,tol) + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>b</term> + <listitem><para> Coefficients of numerator polynomial of system function </para></listitem></varlistentry> + <varlistentry><term>a</term> + <listitem><para> Coefficients of denumerator polynomial of system function</para></listitem></varlistentry> + <varlistentry><term>sos</term> + <listitem><para> Second order section matrix of order Kx6 </para></listitem></varlistentry> + <varlistentry><term>tol</term> + <listitem><para> Tolerence in similarities between two numbers in phase response </para></listitem></varlistentry> + <varlistentry><term>flag</term> + <listitem><para> This function returns logical 1 if system is linear phase (flag = 1) </para> <para> Otherwise it returns logical 0 (flag = 0)</para></listitem></varlistentry> + </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Description</title> + <para> This function takes input a System function in terms of numerator and denumerator coefficients or in second order section (sos) matrix and checks for system having Linear Phase Response or not </para> + <para> </para> +</refsection> + +<refsection> + <title>Examples</title> + + <para>Checking given system function is linear-phase or not</para> + <para> + <latex> + \begin{eqnarray} + H(z) = z^{-1} + 2 z^{-2} + 2 z^{-3} + z^{-4} + \end{eqnarray} + </latex> + </para> + <para> </para> + + <programlisting role="example"><![CDATA[ +b = [0 1 2 2 1 0] ; //Numerator polynomial coefficients +a = 1 ; //Denumerator polynomial coefficients +flag = islinphase(b,a) //This is an example of Symmetric FIR Filter which is Linear Phase, hence it will give output : flag = 1 +]]></programlisting> +</refsection> + + </refentry> diff --git a/help/en_US/ismaxphase.xml b/help/en_US/ismaxphase.xml index 67b480d..f3b3d65 100644 --- a/help/en_US/ismaxphase.xml +++ b/help/en_US/ismaxphase.xml @@ -17,7 +17,61 @@ <refnamediv> <refname>ismaxphase</refname> - <refpurpose>[nargout,nargin]=argn();</refpurpose> + <refpurpose>Checks given system function is Maximum-Phase system or not</refpurpose> + <para> </para> </refnamediv> + +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> +flag = ismaxphase(b,a) +flag = ismaxphase(sos) +flag = ismaxphase(...,tol) + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>b</term> + <listitem><para> Coefficients of numerator polynomial of system function </para></listitem></varlistentry> + <varlistentry><term>a</term> + <listitem><para> Coefficients of denumerator polynomial of system function</para></listitem></varlistentry> + <varlistentry><term>sos</term> + <listitem><para> Second order section matrix of order Kx6 </para></listitem></varlistentry> + <varlistentry><term>tol</term> + <listitem><para> Tolerence in similarities between two numbers in phase response </para></listitem></varlistentry> + <varlistentry><term>flag</term> + <listitem><para> This function returns logical 1 if system is maximum-phase system (flag = 1) </para> <para> Otherwise it returns logical 0 (flag = 0)</para></listitem></varlistentry> + </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Description</title> + <para> This function determines whether the given system function is maximum-phase system or not . Maximum-phase system means all zeros of transfer function will be outside the unit circle in z-plane, also poles must be within unit circle for stability and causality </para> + <para> </para> +</refsection> + +<refsection> + <title>Examples</title> + + <para>Checking given system function is maximum phase system or not</para> + <para> + <latex> + \begin{eqnarray} + H(z) = 1 -5z^{-1} + 6 z^{-2} + \end{eqnarray} + </latex> + </para> + <para> </para> + <programlisting role="example"><![CDATA[ +b = [1 -5 6] ; //Numerator polynomial coefficients +a = 1 ; //Denumerator polynomial coefficients +flag = ismaxphase(b,a) //This is an example of Maximum-Phase system, hence it will give output as : flag = 1 +]]></programlisting> +</refsection> + </refentry> diff --git a/help/en_US/isminphase.xml b/help/en_US/isminphase.xml index f395fbe..40eef06 100644 --- a/help/en_US/isminphase.xml +++ b/help/en_US/isminphase.xml @@ -17,7 +17,61 @@ <refnamediv> <refname>isminphase</refname> - <refpurpose>[nargout,nargin]=argn();</refpurpose> + <refpurpose>Checks given system function is Maximum-Phase system or not</refpurpose> + <para> </para> </refnamediv> +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> +flag = ismaxphase(b,a) +flag = ismaxphase(sos) +flag = ismaxphase(...,tol) + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>b</term> + <listitem><para> Coefficients of numerator polynomial of system function </para></listitem></varlistentry> + <varlistentry><term>a</term> + <listitem><para> Coefficients of denumerator polynomial of system function</para></listitem></varlistentry> + <varlistentry><term>sos</term> + <listitem><para> Second order section matrix of order Kx6 </para></listitem></varlistentry> + <varlistentry><term>tol</term> + <listitem><para> Tolerence in similarities between two numbers in phase response </para></listitem></varlistentry> + <varlistentry><term>flag</term> + <listitem><para> This function returns logical 1 if system is minimum-phase system (flag = 1) </para> <para> Otherwise it returns logical 0 (flag = 0)</para></listitem></varlistentry> + </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Description</title> + <para> This function determines whether the given system function is minimum-phase system or not . Minimum-phase system means all zeros of transfer function will be inside the unit circle in z-plane,also poles must be within unit circle for stability and causality </para> + <para> </para> +</refsection> + +<refsection> + <title>Examples</title> + + <para>Checking given system function is minimum phase system or not</para> + <para> + <latex> + \begin{eqnarray} + H(z) = 1 -0.3z^{-1} + 0.02 z^{-2} + \end{eqnarray} + </latex> + </para> + <para> </para> + + <programlisting role="example"><![CDATA[ +b = [1 -0.3 0.02] ; //Numerator polynomial coefficients +a = 1 ; //Denumerator polynomial coefficients +flag = isminphase(b,a) //This is an example of Minimum-Phase system, hence it will give output as : flag = 1 +]]></programlisting> +</refsection> + </refentry> diff --git a/help/en_US/isstable.xml b/help/en_US/isstable.xml index 295c1d4..9b53add 100644 --- a/help/en_US/isstable.xml +++ b/help/en_US/isstable.xml @@ -17,7 +17,75 @@ <refnamediv> <refname>isstable</refname> - <refpurpose>SOS matrix corresponds to [bi(1) bi(2) bi(3) ai(1) ai(2) ai(3)].</refpurpose> + <refpurpose>Checks stability of given Discrete time system function</refpurpose> + <para> </para> </refnamediv> +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> +flag = ismaxphase(b,a) +flag = ismaxphase(sos) + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>b</term> + <listitem><para> Coefficients of numerator polynomial of system function </para></listitem></varlistentry> + <varlistentry><term>a</term> + <listitem><para> Coefficients of denumerator polynomial of system function</para></listitem></varlistentry> + <varlistentry><term>sos</term> + <listitem><para> Second order section matrix of order Kx6 </para></listitem></varlistentry> + <varlistentry><term>flag</term> + <listitem><para> This function returns logical 1 if system is Stable (flag = 1) </para> <para> Otherwise it returns logical 0 (flag = 0)</para></listitem></varlistentry> + </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Description</title> + <para> This function determines whether the given system function is Stable system function or not. Stable system means all poles of transfer function will be inside the unit circle in z-plane </para> + <para> </para> +</refsection> + +<refsection> + <title>Example : 1 <para>Example of stable system function </para> </title> + <para> + <latex> + \begin{eqnarray} + H(z) = \frac{1 +2z^{-1} } {1 -0.7z^{-1} + 0.1 z^{-2} } + \end{eqnarray} + </latex> + </para> + <para> </para> + + <programlisting role="example"><![CDATA[ +b = [1 2] ; //Numerator polynomial coefficients +a = [1 -0.7 0.1] ; //Denumerator polynomial coefficients +flag = isstable(b,a) //This is an example of Stable system, hence it will give output as : flag = 1 +]]></programlisting> +</refsection> + +<refsection> +<title> Example : 2 <para>Example of unstable system function</para> </title> + + <para> + <latex> + \begin{eqnarray} + H(z) = \frac{1 +2z^{-1} } {1 +5z^{-1} + 6z^{-2} } + \end{eqnarray} + </latex> + </para> + <para> </para> + + <programlisting role="example"><![CDATA[ +b = [1 2] ; //Numerator polynomial coefficients +a = [1 5 6] ; //Denumerator polynomial coefficients +flag = isstable(b,a) //This is an example of Unstable system, hence it will give output as : flag = 0 +]]></programlisting> +</refsection> + </refentry> diff --git a/help/en_US/kaiser.xml b/help/en_US/kaiser.xml index 394119b..32afa90 100644 --- a/help/en_US/kaiser.xml +++ b/help/en_US/kaiser.xml @@ -53,14 +53,9 @@ The second parameter gives the stop band attenuation of the Fourier transform of <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -kaiser(6,0.2) -ans = -0.9900745 -0.9964211 -0.9996020 -0.9996020 -0.9964211 -0.9900745 +L = 6 ; +beta = 0.2 ; +kaiser(L, beta) ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/lar2rc.xml b/help/en_US/lar2rc.xml index 5f07b8d..4a40678 100644 --- a/help/en_US/lar2rc.xml +++ b/help/en_US/lar2rc.xml @@ -17,7 +17,8 @@ <refnamediv> <refname>lar2rc</refname> - <refpurpose></refpurpose> + <refpurpose> Log Area Ratio to Reflection Coefficient</refpurpose> + <para> </para> </refnamediv> @@ -26,6 +27,7 @@ <synopsis> k = lar2rc(g) </synopsis> + <para> </para> </refsynopsisdiv> <refsection> @@ -36,16 +38,21 @@ <varlistentry><term>k:</term> <listitem><para> returns the reflection coefficients.</para></listitem></varlistentry> </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Description</title> + <para> This function takes input as a vector of log area ratios and returns vector of reflection coefficients corresponding to log area ratio vector </para> + <para> </para> </refsection> <refsection> <title>Examples</title> + <para> </para> <programlisting role="example"><![CDATA[ -X = [7 6 5 8 3 6 8 7 5 2 4 7 4 3 2 5 4 9 5 3 5 7 3 9 4 1 2 0 5 4 8 6 4 6 5 3]; -k = lar2rc(X) -or t=[2 5 6; 8 6 5; 8 9 4] -k = lar2rc(t) - +g = [0.6389 4.5989 0.0063 0.0163 -0.0163]; //log area ratio inputs +k = lar2rc(g) // returns reflection coefficients corresponding to log area ratios ]]></programlisting> </refsection> @@ -57,4 +64,5 @@ k = lar2rc(t) <member><link linkend="Modified">to match MATLAB o/p when i/p is of type char and is a string by Debdeep Dey</link></member> </simplelist> </refsection> + </refentry> diff --git a/help/en_US/levinson.xml b/help/en_US/levinson.xml index 056795f..ac340a6 100644 --- a/help/en_US/levinson.xml +++ b/help/en_US/levinson.xml @@ -17,7 +17,81 @@ <refnamediv> <refname>levinson</refname> - <refpurpose></refpurpose> + <refpurpose>Levinson-Durbin Recurssion Algorithm</refpurpose> + <para> </para> </refnamediv> + +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> +a = levinson(r) +a = levinson(r,n) +[a,e] = levinson(r,n) +[a,e,k] = levinson(r,n) + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>r</term> + <listitem><para> Real or complex deterministic autocorrelation sequence input </para></listitem></varlistentry> + <varlistentry><term>a</term> + <listitem><para> Coefficients of length(r)-1 order Autoregressive linear process </para></listitem></varlistentry> + <varlistentry><term>n</term> + <listitem><para> Order of autoregressive model (default value is length(r)-1 , if n is not given)</para></listitem></varlistentry> + <varlistentry><term>e</term> + <listitem><para> Prediction error of order n</para></listitem></varlistentry> + <varlistentry><term>k</term> + <listitem><para> Reflection coefficient vector of length n</para></listitem></varlistentry> + </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Description</title> + <para> The Levinson-Durbin recursion algorithm is used for finding an all-pole IIR filter with a given deterministic autocorrelation sequence (r) </para> + + <para> + <latex> + \begin{eqnarray} + H(z) = \frac{1}{1+a(2)z^{-1}+a(3)z^{-2} + ... +a(n+1)z^{-n}} + \end{eqnarray} + </latex> + </para> + + <para> </para> +</refsection> + +<refsection> + <title>Examples </title> + <para> Estimate the coefficients of an autoregressive process given by equation </para> + + <para> + <latex> + \begin{eqnarray} + x(n) = 0.1x(n-1) - 0.8x(n-2) + w(n) + \end{eqnarray} + </latex> + </para> + <para> </para> + + <programlisting role="example"><![CDATA[ + +a = [1 0.1 -0.8]; + +v = 0.4; //variance, v=0.4 +w = sqrt(v)*rand(15000,1,"normal"); +x = filter(1,a,w); + +[r,lg] = xcorr(x,'biased'); +r(lg<0) = []; + +ar = levinson(r,length(a)-1) //coefficients of autoregressive process + +]]></programlisting> +</refsection> + </refentry> diff --git a/help/en_US/lpc.xml b/help/en_US/lpc.xml index 1ebe531..079923e 100644 --- a/help/en_US/lpc.xml +++ b/help/en_US/lpc.xml @@ -18,6 +18,7 @@ <refnamediv> <refname>lpc</refname> <refpurpose>Linear prediction filter coefficients</refpurpose> + <para> </para> </refnamediv> @@ -26,9 +27,8 @@ <synopsis> [a,g] = lpc(x) [a,g] = lpc(x,p) - - </synopsis> + <para> </para> </refsynopsisdiv> <refsection> @@ -36,44 +36,71 @@ <para> [a,g] = lpc(x,p) Determines the coefficients of a pth order forward linear predictor -filter by minimizing the squared error. If p is unspecified, a -default value of length(x)-1 is used. +filter by minimizing the squared error. <para>If p is unspecified, a +default value of length(x)-1 is used.</para> </para> - <para> -</para> + <para> </para> </refsection> <refsection> <title>Parameters</title> <variablelist> <varlistentry><term>x:</term> - <listitem><para> double</para></listitem></varlistentry> + <listitem><para> double</para><para>input signal, if it is a matrix each column is computed independently</para></listitem></varlistentry> <varlistentry><term>p:</term> - <listitem><para> int, natural number, scalar</para></listitem></varlistentry> + <listitem><para> int, natural number, scalar</para><para>order of linear predictor filter, value must be scalar, positive and must be less than or equal to length of input signal </para></listitem></varlistentry> <varlistentry><term>a:</term> - <listitem><para> double</para></listitem></varlistentry> + <listitem><para> double</para><para>coefficient of forward linear predictor, coefficient for each signal input is returned as a row vector</para></listitem></varlistentry> <varlistentry><term>g:</term> - <listitem><para> double</para></listitem></varlistentry> + <listitem><para> double</para><para>Column vector of averaged square prediction error</para></listitem></varlistentry> </variablelist> </refsection> <refsection> + <title>Description</title> + <para> This function determines coefficients of a forward linear predictor by minimizing prediction error in least squares sense. It is used in Digital Filter Design </para> + <para> </para> +</refsection> + +<refsection> <title>Examples</title> - <programlisting role="example"><![CDATA[ -1) -noise = randn(20000,1); -x = filter(1,[1 1/5 1/3 1/4],noise); -x = x(15904:20000); -[a,g] = lpc(x,3); + <programlisting role="example"><![CDATA[ +noise = rand(50000,1,"normal"); //Gaussian White Noise +x = filter(1,[1 1/2 1/3 1/4],noise); +x = x(45904:50000); +[a,g]= lpc(x,3) +est_x = filter([0 -a(2:$)],1,x); +e = x-est_x; +[acs,lags] = xcorr(e,'coeff'); +plot(1:97,x(4001:4097),1:97,est_x(4001:4097),'--'); +a = gca(); +a.grid = [1,1]; +title 'Original Signal vs. LPC Estimate'; +xlabel 'Sample number', ylabel 'Amplitude'; +legend('Original signal','LPC estimate'); + ]]></programlisting> -References -[1] Hayes, Monson H. Statistical digital signal processing and modeling. -John Wiley & Sons, 2009, pg. 220 + <scilab:image> +noise = rand(50000,1,"normal"); //Gaussian White Noise +x = filter(1,[1 1/2 1/3 1/4],noise); +x = x(45904:50000); +[a,g]= lpc(x,3) +est_x = filter([0 -a(2:$)],1,x); +e = x-est_x; +[acs,lags] = xcorr(e,'coeff'); +plot(1:97,x(4001:4097),1:97,est_x(4001:4097),'--'); +a = gca(); +a.grid = [1,1]; +title 'Original Signal vs. LPC Estimate'; +xlabel 'Sample number', ylabel 'Amplitude'; +legend('Original signal','LPC estimate'); + </scilab:image> + <para> </para> - ]]></programlisting> </refsection> + <refsection> <title>See also</title> <simplelist type="inline"> diff --git a/help/en_US/medfilt1.xml b/help/en_US/medfilt1.xml index 2766e88..2760fe9 100644 --- a/help/en_US/medfilt1.xml +++ b/help/en_US/medfilt1.xml @@ -18,68 +18,107 @@ <refnamediv> <refname>medfilt1</refname> <refpurpose>1D median filtering</refpurpose> + <para> </para> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> + y = medfilt1(x) + y = medfilt1(x, n) + y = medfilt1(x, n, dim) + y = medfitl1(__, nanflag, padding) </synopsis> + <para> </para> </refsynopsisdiv> <refsection> <title>Description</title> <para> y = medfilt1(x) -Applies a 3rd order 1-dimensional median filter to input x along the -first non-zero dimension. The function appropriately pads the signal + </para> +<para>Applies a 3rd order 1-dimensional median filter to input x along the +first non-zero dimension.</para> + <para>The function appropriately pads the signal with zeros at the endings. For a segment, a median is calculated as the middle value (average of two middle values) for odd number -number (even number) of data points. -y = medfilt1(x,n) -Applies a nth order 1-dimensional median filter. -y = medfilt1(x,n,dim) -Applies the median filter along the n-th dimension -y = medfilt1(__, nanflag, padding) -nanflag specifies how NaN values are treated. padding specifies the -type of filtering to be performed at the signal edges. - </para> - <para> -</para> +number (even number) of data points.</para> +<para> </para> +<para>y = medfilt1(x,n)</para> +<para>Applies a nth order 1-dimensional median filter.</para> +<para> </para> +<para>y = medfilt1(x,n,dim)</para> +<para>Applies the median filter along the n-th dimension</para> +<para> </para> +<para>y = medfilt1(__, nanflag, padding)</para> +<para>nanflag specifies how NaN values are treated. padding specifies the +type of filtering to be performed at the signal edges.</para> + + <para> </para> </refsection> <refsection> <title>Parameters</title> <variablelist> <varlistentry><term>x:</term> - <listitem><para> int | double</para></listitem></varlistentry> + <listitem><para> int | double</para> <para>Input signal.</para></listitem></varlistentry> <varlistentry><term>n:</term> - <listitem><para> positive integer scalar</para></listitem></varlistentry> + <listitem><para> positive integer, scalar</para><para> + Filter order. </para> + <para> Defaults to 3.The order of the median filter. Must be less than + (length of the signal) where signals are 1D vectors along the + dimension of x to be filtered </para></listitem></varlistentry> <varlistentry><term>dim:</term> - <listitem><para> positive integer scalar</para></listitem></varlistentry> + <listitem><para> positive integer scalar</para><para> + Dimension to filter along. </para> + <para> Defaults to first non-singleton dimension of x</para></listitem></varlistentry> <varlistentry><term>nanflag:</term> - <listitem><para> 'includenan' (default) | 'omitnan'</para></listitem></varlistentry> - <varlistentry><term>* includenan:</term> - <listitem><para> Filtering such that the median of any segment</para></listitem></varlistentry> - <varlistentry><term>* omitnan:</term> - <listitem><para> Filtering with NaNs omitted in each segment. If a segment</para></listitem></varlistentry> + <listitem><para> 'includenan' (default) | 'omitnan'</para> <para> + NaN condition.</para> + <para> * includenan: Filtering such that the median of any segment containing a NaN is also a NaN. </para> + <para>* omitnan: Filtering with NaNs omitted in each segment. If a segment contains all NaNs, the result is NaN</para> +</listitem></varlistentry> + <varlistentry><term>y:</term> - <listitem><para> int | double</para></listitem></varlistentry> + <listitem><para> int | double</para><para> + The filtered signal.</para> + <para>y has the same size as x</para></listitem></varlistentry> </variablelist> + <para> </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -1) Noise supression using median filtering -fs = 1e3; -t = 1:1/fs:1; -s = sin(2*%pi*2*t)+ cos(2*%pi*5*t); -// Adding noise -x = s + 0.1*randn(size(s)); -y = medfilt1(x); +//Generate a sinusoidal signal sampled for 1 second at 100 Hz. Add a higher-frequency sinusoid to simulate noise. +fs = 100; +t = 0:1/fs:1; +x = sin(2*%pi*t*3)+0.25*sin(2*%pi*t*40); +//Use a 10th-order median filter to smooth the signal. Plot the result. +y = medfilt1(x,10); +plot(t,x,t,y) +legend('Original','Filtered'); +y = round(y*10000)/10000; +y = y' ]]></programlisting> + +<scilab:image> +//Generate a sinusoidal signal sampled for 1 second at 100 Hz. Add a higher-frequency sinusoid to simulate noise. +fs = 100; +t = 0:1/fs:1; +x = sin(2*%pi*t*3)+0.25*sin(2*%pi*t*40); + +//Use a 10th-order median filter to smooth the signal. Plot the result. +y = medfilt1(x,10); +plot(t,x,t,y) +legend('Original','Filtered'); +y = round(y*10000)/10000; +y = y' +</scilab:image> + + </refsection> <refsection> diff --git a/help/en_US/movingrms.xml b/help/en_US/movingrms.xml index c40672d..5498eb9 100644 --- a/help/en_US/movingrms.xml +++ b/help/en_US/movingrms.xml @@ -17,52 +17,54 @@ <refnamediv> <refname>movingrms</refname> - <refpurpose></refpurpose> + <refpurpose>Find moving RMS value of signal in x</refpurpose> + <para> </para> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - [rmsx,w]=movingrms(x,w,rc,Fs=1) + [rmsx,w]=movingrms(x,width,risetime) + [rmsx,w]=movingrms(x,width,risetime,Fs) </synopsis> + <para> </para> </refsynopsisdiv> <refsection> <title>Parameters</title> <variablelist> <varlistentry><term>x:</term> - <listitem><para> Real or complex valued vector or matrix</para></listitem></varlistentry> - <varlistentry><term>w:</term> + <listitem><para> (Real or complex valued vector or matrix) Input signal samples</para></listitem></varlistentry> + <varlistentry><term>width:</term> <listitem><para> Real or complex scalar value</para></listitem></varlistentry> - <varlistentry><term>rc:</term> + <varlistentry><term>risetime:</term> <listitem><para> Real or complex scalar value</para></listitem></varlistentry> <varlistentry><term>Fs:</term> - <listitem><para> Real or complex scalar value</para></listitem></varlistentry> + <listitem><para> (Real or complex scalar value) Smapling frequency</para></listitem></varlistentry> </variablelist> + <para> </para> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -The signal is convoluted against a sigmoid window of width w and risetime rc with the units of these parameters relative to the value of the sampling frequency given in Fs (Default value=1). +In this function signal is convoluted against a sigmoid window of width w and risetime rc with the units of these parameters relative to the value of the sampling frequency given in Fs (Default value=1). </para> + <para> </para> </refsection> <refsection> - <title>Examples</title> + <title>Example : 1</title> + <programlisting role="example"><![CDATA[ +[a,b]=movingrms ([4.4 94 1;-2 5*%i 5],1,-2) // moving rms with default value of Fs = 1 + ]]></programlisting> + +<title>Example : 2</title> <programlisting role="example"><![CDATA[ -1. [a,b]=movingrms ([4.4 94 1;-2 5i 5],1,-2) -a = 0.91237 17.71929 0.96254 -0.91237 17.71929 0.96254 -b = 0.18877 -0.18877 -2. [a,b]=movingrms ([4.4 94 1;-2 5i 5],1,-2,2) -a = 4.8332 93.8669 5.0990 -4.8332 93.8669 5.0990 -b = 1 -1 +[a,b]=movingrms ([4.4 94 1;-2 5*%i 5],1,-2,2)// moving rms with value of Fs = 2 + ]]></programlisting> </refsection> + </refentry> diff --git a/help/en_US/ncauer.xml b/help/en_US/ncauer.xml index a9395af..3260e0f 100644 --- a/help/en_US/ncauer.xml +++ b/help/en_US/ncauer.xml @@ -25,8 +25,6 @@ <title>Calling Sequence</title> <synopsis> [Zz, Zp, Zg] = ncauer(Rp, Rs, n) - [Zz, Zp] = ncauer(Rp, Rs, n) - Zz = ncauer(Rp, Rs, n) </synopsis> </refsynopsisdiv> @@ -36,36 +34,45 @@ <varlistentry><term>n:</term> <listitem><para> Filter Order</para></listitem></varlistentry> <varlistentry><term>Rp:</term> - <listitem><para> Peak-to-peak passband ripple</para></listitem></varlistentry> + <listitem><para> Peak-to-peak passband ripple in dB</para></listitem></varlistentry> <varlistentry><term>Rs:</term> - <listitem><para> Stopband attenuation</para></listitem></varlistentry> + <listitem><para> Stopband attenuation in dB</para></listitem></varlistentry> + <varlistentry><term>Zz:</term> + <listitem><para> Zeros</para></listitem></varlistentry> + <varlistentry><term>Zp:</term> + <listitem><para> Poles</para></listitem></varlistentry> + <varlistentry><term>Zg:</term> + <listitem><para> Gain</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -It designs an analog prototype for Cauer filter of nth order, with a Peak-to-peak passband ripple of Rp and a stopband attenuation of Rs. +It gives an analog prototype for Cauer filter (elliptic filter) of nth order, with a Peak-to-peak passband ripple of Rp and a stopband attenuation of Rs. </para> +<para> +This function is same as ellipap() only order of input argument is different,</para> + <para> This function is only for octave compatibility only </para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -n = 5; -Rp = 5; -Rs = 5; +n = 4; +Rp = 3; +Rs = 10; [Zz, Zp, Zg] = ncauer(Rp, Rs, n) -Zz = -0.0000 + 2.5546i 0.0000 + 1.6835i -0.0000 - 2.5546i -0.0000 - 1.6835i - -Zp = - --0.10199 + 0.64039i -0.03168 + 0.96777i -0.10199 - 0.64039i -0.03168 - 0.96777i -0.14368 + 0.00000i - -Zg = 0.0030628 ]]></programlisting> </refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Sonu Sharma, RGIT Mumbai</member> + <member>FOSSEE, IIT Bombay</member> + </simplelist> + </refsection> + </refentry> diff --git a/help/en_US/postpad.xml b/help/en_US/postpad.xml new file mode 100644 index 0000000..8c96bae --- /dev/null +++ b/help/en_US/postpad.xml @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + * + * This help file was generated from postpad.sci using help_from_sci(). + * + --> + +<refentry version="5.0-subset Scilab" xml:id="postpad" xml:lang="en" + xmlns="http://docbook.org/ns/docbook" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:ns3="http://www.w3.org/1999/xhtml" + xmlns:mml="http://www.w3.org/1998/Math/MathML" + xmlns:scilab="http://www.scilab.org" + xmlns:db="http://docbook.org/ns/docbook"> + + <refnamediv> + <refname>postpad</refname> + <refpurpose></refpurpose> + </refnamediv> + +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> + Y = postpad (X, L) + Y = postpad (X, L, C) + </synopsis> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>X:</term> + <listitem><para>Input vector or matrix of real numbers.</para></listitem></varlistentry> + <varlistentry><term>L:</term> + <listitem><para> The length of the final postpadded sequence.</para></listitem></varlistentry> + <varlistentry><term>C:</term> + <listitem><para>number used for postpadding.</para></listitem></varlistentry> + <varlistentry><term>Y:</term> + <listitem><para>Output</para></listitem></varlistentry> + </variablelist> +</refsection> + +<refsection> + <title>Description</title> + <para> + Append the scalar value C to the vector X until it is of length L. + </para> + <para> + If C is not given, a value of 0 is used. + </para> + <para> + If 'length (X) > L', elements from the end of X are removed until a vector of length L is obtained. + </para> +</refsection> + +<refsection> + <title>Examples</title> + <programlisting role="example"><![CDATA[ + x = [1 2 3]; + L = 6; + y = postpad(x, L) + ]]></programlisting> +</refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> + </refsection> + +</refentry> diff --git a/help/en_US/pulseperiod.xml b/help/en_US/pulseperiod.xml index 7fc379f..c28e26e 100644 --- a/help/en_US/pulseperiod.xml +++ b/help/en_US/pulseperiod.xml @@ -17,20 +17,86 @@ <refnamediv> <refname>pulseperiod</refname> - <refpurpose></refpurpose> + <refpurpose>This function estimate pulse period of real vector x.</refpurpose> + <para> </para> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - p=pulseperiod(x) - p=pulseperiod(x, Fs) - p=pulseperiod(x, t) - p=pulseperiod (x, t, 'Polarity', pol) - p=pulseperiod(x, t, 'MidPercentReferenceLevel', N ) - p=pulseperiod(x, t, 'Tolerance', M) - p=pulseperiod(x, t,'StateLevels', O) + p=pulseperiod(x) + p=pulseperiod(x, Fs) + p=pulseperiod(x, t) + p=pulseperiod (x, t, 'Polarity', pol) + p=pulseperiod(x, t, 'MidPercentReferenceLevel', N ) + p=pulseperiod(x, t, 'Tolerance', M) + p=pulseperiod(x, t,'StateLevels', O) + [p initialcross finalcross nextcross midreference]=pulseperiod(x) + [p initialcross finalcross nextcross midreference]=pulseperiod(x, t) + [p initialcross finalcross nextcross midreference]=pulseperiod(x, t) + [p initialcross finalcross nextcross midreference]=pulseperiod(x, t, 'Polarity', pol) + [p initialcross finalcross nextcross midreference]=pulseperiod(x, t, 'MidPercentReferenceLevel', N ) + [p initialcross finalcross nextcross midreference]= pulseperiod(x, t, 'Tolerance', M) + [p initialcross finalcross nextcross midreference]= pulseperiod(x, t,'StateLevels', O) + [p initialcross finalcross nextcross midreference]= pulseperiod(x, t,'StateLevels', O, 'fig', f) </synopsis> + <para> </para> </refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>x</term> + <listitem><para> : real input vector </para></listitem></varlistentry> + <varlistentry><term>Fs</term> + <listitem><para> : specifies the sample rate, Fs, as a positive scalar, where the first sample instant corresponds to a time of zero. </para></listitem></varlistentry> + <varlistentry><term>t</term> + <listitem><para> : defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.</para></listitem></varlistentry> + <varlistentry><term> 'Polarity', pol</term> + <listitem><para> : pol specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive'</para></listitem></varlistentry> + <varlistentry><term> 'MidPercentReferenceLevel', N </term> + <listitem><para> : specify the mid percent reference leves as a percentage, default value of N is 50.</para></listitem></varlistentry> + <varlistentry><term> 'Tolerance', M </term> + <listitem><para> : define the tolerance value as real scaler value, where default value of M is 2.0.</para></listitem></varlistentry> + <varlistentry><term>'StateLevels', O</term> + <listitem><para> : O define the lower and upper state levels as two element real vector.</para></listitem></varlistentry> + <varlistentry><term> 'fig', f</term> + <listitem><para> : f specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.</para></listitem></varlistentry> + + <varlistentry><term> p </term> + <listitem><para> : returns a vector of difference between the mid-crossings of the initial transition of each positive-polarity pulse and the next positive-going transition </para></listitem></varlistentry> + <varlistentry><term> initialcross </term> + <listitem><para> : returns a vector of initial cross values of bilevel waveform transitions x.</para></listitem></varlistentry> + <varlistentry><term> finalcross </term> + <listitem><para> : returns a vector of final cross values of bilevel waveform transitions x.</para></listitem></varlistentry> + <varlistentry><term> nextcross </term> + <listitem><para> : returns a vector of next cross values of bilevel waveform transitions x. </para></listitem></varlistentry> + <varlistentry><term> midreference </term> + <listitem><para> : return mid reference value corrosponding to mid percent reference value. </para></listitem></varlistentry> +</variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Examples </title> + + <programlisting role="example"><![CDATA[ + + x = fscanfMat("macros/pulsedata_x.txt"); //Importing samples of pulse + t = fscanfMat("macros/pulsedata_t.txt"); + clf //clearing plot history + p = pulseperiod(x,t,'fig','ON') // Detremining pulse period and ploting it + +]]></programlisting> + +<scilab:image> + x = [0. 0.0108 0.0367 -0.0452 0.0172 0.0064 -0.0262 -0.0087 0.0069 0.0716 0.0554 -0.027 0.0607 5.0145 4.9987 5.0143 4.9959 4.9975 5.0298 0.0282 0.0283 0.0134 -0.0241 0.0143 0.0326 0.0098 0.0207 0.0145 -0.0061 0.0059 -0.0157 0.0178 -0.0229 4.9786]; + t = [0. 0.025 0.05 0.075 0.1 0.125 0.15 0.175 0.2 0.225 0.25 0.275 0.3 0.325 0.35 0.375 0.4 0.425 0.45 0.475 0.5 0.525 0.55 0.575 0.6 0.625 0.65 0.675 0.7 0.725 0.75 0.775 0.8 0.825 ]; + clf + p = pulseperiod(x,t,'fig','ON') +</scilab:image> + +</refsection> + </refentry> diff --git a/help/en_US/pulsesep.xml b/help/en_US/pulsesep.xml index 4c28fd4..32a8915 100644 --- a/help/en_US/pulsesep.xml +++ b/help/en_US/pulsesep.xml @@ -17,20 +17,86 @@ <refnamediv> <refname>pulsesep</refname> - <refpurpose></refpurpose> + <refpurpose>This function estimate pulse separation between bilevel waveform pulses.</refpurpose> + <para> </para> </refnamediv> <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - s=pulsesep(x) - s=pulsesep(x, Fs) - s=pulsesep(x, t) - s=pulsesep (x, t, 'Polarity', pol) - s=pulsesep(x, t, 'MidPercentReferenceLevel', N ) - s=pulsesep(x, t, 'Tolerance', M) - s=pulsesep(x, t,'StateLevels', [O 1]) + s=pulsesep(x) + s=pulsesep(x, Fs) + s=pulsesep(x, t) + s=pulsesep (x, t, 'Polarity', pol) + s=pulsesep(x, t, 'MidPercentReferenceLevel', N ) + s=pulsesep(x, t, 'Tolerance', M) + s=pulsesep(x, t,'StateLevels', O) + [s initialcross finalcross nextcross midreference]=pulsesep(x) + [s initialcross finalcross nextcross midreference]=pulsesep(x, t) + [s initialcross finalcross nextcross midreference]=pulsesep(x, t) + [s initialcross finalcross nextcross midreference]=pulsesep(x, t, 'Polarity', pol) + [s initialcross finalcross nextcross midreference]=pulsesep(x, t, 'MidPercentReferenceLevel', N ) + [s initialcross finalcross nextcross midreference]= pulsesep(x, t, 'Tolerance', M) + [s initialcross finalcross nextcross midreference]= pulsesep(x, t,'StateLevels', O) + [s initialcross finalcross nextcross midreference]= pulsesep(x, t,'StateLevels', O, 'fig', f) </synopsis> + <para> </para> </refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>x</term> + <listitem><para> : real input vector </para></listitem></varlistentry> + <varlistentry><term>Fs</term> + <listitem><para> : specifies the sample rate, Fs, as a positive scalar, where the first sample instant corresponds to a time of zero. </para></listitem></varlistentry> + <varlistentry><term>t</term> + <listitem><para> : defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.</para></listitem></varlistentry> + <varlistentry><term> 'Polarity', pol</term> + <listitem><para> : pol specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive'</para></listitem></varlistentry> + <varlistentry><term> 'MidPercentReferenceLevel', N </term> + <listitem><para> : specify the mid percent reference leves as a percentage, default value of N is 50.</para></listitem></varlistentry> + <varlistentry><term> 'Tolerance', M </term> + <listitem><para> : define the tolerance value as real scaler value, where default value of M is 2.0.</para></listitem></varlistentry> + <varlistentry><term>'StateLevels', O</term> + <listitem><para> : O define the lower and upper state levels as two element real vector.</para></listitem></varlistentry> + <varlistentry><term> 'fig', f</term> + <listitem><para> : f specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.</para></listitem></varlistentry> + + <varlistentry><term> s </term> + <listitem><para> : returns a vector of differences between the mid-crossings of each final negative-going transition of every positive-polarity pulse and the next positive-going transition. </para></listitem></varlistentry> + <varlistentry><term> initialcross </term> + <listitem><para> : returns a vector of initial cross values of bilevel waveform transitions x.</para></listitem></varlistentry> + <varlistentry><term> finalcross </term> + <listitem><para> : returns a vector of final cross values of bilevel waveform transitions x.</para></listitem></varlistentry> + <varlistentry><term> nextcross </term> + <listitem><para> : returns a vector of next cross values of bilevel waveform transitions x. </para></listitem></varlistentry> + <varlistentry><term> midreference </term> + <listitem><para> : return mid reference value corrosponding to mid percent reference value. </para></listitem></varlistentry> +</variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Examples </title> + + <programlisting role="example"><![CDATA[ + + x = fscanfMat("macros/pulsedata_x.txt"); //Importing samples of pulse + t = fscanfMat("macros/pulsedata_t.txt"); + clf //clearing plot history + p = pulsesep(x,t,'fig','ON') // Detremining pulse separation and ploting it + +]]></programlisting> + +<scilab:image> + x = [0. 0.0108 0.0367 -0.0452 0.0172 0.0064 -0.0262 -0.0087 0.0069 0.0716 0.0554 -0.027 0.0607 5.0145 4.9987 5.0143 4.9959 4.9975 5.0298 0.0282 0.0283 0.0134 -0.0241 0.0143 0.0326 0.0098 0.0207 0.0145 -0.0061 0.0059 -0.0157 0.0178 -0.0229 4.9786]; + t = [0. 0.025 0.05 0.075 0.1 0.125 0.15 0.175 0.2 0.225 0.25 0.275 0.3 0.325 0.35 0.375 0.4 0.425 0.45 0.475 0.5 0.525 0.55 0.575 0.6 0.625 0.65 0.675 0.7 0.725 0.75 0.775 0.8 0.825 ]; + clf + p = pulsesep(x,t,'fig','ON') +</scilab:image> + +</refsection> + </refentry> diff --git a/help/en_US/pulsewidth.xml b/help/en_US/pulsewidth.xml index ee08682..9964429 100644 --- a/help/en_US/pulsewidth.xml +++ b/help/en_US/pulsewidth.xml @@ -17,20 +17,85 @@ <refnamediv> <refname>pulsewidth</refname> - <refpurpose></refpurpose> + <refpurpose>This function estimate pulse width of real vector x.</refpurpose> + <para> </para> </refnamediv> - <refsynopsisdiv> <title>Calling Sequence</title> <synopsis> - w=pulsewidth(x) - w=pulsewidth(x, Fs) - w=pulsewidth(x, t) - w=pulsewidth (x, t, 'Polarity', pol) - w=pulsewidth(x, t, 'MidPercentReferenceLevel', N ) - w=pulsewidth(x, t, 'Tolerance', M) - w=pulsewidth(x, t,'StateLevels', O) + p=pulsewidth(x) + p=pulsewidth(x, Fs) + p=pulsewidth(x, t) + p=pulsewidth (x, t, 'Polarity', pol) + p=pulsewidth(x, t, 'MidPercentReferenceLevel', N ) + p=pulsewidth(x, t, 'Tolerance', M) + p=pulsewidth(x, t,'StateLevels', O) + [p initialcross finalcross nextcross midreference]=pulsewidth(x) + [p initialcross finalcross nextcross midreference]=pulsewidth(x, t) + [p initialcross finalcross nextcross midreference]=pulsewidth(x, t) + [p initialcross finalcross nextcross midreference]=pulsewidth(x, t, 'Polarity', pol) + [p initialcross finalcross nextcross midreference]=pulsewidth(x, t, 'MidPercentReferenceLevel', N ) + [p initialcross finalcross nextcross midreference]= pulsewidth(x, t, 'Tolerance', M) + [p initialcross finalcross nextcross midreference]= pulsewidth(x, t,'StateLevels', O) + [p initialcross finalcross nextcross midreference]= pulsewidth(x, t,'StateLevels', O, 'fig', f) </synopsis> + <para> </para> </refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>x</term> + <listitem><para> : real input vector </para></listitem></varlistentry> + <varlistentry><term>Fs</term> + <listitem><para> : specifies the sample rate, Fs, as a positive scalar, where the first sample instant corresponds to a time of zero. </para></listitem></varlistentry> + <varlistentry><term>t</term> + <listitem><para> : defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.</para></listitem></varlistentry> + <varlistentry><term> 'Polarity', pol</term> + <listitem><para> : pol specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive'</para></listitem></varlistentry> + <varlistentry><term> 'MidPercentReferenceLevel', N </term> + <listitem><para> : specify the mid percent reference leves as a percentage, default value of N is 50.</para></listitem></varlistentry> + <varlistentry><term> 'Tolerance', M </term> + <listitem><para> : define the tolerance value as real scaler value, where default value of M is 2.0.</para></listitem></varlistentry> + <varlistentry><term>'StateLevels', O</term> + <listitem><para> : O define the lower and upper state levels as two element real vector.</para></listitem></varlistentry> + <varlistentry><term> 'fig', f</term> + <listitem><para> : f specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.</para></listitem></varlistentry> + + <varlistentry><term> p </term> + <listitem><para> : returns a vector of difference between the mid-crossings of the initial transition of each positive-polarity pulse and the next positive-going transition </para></listitem></varlistentry> + <varlistentry><term> initialcross </term> + <listitem><para> : returns a vector of initial cross values of bilevel waveform transitions x.</para></listitem></varlistentry> + <varlistentry><term> finalcross </term> + <listitem><para> : returns a vector of final cross values of bilevel waveform transitions x.</para></listitem></varlistentry> + <varlistentry><term> nextcross </term> + <listitem><para> : returns a vector of next cross values of bilevel waveform transitions x. </para></listitem></varlistentry> + <varlistentry><term> midreference </term> + <listitem><para> : return mid reference value corrosponding to mid percent reference value. </para></listitem></varlistentry> +</variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Examples </title> + + <programlisting role="example"><![CDATA[ + + x = fscanfMat("macros/pulsedata_x.txt"); //Importing samples of pulse + t = fscanfMat("macros/pulsedata_t.txt"); + clf //clearing plot history + p = pulsewidth(x,t,'fig','ON') // Detremining pulse width and ploting it + +]]></programlisting> + +<scilab:image> + x = [0. 0.0108 0.0367 -0.0452 0.0172 0.0064 -0.0262 -0.0087 0.0069 0.0716 0.0554 -0.027 0.0607 5.0145 4.9987 5.0143 4.9959 4.9975 5.0298 0.0282 0.0283 0.0134 -0.0241 0.0143 0.0326 0.0098 0.0207 0.0145 -0.0061 0.0059 -0.0157 0.0178 -0.0229 4.9786]; + t = [0. 0.025 0.05 0.075 0.1 0.125 0.15 0.175 0.2 0.225 0.25 0.275 0.3 0.325 0.35 0.375 0.4 0.425 0.45 0.475 0.5 0.525 0.55 0.575 0.6 0.625 0.65 0.675 0.7 0.725 0.75 0.775 0.8 0.825 ]; + clf + p = pulsewidth(x,t,'fig','ON') +</scilab:image> + +</refsection> + </refentry> diff --git a/help/en_US/sftrans.xml b/help/en_US/sftrans.xml index 56aee48..3a2e0c5 100644 --- a/help/en_US/sftrans.xml +++ b/help/en_US/sftrans.xml @@ -17,7 +17,7 @@ <refnamediv> <refname>sftrans</refname> - <refpurpose>Transform band edges of a generic lowpass filter (cutoff at W=1) represented in splane zero-pole-gain form.</refpurpose> + <refpurpose>Transform band edges of a prototype filter (cutoff at W=1) represented in s-plane zero-pole-gain form (Frequency Transformation in Analog domain).</refpurpose> </refnamediv> @@ -42,59 +42,39 @@ <varlistentry><term>W:</term> <listitem><para> Edge of target filter.</para></listitem></varlistentry> <varlistentry><term>stop:</term> - <listitem><para> True for high pass and band stop filters or false for low pass and band pass filters.</para></listitem></varlistentry> + <listitem><para> True(%T or 1) for high pass and band stop filters or false (%F or 0) for low pass and band pass filters.</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -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: - </para> - <para> -Transform Zero at x Pole at x ----------------- ------------------------- ------------------------ -Low Pass zero: Fc x/C pole: Fc x/C -S -> C S/Fc gain: C/Fc gain: Fc/C ----------------- ------------------------- ------------------------ -High Pass zero: Fc C/x pole: Fc C/x -S -> C Fc/S pole: 0 zero: 0 -gain: -x gain: -1/x ----------------- ------------------------- ------------------------ -Band Pass zero: b +- sqrt(b^2-FhFl) pole: b +- sqrt(b^2-FhFl) -S^2+FhFl pole: 0 zero: 0 -S -> C -------- gain: C/(Fh-Fl) gain: (Fh-Fl)/C -S(Fh-Fl) b=x/C (Fh-Fl)/2 b=x/C (Fh-Fl)/2 ----------------- ------------------------- ------------------------ -Band Stop zero: b +- sqrt(b^2-FhFl) pole: b +- sqrt(b^2-FhFl) -S(Fh-Fl) pole: +-sqrt(-FhFl) zero: +-sqrt(-FhFl) -S -> C -------- gain: -x gain: -1/x -S^2+FhFl b=C/x (Fh-Fl)/2 b=C/x (Fh-Fl)/2 ----------------- ------------------------- ------------------------ -Bilinear zero: (2+xT)/(2-xT) pole: (2+xT)/(2-xT) -2 z-1 pole: -1 zero: -1 -S -> - --- gain: (2-xT)/T gain: (2-xT)/T -T z+1 ----------------- ------------------------- ------------------------ - </para> - <para> -where C is the cutoff frequency of the initial lowpass filter, Fc is the edge of the target low/high pass filter and [Fl,Fh] are the edges of the target band pass/stop filter. With abundant tedious -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: - </para> - <para> -H(S)=g prod(S-Xi)/prod(S-Xj) -</para> +Given a low pass filter represented by poles and zeros in the splane, can be converted into a </para> +<para> low pass (having diffrent cutoff frequency),</para> +<para> high pass,</para> +<para> band pass,</para> +<para> band stop.</para> +<para> by transforming each of the poles and zeros individually.</para> </refsection> <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -[Sz, Sp, Sg] = sftrans (5, 10, 15, 20, 30) -Sz = 4 -Sp = 2 -Sg = 7.5000 +Sz = [1 2 3]; +Sp = [4 5 6]; +Sg = 15; +W = 20; +stop = %T; +[Sz, Sp, Sg] = sftrans (Sz, Sp, Sg, W, stop) + ]]></programlisting> </refsection> + +<refsection> +<title>Modified by :</title> +<simplelist type="vert"> +<member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> +</refsection> + </refentry> diff --git a/help/en_US/sigmoid_train.xml b/help/en_US/sigmoid_train.xml index 6f57b3f..3e23d09 100644 --- a/help/en_US/sigmoid_train.xml +++ b/help/en_US/sigmoid_train.xml @@ -17,7 +17,8 @@ <refnamediv> <refname>sigmoid_train</refname> - <refpurpose>Evaluate a train of sigmoid functions at T.</refpurpose> + <refpurpose>Evaluate a train of sigmoid functions at t.</refpurpose> + <para> </para> </refnamediv> @@ -35,6 +36,8 @@ <listitem><para> integer</para></listitem></varlistentry> <varlistentry><term>ranges:</term> <listitem><para> matrix</para></listitem></varlistentry> + <varlistentry><term>rc:</term> + <listitem><para> time constant (scalar)</para></listitem></varlistentry> </variablelist> </refsection> @@ -49,8 +52,6 @@ The number and duration of each sigmoid is determined from RANGES. Each row of R <title>Examples</title> <programlisting role="example"><![CDATA[ sigmoid_train(0.1,[1:3],4) -ans = -0.27375 ]]></programlisting> </refsection> </refentry> diff --git a/help/en_US/stmcb.xml b/help/en_US/stmcb.xml index 2490a4b..7972926 100644 --- a/help/en_US/stmcb.xml +++ b/help/en_US/stmcb.xml @@ -17,7 +17,128 @@ <refnamediv> <refname>stmcb</refname> - <refpurpose>function [b,a] = stmcb( x, u_in, q, p, niter, a_in )</refpurpose> + <refpurpose>Compute linear model using Steiglitz-McBride iteration</refpurpose> + <para> </para> </refnamediv> + +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> +[b,a] = stmcb(h,nb,na) +[b,a] = stmcb(y,x,nb,na) +[b,a] = stmcb(h,nb,na,niter) +[b,a] = stmcb(y,x,nb,na,niter) +[b,a] = stmcb(h,nb,na,niter,ai) +[b,a] = stmcb(y,x,nb,na,niter,ai) + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>b,a </term> + <listitem><para> : coefficients of the system function,nb is number of zeros and na is number of poles</para></listitem></varlistentry> + <varlistentry><term>h</term> + <listitem><para> : impulse response of the system</para></listitem></varlistentry> + <varlistentry><term>x, y</term> + <listitem><para> : input and output of same length given to the system</para></listitem></varlistentry> + <varlistentry><term>nitren</term> + <listitem><para> : number of iterations</para></listitem></varlistentry> + <varlistentry><term>ai</term> + <listitem><para> : initial estimate of the denominator coefficients</para></listitem></varlistentry> + <para> </para> + <para>Accepts only real i/ps, complex i/ps are not accepted due to limitations of the 'filter' function in Scilab</para> +</variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Examples</title> + <programlisting role="example"><![CDATA[ +h = fscanfMat("macros/stmcb_h_data.txt"); //required impulse response samples +plot(h); //plotting required impulse response +title "Required impulse respose (h) plot " +xlabel "samples (n)" +ylabel "magnitude {h(n)} " +nb = 4 ; // four zeros +na = 4 ; //four poles +stmcb(h,nb,na) + ]]></programlisting> + +<scilab:image> +h = [0.0003 +0.0033 +0.0149 +0.0432 +0.0911 +0.1493 +0.1985 +0.2190 +0.2007 +0.1479 +0.0764 +0.0070 +-0.0429 +-0.0649 +-0.0601 +-0.0375 +-0.0092 +0.0142 +0.0265 +0.0267 +0.0180 +0.0057 +-0.0052 +-0.0115 +-0.0123 +-0.0088 +-0.0033 +0.0018 +0.0050 +0.0057 +0.0043 +0.0018 +-0.0006 +-0.0021 +-0.0026 +-0.0021 +-0.0010 +0.0001 +0.0009 +0.0012 +0.0010 +0.0005 +0.0000 +-0.0004 +-0.0005 +-0.0005 +-0.0003 +-0.0000 +0.0002 +0.0002 +0.0002 +0.0001 +0.0000 +-0.0001 +-0.0001 +-0.0001 +-0.0001 +-0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +-0.0000 ] + +plot(h); //plotting required impulse response +title "Required impulse respose (h) plot " +xlabel "samples (n)" +ylabel "magnitude {h(n)} " + +</scilab:image> +</refsection> + </refentry> diff --git a/help/en_US/tf2zp.xml b/help/en_US/tf2zp.xml index 176e203..d8ae69b 100644 --- a/help/en_US/tf2zp.xml +++ b/help/en_US/tf2zp.xml @@ -17,7 +17,56 @@ <refnamediv> <refname>tf2zp</refname> - <refpurpose>[z,p,k]= tf2zp(b,a);</refpurpose> + <refpurpose>Transfer function to zero pole conversion</refpurpose> </refnamediv> +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> + [z p k] = tf2zp(num, den) + </synopsis> +</refsynopsisdiv> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>z:</term> + <listitem><para> Zeros</para></listitem></varlistentry> + <varlistentry><term>p:</term> + <listitem><para> Poles</para></listitem></varlistentry> + <varlistentry><term>k:</term> + <listitem><para> Leading coefficient (Gain)</para></listitem></varlistentry> + <varlistentry><term>Num:</term> + <listitem><para> Numerator coefficients of the transfer function</para></listitem></varlistentry> + <varlistentry><term>den:</term> + <listitem><para> Denomenator coefficients of the transfer function</para></listitem></varlistentry> + </variablelist> +</refsection> + +<refsection> + <title>Description</title> + <para> +It converts transfer function representation to zeros / poles representation. +</para> +</refsection> + +<refsection> + <title>Examples</title> + <programlisting role="example"><![CDATA[ +b = [1 2 3] +a = [4 5 6] +[z, p, k] = zp2tf(b, a) + + ]]></programlisting> +</refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Debdeep Dey (FOSSEE, IIT Bombay)</member> + <member>MODIFIED BY: Sonu Sharma (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> + </refsection> + + </refentry> diff --git a/help/en_US/wconv.xml b/help/en_US/wconv.xml index acbf777..4fe678b 100644 --- a/help/en_US/wconv.xml +++ b/help/en_US/wconv.xml @@ -33,20 +33,26 @@ <title>Parameters</title> <variablelist> <varlistentry><term>type:</term> - <listitem><para> convolution type.</para></listitem></varlistentry> + <listitem><para> convolution type.</para> + <para> * 1 or "1" for 1D convolution.</para> + <para> * 2 or "2" for 2D convolution.</para> + </listitem></varlistentry> <varlistentry><term>x:</term> <listitem><para> Signal vector or matrix.</para></listitem></varlistentry> <varlistentry><term>f:</term> <listitem><para> FIR filter coefficients.</para></listitem></varlistentry> <varlistentry><term>shape:</term> - <listitem><para> Shape.</para></listitem></varlistentry> + <listitem> + <para> * "full", computes the full one/two-dimensional convolution. It is the default value.</para> + <para> * "same", computes the central part of the convolution of the same size as x.</para> + <para> * "valid", computes the convolution parts without the zero-padding of x.</para> + </listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. It performs 1D or 2D convolution between the signal x and the filter coefficients f. </para> </refsection> @@ -54,11 +60,17 @@ It performs 1D or 2D convolution between the signal x and the filter coefficient <refsection> <title>Examples</title> <programlisting role="example"><![CDATA[ -a = [1 2 3 4 5] -b = [7 8 9 10] -wconv(1,a,b) -ans = -7 22 46 80 114 106 85 50 +a = [1 2 3 4 5]; +b = [7 8 9 10]; +wconv(1, a, b) ]]></programlisting> </refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> + </refsection> + </refentry> diff --git a/help/en_US/xcorr1.xml b/help/en_US/xcorr1.xml deleted file mode 100644 index b89de1a..0000000 --- a/help/en_US/xcorr1.xml +++ /dev/null @@ -1,81 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - * - * This help file was generated from xcorr1.sci using help_from_sci(). - * - --> - -<refentry version="5.0-subset Scilab" xml:id="xcorr1" xml:lang="en" - xmlns="http://docbook.org/ns/docbook" - xmlns:xlink="http://www.w3.org/1999/xlink" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns:ns3="http://www.w3.org/1999/xhtml" - xmlns:mml="http://www.w3.org/1998/Math/MathML" - xmlns:scilab="http://www.scilab.org" - xmlns:db="http://docbook.org/ns/docbook"> - - <refnamediv> - <refname>xcorr1</refname> - <refpurpose>Estimates the cross-correlation.</refpurpose> - </refnamediv> - - -<refsynopsisdiv> - <title>Calling Sequence</title> - <synopsis> - [R, lag] = xcorr1 (X, Y, maxlag, scale) - [R, lag] = xcorr1 (X, Y, maxlag) - [R, lag] = xcorr1 (X, Y) - </synopsis> -</refsynopsisdiv> - -<refsection> - <title>Parameters</title> - <variablelist> - <varlistentry><term>X:</term> - <listitem><para> [non-empty; real or complex; vector or matrix] data.</para></listitem></varlistentry> - <varlistentry><term>Y:</term> - <listitem><para> [real or complex vector] data.</para></listitem></varlistentry> - <varlistentry><term>maxlag:</term> - <listitem><para> [integer scalar] maximum correlation lag If omitted, the default value is N-1, where N is the greater of the lengths of X and Y or, if X is a matrix, the number of rows in X.</para></listitem></varlistentry> - <varlistentry><term>scale:</term> - <listitem><para> [character string] specifies the type of scaling applied to the correlation vector (or matrix). is one of:</para></listitem></varlistentry> - </variablelist> -</refsection> - -<refsection> - <title>Description</title> - <para> -This is an Octave function. -Estimate the cross correlation R_xy(k) of vector arguments X and Y or, if Y is omitted, estimate autocorrelation R_xx(k) of vector X, for a range of lags k specified by argument "maxlag". If X is a -matrix, each column of X is correlated with itself and every other column. - </para> - <para> -The cross-correlation estimate between vectors "x" and "y" (of length N) for lag "k" is given by - </para> - <para> -N -R_xy(k) = sum x_{i+k} conj(y_i), -i=1 - </para> - <para> -where data not provided (for example x(-1), y(N+1)) is zero. Note the definition of cross-correlation given above. To compute a cross-correlation consistent with the field of statistics, see xcov. -</para> -</refsection> - -<refsection> - <title>Examples</title> - <programlisting role="example"><![CDATA[ -[R, lag] = xcorr1 ( [5 5], [2 2], 2, 'biased' ) - -R = - -0 5 10 5 0 - -lag = - --2 -1 0 1 2 - ]]></programlisting> -</refsection> -</refentry> diff --git a/help/en_US/xcov1.xml b/help/en_US/xcov1.xml deleted file mode 100644 index 3872563..0000000 --- a/help/en_US/xcov1.xml +++ /dev/null @@ -1,64 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - * - * This help file was generated from xcov1.sci using help_from_sci(). - * - --> - -<refentry version="5.0-subset Scilab" xml:id="xcov1" xml:lang="en" - xmlns="http://docbook.org/ns/docbook" - xmlns:xlink="http://www.w3.org/1999/xlink" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns:ns3="http://www.w3.org/1999/xhtml" - xmlns:mml="http://www.w3.org/1998/Math/MathML" - xmlns:scilab="http://www.scilab.org" - xmlns:db="http://docbook.org/ns/docbook"> - - <refnamediv> - <refname>xcov1</refname> - <refpurpose>Compute covariance at various lags [=correlation(x-mean(x),y-mean(y))].</refpurpose> - </refnamediv> - - -<refsynopsisdiv> - <title>Calling Sequence</title> - <synopsis> - [R, lag] = xcov (X) - ... = xcov (X, Y) - ... = xcov (..., maxlag) - ... = xcov (..., scale) - </synopsis> -</refsynopsisdiv> - -<refsection> - <title>Parameters</title> - <variablelist> - <varlistentry><term>X:</term> - <listitem><para> Input vector</para></listitem></varlistentry> - <varlistentry><term>Y:</term> - <listitem><para> if specified, compute cross-covariance between X and Y, otherwise compute autocovariance of X.</para></listitem></varlistentry> - <varlistentry><term>maxlag:</term> - <listitem><para> is specified, use lag range [-maxlag:maxlag], otherwise use range [-n+1:n-1].</para></listitem></varlistentry> - <varlistentry><term>scale:</term> - <listitem><para> </para></listitem></varlistentry> - <varlistentry><term>'biased':</term> - <listitem><para> for covariance=raw/N,</para></listitem></varlistentry> - <varlistentry><term>'unbiased':</term> - <listitem><para> for covariance=raw/(N-|lag|),</para></listitem></varlistentry> - <varlistentry><term>'coeff':</term> - <listitem><para> for covariance=raw/(covariance at lag 0),</para></listitem></varlistentry> - <varlistentry><term>'none':</term> - <listitem><para> for covariance=raw</para></listitem></varlistentry> - <varlistentry><term>'none':</term> - <listitem><para> is the default.</para></listitem></varlistentry> - </variablelist> -</refsection> - -<refsection> - <title>Description</title> - <para> -Compute covariance at various lags [=correlation(x-mean(x),y-mean(y))]. Returns the covariance for each lag in the range, plus an optional vector of lags. -</para> -</refsection> -</refentry> diff --git a/help/en_US/zp2tf.xml b/help/en_US/zp2tf.xml index c9e16af..7d8852b 100644 --- a/help/en_US/zp2tf.xml +++ b/help/en_US/zp2tf.xml @@ -37,19 +37,18 @@ <varlistentry><term>p:</term> <listitem><para> Poles</para></listitem></varlistentry> <varlistentry><term>k:</term> - <listitem><para> Leading coefficient</para></listitem></varlistentry> + <listitem><para> Leading coefficient (Gain)</para></listitem></varlistentry> <varlistentry><term>Num:</term> - <listitem><para> Numerator of the transfer function</para></listitem></varlistentry> + <listitem><para> Numerator coefficients of the transfer function</para></listitem></varlistentry> <varlistentry><term>den:</term> - <listitem><para> Denomenator of the transfer function</para></listitem></varlistentry> + <listitem><para> Denomenator coefficients of the transfer function</para></listitem></varlistentry> </variablelist> </refsection> <refsection> <title>Description</title> <para> -This is an Octave function. -It converts zeros / poles to a transfer function. +It converts zeros / poles representation to transfer function representation. </para> </refsection> @@ -60,13 +59,16 @@ z = [1 2 3] p = [4 5 6] k = 5 [num, den] = zp2tf (z, p, k) -num = -5 -30 55 -30 - -den = - -1 -15 74 -120 ]]></programlisting> </refsection> + + <refsection> + <title>Authors</title> + <simplelist type="vert"> + <member>Sonu Sharma, RGIT Mumbai (fellow at FOSSEE, IIT Bombay)</member> + </simplelist> + </refsection> + + </refentry> diff --git a/help/en_US/zplane.xml b/help/en_US/zplane.xml index 64a7172..57b9d40 100644 --- a/help/en_US/zplane.xml +++ b/help/en_US/zplane.xml @@ -17,7 +17,53 @@ <refnamediv> <refname>zplane</refname> - <refpurpose>funcprot(0);</refpurpose> + <refpurpose>Pole-Zero plot for Discrete time systems</refpurpose> + <para> </para> </refnamediv> + +<refsynopsisdiv> + <title>Calling Sequence</title> + <synopsis> +zplane(z); +zplane(z,p); + </synopsis> + <para> </para> +</refsynopsisdiv> + +<refsection> + <title>Description</title> + <para> +This function gives pole zero plote of discrete time systems + </para> + <para> </para> +</refsection> + +<refsection> + <title>Parameters</title> + <variablelist> + <varlistentry><term>z</term> + <listitem><para> : vector containing numerator coefficients</para></listitem></varlistentry> + <varlistentry><term>p</term> + <listitem><para> : vector containing denumerator coefficients</para></listitem></varlistentry> + </variablelist> + <para> </para> +</refsection> + +<refsection> + <title>Examples</title> + <programlisting role="example"><![CDATA[ +z = [1 2 3]; +p = [4 5 6]; +zplane(z,p); + ]]></programlisting> + +<scilab:image> +z = [1 2 3]; +p = [4 5 6]; +zplane(z,p); +</scilab:image> + +</refsection> + </refentry> diff --git a/macros/arburg.sci b/macros/arburg.sci index de4dcbb..ee85ac5 100644 --- a/macros/arburg.sci +++ b/macros/arburg.sci @@ -1,57 +1,194 @@ -function varargout = arburg( x, poles, criterion ) -//This function calculates coefficients of an autoregressive (AR) model of complex data. +//This function calculates coefficients of an autoregressive (AR) model of complex data + //Calling Sequence //a = arburg(x, poles) //a = arburg(x, poles, criterion) //[a, v] = arburg(...) //[a, v, k] = arburg(...) -//Parameters + +//Parameters //x: vector of real or complex numbers, of length > 2 -//poles: positive integer value < length(x) - 2 -//criterion: string value, takes in "AKICc", "KIC", "AICc", "AIC" and "FPE", default it not using a model-selection criterion -//a, v, k: Output variables +//poles: positive integer value < length(x) - 2 +//criterion: string value, takes in "AKICc", "KIC", "AICc", "AIC" and "FPE", default it not using a model-selection criterion +//a: list of P+1 autoregression coefficients. +//v: mean square of residual noise from the whitening operation of the Burg lattice filter +//k: reflection coefficients defining the lattice-filter embodiment of the model + //Description -//This is an Octave function. -// //This function calculates coefficients of an autoregressive (AR) model of complex data x using the whitening lattice-filter method of Burg. -// //The first argument is the data sampled. The second argument is the number of poles in the model (or limit in case a criterion is supplied). //The third parameter takes in the criterion to limit the number of poles. The acceptable values are "AIC", "AKICc", "KIC", "AICc" which are based on information theory. -//Output variable a is a list of P+1 autoregression coefficients. -//Output variable v is the mean square of residual noise from the whitening operation of the Burg lattice filter. -//Output variable k corresponds to the reflection coefficients defining the lattice-filter embodiment of the model. + //Examples //arburg([1,2,3,4,5],2) -//ans = -// 1.00000 -1.86391 0.95710 - -funcprot(0); -rhs = argn(2) -lhs = argn(1) -if(lhs>3) -error("Wrong number of output arguments.") -elseif(rhs<2) -error("Wrong number of input arguments.") -end - - select(lhs) - case 1 then - if(rhs==2) - a = callOctave("arburg",x,poles) - elseif(rhs==3) - a = callOctave("arburg",x,poles,criterion) - end - case 2 then - if(rhs==2) - [a,v] = callOctave("arburg",x,poles) - elseif(rhs==3) - [a,v] = callOctave("arburg",x,poles,criterion) - end - case 3 then - if(rhs==2) - [a,v,k] = callOctave("arburg",x,poles) - elseif(rhs==3) - [a,v,k] = callOctave("arburg",x,poles,criterion) - end - end +// ans = +// +// 1. - 1.8639053 0.9571006 + + +//************************************************************************************* +//-------------------version1 (using callOctave / errored)----------------------------- +//************************************************************************************* +//function varargout = arburg( x, poles, criterion ) +//funcprot(0); +//rhs = argn(2) +//lhs = argn(1) +//if(lhs>3) +//error("Wrong number of output arguments.") +//elseif(rhs<2) +//error("Wrong number of input arguments.") +//end +// +// select(lhs) +// case 1 then +// if(rhs==2) +// a = callOctave("arburg",x,poles) +// elseif(rhs==3) +// a = callOctave("arburg",x,poles,criterion) +// end +// case 2 then +// if(rhs==2) +// [a,v] = callOctave("arburg",x,poles) +// elseif(rhs==3) +// [a,v] = callOctave("arburg",x,poles,criterion) +// end +// case 3 then +// if(rhs==2) +// [a,v,k] = callOctave("arburg",x,poles) +// elseif(rhs==3) +// [a,v,k] = callOctave("arburg",x,poles,criterion) +// end +// end +//endfunction +// + +//************************************************************************************* +//-----------------------------version2 (pure scilab code)----------------------------- +//************************************************************************************* + +function varargout = arburg( x, poles, criterion ) + + funcprot(0); + // Check arguments + [nargout nargin ] = argn() ; + if ( nargin < 2 ) + error( 'arburg(x,poles): Need at least 2 args.' ); + elseif ( ~isvector(x) | length(x) < 3 ) + error( 'arburg: arg 1 (x) must be vector of length >2.' ); + elseif ( ~isscalar(poles) | ~isreal(poles) | fix(poles)~=poles | poles<=0.5) + error( 'arburg: arg 2 (poles) must be positive integer.' ); + elseif ( poles >= length(x)-2 ) + // lattice-filter algorithm requires "poles<length(x)" + // AKICc and AICc require "length(x)-poles-2">0 + error( 'arburg: arg 2 (poles) must be less than length(x)-2.' ); + elseif ( nargin>2 & ~isempty(criterion) & ... + (~(type(criterion) == 10 ) | size(criterion,1)~=1 ) ) + error( 'arburg: arg 3 (criterion) must be string.' ); + else + // + // Set the model-selection-criterion flags. + // is_AKICc, isa_KIC and is_corrected are short-circuit flags + if ( nargin > 2 & ~isempty(criterion) ) + is_AKICc = strcmp(criterion,'AKICc'); // AKICc + isa_KIC = is_AKICc | strcmp(criterion,'KIC'); // KIC or AKICc + is_corrected = is_AKICc | strcmp(criterion,'AICc'); // AKICc or AICc + use_inf_crit = is_corrected | isa_KIC | strcmp(criterion,'AIC'); + use_FPE = strcmp(criterion,'FPE'); + if ( ~use_inf_crit & ~use_FPE ) + error( 'arburg: value of arg 3 (criterion) not recognized' ); + end + else + use_inf_crit = 0; + use_FPE = 0; + end + // + // f(n) = forward prediction error + // b(n) = backward prediction error + // Storage of f(n) and b(n) is a little tricky. Because f(n) is always + // combined with b(n-1), f(1) and b(N) are never used, and therefore are + // not stored. Not storing unused data makes the calculation of the + // reflection coefficient look much cleaner :) + // N.B. {initial v} = {error for zero-order model} = + // {zero-lag autocorrelation} = E(x*conj(x)) = x*x'/N + // E = expectation operator + N = length(x); + k = []; + if ( size(x,1) > 1 ) // if x is column vector + f = x(2:N); + b = x(1:N-1); + v = real(x'*x) / N; + else // if x is row vector + f = x(2:N).'; + b = x(1:N-1).'; + v = real(x*x') / N; + end + // new_crit/old_crit is the mode-selection criterion + new_crit = abs(v); + old_crit = 2 * new_crit; + for p = 1:poles + // + // new reflection coeff = -2* E(f.conj(b)) / ( E(f^2)+E(b(^2) ) + last_k= -2 * (b' * f) / ( f' * f + b' * b); + // Levinson-Durbin recursion for residual + new_v = v * ( 1.0 - real(last_k * conj(last_k)) ); + if ( p > 1 ) + // + // Apply the model-selection criterion and break out of loop if it + // increases (rather than decreases). + // Do it before we update the old model "a" and "v". + // + // * Information Criterion (AKICc, KIC, AICc, AIC) + if ( use_inf_crit ) + old_crit = new_crit; + // AKICc = log(new_v)+p/N/(N-p)+(3-(p+2)/N)*(p+1)/(N-p-2); + // KIC = log(new_v)+ 3 *(p+1)/N; + // AICc = log(new_v)+ 2 *(p+1)/(N-p-2); + // AIC = log(new_v)+ 2 *(p+1)/N; + // -- Calculate KIC, AICc & AIC by using is_AKICc, is_KIC and + // is_corrected to "short circuit" the AKICc calculation. + // The extra 4--12 scalar arithmetic ops should be quicker than + // doing if...elseif...elseif...elseif...elseif. + new_crit = log(new_v) + is_AKICc*p/N/(N-p) + ... + (2+isa_KIC-is_AKICc*(p+2)/N) * (p+1) / (N-is_corrected*(p+2)); + if ( new_crit > old_crit ) + break; + end + // + // (FPE) Final prediction error + elseif ( use_FPE ) + old_crit = new_crit; + new_crit = new_v * (N+p+1)/(N-p-1); + if ( new_crit > old_crit ) + break; + end + end + // Update model "a" and "v". + // Use Levinson-Durbin recursion formula (for complex data). + a = [ prev_a + last_k .* conj(prev_a(p-1:-1:1)) last_k ]; + else // if( p==1 ) + a = last_k; + end + k = [ k; last_k ]; + v = new_v; + if ( p < poles ) + prev_a = a; + // calculate new prediction errors (by recursion): + // f(p,n) = f(p-1,n) + k * b(p-1,n-1) n=2,3,...n + // b(p,n) = b(p-1,n-1) + conj(k) * f(p-1,n) n=2,3,...n + // remember f(p,1) is not stored, so don't calculate it; make f(p,2) + // the first element in f. b(p,n) isn't calculated either. + nn = N-p; + new_f = f(2:nn) + last_k * b(2:nn); + b = b(1:nn-1) + conj(last_k) * f(1:nn-1); + f = new_f; + end + end + + varargout(1) = [1,a]; + varargout(2) = v; + if ( nargout>=3 ) + varargout(3) = k; + end + end + endfunction diff --git a/macros/arch_rnd.sci b/macros/arch_rnd.sci index 50facc4..9e3d88c 100644 --- a/macros/arch_rnd.sci +++ b/macros/arch_rnd.sci @@ -1,11 +1,13 @@ -function res = arch_rnd (a, b, t) //Simulate an ARCH sequence of length t with AR coefficients b and CH coefficients a. + //Calling Sequence //arch_rnd (a, b, t) -//Parameters + +//Parameters //a: CH coefficients //b: AR coefficients //t: Length of ARCH sequence + //Description //This is an Octave function. //It Simulates an ARCH sequence of length t with AR coefficients b and CH coefficients a. @@ -15,29 +17,100 @@ function res = arch_rnd (a, b, t) //where e(t), given y up to time t-1, is N(0, h(t)), with // //h(t) = a(1) + a(2) * e(t-1)^2 + … + a(la) * e(t-la+1)^2 + //Examples //a = [1 2 3 4 5]; //b = [7 8 9 10]; +//t = 5 ; //arch_rnd (a, b, t) -//ans = +//Output +// ans = +// +// 7.2113249 +// 65.479684 +// 654.00814 +// 7194.6572 +// 78364.905 + + + +//function res = arch_rnd (a, b, t) +//funcprot(0); +//lhs = argn(1) +//rhs = argn(2) +//if (rhs < 3 | rhs > 3) +//error("Wrong number of input arguments.") +//end +// +//select(rhs) // -// 6.1037e+00 -// 5.7294e+01 -// 5.7390e+02 -// 6.3063e+03 -// 6.8695e+04 - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 3 | rhs > 3) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 3 then - res = callOctave("arch_rnd",a, b, t) - - end +// case 3 then +// res = callOctave("arch_rnd",a, b, t) +// +// end +//endfunction + + +function y = arch_rnd (a, b, t) + + funcprot(0); + [nargout, nargin] = argn() ; + + if (nargin ~= 3) + error("arch_rnd: invalid input arguments") + end + + if (~ ((min (size (a)) == 1) & (min (size (b)) == 1))) + error ("arch_rnd: A and B must both be scalars or vectors"); + end + if (~ (isscalar (t) & (t > 0) & (modulo(t, 1) == 0))) + error ("arch_rnd: T must be a positive integer"); + end + + if (~ (a(1) > 0)) + error ("arch_rnd: A(1) must be positive"); + end + // perhaps add a test for the roots of a(z) here ... + + la = length (a); + a = matrix(a, 1, la); + if (la == 1) + a = [a, 0]; + la = la + 1; + end + + lb = length (b); + b = matrix(b, 1, lb); + if (lb == 1) + b = [b, 0]; + lb = lb + 1; + end + m = max ([la, lb]); + + e = zeros (t, 1); + h = zeros (t, 1); + y = zeros (t, 1); + + h(1) = a(1); + e(1) = sqrt (h(1)) * rand(); + y(1) = b(1) + e(1); + + for t = 2:m + ta = min ([t, la]); + h(t) = a(1) + a(2:ta) * e(t-ta+1:t-1).^2; + e(t) = sqrt (h(t)) * rand() ; + tb = min ([t, lb]); + y(t) = b(1) + b(2:tb) * y(t-tb+1:t-1) + e(t); + end + + if (t > m) + for t = m+1:t + h(t) = a(1) + a(2:la) * e(t-la+1:t-1).^2; + e(t) = sqrt (h(t)) * rand() ; + y(t) = b(1) + b(2:lb) * y(t-tb+1:t-1) + e(t); + end + end + + y = y(1:t); + endfunction diff --git a/macros/arma_rnd.sci b/macros/arma_rnd.sci index bc826f4..5e9ca12 100644 --- a/macros/arma_rnd.sci +++ b/macros/arma_rnd.sci @@ -1,14 +1,16 @@ -function res = arma_rnd (a, b, v, t, n) //Return a simulation of the ARMA model. + //Calling Sequence //arma_rnd (a, b, v, t, n) //arma_rnd (a, b, v, t) -//Parameters + +//Parameters //a: vector //b: vector //v: Variance //t: Length of output vector //n: Number of dummy x(i) used for initialization + //Description //This is an Octave function. //The ARMA model is defined by @@ -18,35 +20,81 @@ function res = arma_rnd (a, b, v, t, n) //in which k is the length of vector a, l is the length of vector b and e is Gaussian white noise with variance v. The function returns a vector of length t. // //The optional parameter n gives the number of dummy x(i) used for initialization, i.e., a sequence of length t+n is generated and x(n+1:t+n) is returned. If n is omitted, n = 100 is used. + //Examples //a = [1 2 3 4 5]; -//b = [7; 8; 9; 10; 11]; +//b = [7 8 9 10 11]; //v = 10; //t = 5; //n = 100; //arma_rnd (a, b, v, t, n) -//ans = +//Output : +// ans = // -// -1.6176e+05 -// -4.1663e+05 -// -1.0732e+06 -// -2.7648e+06 -// -7.1221e+06 - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 5 | rhs > 6) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 5 then - res = callOctave("arma_rnd",a, b, v, t) - - case 6 then - res = callOctave("arma_rnd",a, b, v, t, n) - - end +// 61400.907 +// 158177.11 +// 407440.29 +// 1049604. +// 2703841.3 + + +//function res = arma_rnd (a, b, v, t, n) +//funcprot(0); +//lhs = argn(1) +//rhs = argn(2) +//if (rhs < 5 | rhs > 6) +//error("Wrong number of input arguments.") +//end +// +//select(rhs) +// +// case 5 then +// res = callOctave("arma_rnd",a, b, v, t) +// +// case 6 then +// res = callOctave("arma_rnd",a, b, v, t, n) +// +// end +//endfunction + +function x = arma_rnd (a, b, v, t, n) + + funcprot(); + [nargout,nargin] = argn() ; + + if (nargin == 4) + n = 100; + elseif (nargin == 5) + if (~ isscalar (n)) + error ("arma_rnd: N must be a scalar"); + end + else + error("arma_rnd: invalid input"); + end + + if ((min (size (a)) > 1) | (min (size (b)) > 1)) + error ("arma_rnd: A and B must not be matrices"); + end + + if (~ isscalar (t)) + error ("arma_rnd: T must be a scalar"); + end + + ar = length (a); + br = length (b); + + a = matrix (a, ar, 1); + b = matrix (b, br, 1); + + // Apply our notational convention. + a = [1; -a]; + b = [1; b]; + + n = min (n, ar + br); + + e = sqrt (v) * rand(t + n, 1); + + x = filter (b, a, e); + x = x(n + 1 : t + n); + endfunction diff --git a/macros/aryule.sci b/macros/aryule.sci index e752ced..dd4ac7c 100644 --- a/macros/aryule.sci +++ b/macros/aryule.sci @@ -1,39 +1,74 @@ -function [a, v, k] = aryule (x, p) //This function fits an AR (p)-model with Yule-Walker estimates. + //Calling Sequence //a = aryule (x, p) //[a, v] = aryule (x, p) //[a, v, k] = aryule (x, p) -//Parameters + +//Parameters //x: vector of real or complex numbers, length > 2 //p: positive integer value < length(x) - 1 -//a, v, k: Output variables +//a: gives the AR coefficients +//v: gives the variance of the white noise, +//k: gives the reflection coefficients to be used in the lattice filter + //Description -//This is an Octave function. -// //This function fits an AR (p)-model with Yule-Walker estimates. -//The first argument is the data vector which is to be estimated. -//Output variable a gives the AR coefficients, v gives the variance of the white noise and k gives the reflection coefficients to be used in the lattice filter. +//The first argument is the data vector which is to be estimated. + //Examples //aryule([1,2,3,4,5],2) //ans = // 1. - 0.8140351 0.1192982 -funcprot(0); -rhs = argn(2) -lhs = argn(1) - -if(rhs~=2) -error("Wrong number of input arguments.") -end - - select(lhs) - case 1 then - a = callOctave("aryule",x,p) - case 2 then - [a,v] = callOctave("aryule",x,p) - case 3 then - [a,v,k] = callOctave("aryule",x,p) - end +//************************************************************************************* +//-------------------version1 (using callOctave / errored)----------------------------- +//************************************************************************************* +//function [a, v, k] = aryule (x, p) +//funcprot(0); +//rhs = argn(2) +//lhs = argn(1) +// +//if(rhs~=2) +//error("Wrong number of input arguments.") +//end +// +// select(lhs) +// case 1 then +// a = callOctave("aryule",x,p) +// case 2 then +// [a,v] = callOctave("aryule",x,p) +// case 3 then +// [a,v,k] = callOctave("aryule",x,p) +// end +// +//endfunction + +//************************************************************************************* +//-----------------------------version2 (pure scilab code)----------------------------- +//************************************************************************************* + +function [a, v, k] = aryule (x, p) + + [nargout,nargin] = argn() ; + + if ( nargin~=2 ) + error('aryule : invalid number of inputs'); + elseif ( ~isvector(x) | length(x)<3 ) + error( 'aryule: arg 1 (x) must be vector of length >2' ); + elseif ( ~isscalar(p) | fix(p)~=p | p > length(x)-2 ) + error( 'aryule: arg 2 (p) must be an integer >0 and <length(x)-1' ); + end + + c = xcorr(x, p+1, 'biased'); + c(1:p+1) = []; // remove negative autocorrelation lags + c(1) = real(c(1)); // levinson/toeplitz requires exactly c(1)==conj(c(1)) + if nargout <= 1 + a = levinson(c, p); + elseif nargout == 2 + [a, v] = levinson(c, p); + else + [a, v, k] = levinson(c, p); + end endfunction diff --git a/macros/autoreg_matrix.sci b/macros/autoreg_matrix.sci index 8778a84..2b70ced 100644 --- a/macros/autoreg_matrix.sci +++ b/macros/autoreg_matrix.sci @@ -1,30 +1,59 @@ -function y = autoreg_matrix(Y, varargin) // Given a time series (vector) Y, return a matrix with ones in the first column and the first K lagged values of Y in the other columns. + //Calling Sequence //autoreg_matrix(Y, K) + //Parameters //Y: Vector //K: Scalar or Vector + //Description // Given a time series (vector) Y, return a matrix with ones in the first column and the first K lagged values of Y in the other columns. // //In other words, for T > K, '[1, Y(T-1), ..., Y(T-K)]' is the t-th row of the result. // //The resulting matrix may be used as a regressor matrix in autoregressions. + //Examples //autoreg_matrix([1,2,3],2) -//ans = -// 1. 0. 0. -// 1. 1. 0. -// 1. 2. 1. -funcprot(0); -rhs = argn(2) -if(rhs<2 | rhs>2) -error("Wrong number of input arguments."); -end - - select(rhs) - case 2 then - y = callOctave("autoreg_matrix", Y, varargin(1)); - end +//ans = +// 1. 0. 0. +// 1. 1. 0. +// 1. 2. 1. + + + +//function y = autoreg_matrix(Y, varargin) +//funcprot(0); +//rhs = argn(2) +//if(rhs<2 | rhs>2) +//error("Wrong number of input arguments."); +//end +// +// select(rhs) +// case 2 then +// y = callOctave("autoreg_matrix", Y, varargin(1)); +// end +//endfunction + +function X = autoreg_matrix (y, k) + + funcprot(0); + [nargout, nargin] = argn() ; + + if (nargin ~= 2) + error('autoreg_matrix: invalid input') ; + end + + if (~ (isvector (y))) + error ("autoreg_matrix: Y must be a vector"); + end + + T = length (y); + y = matrix(y, T, 1); + X = ones (T, k+1); + for j = 1 : k; + X(:, j+1) = [(zeros (j, 1)); y(1:T-j)]; + end + endfunction diff --git a/macros/besselap.sci b/macros/besselap.sci index 6fe4f47..2ed0047 100644 --- a/macros/besselap.sci +++ b/macros/besselap.sci @@ -1,48 +1,81 @@ -function [zero, pole, gain] = besselap (n) -//Return bessel analog filter prototype. -//Calling Sequence -//[zero, pole, gain] = besselap (n) -//[zero, pole] = besselap (n) -//zero = besselap (n) -//Parameters -//n: Filter Order -//zero: Zeros -//pole: Poles -//gain: Gain -//Description -//This is an Octave function. -//It Return bessel analog filter prototype of nth order. -//Examples -//[zero, pole, gain] = besselap (5) -//zero = [](0x0) -//pole = +// Copyright (C) 2018 - IIT Bombay - FOSSEE // -// -0.59058 + 0.90721i -// -0.59058 - 0.90721i -// -0.92644 + 0.00000i -// -0.85155 + 0.44272i -// -0.85155 - 0.44272i -// -//gain = 1 - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 1 | rhs > 1) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 1 then - if(lhs==1) - zero = callOctave("besselap",n) - elseif(lhs==2) - [zero, pole] = callOctave("besselap",n) - elseif(lhs==3) - [zero, pole, gain] = callOctave("besselap",n) - else - error("Wrong number of output argments.") - end - end +// 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 contribution: FOSSEE, IIT Bombay +// Original Source : https://octave.sourceforge.io/signal/ +// Modifieded by: Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + + +function [zero, pole, gain]=besselap(n) + //Bessel analog filter prototype. + + //Calling Sequence + //[zero, pole, gain] = besselap(n) + //zero = besselap(n) + + //Parameters + //n: Filter Order + //zero: Zeros + //pole: Poles + //gain: Gain + + //Description + //It Return bessel analog filter prototype of nth order. + + //Examples + //[zero, pole, gain] = besselap (5) + //Output : + // gain = + // + // 1. + // pole = + // + // - 0.5905759 + 0.9072068i + // - 0.5905759 - 0.9072068i + // - 0.9264421 + // - 0.8515536 + 0.4427175i + // - 0.8515536 - 0.4427175i + // zero = + // + // [] + + + + funcprot(0); + [nargout, nargin] = argn() ; + + if (nargin>1 | nargin<1) + error("besselap : wrong number of input argument") + end + + // interpret the input parameters + if (~(length(n)==1 & n == round(n) & n > 0)) + error ("besselap: filter order n must be a positive integer"); + end + + p0=1; + p1=[1 1]; + for nn=2:n + px=(2*nn-1)*p1; + py=[p0 0 0]; + px=prepad(px,max(length(px),length(py)),0); + py=prepad(py,length(px)); + p0=p1; + p1=px+py; + end + // p1 now contains the reverse bessel polynomial for n + + // scale it by replacing s->s/w0 so that the gain becomes 1 + p1=p1.*p1(length(p1)).^((length(p1)-1:-1:0)/(length(p1)-1)); + + zero=[]; + pole=roots(p1); + gain=1; + endfunction diff --git a/macros/besself.sci b/macros/besself.sci index f65b12a..c52f3ac 100644 --- a/macros/besself.sci +++ b/macros/besself.sci @@ -1,53 +1,133 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [a, b, c, d] = besself (n, w, varargin) -//This function generates a Bessel filter. -//Calling Sequence -//[a, b] = besself(n, w) -//[a, b] = besself (n, w, "high") -//[a, b, c] = besself (…) -//[a, b, c, d] = besself (…) -//[…] = besself (…, "z") -//Parameters -//n: positive integer value -//w: positive real value -//Description -//This is an Octave function. -//This function generates a Bessel filter. The default is a Laplace space (s) filter. -//The third parameter takes in high or low, the default value being low. The cutoff is pi*Wc radians. -//[z,p,g] = besself(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. -//[...] = besself(...,’z’) returns a discrete space (Z) filter. w must be less than 1. -//[a,b,c,d] = besself(...) returns state-space matrices. -//Examples -//[a,b]=besself(2,3,"low") -//a = 9.0000 -//b = -// 1.0000 5.1962 9.0000 - -funcprot(0); -rhs = argn(2) -lhs = argn(1) -if(rhs<2 | rhs>4) -error("Wrong number of input arguments.") -end -if(lhs<2 | lhs>4) -error("Wrong number of output arguments.") -end - - - select (rhs) - case 2 then - if (lhs==2) [a,b] = callOctave("besself",n, w) - elseif (lhs==3) [a,b,c] = callOctave("besself",n, w) - elseif (lhs==4) [a,b,c,d] = callOctave("besself",n, w) - end - case 3 then - if (lhs==2) [a,b] = callOctave("besself",n, w,varargin(1)) - elseif (lhs==3) [a,b,c] = callOctave("besself",n, w,varargin(1)) - elseif (lhs==4) [a,b,c,d] = callOctave("besself",n, w,varargin(1)) - end - case 4 then - if (lhs==2) [a,b] = callOctave("besself",n, w,varargin(1),varargin(2)) - elseif (lhs==3) [a,b,c] = callOctave("besself",n, w,varargin(1),varargin(2)) - elseif (lhs==4) [a,b,c,d] = callOctave("besself",n, w,varargin(1),varargin(2)) - end - end + //Bessel filter design. + + //Canding Sequence + //[b, a] = besself(n, Wc) + //[b, a] = besself (n, Wc, "high") + //[b, a] = besself (n, [Wl, Wh]) + //[b, a] = besself (n, [Wl, Wh], "stop") + //[z, p, g] = besself (…) + //[…] = besself (…, "z") + + + //Parameters + //n: positive integer value (order of filter) + //Wc: positive real value, + // 1).Analog 3dB cutoff frequency/frequencies for analog filter, in the range [0, Inf] {rad/sec} + // 2).Normalised digital 3dB cutoff frequency/frequencies for digital filter, in the range [0, 1] {dimensionless} + + //Description + //This function generates a Bessel filter. The default is a Laplace space (s) or analog filter. + //If second argument is scalar the third parameter takes in high or low, the default value being low. The cutoff is Wc rad/sec. + //If second argument is vector of length 2 ie [Wl Wh] then third parameter may be pass or stop default is pass for bandpass and band reject filter respectively + //[z,p,g] = besself(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. + //[...] = besself(...,’z’) returns a discrete space (Z) filter. Wc must be less than 1 {dimensionless}. + + + //Examples + //[b, a]=besself(2,.3,"high","z") + //Output : + // a = + // + // 1. - 0.6912562 0.1760353 + // b = + // + // 0.4668229 - 0.9336457 0.4668229 + // + + funcprot(0); + [nargout nargin] = argn(); + + if (nargin > 4 | nargin < 2 | nargout > 4 | nargout < 2) + error("besself: invalid number of inputs") + end + + // interpret the input parameters + if (~ (isscalar (n) & (n == fix (n)) & (n > 0))) + error ("besself: filter order N must be a positive integer"); + end + + stop = %F; + digital = %F; + for i = 1:length (varargin) + select (varargin(i)) + case "s" + digital = %F; + case "z" + digital = %T; + case "high" + stop = %T; + case "stop" + stop = %T; + case "low" + stop = %F; + case "pass" + stop = %F; + else + error ("besself: expected [high|stop] or [s|z]"); + end + end + + // FIXME: Band-pass and stop-band currently non-functional, remove + // this check once low-pass to band-pass transform is implemented. + if (~ isscalar (w)) + error ("besself: band-pass and stop-band filters not yet implemented"); + end + + [rows_w colums_w] = size(w); + + if (~ ((length (w) <= 2) & (rows_w == 1 | columns_w == 1))) + error ("besself: frequency must be given as WC or [WL, WH]"); + elseif ((length (w) == 2) & (w(2) <= w(1))) + error ("besself: W(1) must be less than W(2)"); + end + + if (digital & ~ and ((w >= 0) & (w <= 1))) + error ("besself: and elements of W must be in the range [0,1]"); + elseif (~ digital & ~ and (w >= 0)) + error ("besself: and elements of W must be in the range [0,inf]"); + end + + // Prewarp to the band edges to s plane + if (digital) + T = 2; // sampling frequency of 2 Hz + w = 2 / T * tan (%pi * w / T); + end + + // Generate splane poles for the prototype Bessel filter + [zero, pole, gain] = besselap (n); + // splane frequency transform + [zero, pole, gain] = sftrans (zero, pole, gain, w, stop); + + // Use bilinear transform to convert poles to the z plane + if (digital) + [zero, pole, gain] = bilinear (zero, pole, gain, T); + end + + // convert to the correct output form + if (nargout == 2) + // a = real (gain * poly (zero)); + // b = real (poly (pole)); + [a b] = zp2tf(zero, pole, gain); + elseif (nargout == 3) + a = zero; + b = pole; + c = gain; + else + // output ss results + // [a, b, c, d] = zp2ss (zero, pole, gain); + error("besself: yet not implemented in state-space form OR invalid number of o/p arguments") + end endfunction diff --git a/macros/bilinear.sci b/macros/bilinear.sci index 387b8d0..9030bfd 100644 --- a/macros/bilinear.sci +++ b/macros/bilinear.sci @@ -1,40 +1,117 @@ -function [Zb, Za, Zg]= bilinear(Sb,varargin) -// Transform a s-plane filter specification into a z-plane specification -//Calling Sequence -// [ZB, ZA] = bilinear (SB, SA, T) -// [ZB, ZA] = bilinear (SZ, SP, SG, T) -// [ZZ, ZP, ZG] = bilinear (...) -//Description -//Transform a s-plane filter specification into a z-plane specification. Filters can be specified in either zero-pole-gain or transfer function form. The input form does not have to match the output form. 1/T is the sampling frequency represented in the z plane. +// Copyright (C) 2018 - IIT Bombay - FOSSEE // -//Note: this differs from the bilinear function in the signal processing toolbox, which uses 1/T rather than T. -// -//Theory: Given a piecewise flat filter design, you can transform it from the s-plane to the z-plane while maintaining the band edges by means of the bilinear transform. This maps the left hand side of the s-plane into the interior of the unit circle. The mapping is highly non-linear, so you must design your filter with band edges in the s-plane positioned at 2/T tan(w*T/2) so that they will be positioned at w after the bilinear transform is complete. -//Examples -//[ZB,ZA]=bilinear([1],[2,3],3) - funcprot(0); - lhs= argn(1); - rhs= argn(2); - if(rhs < 3 | rhs > 4) - error("Wrong number of input arguments"); - end - if(lhs < 2 | lhs > 3) - error("Wrong number of output arguments"); - end - select(rhs) - case 3 then - select(lhs) - case 2 then - [Zb, Za]= callOctave("bilinear", Sb, varargin(1), varargin(2)); - case 3 then - [Zb, Za, Zg]= callOctave("bilinear", Sb, varargin(1), varargin(2)); - end - case 4 then - select(lhs) - case 2 then - [Zb, Za]= callOctave("bilinear", Sb, varargin(1), varargin(2), varargin(3)); - case 3 then - [Zb, Za, Zg]= callOctave("bilinear", Sb, varargin(1), varargin(2), varargin(3)); - end - end -endfunction
\ No newline at end of file +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [Zz, Zp, Zg] = bilinear(Sz, Sp, Sg, T) + + //Transforms a s-plane filter (Analog) into a z-plane filter (Digital) using Bilinear transformation + + //Calling Sequence + // [Zb, Za] = bilinear(Sb, Sa, T) + // [Zb, Zb] = bilinear(Sz, Sp, Sg, T) + // [Zz, Zp, Zg] = bilinear(...) + + //Prameters + //Sb: Numerator coefficient vector in s-domain + //Sa: denumerator coefficient vector s-domain + //Sz: zeros in s-plane + //Sp: poles in s-plane + //Sg: gain in s-domain + //T: Sampling period (double) + //Zb: Numerator coefficient vector in z-domain + //Za: denumerator coefficient vector z-domain + //Zz: zeros in z-plane + //Zp: poles in z-plane + //Zg: gain in z-domain + + //Description: + //a filter design can be transformed from the s-plane to the z-plane while maintaining the band edges by means of the bilinear transform. This maps the left hand side of the s-plane into the interior of the unit circle in z-plane. The mapping is highly non-linear, so you must design your filter with band edges in the s-plane positioned at 2/T tan(w*T/2) so that they will be positioned at w after the bilinear transform is complete. + //It does following transformation from s-plane to z-plane + // 2 z-1 + // s -> - ---- + // T z+1 + + //Examples + //[b a] = bilinear ([1 2 3], [4 5 6], 1, 1) + //Output : + // a = + // + // 1. 7.3333333 17.666667 14. + // b = + // + // 0. - 0.1666667 - 0.3333333 2.5 + + funcprot(0); + [nargout nargin] = argn(); + ieee(1); + + if nargin==3 + T = Sg; + [Sz, Sp, Sg] = tf2zp(Sz, Sp); + elseif nargin~=4 + error("bilinear: invalid number of inputs") + end + + p = length(Sp); + z = length(Sz); + if z > p | p==0 + error("bilinear: must have at least as many poles as zeros in s-plane"); + end + + // ---------------- ------------------------- ------------------------ + // Bilinear zero: (2+xT)/(2-xT) pole: (2+xT)/(2-xT) + // 2 z-1 pole: -1 zero: -1 + // S -> - --- gain: (2-xT)/T gain: (2-xT)/T + // T z+1 + // ---------------- ------------------------- ------------------------ + Zg = real(Sg * prod((2-Sz*T)/T) / prod((2-Sp*T)/T)); + + if Zg == 0 & nargout == 3 then + error("bilinear: invalid value of gain due to zero(s) at infinity avoid z-p-g form and use tf form ") + end + + + + Zp = (2+Sp*T)./(2-Sp*T); + SZp = size(Zp); + if isempty(Sz) + Zz = -ones(SZp(1), SZp(2)); + else + Zz = [(2+Sz*T)./(2-Sz*T)]; + Zz = postpad(Zz, p, -1); + end + + + if nargout==2 + // zero at infinity + Zz1 = []; + for i=1:length(Zz) + if Zz(i) ~= %inf + Zz1 = [Zz1 Zz(i)]; + end + end + Zz = Zz1; + + if Zg == 0 + z = %z; + bi = (2*(z - 1))/(T*(z + 1)); + Hs = Sg * real(poly(Sz, "s"))/real(poly(Sp, "s")); + Hz = horner(Hs, bi); + b = coeff(Hz.num); + a = coeff(Hz.den); + Zg = b($)/a($); + end + + [Zz, Zp] = zp2tf(Zz, Zp, Zg); + Zz = prepad(Zz, length(Zp)); + end + +endfunction diff --git a/macros/bitrevorder.sci b/macros/bitrevorder.sci index a4b6da8..cf27cd8 100644 --- a/macros/bitrevorder.sci +++ b/macros/bitrevorder.sci @@ -1,25 +1,59 @@ -function [y,i]=bitrevorder(x) +// Returns input data in bit-reversed order -// Returns input data in bit-reversed order // Calling Sequence -// [y,i]=bitrevorder(x) +//[y,i] = bitrevorder(x) +//y = bitrevorder(x) + // Parameters -// x: Vector of real or complex values +//x: Vector of real or complex values +//y: input vector in bit reverse order +//i: indices + // Description -// This is an Octave function. -// This function returns the input data after reversing the bits of the indices and reordering the elements of the input array. +//This function returns the input data after reversing the bits of the indices and reordering the elements of the input array. + // Examples -// 1. [y]=bitrevorder ([i,1,3,6i]) -// y = [0 + 1i 3 + 0i 1 + 0i 0 + 6i] -// 2. [y,i]=bitrevorder (['a','b','c','d']) -// y = acbd -// i = [1 3 2 4] - -funcprot(0); -[lhs,rhs]=argn(0); -if (rhs<1) then - error ("Wrong number of input arguments.") -end -[y,i]=callOctave("bitrevorder",x) +//x = [%i,1,3,6*%i] ; +//[y i]=bitrevorder(x) +//Output : +// i = +// +// 1. 3. 2. 4. +// y = +// +// i 3. 1. 6.i + + +//************************************************************************************* +//-------------------version1 (using callOctave / errored)----------------------------- +//************************************************************************************* + +//function [y,i]=bitrevorder(x) +//funcprot(0); +//[lhs,rhs]=argn(0); +//if (rhs<1) then +// error ("Wrong number of input arguments.") +//end +//[y,i]=callOctave("bitrevorder",x) +// +//endfunction + +//************************************************************************************* +//-----------------------------version2 (pure scilab code)----------------------------- +//************************************************************************************* +function [y, i] = bitrevorder (x) + + funcprot(0); + [nargout, nargin] = argn() ; + + if (nargin ~= 1) + print_usage (); + elseif (~ isvector (x)) + error ("bitrevorder: X must be a vector"); + elseif (fix (log2 (length (x))) ~= log2 (length (x))) + error ("bitrevorder: X must have length equal to an integer power of 2"); + end + + [y, i] = digitrevorder (x, 2); endfunction diff --git a/macros/buffer.sci b/macros/buffer.sci index 5cc480a..ef043a6 100644 --- a/macros/buffer.sci +++ b/macros/buffer.sci @@ -1,11 +1,10 @@ -function [y, z, opt] = buffer (x, n, p, opt) //This function buffers the given data into a matrix of signal frames //Calling Sequence //[y] = buffer (x, n) //[y] = buffer (x, n, p) //[y] = buffer (x, n, p) //[y, z, opt] = buffer (...) -//Parameters +//Parameters //x: Data to be buffered //n: Positive integer equal to number of rows in the produced data buffer //p: Integer less than n, default value 0 @@ -18,42 +17,193 @@ function [y, z, opt] = buffer (x, n, p, opt) // 0 0 // 0 1 // 1 0 -//This function is being called from Octave - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 2 | rhs > 4) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 2 then - if(lhs==1) - y = callOctave("buffer",x,n) - elseif(lhs==3) - [y,z,opt] = callOctave("buffer",x,n) - else - error("Wrong number of output argments.") - end - - case 3 then - if(lhs==1) - y = callOctave("buffer",x,n,p) - elseif(lhs==3) - [y,z,op] = callOctave("buffer",x,n,p) - else - error("Wrong number of output argments.") - end - case 4 then - if(lhs==1) - y = callOctave("buffer",x,n,p,opt) - elseif(lhs==3) - [y,z,opt] = callOctave("buffer",x,n,p,opt) - else - error("Wrong number of output argments.") - end - end -endfunction +//Older code + +//function [y, z, opt] = buffer (x, n, p, opt) +//funcprot(0); +//lhs = argn(1) +//rhs = argn(2) +//if (rhs < 2 | rhs > 4) +//error("Wrong number of input arguments.") +//end +// +//select(rhs) +// +// case 2 then +// if(lhs==1) +// y = callOctave("buffer",x,n) +// elseif(lhs==3) +// [y,z,opt] = callOctave("buffer",x,n) +// else +// error("Wrong number of output argments.") +// end +// +// case 3 then +// if(lhs==1) +// y = callOctave("buffer",x,n,p) +// elseif(lhs==3) +// [y,z,op] = callOctave("buffer",x,n,p) +// else +// error("Wrong number of output argments.") +// end +// case 4 then +// if(lhs==1) +// y = callOctave("buffer",x,n,p,opt) +// elseif(lhs==3) +// [y,z,opt] = callOctave("buffer",x,n,p,opt) +// else +// error("Wrong number of output argments.") +// end +// end +//endfunction + + +function [y, z, opt] = buffer (x, n, p, opt) + + [nargout, nargin] = argn() ; + + if (nargin < 2 | nargin > 4) + error("buffer : invalid input"); + end + if (~isscalar (n) | n ~= floor (n)) + error ("buffer: n must be an integer"); + end + if (nargin < 3) + p = 0; + elseif (~isscalar (p) | p ~= floor (p) | p >= n) + error ("buffer: p must be an integer less than n"); + end + if (nargin < 4) + if (p < 0) + opt = 0; + else + opt = zeros (1, p); + end + end + + [rows_x columns_x] = size(x) ; + + if (rows_x == 1) + isrowvec = %T; + else + isrowvec = %F; + end + + if (p < 0) + if (isscalar (opt) & opt == floor (opt) & opt >= 0 & opt <= -p) + lopt = opt; + else + error ("buffer: expecting fourth argument to be and integer between 0 and -p"); + end + else + lopt = 0; + end + + x = x (:); + l = length (x); + m = ceil ((l - lopt) / (n - p)); + y = zeros (n - p, m); + y (1 : l - lopt) = x (lopt + 1 : $); + if (p < 0) + y ($ + p + 1 : $, :) = []; + elseif (p > 0) + if (type(opt) == 10) + if (strcmp (opt, "nodelay")) + y = [y ; zeros(p, m)]; + if (p > n / 2) + is = n - p + 1; + in = n - p; + ie = is + in - 1; + off = 1; + while (in > 0) + y (is : ie, 1 : $ - off) = y (1 : in, 1 + off : $); + off = off + 1; + is = ie + 1; + ie = ie + in; + if (ie > n) + ie = n; + end + in = ie - is + 1; + end + [i, j] = ind2sub([n-p, m], l); + if (all ([i, j] == [n-p, m])) + off = off -1 ; + end + y (:, $ - off + 2 : $) = []; + else + y ($ - p + 1 : $, 1 : $ - 1) = y (1 : p, 2 : $); + if (sub2ind([n-p, m], p, m) >= l) + y (:, $) = []; + end + end + else + error ("buffer: unexpected string argument"); + end + elseif (isvector (opt)) + if (length (opt) == p) + lopt = p; + y = [zeros(p, m); y]; + in = p; + off = 1; + while (in > 0) + y (1 : in, off) = opt(off:$); + off = off + 1; + in = in - n + p; + end + if (p > n / 2) + in = n - p; + ie = p; + is = p - in + 1; + off = 1; + while (ie > 0) + y (is : ie, 1 + off : $) = ... + y ($ - in + 1 : $, 1 : $ - off); + off = off + 1; + ie = is - 1; + is = is - in; + if (is < 1) + is = 1; + end + in = ie - is + 1; + end + else + y (1 : p, 2 : $) = y ($ - p + 1 : $, 1 : $ - 1); + end + else + error ("buffer: opt vector must be of length p"); + end + else + error ("buffer: unrecognized fourth argument"); + end + end + if (nargout > 1) + if (p >= 0) + [i, j] = ind2sub (size(y), l + lopt + p * (size (y, 2) - 1)); + if (any ([i, j] ~= size (y))) + z = y (1 + p : i, $); + y (:, $) = []; + else + z = zeros (0, 1); + end + else + [i, j] = ind2sub (size (y) + [-p, 0], l - lopt); + if (i < size (y, 1)) + z = y (1: i, $); + y (:, $) = []; + else + z = zeros (0, 1); + end + end + if (isrowvec) + z = z.'; + end + if (p < 0) + opt = max(0, size (y, 2) * (n - p) + opt - l); + elseif (p > 0) + opt = y($-p+1:$)(:); + else + opt = []; + end + end +endfunction diff --git a/macros/buttap.sci b/macros/buttap.sci index 9c2e08d..f42141b 100644 --- a/macros/buttap.sci +++ b/macros/buttap.sci @@ -1,45 +1,56 @@ -function [z, p, g] = buttap (n) -//Design a lowpass analog Butterworth filter. -//Calling Sequence -//z = buttap (n) -//[z, p] = buttap (n) -//[z, p, g] = buttap (n) -//Parameters -//n: Filter Order -//z: Zeros -//p: Poles -//g: Gain -//Description -//This is an Octave function. -//It designs a lowpass analog Butterworth filter of nth order. -//Examples -//[z, p, g] = buttap (5) -//z = [](0x0) -//p = -// -// -0.30902 + 0.95106i -0.80902 + 0.58779i -1.00000 + 0.00000i -0.80902 - 0.58779i -0.30902 - 0.95106i +// Copyright (C) 2018 - IIT Bombay - FOSSEE // -//g = 1 - - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 1 | rhs > 1) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 1 then - if(lhs==1) - z = callOctave("buttap",n) - elseif(lhs==2) - [z, p] = callOctave("buttap",n) - elseif(lhs==3) - [z, p, g] = callOctave("buttap",n) - else - error("Wrong number of output argments.") - end - end +// 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 +// Author:Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [z, p, g] = buttap (n) + //Produces analog prototype Butterworth filter + + //Calling Sequence + //[z, p, g] = buttap (n) + + //Parameters + //n: Filter Order + //z: Zeros + //p: Poles + //g: Gain + + //Description + //It gives a lowpass analog prototype Butterworth filter of nth order. + + //Examples + //[z, p, g] = buttap(5) + //Output : + // g = + // + // 1. + // p = + // + // - 0.3090170 - 0.9510565i + // - 0.8090170 - 0.5877853i + // - 1. - 1.225D-16i + // - 0.8090170 + 0.5877853i + // - 0.3090170 + 0.9510565i + // z = + // + // [] + + + funcprot(0); + lhs = argn(1) + rhs = argn(2) + if (rhs < 1 | rhs > 1) + error("buttap: Wrong number of input arguments.") + end + + [Hs, p, z, g] = analpf(n, "butt", [],1 ); + p = p' ; + z = z' ; + endfunction diff --git a/macros/butter.sci b/macros/butter.sci index a11da7e..73cdb71 100644 --- a/macros/butter.sci +++ b/macros/butter.sci @@ -1,58 +1,147 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [a, b, c, d] = butter (n, w, varargin) -//This function generates a Butterworth filter. -//Calling Sequence -//[a, b] = butter (n, w) -//[a, b] = butter (n, w, "high") -//[a, b] = butter (n, [wl, wh]) -//[b, a] = butter (n, [wl, wh], "stop") -//[a, b, c] = butter (…) -//[a, b, c, d] = butter (…) -//[…] = butter (…, "s") -//Parameters -//n: positive integer value -//w: positive real value, w in the range [0,1] -//Description -//This is an Octave function. -//This function generates a Butterworth filter. Default is a discrete space (Z) filter. -//The third parameter takes in low or high, default value is low. The cutoff is pi*Wc radians. -//[b,a] = butter(n, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians. -//[b,a] = butter(n, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians. -//[z,p,g] = butter(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. -//[...] = butter(...,’s’) returns a Laplace space filter, w can be larger than 1. -//[a,b,c,d] = butter(...) returns state-space matrices. -//Examples -//[a,b]=butter(3, 0.7) -//a = -// 0.37445 1.12336 1.12336 0.37445 -//b = -// 1.00000 1.16192 0.69594 0.13776 - -rhs = argn(2) -lhs = argn(1) -if(rhs>4 | rhs<2) -error("Wrong number of input arguments.") -end -if(lhs>4 | lhs<2) -error("Wrong number of output arguments.") -end - - select (rhs) - case 2 then - if (lhs==2) [a,b] = callOctave("butter",n, w) - elseif (lhs==3) [a,b,c] = callOctave("butter",n, w) - elseif (lhs==4) [a,b,c,d] = callOctave("butter",n, w) - end - case 3 then - if (lhs==2) [a,b] = callOctave("butter",n, w,varargin(1)) - elseif (lhs==3) [a,b,c] = callOctave("butter",n, w,varargin(1)) - elseif (lhs==4) [a,b,c,d] = callOctave("butter",n, w,varargin(1)) - end - case 4 then - if (lhs==2) [a,b] = callOctave("butter",n, w,varargin(1),varargin(2)) - elseif (lhs==3) [a,b,c] = callOctave("butter",n, w,varargin(1),varargin(2)) - elseif (lhs==4) [a,b,c,d] = callOctave("butter",n, w,varargin(1),varargin(2)) - end - end -endfunction - + //Butterworth filter design. + + //Calling Sequence + //[b, a] = butter (n, wc) + //[b, a] = butter (n, wc, "high") + //[b, a] = butter (n, [wl, wh]) + //[b, a] = butter (n, [wl, wh], "stop") + //[z, p, g] = butter (…) + //[…] = butter (…, "s") + + //Parameters + //n: positive integer value (order of filter) + //wc: positive real value, + // 1).Normalised digital 3dB cutoff frequency/frequencies for digital filter, in the range [0, 1] {dimensionless} + // 2).Analog 3dB cutoff frequency/frequencies for analog filter, in the range [0, Inf] {rad/sec} + + //Description + //This function generates a Butterworth filter. Default is a discrete space (z) or digital filter using Bilinear transformation from s to z plane. + //If second argument is scalar the third parameter takes in low or high, default value is low. The cutoff is pi*wc radians. + //[b,a] = butter(n, [wl, wh]) indicates a band pass filter with cutoffs pi*Wl and pi*wh radians. + //[b,a] = butter(n, [wl, wh], ’stop’) indicates a band reject filter with cutoffs pi*wl and pi*wh radians. + //[z,p,g] = butter(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. + //[...] = butter(...,’s’) returns a Laplace space filter,here cutoff(s) wc can be larger than 1 (rad/sec). + + //Examples + //[b a] = butter(4,0.3,"high") + //Output + // a = + // + // + // column 1 to 4 + // + // 1. - 1.5703989 1.2756133 - 0.4844034 + // + // column 5 + // + // 0.0761971 + // b = + // + // + // column 1 to 4 + // + // 0.2754133 - 1.1016532 1.6524797 - 1.1016532 + // + // column 5 + // + // 0.2754133 + + + funcprot(); + [nargout nargin] = argn(); + if (nargin > 4 | nargin < 2 | nargout > 4 | nargout < 2) + error("butter: Invalid number of input argument") + end + + // interpret the input parameters + if (~ (isscalar (n) & (n == fix (n)) & (n > 0))) + error ("butter: filter order N must be a positive integer"); + end + stop = %F; + digital = %T; + for i = 1:length (varargin) + select (varargin(i)) + case "s" + digital = %F; + case "z" + digital = %T; + case "high" + stop = %T; + case "stop" + stop = %T; + case "low" + stop = %T; + case "pass" + stop = %F; + else + error ("butter: expected [high|stop] or [s|z]"); + end + end + + [rows_w columns_w] = size(w); + + if (~ ((length (w) <= 2) & (rows_w == 1 | columns_w == 1))) + error ("butter: frequency must be given as WC or [WL, WH]"); + elseif ((length (w) == 2) & (w(2) <= w(1))) + error ("butter: W(1) must be less than W(2)"); + end + + if (digital & ~ and ((w >= 0) & (w <= 1))) + error ("butter: all elements of W must be in the range [0,1] for digital filter"); + elseif (~ digital & ~ and (w >= 0)) + error ("butter: all elements of W must be in the range [0,inf] for analog filter"); + end + + // Prewarp to the band edges to s plane + if (digital) + T = 2; // sampling frequency of 2 Hz + w = 2 / T * tan (%pi * w / T); + end + + // Generate splane poles for the prototype Butterworth filter + // source: Kuc + C = 1; // default cutoff frequency + pole = C * exp (1*%i * %pi * (2 * [1:n] + n - 1) / (2 * n)); + if (pmodulo (n, 2) == 1) + pole((n + 1) / 2) = -1; // pure real value at exp(%i*%pi) + end + zero = []; + gain = C^n; + + // splane frequency transform + [zero, pole, gain] = sftrans (zero, pole, gain, w, stop); + + // Use bilinear transform to convert poles to the z plane + if (digital) + [zero, pole, gain] = bilinear (zero, pole, gain, T); + end + + // convert to the correct output form + if (nargout == 2) + // a = real (gain * poly (zero)); + // b = real (poly (pole)); + [a b] = zp2tf(zero, pole, gain); + elseif (nargout == 3) + a = zero; + b = pole; + c = gain; + else + // output ss results + //[a, b, c, d] = zp2ss (zero, pole, gain); + error("butter: yet not implemented in state-space form OR invalid number of o/p arguments") + end +endfunction diff --git a/macros/buttord.sci b/macros/buttord.sci index 2a17521..dbf0e10 100644 --- a/macros/buttord.sci +++ b/macros/buttord.sci @@ -1,39 +1,89 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [n, Wc] = buttord(Wp, Ws, Rp, Rs) -///This function computes the minimum filter order of a Butterworth filter with the desired response characteristics. -//Calling Sequence -//n = buttord(Wp, Ws, Rp, Rs) -//[n, Wc] = buttord(Wp, Ws, Rp, Rs) -//Parameters -//Wp: scalar or vector of length 2 -//Ws: scalar or vector of length 2, elements must be in the range [0,1] -//Rp: real or complex value -//Rs: real or complex value -//Description -//This is an Octave function. -//This function computes the minimum filter order of a Butterworth filter with the desired response characteristics. -//The filter frequency band edges are specified by the passband frequency wp and stopband frequency ws. -//Frequencies are normalized to the Nyquist frequency in the range [0,1]. -//Rp is measured in decibels and is the allowable passband ripple, and Rs is also in decibels and is the minimum attenuation in the stop band. -//If ws>wp, the filter is a low pass filter. If wp>ws, the filter is a high pass filter. -//If wp and ws are vectors of length 2, then the passband interval is defined by wp the stopband interval is defined by ws. -//If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp the filter is a band-stop or band-reject filter. -//Examples -//Wp = 40/500 -//Ws = 150/500 -//[n, Wn] = buttord(Wp, Ws, 3, 60) -//n = 5 -//Wn = 0.080038 - -rhs = argn(2) -lhs = argn(1) -if(rhs~=4) -error("Wrong number of input arguments.") -end - - select(lhs) - case 1 then - n = callOctave(Wp,Ws,Rp,Rs) - case 2 then - [n,Wc] = callOctave(Wp,Ws,Rp,Rs) - end + //Minimum filter order and 3dB cutoff frequency of a digital Butterworth filter with the desired response characteristics + + //Calling Sequence + //n = buttord(Wp, Ws, Rp, Rs) + //[n, Wc] = buttord(Wp, Ws, Rp, Rs) + + //Parameters + //Wp: scalar or vector of length 2 (passband edge(s) ), elements must be in the range [0,1] + //Ws: scalar or vector of length 2 (stopband edge(s) ), elements must be in the range [0,1] + //Rp: passband ripple in dB. + //Rs: stopband attenuation in dB. + //n: Minimum filter order satisfying specs + //Wc: 3dB cutoff frequency/frequencies + + //Description. + //This function computes the minimum filter order of a Butterworth filter with the desired response characteristics. + //The filter frequency band edges are specified by the passband frequency wp and stopband frequency ws. + //Frequencies are normalized to the Nyquist frequency in the range [0,1]. + //Rp is measured in decibels and is the allowable passband ripple, and Rs is also in decibels and is the minimum attenuation in the stop band. + //If ws>wp, the filter is a low pass filter. If wp>ws, the filter is a high pass filter. + //If wp and ws are vectors of length 2, then the passband interval is defined by wp the stopband interval is defined by ws. + //If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp the filter is a band-stop or band-reject filter. + + //Examples + //Wp = 40/500 ; + //Ws = 150/500 ; + //[n, Wc] = buttord(Wp, Ws, 3, 60) + //Output : + // Wc = + // + // 0.0800376 + // n = + // + // 5. + + funcprot(0); + [nargout nargin] = argn(); + + if (nargin ~= 4) + error("buttord: invalid number of inputs"); + else + validate_filter_bands ("buttord", Wp, Ws); + end + + if (length (Wp) == 2) + warning ("buttord: seems to overdesign bandpass and bandreject filters"); + end + + T = 2; + + // if high pass, reverse the sense of the test + stop = find(Wp > Ws); + Wp(stop) = 1-Wp(stop); // stop will be at most length 1, so no need to + Ws(stop) = 1-Ws(stop); // subtract from ones(1,length(stop)) + + // warp the target frequencies according to the bilinear transform + Ws = (2/T)*tan(%pi*Ws./T); + Wp = (2/T)*tan(%pi*Wp./T); + + // compute minimum n which satisfies all band edge conditions + // the factor 1/length(Wp) is an artificial correction for the + // band pass/stop case, which otherwise significantly overdesigns. + qs = log(10^(Rs/10) - 1); + qp = log(10^(Rp/10) - 1); + n = ceil(max(0.5*(qs - qp)./log(Ws./Wp))/length(Wp)); + + // compute -3dB cutoff given Wp, Rp and n + Wc = exp(log(Wp) - qp/2/n); + + // unwarp the returned frequency + Wc = atan(T/2*Wc)*T/%pi; + + // if high pass, reverse the sense of the test + Wc(stop) = 1-Wc(stop); + endfunction diff --git a/macros/cheb1ap.sci b/macros/cheb1ap.sci index 361f272..51bc03b 100644 --- a/macros/cheb1ap.sci +++ b/macros/cheb1ap.sci @@ -1,51 +1,64 @@ -function [z, p, g] = cheb1ap (n, Rp) -//This function designs a lowpass analog Chebyshev type I filter. -//Calling Sequence -//[z, p, g] = cheb1ap (n, Rp) -//[z, p] = cheb1ap (n, Rp) -//p = cheb1ap (n, Rp) -//Parameters -//n: Filter Order -//Rp: Peak-to-peak passband ripple -//z: Zeros -//p: Poles -//g: Gain -//Description -//This is an Octave function. -//It designs a lowpass analog Chebyshev type I filter of nth order and with a Peak-to-peak passband ripple of Rp. -//Examples -//[z, p, g] = cheb1ap (10, 20) -//z = [](0x0) -//p = -// -// Columns 1 through 6: -// -// -0.00157 - 0.98774i -0.00456 - 0.89105i -0.00709 - 0.70714i -0.00894 - 0.45401i -0.00991 - 0.15644i -0.00991 + 0.15644i -// -// Columns 7 through 10: +// Copyright (C) 2018 - IIT Bombay - FOSSEE // -// -0.00894 + 0.45401i -0.00709 + 0.70714i -0.00456 + 0.89105i -0.00157 + 0.98774i -// -//g = 1.9630e-04 - 6.3527e-22i - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 2 | rhs > 2) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 2 then - if(lhs==1) - z = callOctave("cheb1ap", n, Rp) - elseif(lhs==2) - [z, p] = callOctave("cheb1ap", n, Rp) - elseif(lhs==3) - [z, p, g] = callOctave("cheb1ap", n, Rp) - else - error("Wrong number of output argments.") - end - end +// 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 +// Author:Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [z, p, g] = cheb1ap (n, Rp) + //This function designs a lowpass analog Chebyshev type I filter. + + //Calling Sequence + //[z, p, g] = cheb1ap (n, Rp) + + //Parameters + //n: Filter Order + //Rp: Peak-to-peak passband ripple (in dB) + //z: Zeros + //p: Poles + //g: Gain + + //Description + //It gives a lowpass analog Chebyshev type I filter of nth order and with a Peak-to-peak passband ripple of Rp. + + //Examples + //[z, p, g] = cheb1ap (10, 3) + //Output : + // g = + // + // 0.0019578 + // p = + // + // - 0.0138320 - 0.9915418i + // - 0.0401419 - 0.8944827i + // - 0.0625225 - 0.7098655i + // - 0.0787829 - 0.4557617i + // - 0.0873316 - 0.1570448i + // - 0.0873316 + 0.1570448i + // - 0.0787829 + 0.4557617i + // - 0.0625225 + 0.7098655i + // - 0.0401419 + 0.8944827i + // - 0.0138320 + 0.9915418i + // z = + // + // [] + + funcprot(0); + lhs = argn(1) + rhs = argn(2) + if (rhs < 2 | rhs > 2) + error("cheb1ap: Wrong number of input arguments.") + end + + Rpf = 10 ^ (-Rp/20); //passband pick to pick ripple in fraction + rp = 1 - Rpf ; //analpf function compitable passband ripple (delta-p) + [hs,p,z,g]=analpf(n,"cheb1",[rp 0],1); //cutoff frequency of 1 rad/sec for prototype filter + p = p' ; + z = z' ; + g = abs(g); + endfunction diff --git a/macros/cheb1ord.sci b/macros/cheb1ord.sci index b2789bf..61737a0 100644 --- a/macros/cheb1ord.sci +++ b/macros/cheb1ord.sci @@ -1,36 +1,87 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in function [n, Wc] = cheb1ord(Wp, Ws, Rp, Rs) -//This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics. -//Calling Sequence -//n = cheb1ord(Wp, Ws, Rp, Rs) -//[n, Wc] = cheb1ord(Wp, Ws, Rp, Rs) -//Parameters -//Wp: scalar or vector of length 2, all elements must be in the range [0,1] -//Ws: scalar or vector of length 2, all elements must be in the range [0,1] -//Rp: real value -//Rs: real value -//Description -//This is an Octave function. -//This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics. -//Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. -//Frequencies are normalized to the Nyquist frequency in the range [0,1]. -//Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. -//If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. -//If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. -//If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. -//Examples -//cheb1ord(0.1,0.2,-0.3,4) -//ans = 2 - -rhs = argn(2) -lhs = argn(1) -if(rhs~=4) -error("Wrong number of input arguments.") -end - - select(lhs) - case 1 then - n = callOctave("cheb1ord",Wp,Ws,Rp,Rs) - case 2 then - [n,Wc] = callOctave("cheb1ord",Wp,Ws,Rp,Rs) - end + //Minimum filter order of a digital Chebyshev type I filter with the desired response characteristics. + + //Calling Sequence + //n = cheb1ord(Wp, Ws, Rp, Rs) + //[n, Wp] = cheb1ord(Wp, Ws, Rp, Rs) + + //Parameters + //Wp: scalar or vector of length 2 (passband edge(s)), all elements must be in the range [0,1] + //Ws: scalar or vector of length 2 (stopband edge(s)), all elements must be in the range [0,1] + //Rp: passband ripple in dB. + //Rs: stopband attenuation in dB. + //n: Minimum filter order satisfying specs + //Wp: passband edge(s) + + //Description + //This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics. + //Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. + //Frequencies are normalized to the Nyquist frequency in the range [0,1]. + //Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. + //If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. + //If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. + //If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. + + //Examples + //[n, wp]=cheb1ord([0.25 0.3],[0.24 0.31],3,10) + // wp = + // + // 0.25 0.3 + // n = + // + // 3. + + funcprot(0); + [nargout nargin] = argn(); + + if nargin ~= 4 + error("cheb1ord: invalid number of inputs"); + else + validate_filter_bands ("cheb1ord", Wp, Ws); + end + + T = 2; + + // returned frequency is the same as the input frequency + Wc = Wp; + + // warp the target frequencies according to the bilinear transform + Ws = (2/T)*tan(%pi*Ws./T); + Wp = (2/T)*tan(%pi*Wp./T); + + if (Wp(1) < Ws(1)) + // low pass + if (length(Wp) == 1) + Wa = Ws/Wp; + else + // FIXME: Implement band reject filter type + error ("cheb1ord: band reject is not yet implemented"); + end; + else + // if high pass, reverse the sense of the test + if (length(Wp) == 1) + Wa = Wp/Ws; + else + // band pass + Wa=(Ws.^2 - Wp(1)*Wp(2))./(Ws*(Wp(1)-Wp(2))); + end; + end; + Wa = min(abs(Wa)); + + // compute minimum n which satisfies all band edge conditions + stop_atten = 10^(abs(Rs)/10); + pass_atten = 10^(abs(Rp)/10); + n = ceil(acosh(sqrt((stop_atten-1)/(pass_atten-1)))/acosh(Wa)); + endfunction diff --git a/macros/cheb2ap.sci b/macros/cheb2ap.sci index 007d2d5..a599f31 100644 --- a/macros/cheb2ap.sci +++ b/macros/cheb2ap.sci @@ -1,39 +1,61 @@ -function [z, p, g] = cheb2ap (n, Rs) -//This function designs a lowpass analog Chebyshev type II filter. -//Calling Sequence -//[z, p, g] = cheb2ap (n, Rs) -//[z, p] = cheb2ap (n, Rs) -//p = cheb2ap (n, Rs) -//Parameters -//n: Filter Order -//Rs: Stopband attenuation -//z: Zeros -//p: Poles -//g: Gain -//Description -//This is an Octave function. -//This function designs a lowpass analog Chebyshev type II filter of nth order and with a stopband attenuation of Rs. -//Examples +// 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 +// Author:Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [z, p, g] = cheb2ap (n, Rs) + //This function produces a lowpass analog Chebyshev type II prototype filter. + + //Calling Sequence + //[z, p, g] = cheb2ap (n, Rs) + + //Parameters + //n: Filter Order + //Rs: Stopband attenuation (in dB) + //z: Zeros + //p: Poles + //g: Gain + + //Description + //This function designs a lowpass analog Chebyshev type II filter of nth order and with a stopband attenuation of Rs. + + //Examples + //[z, p, g] = cheb2ap (4, 10) + //Output : + // g = + // + // 0.3162278 + // p = + // + // - 0.1674887 + 0.9498949i + // - 1.1818323 + 1.1499912i + // - 1.1818323 - 1.1499912i + // - 0.1674887 - 0.9498949i + // z = + // + // - 1.0823922i + // - 2.6131259i + // 2.6131259i + // 1.0823922i + + + funcprot(0); + lhs = argn(1) + rhs = argn(2) + if (rhs < 2 | rhs > 2) + error("cheb2ap: Wrong number of input arguments.") + end -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 2 | rhs > 2) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 2 then - if(lhs==1) - z = callOctave("cheb2ap", n, Rs) - elseif(lhs==2) - [z, p] = callOctave("cheb2ap", n, Rs) - elseif(lhs==3) - [z, p, g] = callOctave("cheb2ap", n, Rs) - else - error("Wrong number of output argments.") - end - end + Rsf = 10 ^ (-Rs/20); //stop band pick to pick ripple in fraction + rs = Rsf ; //analpf function compitable stop band ripple (delta-s) + [hs,p,z,g]=analpf(n,"cheb2",[0 rs],1); //cutoff frequency of 1 rad/sec for prototype filter + p = p' ; + z = z' ; + g = abs(g); endfunction diff --git a/macros/cheb2ord.sci b/macros/cheb2ord.sci index 815ba0d..27ca7e6 100644 --- a/macros/cheb2ord.sci +++ b/macros/cheb2ord.sci @@ -1,36 +1,93 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [n, Wc] = cheb2ord(Wp, Ws, Rp, Rs) -//This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics. -//Calling Sequence -//n = cheb2ord(Wp, Ws, Rp, Rs) -//[n, Wc] = cheb2ord(Wp, Ws, Rp, Rs) -//Parameters -//Wp: scalar or vector of length 2, all elements must be in the range [0,1] -//Ws: scalar or vector of length 2, all elements must be in the range [0,1] -//Rp: real value -//Rs: real value -//Description -//This is an Octave function. -//This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics. -//Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. -//Frequencies are normalized to the Nyquist frequency in the range [0,1]. -//Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. -//If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. -//If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. -//If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. -//Examples -//cheb2ord([0.25,0.3],[0.2,0.8],0.3,0.4) -//ans = 1 - -rhs = argn(2) -lhs = argn(1) -if(rhs~=4) -error("Wrong number of input arguments.") -end - - select(lhs) - case 1 then - n = callOctave("cheb2ord",Wp,Ws,Rp,Rs) - case 2 then - [n,Wc] = callOctave("cheb2ord",Wp,Ws,Rp,Rs) - end + //Minimum filter order of a digital Chebyshev type II filter with the desired response characteristics. + + //Calling Sequence + //n = cheb2ord(Wp, Ws, Rp, Rs) + //[n, Ws] = cheb2ord(Wp, Ws, Rp, Rs) + + //Parameters + //Wp: scalar or vector of length 2 (passband edge(s)), all elements must be in the range [0,1] + //Ws: scalar or vector of length 2 (stopband edge(s)), all elements must be in the range [0,1] + //Rp: passband ripple in dB. + //Rs: stopband attenuation in dB. + //n: Minimum order of filter satisfying given specs. + + //Description + //This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics. + //Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. + //Frequencies are normalized to the Nyquist frequency in the range [0,1]. + //Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. + //If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. + //If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. + //If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. + + //Examples + //Wp = 40/500; + //Ws = 150/500; + //Rp = 3; + //Rs = 60; + //[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs) + //Output : + // Ws = + // + // 0.3 + // n = + // + // 4. + // + + funcprot(0); + [nargout nargin] = argn(); + + if nargin ~= 4 + error("cheb2ord: invalid number of inputs") + else + validate_filter_bands ("cheb2ord", Wp, Ws); + end + + T = 2; + + // returned frequency is the same as the input frequency + Wc = Ws; + + // warp the target frequencies according to the bilinear transform + Ws = (2/T)*tan(%pi*Ws./T); + Wp = (2/T)*tan(%pi*Wp./T); + + if (Wp(1) < Ws(1)) + // low pass + if (length(Wp) == 1) + Wa = Wp/Ws; + else + // FIXME: Implement band reject filter type + error ("cheb2ord: band reject is not yet implemented"); + end + else + // if high pass, reverse the sense of the test + if (length(Wp) == 1) + Wa = Ws/Wp; + else + // band pass + Wa=(Wp.^2 - Ws(1)*Ws(2))./(Wp*(Ws(1)-Ws(2))); + end; + end; + Wa = min(abs(Wa)); + + // compute minimum n which satisfies all band edge conditions + stop_atten = 10^(abs(Rs)/10); + pass_atten = 10^(abs(Rp)/10); + n = ceil(acosh(sqrt((stop_atten-1)/(pass_atten-1)))/acosh(1/Wa)); + endfunction diff --git a/macros/cheby1.sci b/macros/cheby1.sci index 52ff1ad..272f7f9 100644 --- a/macros/cheby1.sci +++ b/macros/cheby1.sci @@ -1,59 +1,149 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [a, b, c, d] = cheby1 (n, rp, w, varargin) -//This function generates a Chebyshev type I filter with rp dB of passband ripple. -//Calling Sequence -//[a, b] = cheby1 (n, rp, w) -//[a, b] = cheby1 (n, rp, w, "high") -//[a, b] = cheby1 (n, rp, [wl, wh]) -//[a, b] = cheby1 (n, rp, [wl, wh], "stop") -//[a, b, c] = cheby1 (…) -//[a, b, c, d] = cheby1 (…) -//[…] = cheby1 (…, "s") -//Parameters -//n: positive integer value -//rp: non negative scalar value -//w: vector, all elements must be in the range [0,1] -//Description -//This is an Octave function. -//This function generates a Chebyshev type I filter with rp dB of passband ripple. -//The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians. -//[b, a] = cheby1(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians. -//[b, a] = cheby1(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians. -//[z, p, g] = cheby1(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. -//[...] = cheby1(...,’s’) returns a Laplace space filter, w can be larger than 1. -//[a,b,c,d] = cheby1(...) returns state-space matrices. -//Examples -//[a,b,c]=cheby1(2,6,0.7,"high") -//a = -// 1 1 -//b = -// -0.62915 + 0.55372i -0.62915 - 0.55372i -//c = 0.055649 - -rhs = argn(2) -lhs = argn(1) -[rows,columns] = size(w) -if(rhs>5 | rhs<3) -error("Wrong number of input arguments.") -end -if(lhs>4 | lhs<2) -error("Wrong number of output arguments.") -end - - select (rhs) - case 3 then - if (lhs==2) [a,b] = callOctave("cheby1",n, rp, w) - elseif (lhs==3) [a,b,c] = callOctave("cheby1",n, rp, w) - elseif (lhs==4) [a,b,c,d] = callOctave("cheby1",n, rp, w) - end - case 4 then - if (lhs==2) [a,b] = callOctave("cheby1",n, rp, w, varargin(1)) - elseif (lhs==3) [a,b,c] = callOctave("cheby1",n, rp, w, varargin(1)) - elseif (lhs==4) [a,b,c,d] = callOctave("cheby1",n, rp, w, varargin(1)) - end - case 5 then - if (lhs==2) [a,b] = callOctave("cheby1",n, rp, rs, w, varargin(1), varargin(2)) - elseif (lhs==3) [a,b,c] = callOctave("cheby1",n, rp, rs, w, varargin(1), varargin(2)) - elseif (lhs==4) [a,b,c,d] = callOctave("cheby1",n, rp, rs, w, varargin(1), varargin(2)) - end - end + //Chebyshev type I filter design with rp dB of passband ripple. + + //Calling Sequence + //[b, a] = cheby1 (n, rp, wp) + //[b, a] = cheby1 (n, rp, wp, "high") + //[b, a] = cheby1 (n, rp, [wl, wh]) + //[b, a] = cheby1 (n, rp, [wl, wh], "stop") + //[z, p, g] = cheby1 (…) + //[…] = cheby1 (…, "s") + + //Parameters + //n: positive integer value (order of filter) + //rp: non negative scalar value (passband ripple) + //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 a Chebyshev type I filter with rp dB of passband ripple. + //if second parameter is scalar the fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians. + //[b, a] = cheby1(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians. + //[b, a] = cheby1(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians. + //[z, p, g] = cheby1(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. + //[...] = cheby1(...,’s’) returns a Laplace space filter, w can be larger than 1 rad/sec. + + //Examples + //[z, p, k]=cheby1(2,6,0.7,"high") + // k = + // + // 0.0556491 + // p = + // + // - 0.6291539 + 0.5537247i - 0.6291539 - 0.5537247i + // z = + // + // 1. 1. + + funcprot(0); + [nargout nargin] = argn(); + + if (nargin > 5 | nargin < 3 | nargout > 4 | nargout < 2) + error("cheby1: invalid number of inputs"); + end + + // interpret the input parameters + if (~ (isscalar (n) & (n == fix (n)) & (n > 0))) + error ("cheby1: filter order N must be a positive integer"); + end + + stop = %F; + digital = %T; + for i = 1:length (varargin) + select (varargin(i)) + case "s" + digital = %F; + case "z" + digital = %T; + case "high" + stop = %T; + case "stop" + stop = %T; + case "low" + stop = %T; + case "pass" + stop = %F; + else + error ("cheby1: expected [high|stop] or [s|z]"); + end + end + + [rows_w columns_w] = size(w); + + if (~ ((length (w) <= 2) & (rows_w == 1 | columns_w == 1))) + error ("cheby1: frequency must be given as WP or [WL, WH]"); + elseif ((length (w) == 2) & (w(2) <= w(1))) + error ("cheby1: W(1) must be less than W(2)"); + end + + if (digital & ~ and ((w >= 0) & (w <= 1))) + error ("cheby1: all elements of W must be in the range [0,1]"); + elseif (~ digital & ~ and (w >= 0)) + error ("cheby1: all elements of W must be in the range [0,inf]"); + end + + if (~ (isscalar (rp) & or(type (rp) == [1 5 8]) & (rp >= 0))) + error ("cheby1: passband ripple RP must be a non-negative scalar"); + end + + // Prewarp to the band edges to s plane + if (digital) + T = 2; // sampling frequency of 2 Hz + w = 2 / T * tan (%pi * w / T); + end + + // Generate splane poles and zeros for the Chebyshev type 1 filter + C = 1; // default cutoff frequency + epsilon = sqrt (10^(rp / 10) - 1); + v0 = asinh (1 / epsilon) / n; + pole = exp (1*%i * %pi * [-(n - 1):2:(n - 1)] / (2 * n)); + pole = -sinh (v0) * real (pole) + 1*%i * cosh (v0) * imag (pole); + zero = []; + + + + // compensate for amplitude at s=0 + gain = prod (-pole); + // if n is even, the ripple starts low, but if n is odd the ripple + // starts high. We must adjust the s=0 amplitude to compensate. + if (modulo (n, 2) == 0) + gain = gain / 10^(rp / 20); + end + + + // splane frequency transform + [zero, pole, gain] = sftrans (zero, pole, gain, w, stop); + + + // Use bilinear transform to convert poles to the z plane + if (digital) + [zero, pole, gain] = bilinear (zero, pole, gain, T); + end + + // convert to the correct output form + if (nargout == 2) + [a b] = zp2tf(zero, pole, gain); + elseif (nargout == 3) + a = zero; + b = pole; + c = gain; + else + // output ss results + // [a, b, c, d] = zp2ss (zero, pole, gain); + error("cheby1: yet not implemented in state-space form OR invalid number of o/p arguments") + end + endfunction diff --git a/macros/cheby2.sci b/macros/cheby2.sci index 6504837..d22ef86 100644 --- a/macros/cheby2.sci +++ b/macros/cheby2.sci @@ -1,59 +1,153 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [a, b, c, d] = cheby2 (n, rs, w, varargin) -//This function generates a Chebyshev type II filter with rs dB of stopband attenuation. -//Calling Sequence -//[a, b] = cheby2 (n, rs, wc) -//[a, b] = cheby2 (n, rs, wc, "high") -//[a, b] = cheby2 (n, rs, [wl, wh]) -//[a, b] = cheby2 (n, rs, [wl, wh], "stop") -//[a, b, c] = cheby2 (…) -//[a, b, c, d] = cheby2 (…) -//[…] = cheby2 (…, "s") -//Parameters -//n: positive integer value -//rp: non negative scalar value -//w: vector, all elements must be in the range [0,1] -//Description -//This is an Octave function. -//This function generates a Chebyshev type II filter with rs dB of stopband attenuation. -//The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians. -//[b, a] = cheby2(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians. -//[b, a] = cheby2(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians. -//[z, p, g] = cheby2(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. -//[...] = cheby2(...,’s’) returns a Laplace space filter, w can be larger than 1. -//[a,b,c,d] = cheby2(...) returns state-space matrices. -//Examples -//[a,b,c]=cheby2(2,5,0.7,"high") -//a = -// -0.31645 - 0.94861i -0.31645 + 0.94861i -//b = -// -0.39388 + 0.53138i -0.39388 - 0.53138i -//c = 0.47528 - -rhs = argn(2) -lhs = argn(1) - -if(rhs>5 | rhs<3) -error("wrong number of input arguments.") -end -if(lhs<4 | lhs<2) -error("Wrong number of output arguments.") -end - -select (rhs) - case 3 then - if (lhs==2) [a,b] = callOctave("cheby2",n, rp, w) - elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, w) - elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, w) - end - case 4 then - if (lhs==2) [a,b] = callOctave("cheby2",n, rp, w, varargin(1)) - elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, w, varargin(1)) - elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, w, varargin(1)) - end - case 5 then - if (lhs==2) [a,b] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2)) - elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2)) - elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2)) - end - end + //Chebyshev type II filter design with rs dB of stopband attenuation. + + //Calling Sequence + //[b, a] = cheby2 (n, rs, ws) + //[b, a] = cheby2 (n, rs, ws, "high") + //[b, a] = cheby2 (n, rs, [wl, wh]) + //[b, a] = cheby2 (n, rs, [wl, wh], "stop") + //[z, p, g] = cheby2 (…) + //[…] = cheby2 (…, "s") + + //Parameters + //n: positive integer value (order of filter) + //rs: non negative scalar value (stopband attenuation in dB) + //ws: positive real value, + // 1).Normalised digital stopband edge(s) for digital filter, in the range [0, 1] {dimensionless} + // 2).Analog stopband edge(s) for analog filter, in the range [0, Inf] {rad/sec} + + //Description + //This function generates a Chebyshev type II filter with rs dB of stopband attenuation. + //The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians. + //[b, a] = cheby2(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians. + //[b, a] = cheby2(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians. + //[z, p, g] = cheby2(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials. + //[...] = cheby2(...,’s’) returns a Laplace space filter, w can be larger than 1. + + //Examples + //[z, p, g]=cheby2(2,5,0.7,"high") + //Output: + // g = + // + // 0.4752770 + // p = + // + // - 0.3938806 + 0.5313815i - 0.3938806 - 0.5313815i + // z = + // + // - 0.3164543 - 0.9486078i - 0.3164543 + 0.9486078i + + funcprot(0); + [nargout nargin] = argn(); + + if (nargin > 5 | nargin < 3 | nargout > 4 | nargout < 2) + error("cheby2: invalid number of inputs"); + end + + // interpret the input parameters + if (~ (isscalar (n) & (n == fix (n)) & (n > 0))) + error ("cheby2: filter order N must be a positive integer"); + end + + stop = %F; + digital = %T; + for i = 1:length(varargin) + select (varargin(i)) + case "s" + digital = %F; + case "z" + digital = %T; + case "high" + stop = %T; + case "stop" + stop = %T; + case "low" + stop = %T; + case "pass" + stop = %F; + else + error ("cheby2: expected [high|stop] or [s|z]"); + end + end + + [rows_w columns_w] = size(w); + + if (~ ((length (w) <= 2) & (rows_w == 1 | columns_w == 1))) + error ("cheby2: frequency must be given as WS or [WL, WH]"); + elseif ((length (w) == 2) & (w(2) <= w(1))) + error ("cheby2: W(1) must be less than W(2)"); + end + + if (digital & ~ and ((w >= 0) & (w <= 1))) + error ("cheby2: all elements of W must be in the range [0,1]"); + elseif (~ digital & ~ and (w >= 0)) + error ("cheby2: all elements of W must be in the range [0,inf]"); + end + + if (~ (isscalar (rs) & or(type(rs) == [1 5 8]) & (rs >= 0))) + error ("cheby2: stopband attenuation RS must be a non-negative scalar"); + end + + // Prewarp to the band edges to s plane + if (digital) + T = 2; // sampling frequency of 2 Hz + w = 2 / T * tan (%pi * w / T); + end + + // Generate splane poles and zeros for the Chebyshev type 2 filter + // From: Stearns, SD; David, RA; (1988). Signal Processing Algorithms. + // New Jersey: Prentice-Hall. + C = 1; // default cutoff frequency + lambda = 10^(rs / 20); + phi = log (lambda + sqrt (lambda^2 - 1)) / n; + theta = %pi * ([1:n] - 0.5) / n; + alpha = -sinh (phi) * sin (theta); + beta = cosh (phi) * cos (theta); + if (modulo (n, 2)) + // drop theta==pi/2 since it results in a zero at infinity + zero = 1*%i * C ./ cos (theta([1:(n - 1) / 2, (n + 3) / 2:n])); + else + zero = 1*%i * C ./ cos (theta); + end + pole = C ./ (alpha.^2 + beta.^2) .* (alpha - 1*%i * beta); + + // Compensate for amplitude at s=0 + // Because of the vagaries of floating point computations, the + // prod(pole)/prod(zero) sometimes comes out as negative and + // with a small imaginary component even though analytically + // the gain will always be positive, hence the abs(real(...)) + gain = abs (real (prod (pole) / prod (zero))); + + // splane frequency transform + [zero, pole, gain] = sftrans (zero, pole, gain, w, stop); + + // Use bilinear transform to convert poles to the z plane + if (digital) + [zero, pole, gain] = bilinear (zero, pole, gain, T); + end + + // convert to the correct output form + if (nargout == 2) + [a b] = zp2tf(zero, pole, gain); + elseif (nargout == 3) + a = zero; + b = pole; + c = gain; + else + // output ss results + //[a, b, c, d] = zp2ss (zero, pole, gain); + error("cheby2: yet not implemented in state-space form OR invalid number of o/p arguments") + end endfunction diff --git a/macros/chirp.sci b/macros/chirp.sci index 41a94e6..c8acdeb 100644 --- a/macros/chirp.sci +++ b/macros/chirp.sci @@ -1,55 +1,86 @@ -function [y] = chirp(t,f0,t1,f1,frm,phse) -//This function evaluates a chirp signal at time t. -//Calling Sequence -//y = chirp(t) -//y = chirp(t, f0) -//y = chirp(t, f0, t1) -//y = chirp(t, f0, t1, f1) -//y = chirp(t, f0, t1, f1, frm) -//y = chirp(t, f0, t1, f1, frm, phse) -//Parameters -//t: vector -//f0: -//t1: -//f1: -//frm: string value, takes in "linear", "quadratic", "logarithmic" -//phse: -//Description -//This is an Octave function. -//This function evaluates a chirp signal at time t. A chirp signal is a frequency swept cosine wave. -//The first argument is a vector of times to evaluate the chirp signal, second argument is the frequency at t=0, third argument is time t1 and fourth argument is frequency at t1. -//The fifth argument is the form which takes in values "linear", "quadratic" and "logarithmic", the sixth argument gives the phase shift at t=0. -//Examples -//chirp([4,3,2,1],4,5,0.9) -//ans = -// column 1 to 3 -// 0.9685832 0.2486899 0.0627905 -// column 4 -// - 0.3681246 - -funcprot(0); - -rhs = argn(2) -if(rhs<1 | rhs>6) -error("Wrong number of input arguments.") -end - select(rhs) - case 1 then - y = callOctave("chirp",t) - case 2 then - y = callOctave("chirp",t,f0) - case 3 then - y = callOctave("chirp",t,f0,t1) - case 4 then - y = callOctave("chirp",t,f0,t1,f1) - case 5 then - //if(~(form == "linear" | form == "quadratic" | form == "logarithmic")) - //error("Chirp does not understand that form. Enter linear, quadratic or logarithmic.") - //else - y = callOctave("chirp",t,f0,t1,f1,frm) - //end - case 6 then - y = callOctave("chirp",t,f0,t1,f1,frm,phse) - end +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [y] = chirp(t,f0,t1,f1,form,phase) + //This function evaluates a chirp signal at time t. + + //Calling Sequence + //y = chirp(t) + //y = chirp(t, f0) + //y = chirp(t, f0, t1) + //y = chirp(t, f0, t1, f1) + //y = chirp(t, f0, t1, f1, frm) + //y = chirp(t, f0, t1, f1, frm, phse) + + //Parameters + //t: a vector of times to evaluate the chirp signal + //f0: the frequency at t=0 [default value = 0 Hz] + //t1: some intermediate time [default value = 1 sec] + //f1: frequency at t1. [default value = 100 Hz] + //frm: string value, takes in "linear", "quadratic", "logarithmic" [default value = "linear"] + //phse: phase shift at t=0. [default value = 0] + //y: chirp signal value corresponding to t. + + //Description + //This function evaluates a chirp signal at time t. A chirp signal is a frequency swept cosine wave. + //The first argument is a vector of times to evaluate the chirp signal, second argument is the frequency at t=0, third argument is time t1 and fourth argument is frequency at t1. + //The fifth argument is the form which takes in values "linear", "quadratic" and "logarithmic", the sixth argument gives the phase shift at t=0. + + //Examples + //t = [4,3,2,1]; + //f0 = 4; + //t1 = 5; + //f1 = 0.9; + //form = "quadratic"; + //y = chirp(t, f0, t1, f1, form) + //Output : + // y = + // + // - 0.6112508 0.7459411 - 0.4854201 0.9664658 + + funcprot(0); + [nargout,nargin]=argn(0); + + if nargin < 1 | nargin > 6 + error("chirp: invalid number of inputs"); + end + if nargin < 2, f0 = []; end + if nargin < 3, t1 = []; end + if nargin < 4, f1 = []; end + if nargin < 5, form = []; end + if nargin < 6, phase = []; end + + if isempty(f0), f0 = 0; end + if isempty(t1), t1 = 1; end + if isempty(f1), f1 = 100; end + if isempty(form), form = "linear"; end + if isempty(phase), phase = 0; end + + phase = 2*%pi*phase/360; + + if (form== "linear") + a = %pi*(f1 - f0)/t1; + b = 2*%pi*f0; + y = cos(a*t.^2 + b*t + phase); + elseif (form== "quadratic") + a = (2/3*%pi*(f1-f0)/t1/t1); + b = 2*%pi*f0; + y = cos(a*t.^3 + b*t + phase); + elseif (form== "logarithmic") + a = 2*%pi*t1/log(f1-f0); + b = 2*%pi*f0; + x = (f1-f0)^(1/t1); + y = cos(a*x.^t + b*t + phase); + else + error(sprintf("chirp: chirp doesnt understand ''%s''",form)); + end endfunction - diff --git a/macros/circshift.sci b/macros/circshift.sci new file mode 100644 index 0000000..3717cd3 --- /dev/null +++ b/macros/circshift.sci @@ -0,0 +1,49 @@ + +function R = circshift(M,d) + +// Shifts array circularly + +// CALLING SEQUENCES: +// R = circshift(M, d) +// circularly shifts by d(i) positions components of M along its #ith dimensions + +// PARAMETERS: +// M,R : vector or matrix of any data type +// d : vector of integers. d(i) is the shift to be applied to the M's components +// along its ith dimension. +// for example d = [0 n] will shift element n position along column + +// EXAMPLES: +// M = [1 2 3 4]; +// circshift(M, [0 1]) + +//Output : +// ans = +// +// 4. 1. 2. 3. + + + + if argn(2)==0 + error("Invalid input") + R = [] + return + end + s = size(M) + R = M + for i=1:length(d) + if s(i)>1 + D = pmodulo(d(i),s(i)) + if D~=0 + S = emptystr(1,length(s))+":" + S(i) = "[s(i)-D+1:s(i) 1:s(i)-D]" + S = strcat(S,",") + if typeof(R) ~= "ce" + execstr("R = R("+S+")") + else + execstr("R.entries = R("+S+").entries") + end + end + end + end +endfunction diff --git a/macros/dctmtx.sci b/macros/dctmtx.sci index e0c2354..e399d47 100644 --- a/macros/dctmtx.sci +++ b/macros/dctmtx.sci @@ -1,25 +1,50 @@ -function [y]= dctmtx(n) - -// Performs Direct Cosine Transformation -// Calling Sequence -// [y]=dctmtx(n) -// Parameters -// n: Real scalar integer greater than or equal to 1 -// Description -// This is an Octave function -// dctmtx(n) returns a Discrete cosine transform matrix of order n-by-n. It is useful for jpeg image compression. D*A is the DCT of the columns of A and D'*A is the inverse DCT of the columns of A (when A is n-by-n). -// Examples -// 1. dctmtx(2) -// ans = [0.70711 0.70711; 0.70711 -0.70711] -// 2. dctmtx(3) -// ans = [5.7735e-01 5.7735e-01 5.7735e-01; -// 7.0711e-01 4.9996e-17 -7.0711e-01; -// 4.0825e-01 -8.1650e-01 4.0825e-01] - -funcprot(0); -rhs=argn(2); -if (rhs<1) then - error ("Wrong number of input arguments.") -else [y]=callOctave("dctmtx",n) -end +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function T = dctmtx(n) + // Return the DCT transformation matrix of size N-by-N. + + //Calling Sequence + //T = dctmtx(n) + + //Parameters + //n: Real scalar integer greater than or equal to 1 + + //Description + //dctmtx(n) returns a Discrete cosine transform matrix (D) of order n-by-n. It is useful for jpeg image compression. D*A is the DCT of the columns of A and D'*A is the inverse DCT of the columns of A (when A is n-by-n). + + // Examples + //n= 3; + //T = dctmtx(n) + //Output: + // T = + // + // 0.5773503 0.5773503 0.5773503 + // 0.7071068 5.000D-17 - 0.7071068 + // 0.4082483 - 0.8164966 0.4082483 + + + funcprot(); + [nargout nargin] = argn(); + if nargin ~= 1 + error("dctmtx: invalid number of inputs") + end + + if n > 1 + T = [ sqrt(1/n)*ones(1,n) ; ... + sqrt(2/n)*cos((%pi/2/n)*([1:n-1]'*[1:2:2*n])) ]; + elseif n == 1 + T = 1; + else + error ("dctmtx: n must be at least 1"); + end endfunction diff --git a/macros/dftmtx.sci b/macros/dftmtx.sci index 39ef91f..68c00aa 100644 --- a/macros/dftmtx.sci +++ b/macros/dftmtx.sci @@ -1,23 +1,49 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [d]=dftmtx(n) + // Computes n-by-n Discrete Fourier transformation matrix + + //Calling Sequence + //d=dftmtx(n) + + //Parameters + //n: Real positive scalar number + + // Description + //This fuction gives a complex matrix of values whose product with a vector produces the discrete Fourier transform. This can also be achieved by directly using the fft function i.e. y=fft(x) is same as y=A*x where A=dftmtx(n). + + // Examples + //d = dftmtx(4) + //Output: + // d = + // + // 1. 1. 1. 1. + // 1. - i - 1. i + // 1. - 1. 1. - 1. + // 1. i - 1. - i + + funcprot(0); + [nargout nargin] = argn(); + if (nargin ~= 1) + error("dftmtx: invalid number of inputs") + elseif (~isscalar(n)) + error ("dftmtx: argument must be scalar"); + end + + c = eye(n, n); + d = []; + for i = 1:n + d = [d fft(c(:, i))] + end -// Computes Discrete n-by-n Fourier transformation matrix -// Calling Sequence -// [d]=dftmtx(n) -// Parameters -// n: Real positive scalar number -// Description -// This is an Octave function -// This fuction gives a complex matrix of values whose product with a vector produces the discrete Fourier transform. This can also be achieved by directly using the fft function i.e. y=fft(x) is same as y=A*x where A=dftmtx(n). -// Examples -// 1. dftmtx(3) -// ans = 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i -// 1.00000 + 0.00000i -0.50000 - 0.86603i -0.50000 + 0.86603i -// 1.00000 - 0.00000i -0.50000 + 0.86603i -0.50000 - 0.86603i - -funcprot(0); -rhs=argn(2); -if (rhs<1) then - error("Wrong number of input arguments.") -else d= callOctave("dftmtx",n) -end endfunction diff --git a/macros/digitrevorder.sci b/macros/digitrevorder.sci new file mode 100644 index 0000000..886c43f --- /dev/null +++ b/macros/digitrevorder.sci @@ -0,0 +1,67 @@ +// Returns input data in digit-reversed order + +// Calling Sequence +//[y,i] = digitrevorder(x,r) +//y = digitrevorder(x,r) + +// Parameters +//x: Vector of real or complex values +//r: radix / base +//y: input vector in digit reverse order +//i: indices + +// Description +//This function returns the input data after reversing the digits of the indices and reordering the elements of the input array. + +// Examples +//x = [%i,1,3,6*%i] ; +//r = 2 ; +//[y i]=digitrevorder(x, r) +//Output : +// i = +// +// 1. 3. 2. 4. +// y = +// +// i 3. 1. 6.i +function [y, i] = digitrevorder (x, r) + funcprot(0); + [nargout, nargin] = argn() ; + + if (nargin > 2 | nargin <= 1) + error("digitrevorder : invalid number of inputs") + elseif (~ isvector (x)) + error ("digitrevorder : X must be a vector"); + elseif (~ (isscalar (r) & r == fix (r) & r >= 2 & r <= 36)) + error ("digitrevorder : R must be an integer between 2 and 36"); + else + tmp = log (length(x)) / log (r); + if (fix (tmp) ~= tmp) + error ("digitrevorder: X must have length equal to an integer power of radix"); + end + end + + old_ind = 0:length(x) - 1; + + //new_ind = base2dec(mtlb_fliplr(dec2base(old_ind, r)), r); //it works only on octave + old_ind_base = dec2base(old_ind, r) ; + new_ind_base = [] ; + b = [] ; + for i=1:length(x) + new_ind_base = [new_ind_base mtlb_fliplr(old_ind_base(i))]; + end + new_ind = base2dec(new_ind_base,r) ; + //end of index conversion + + i = new_ind + 1; + y(old_ind + 1) = x(i); + + [rows_x columns_x] = size(x) ; + + if (columns_x == 1) + y = y'; + else + i = i; + end + +endfunction diff --git a/macros/ellip.sci b/macros/ellip.sci index 264d9fe..ab34458 100644 --- a/macros/ellip.sci +++ b/macros/ellip.sci @@ -1,60 +1,150 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [a, b, c, d] = ellip (n, rp, rs, w, varargin) -//This function generates an elliptic or Cauer filter with rp dB of passband ripple and rs dB of stopband attenuation. -//Calling Sequence -//[a, b] = ellip (n, rp, rs, wp) -//[a, b] = ellip (n, rp, rs, wp, "high") -//[a, b] = ellip (n, rp, rs, [wl, wh]) -//[a, b] = ellip (n, rp, rs, [wl, wh], "stop") -//[a, b, c] = ellip (…) -//[a, b, c, d] = ellip (…) -//[…] = ellip (…, "s") -//Parameters -//n: positive integer value -//rp: non negative scalar value -//rs: non negative scalar value -//w: scalar or vector, all elements should be in the range [0,1] -//Description -//This is an Octave function. -//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, w can be larger than 1. -//[a, b, c, d] = ellip(...) returns state-space matrices. -//Examples -//[a,b]=ellip(2, 0.5, 0.7, [0.3,0.4]) -//a = -// 0.88532 -1.58410 2.40380 -1.58410 0.88532 -//b = -// 1.00000 -1.78065 2.68703 -1.75725 0.97454 - -rhs = argn(2) -lhs = argn(1) -if(rhs>3) -[rows,columns] = size(w) -end -if(rhs>6 | rhs<4) -error("Wrong number of input arguments.") -end -if(lhs>4 | lhs<2) -error("Wrong number of output arguments.") -end - -select (rhs) - case 4 then - if (lhs==2) [a,b] = callOctave("ellip",n, rp, rs, w) - elseif (lhs==3) [a,b,c] = callOctave("ellip",n, rp, rs, w) - elseif (lhs==4) [a,b,c,d] = callOctave("ellip",n, rp, rs, w) - end - case 5 then - if (lhs==2) [a,b] = callOctave("ellip",n, rp, rs, w, varargin(1)) - elseif (lhs==3) [a,b,c] = callOctave("ellip",n, rp, rs, w, varargin(1)) - elseif (lhs==4) [a,b,c,d] = callOctave("ellip",n, rp, rs, w, varargin(1)) - end - case 6 then - if (lhs==2) [a,b] = callOctave("ellip",n, rp, rs, w, varargin(1), varargin(2)) - elseif (lhs==3) [a,b,c] = callOctave("ellip",n, rp, rs, w,varargin(1), varargin(2)) - elseif (lhs==4) [a,b,c,d] = callOctave("ellip",n, rp, rs, w, varargin(1), varargin(2)) - end - end + //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") + //[b, a] = ellip (n, rp, rs, [wl, wh]) + //[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) + //rs: non negative scalar value (stopband attenuation) + //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 : + // a = + // + // + // column 1 to 4 + // + // 1. - 1.7258519 2.5097172 - 1.5592802 + // + // column 5 + // + // 0.8188057 + // b = + // + // + // column 1 to 4 + // + // 0.0202774 - 0.0164257 0.0027304 - 0.0164257 + // + // column 5 + // + // 0.0202774 + + funcprot(0); + [nargout nargin] = argn(); + + if (nargin > 6 | nargin < 4 | nargout > 4 | nargout < 2) + error("ellip: invalid number of inputs"); + end + + // interpret the input parameters + if (~ (isscalar (n) & (n == fix (n)) & (n > 0))) + error ("ellip: filter order N must be a positive integer"); + end + + stop = %F; + digital = %T; + for i = 1:length(varargin) + select (varargin(i)) + case "s" + digital = %F; + case "z" + digital = %T; + case "high" + stop = %T; + case "stop" + stop = %T; + case "low" + stop = %T; + case "pass" + stop = %F; + else + error ("ellip: expected [high|stop] or [s|z]"); + end + end + + [rows_w colums_w] = size(w); + + if (~ ((length (w) <= 2) & (rows_w == 1 | columns_w == 1))) + error ("ellip: frequency must be given as WP or [WL, WH]"); + elseif ((length (w) == 2) & (w(2) <= w(1))) + error ("ellip: W(1) must be less than W(2)"); + end + + if (digital & ~ and ((w >= 0) & (w <= 1))) + error ("ellip: all elements of W must be in the range [0,1]"); + elseif (~ digital & ~ and (w >= 0)) + error ("ellip: all elements of W must be in the range [0,inf]"); + end + + if (~ (isscalar (rp) & or(type(rp) == [1 5 8]) & (rp >= 0))) + error ("ellip: passband ripple RP must be a non-negative scalar"); + end + + if (~ (isscalar (rs) & or(type(rs) == [1 5 8]) & (rs >= 0))) + error ("ellip: stopband attenuation RS must be a non-negative scalar"); + end + + + // Prewarp the digital frequencies + if (digital) + T = 2; // sampling frequency of 2 Hz + w = 2 / T * tan (%pi * w / T); + end + + // Generate s-plane poles, zeros and gain + [zero, pole, gain] = ellipap (n, rp, rs); + zero = zero'; + pole = pole'; + + // splane frequency transform + [zero, pole, gain] = sftrans (zero, pole, gain, w, stop); + + // Use bilinear transform to convert poles to the z plane + if (digital) + [zero, pole, gain] = bilinear (zero, pole, gain, T); + end + + // convert to the correct output form + if (nargout == 2) + [a b] = zp2tf(zero, pole, gain); + elseif (nargout == 3) + a = zero; + b = pole; + c = gain; + else + // output ss results + //[a, b, c, d] = zp2ss (zero, pole, gain); + error("ellip: yet not implemented in state-space form OR invalid number of o/p arguments") + end endfunction diff --git a/macros/ellipap.sci b/macros/ellipap.sci index 7b4c1ae..d360d2e 100644 --- a/macros/ellipap.sci +++ b/macros/ellipap.sci @@ -1,46 +1,61 @@ -function [z, p, g] = ellipap (n, Rp, Rs) -//Designs a lowpass analog elliptic filter. -//Calling Sequence -//[z, p, g] = ellipap (n, Rp, Rs) -//[z, p] = ellipap (n, Rp, Rs) -//z = ellipap (n, Rp, Rs) -//Parameters -//n: Filter Order -//Rp: Peak-to-peak passband ripple -//Rs: Stopband attenuation -//Description -//This is an Octave function. -//It designs a lowpass analog elliptic filter of nth order, with a Peak-to-peak passband ripple of Rp and a stopband attenuation of Rs. -//Examples -//[z, p, g] = ellipap (5, 10, 10) -//z = -// -// 0.0000 + 2.5546i 0.0000 + 1.6835i -0.0000 - 2.5546i -0.0000 - 1.6835i -// -//p = -// -// -0.05243 + 0.63524i -0.01633 + 0.96289i -0.05243 - 0.63524i -0.01633 - 0.96289i -0.07369 + 0.00000i +// Copyright (C) 2018 - IIT Bombay - FOSSEE // -//g = 0.0015012 - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 3 | rhs > 3) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 3 then - if(lhs==1) - z = callOctave("ellipap", n, Rp, Rs) - elseif(lhs==2) - [z, p] = callOctave("ellipap", n, Rp, Rs) - elseif(lhs==3) - [z, p, g] = callOctave("ellipap", n, Rp, Rs) - else - error("Wrong number of output argments.") - end - end +// 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 +// Author:Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [z, p, g] = ellipap (n, Rp, Rs) + //Produces a lowpass analog prototype elliptic filter. + + //Calling Sequence + //[z, p, g] = ellipap (n, Rp, Rs) + + //Parameters + //n: Filter Order + //Rp: Peak-to-peak passband ripple (in dB) + //Rs: Stopband attenuation (in dB) + + //Description + //It gives a lowpass analog elliptic prototype filter of nth order, with a Peak-to-peak passband ripple of Rp dB and a stopband attenuation of Rs dB. + + //Examples + //[z, p, g] = ellipap (4, 3,10) + //Output : + // g = + // + // 0.3162 + // p = + // + // - 0.2071 - 0.8587i + // - 0.0042 - 0.9990i + // - 0.2071 + 0.8587i + // - 0.0042 + 0.9990i + // z = + // + // - 1.3121i + // - 1.0063i + // 1.3121i + // 1.0063i + + funcprot(0); + lhs = argn(1) + rhs = argn(2) + if (rhs < 3 | rhs > 3) + error("Wrong number of input arguments.") + end + + Rpf = 10 ^ (-Rp/20); //passband pick to pick ripple in fraction + rp = 1 - Rpf ; //analpf function compitable passband ripple (delta-p) + Rsf = 10 ^ (-Rs/20); //stop band pick to pick ripple in fraction + rs = Rsf ; //analpf function compitable stop band ripple (delta-s) + [hs,p,z,g]=analpf(n,"ellip",[rp rs],1); //cutoff frequency of 1 rad/sec for prototype filter + p = p' ; + z = z' ; + g = abs(g); + endfunction diff --git a/macros/ellipord.sci b/macros/ellipord.sci index cc81ab7..f0c52a4 100644 --- a/macros/ellipord.sci +++ b/macros/ellipord.sci @@ -1,36 +1,93 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [n, Wp] = ellipord(Wp, Ws, Rp, Rs) -//This function computes the minimum filter order of an elliptic filter with the desired response characteristics. -//Calling Sequence -//[n] = ellipord(Wp, Ws, Rp, Rs) -//[n, Wp] = ellipord(Wp, Ws, Rp, Rs) -//Parameters -//Wp: scalar or vector of length 2, all elements must be in the range [0,1] -//Ws: scalar or vector of length 2, all elements must be in the range [0,1] -//Rp: real or complex value -//Rs: real or complex value -//Description -//This is an Octave function. -//This function computes the minimum filter order of an elliptic filter with the desired response characteristics. -//Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. -//Frequencies are normalized to the Nyquist frequency in the range [0,1]. -//Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. -//If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. -//If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. -//If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. -//Examples -//[a,b]=ellipord(0.2, 0.5, 0.7, 0.4) -//a = 1 -//b = 0.20000 - -rhs = argn(2) -lhs = argn(1) -if(rhs~=4) -error("Wrong number of input arguments.") -end -select(lhs) -case 1 then -n = callOctave("ellipord",Wp,Ws,Rp,Rs) -case 2 then -[n,Wp] = callOctave("ellipord",Wp,Ws,Rp,Rs) -end + //Minimum filter order of a digital elliptic or Cauer filter with the desired response characteristics. + + //Calling Sequence + //[n] = ellipord(Wp, Ws, Rp, Rs) + //[n, Wp] = ellipord(Wp, Ws, Rp, Rs) + + //Parameters + //Wp: scalar or vector of length 2 (passband edge(s)), all elements must be in the range [0,1] + //Ws: scalar or vector of length 2 (stopband edge(s)), all elements must be in the range [0,1] + //Rp: passband ripple in dB. + //Rs: stopband attenuation in dB. + //n: Minimum order of filter satisfying given specs. + + //Description + //This function computes the minimum filter order of an elliptic filter with the desired response characteristics. + //Stopband frequency ws and passband frequency wp specify the the filter frequency band edges. + //Frequencies are normalized to the Nyquist frequency in the range [0,1]. + //Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band. + //If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter. + //If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws. + //If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter. + //Examples + //Wp = [60 200]/500; + //Ws = [50 250]/500; + //Rp = 3; + //Rs = 40; + //[n,Wp] = ellipord(Wp,Ws,Rp,Rs) + //Output : + // Wp = + // + // 0.12 0.4 + // n = + // + // 5. + + funcprot(0); + [nargout nargin] = argn(); + + if (nargin ~= 4) + error("ellipord: invalid number of inputs"); + else + validate_filter_bands ("ellipord", Wp, Ws); + end + + // sampling frequency of 2 Hz + T = 2; + + Wpw = tan(%pi.*Wp./T); // prewarp + Wsw = tan(%pi.*Ws./T); // prewarp + + // pass/stop band to low pass filter transform: + if (length(Wpw)==2 & length(Wsw)==2) + wp=1; + w02 = Wpw(1) * Wpw(2); // Central frequency of stop/pass band (square) + w3 = w02/Wsw(2); + w4 = w02/Wsw(1); + if (w3 > Wsw(1)) + ws = (Wsw(2)-w3)/(Wpw(2)-Wpw(1)); + elseif (w4 < Wsw(2)) + ws = (w4-Wsw(1))/(Wpw(2)-Wpw(1)); + else + ws = (Wsw(2)-Wsw(1))/(Wpw(2)-Wpw(1)); + end + elseif (Wpw > Wsw) + wp = Wsw; + ws = Wpw; + else + wp = Wpw; + ws = Wsw; + end + + k=wp/ws; + k1=sqrt(1-k^2); + q0=(1/2)*((1-sqrt(k1))/(1+sqrt(k1))); + q= q0 + 2*q0^5 + 15*q0^9 + 150*q0^13; //(....) + D=(10^(0.1*Rs)-1)/(10^(0.1*Rp)-1); + + n=ceil(log10(16*D)/log10(1/q)); + endfunction diff --git a/macros/isfir.sci b/macros/isfir.sci index d9e4a05..329ba09 100644 --- a/macros/isfir.sci +++ b/macros/isfir.sci @@ -1,7 +1,35 @@ //Author: Parthasarathi Panda //parthasarathipanda314@gmail.com + +// This function checks whether given system function is FIR or not + +//. Calling Sequence +// fir = isfir(b,a) +// fir = isfir(sos) + +// Input Parameters +// a -->denumerator coefficient matrix +// b --> numerator coefficient matrix +// sos --> second order split matrix +// Output parameter +// fir --> fir == 1 if system is FIR , fir == 0 if system is not FIR + +//Description +// This function take a system function (in terms of denumerator and numerator coefficient matrix or in term of second order split (sos) matrix) as input and checks + +//Example +// 1.) +// fir = isfir([1 -1 1], 1) +//-->fir = isfir([1 -1 1],1) +// fir = +// +// 1. + +//Conclusion : Output of above example is fir = 1 this means system is FIR + function fir=isfir(varargin) [nargout,nargin]=argn(); +// checking for input in terms of numerator (b) and denumerator (a) coefficient matrices if (nargin==2) then a=varargin(1); b=varargin(2); @@ -29,6 +57,7 @@ function fir=isfir(varargin) elseif n~=1 then error('check input dimension'); end +//Checking for input in terms of second orer split (sos) matrix elseif (nargin==1) then sos=varargin(1); if type(sos)~=1 then diff --git a/macros/islinphase.sci b/macros/islinphase.sci index f004419..a36eef3 100644 --- a/macros/islinphase.sci +++ b/macros/islinphase.sci @@ -1,12 +1,27 @@ //islinphase Determine whether filter has linear phase -// Calling Syntax +// Calling Syntax and Parameter description //flag = islinphase(b,a) +//takes input as numerator and denumerator coefficint matrices and returns flag =1 if filter is linear phase else return flag = 0 + //flag = islinphase(sos) +//takes input as K x 6 second order split (sos) matrix and returns flag =1 if filter is linear phase else returns flag =0 + //flag = islinphase(...,tol) +// tol -->this takes tolerence in similarities between two numbers in phase respose + +//Example : +//flag = islinphase([0 1 2 2 1 0],1) +//Output: +//flag = + +// 1. + +//conclusion : output of above example is flag = 1 means filter is linear phase which must be as example is of symmetric linear phase fir filter //Author: Parthasarathi Panda //parthasarathipanda314@gmail.com + function islin=islinphase(varargin) [nargout,nargin]=argn(); if (nargin==2) then @@ -130,5 +145,5 @@ function islin=islinphase(varargin) else islin=0; end - + endfunction diff --git a/macros/ismaxphase.sci b/macros/ismaxphase.sci index e40adbe..1fda072 100644 --- a/macros/ismaxphase.sci +++ b/macros/ismaxphase.sci @@ -1,10 +1,22 @@ -//ismaxphase Determine whether filter is maximum phase +//ismaxphase Determine whether filter is maximum phase or not + +// Description : It determines whether the given system function is maximum phase system or not . Maximum phase system means all zeros of transfer function will be outside the unit circle in z-plane also poles mustbe within unit circle for stability and causality + //Syntax //flag = ismaxphase(b,a) //flag = ismaxphase(sos) //flag = ismaxphase(...,tol) -// b and a are the vectors containing zero and pole coefficients respectively -//tol, tolerance is used to determine when two numbers are close enough to be considered equal. +// b and a are the vectors containing numerator and denumerator coefficients respectively +//tol, tolerance is used to determine when two numbers are close enough to be considered equal. + +//Example : of maximum phase system +//flag = ismaxphase([1 -5 6],1) + +//Output +// flag = +// +// 1. + //Author: Parthasarathi Panda //parthasarathipanda314@gmail.com function ismax=ismaxphase(varargin) @@ -62,18 +74,18 @@ function ismax=ismaxphase(varargin) gc=gcd([poly_a,poly_b]); [r,den]=pdiv(poly_b,gc); [r,num]=pdiv(poly_a,gc); - maxpole=min(abs(roots(den))); - minzero=max(abs(roots(num))); - if length(a)==1 then - if length(b)==1 then - ismax=0; + maxpole=max(abs(roots(den))); + minzero=min(abs(roots(num))); + if length(b)==1 then + if length(a)==1 then + ismax=1; elseif minzero>1 then ismax=0; else ismax=1; end elseif maxpole>1 then - if length(b)==1 then + if length(a)==1 then ismax=0; elseif minzero>1 then ismax=0; diff --git a/macros/isminphase.sci b/macros/isminphase.sci index ccd2754..9a76e0f 100644 --- a/macros/isminphase.sci +++ b/macros/isminphase.sci @@ -1,3 +1,22 @@ +//isminphase Determine whether filter is minimum phase or not + +// Description : It determines whether the given system function is minimum phase system or not . Minimum phase system means all zeros of transfer function will be inside the unit circle in z-plane , also poles mustbe within unit circle for stability and causality + +//Syntax +//flag = isminphase(b,a) +//flag = isminphase(sos) +//flag = isminphase(...,tol) +// b and a are the vectors containing numerator and denumerator coefficients respectively +//tol, tolerance is used to determine when two numbers are close enough to be considered equal. + +//Example : of minimum phase system +//flag = isminphase([1 -0.3 0.02],1) + +//Output +// flag = +// +// 1. + //Author: Parthasarathi Panda //parthasarathipanda314@gmail.com function ismin=isminphase(varargin) @@ -55,18 +74,18 @@ function ismin=isminphase(varargin) gc=gcd([poly_a,poly_b]); [r,den]=pdiv(poly_b,gc); [r,num]=pdiv(poly_a,gc); - maxpole=min(abs(roots(den))); - maxzero=min(abs(roots(num))); - if length(a)==1 then - if length(b)==1 then + maxpole=max(abs(roots(den))); + maxzero=max(abs(roots(num))); + if length(b)==1 then + if length(a)==1 then ismin=1; - elseif maxzero>1 then - ismin=1; - else + elseif maxzero<1 then ismin=0; + else + ismin=1; end elseif maxpole>1 then - if length(b)==1 then + if length(a)==1 then ismin=1; elseif maxzero>1 then ismin=1; diff --git a/macros/isstable.sci b/macros/isstable.sci index db7d5b5..16cf5a2 100644 --- a/macros/isstable.sci +++ b/macros/isstable.sci @@ -1,26 +1,35 @@ -//isstable True for stable filter -// FLAG = ISSTABLE(B,A) returns a logical output, FLAG, equal to TRUE if -// the filter specified by numerator coefficients B, and denominator -// coefficients A, is stable. Input vectors B, and A define a filter with -// transfer function: -// -// jw -jw -jmw -// jw B(e) b(1) + b(2)e + .... + b(m+1)e -// H(e) = ---- = ------------------------------------ -// jw -jw -jnw -// A(e) a(1) + a(2)e + .... + a(n+1)e -// -// FLAG = ISSTABLE(SOS) returns TRUE if the filter specified using the -// second order sections matrix, SOS, is stable. SOS is a Kx6 matrix, -// where the number of sections, K, must be greater than or equal to 2. -// Each row of SOS corresponds to the coefficients of a second order -// filter. From the transfer function displayed above, the ith row of the -// SOS matrix corresponds to [bi(1) bi(2) bi(3) ai(1) ai(2) ai(3)]. +//Checks for stability of Discrete time System function + +//Description : A Discrete time system is stable if all poles of system function are inside unit circle + // Calling Syntax // flag=isstable(b,a); // flag=isstable(sos); -//Author: Parthasarathi Panda -//parthasarathipanda314@gmail.com + +//It takes input b and a which are array vector of numerator and denumerator coefficients respectively also it takes second order section (sos) system function input.SOS is a Kx6 matrix,where the number of sections, K, must be greater than or equal to 2.Each row of SOS corresponds to the coefficients of a second order filter +//It returns a logical flag = 1(true) if given system is stable and 0(false) otherwise + +// Eample : 1 +// flag = isstable([1 2],[1 -0.7 0.1]) + +// Output: +// flag = +// +// 1. + +// Conclusion : as flag output is 1 system is stable + +// Example : 2 +// flag = isstable([1 2 0],[1 5 6]) + +//Output : +//unstable system +// flag = +// +// 0. + +// Conclusion : this system is unstable as flag output is 0 + function isstab=isstable(varargin) [nargout,nargin]=argn(); if (nargin==2) then//(a,b) is the input @@ -59,7 +68,7 @@ elseif (nargin==1) then//sos form is given as input if type(sos)~=1 then error('check input type'); end - + if length(v)>2 then error('check input dimension'); end diff --git a/macros/kaiser.sci b/macros/kaiser.sci index 2c33b3f..b36e931 100644 --- a/macros/kaiser.sci +++ b/macros/kaiser.sci @@ -1,33 +1,44 @@ -function w = kaiser (m, beta) +function w = kaiser (m, varargin) //This function returns the filter coefficients of a Kaiser window. + //Calling Sequence //w = kaiser (m) //w = kaiser (m, beta) -//Parameters + +//Parameters //m: positive integer value //beta: real scalar value -//w: output variable, vector of real numbers +//w: output variable, vector of real numbers + //Description //This is an Octave function. //This function returns the filter coefficients of a Kaiser window of length m supplied as input, to the output vector w. //The second parameter gives the stop band attenuation of the Fourier transform of the window on derivation. + //Examples //kaiser(6,0.2) -//ans = -// 0.9900745 -// 0.9964211 -// 0.9996020 -// 0.9996020 -// 0.9964211 -// 0.9900745 +// ans = +// +// 0.9900745 +// 0.9964211 +// 0.9996020 +// 0.9996020 +// 0.9964211 +// 0.9900745 + funcprot(0); -rhs = argn(2) -if(rhs<1 | rhs>2) -error("Wrong number of input arguments.") -end -if(rhs==1) -w = callOctave("kaiser", m) -elseif(rhs==2) -w = callOctave("kaiser", m, beta) -end -endfunction + rhs = argn(2) + if(rhs<1 | rhs>2) + error("Wrong number of input arguments.") + end + + if length(varargin)==0 then + bet = 0.5; //default value of beta is 0.5 + else + bet = varargin(1); + end + +w = window('kr', m, bet) //default value of beta is 0.5 +w = w' ; + +endfunction diff --git a/macros/lar2rc.sci b/macros/lar2rc.sci index 15fa4ee..6a41b36 100644 --- a/macros/lar2rc.sci +++ b/macros/lar2rc.sci @@ -1,22 +1,34 @@ function k=lar2rc(g) - + //lar2rc convert log area ratios to reflection coefficients. // Calling Sequence // k = lar2rc(g) // Parameters // g: define log area ratios. // k: returns the reflection coefficients. -// Examples -//X = [7 6 5 8 3 6 8 7 5 2 4 7 4 3 2 5 4 9 5 3 5 7 3 9 4 1 2 0 5 4 8 6 4 6 5 3]; -// k = lar2rc(X) -// or t=[2 5 6; 8 6 5; 8 9 4] -// k = lar2rc(t) + +// Example +//g = [0.6389 4.5989 0.0063 0.0163 -0.0163]; +//k = lar2rc(g) + +// Output : +//k = // +// +// column 1 to 4 +// +// 0.3090095 0.9800747 0.0031500 0.0081498 +// +// column 5 +// +// - 0.0081498 + + // See also // // Author // Jitendra Singh -// +// //Modified to match MATLAB o/p when i/p is of type char and is a string by Debdeep Dey if or(type(g)==10) then [r,c]=size(g); @@ -25,7 +37,7 @@ function k=lar2rc(g) else k=ones(size(g,1), size(g,2)) end - + else if ~isreal(g) then error('Log area ratios must be real.') diff --git a/macros/levin.sci b/macros/levin.sci index 9f4d002..16d3768 100644 --- a/macros/levin.sci +++ b/macros/levin.sci @@ -1,58 +1,60 @@ -function [ar, sigma2,rc] = levin(r);
-// //[ar,sigma2,rc]=lev(r)
-// //Resolve the Yule-Walker equations:
-// //
-// // |r(0) r(1) ... r(N-1)|| a(1) | |sigma2|
-// // |r(1) r(0) ... r(n-1)|| a(2) | | 0 |
-// // | : : ... : || : |=| 0 |
-// // | : : ... : || : | | 0 |
-// // |r(N-1) r(N-2) ... r(0) ||a(N-1)| | 0 |
-// //
-// //using Levinson's algorithm.
-// // r :Correlation coefficients
-// // ar :Auto-Regressive model parameters
-// // sigma2 :Scale constant
-// // rc :Reflection coefficients
-if length(r)==1 then
- ar=1;
- sigma2=r;
- rc=[];
- else
-
-
-
- ar = 0;
- aj(1) = 1;
- ej = r(1);
- rc = [];
- p=length(r)-1
-
-
- for j=1:p,
- aj1 = zeros(j+1, 1);
- aj1(1) = 1;
- gammaj = r(j+1);
- for i=2:j,
- gammaj = gammaj + aj(i)*r(j-i+2);
- end
- if ej==0 then
- lambdaj1=%nan
- else
- lambdaj1 = -gammaj/ej;
- end
-
- rc=[rc; lambdaj1];
-
- for i=2:j,
- aj1(i) = aj(i)+lambdaj1*(aj(j-i+2)');
- end
- aj1(j+1) = lambdaj1;
- ej1 = ej*(1-abs(lambdaj1)^2);
-
- aj = aj1;
- ar = aj1;
- ej = ej1;
- end
- sigma2 = sqrt(ej1);
- end
- endfunction
+function [ar, sigma2,rc] = levin(r); +// //[ar,sigma2,rc]=lev(r) +// //Resolve the Yule-Walker equations: +// // +// // |r(0) r(1) ... r(N-1)|| a(1) | |sigma2| +// // |r(1) r(0) ... r(n-1)|| a(2) | | 0 | +// // | : : ... : || : |=| 0 | +// // | : : ... : || : | | 0 | +// // |r(N-1) r(N-2) ... r(0) ||a(N-1)| | 0 | +// // +// //using Levinson's algorithm. +// // r :Correlation coefficients +// // ar :Auto-Regressive model parameters +// // sigma2 :Scale constant +// // rc :Reflection coefficients + +// Example : +if length(r)==1 then + ar=1; + sigma2=r; + rc=[]; + else + + + + ar = 0; + aj(1) = 1; + ej = r(1); + rc = []; + p=length(r)-1 + + + for j=1:p, + aj1 = zeros(j+1, 1); + aj1(1) = 1; + gammaj = r(j+1); + for i=2:j, + gammaj = gammaj + aj(i)*r(j-i+2); + end + if ej==0 then + lambdaj1=%nan + else + lambdaj1 = -gammaj/ej; + end + + rc=[rc; lambdaj1]; + + for i=2:j, + aj1(i) = aj(i)+lambdaj1*(aj(j-i+2)'); + end + aj1(j+1) = lambdaj1; + ej1 = ej*(1-abs(lambdaj1)^2); + + aj = aj1; + ar = aj1; + ej = ej1; + end + sigma2 = sqrt(ej1); + end +endfunction diff --git a/macros/levinson.sci b/macros/levinson.sci index ccb0ab9..63ae994 100644 --- a/macros/levinson.sci +++ b/macros/levinson.sci @@ -1,83 +1,158 @@ -//levinson levinson- durbin algorithm -//calling syntax +//Levinson- Durbin Recurssion Algorithm + +////calling syntax //a = levinson(r) //a = levinson(r,n) //[a,e] = levinson(r,n) //[a,e,k] = levinson(r,n) -// where -// a is the coefficients of a length(r)-1 order autoregressive -//linear process +// where +// a is the coefficients of a length(r)-1 order autoregressive linear process //e is the prediction error when order is n // k is a column vector containing the reflection coefficients of length n -// Author Debdeep Dey -function [a, v_f, ref_f] = levinson (acf, p) -if ( argn(2)<1 ) - error("Too few input arguments"); - // elseif( length(acf)<2 ) - // error( "levinson: arg 1 (acf) must be vector of length >1\n"); -elseif ( argn(2)>1 & ( ~isscalar(p) | fix(p)~=p ) ) +//Example : +//a = [1 0.1 -0.8]; //Estimate the coefficients of an autoregressive process given by x(n) = 0.1x(n-1) - 0.8x(n-2) + w(n) +// +//v = 0.4; +//w = sqrt(v)*rand(15000,1,"normal"); +//x = filter(1,a,w); +// +//[r,lg] = xcorr(x,'biased'); +//r(lg<0) = []; +// +//ar = levinson(r,length(a)-1) + +// // Output :--- +// ar = +// +// 1. 0.0983843 - 0.7929775 +// + +//************************************************************************************************** +//______________________________________________version1 code (not working)_________________________ +//__________________________________________________________________________________________________ +//************************************************************************************************** +//function [a, v_f, ref_f] = levinson (acf, p) + +//if ( argn(2)<1 ) +// error("Too few input arguments"); +// elseif( length(acf)<2 ) +// error( "levinson: arg 1 (acf) must be vector of length >1\n"); +//elseif ( argn(2)>1 & ( ~isscalar(p) | fix(p)~=p ) ) +// error( "levinson: arg 2 (p) must be integer >0\n"); +//elseif (isempty(acf)) +// error("R cannot be empty"); +//else +// if ((argn(2) == 1)|(p>=length(acf))) +// p = length(acf) - 1; +// end +// if( size(acf,1)==1 & size(acf,2)>1 ) then +// acf=acf(:); +// +// end force a column vector +// if size(acf,1)>=1 then handles matrix i/p +// +// acf=acf'; +// a=acf; +// rows=size(acf,1); +// for i=1:rows +// acf_temp=acf(i,:); +// acf_temp=acf_temp(:); +// p=length(acf_temp)-1; +// disp(acf_temp); +// if argn(1) < 3 & p < 100 +// +// // Kay & Marple Eqn (2.39) +// +// R = toeplitz(acf_temp(1:p), conj(acf_temp(1:p))); +// an = R \ -acf_temp(2:p+1); +// an= [ 1, an.' ]; +// v_f(i,:)= real( an*conj(acf_temp(1:p+1)) ); +// a(i,:)=an; +// an=[]; +// +// else +// +// // Kay & Marple Eqns (2.42-2.46) +// +// ref = zeros(p,1); +// g = -acf_temp(2)/acf_temp(1); +// +// an = [ g ]; +// v= real( ( 1 - g*conj(g)) * acf_temp(1) ); +// ref(1) = g; +// for t = 2 : p +// g = -(acf_temp(t+1) + an * acf_temp(t:-1:2)) / v; +// an = [ an+g*conj(an(t-1:-1:1)), g ]; +// v = v * ( 1 - real(g*conj(g)) ) ; +// ref(t) = g; +// end +// v_f(i,:)=v; +// v=[]; +// ref_f(:,i)=ref; +// an = [1, an]; +// a(i,:)=an; +// an=[]; +// end end if +// end end for +// end +//end + +// +//endfunction + + +//************************************************************************************************** +//______________________________________________version2 code ( working)____________________________ +//__________________________________________________________________________________________________ +//************************************************************************************************** + + +function [a, v, ref] = levinson(bcf, p) + + funcprot(0); + + + nargin = argn(2); + nargout = argn(1); + [rows columns] = size(bcf) + + if ( nargin<1 ) + error("Wrong input argument "); + elseif( ~isvector(bcf) | length(bcf)<2 ) + error( "levinson: arg 1 (bcf) must be vector of length >1\n"); + elseif ( nargin>1 & ( ~isscalar(p) | fix(p)~=p ) ) error( "levinson: arg 2 (p) must be integer >0\n"); -elseif (isempty(acf)) - error("R cannot be empty"); -else - if ((argn(2) == 1)|(p>=length(acf))) - p = length(acf) - 1; - end - if( size(acf,1)==1 & size(acf,2)>1 ) then - acf=acf(:); - - end // force a column vector - if size(acf,1)>=1 then // handles matrix i/p - - acf=acf'; - a=acf; - rows=size(acf,1); - for i=1:rows - acf_temp=acf(i,:); - acf_temp=acf_temp(:); - p=length(acf_temp)-1; - //disp(acf_temp); - if argn(1) < 3 & p < 100 - - //// Kay & Marple Eqn (2.39) - - R = toeplitz(acf_temp(1:p), conj(acf_temp(1:p))); - an = R \ -acf_temp(2:p+1); - an= [ 1, an.' ]; - v_f(i,:)= real( an*conj(acf_temp(1:p+1)) ); - a(i,:)=an; - an=[]; - - else - - //// Kay & Marple Eqns (2.42-2.46) - - ref = zeros(p,1); - g = -acf_temp(2)/acf_temp(1); - - an = [ g ]; - v= real( ( 1 - g*conj(g)) * acf_temp(1) ); - ref(1) = g; - for t = 2 : p - g = -(acf_temp(t+1) + an * acf_temp(t:-1:2)) / v; - an = [ an+g*conj(an(t-1:-1:1)), g ]; - v = v * ( 1 - real(g*conj(g)) ) ; - ref(t) = g; - end - v_f(i,:)=v; - v=[]; - ref_f(:,i)=ref; - an = [1, an]; - a(i,:)=an; - an=[]; - end //end if - end //end for - end -end + else + if ((nargin == 1)|(p>=length(bcf))) p = length(bcf) - 1; end + if( columns >1 ) bcf=bcf(:); end + if nargout < 3 & p < 100 +// ## direct solution [O(p^3), but no loops so slightly faster for small p] +// ## Kay & Marple Eqn (2.39) + R = toeplitz(bcf(1:p), conj(bcf(1:p))); + a = R \ -bcf(2:p+1); + a = [ 1, a.' ]; + v = real( a*conj(bcf(1:p+1)) ); + else +// ## durbin-levinson [O(p^2), so significantly faster for large p] +// ## Kay & Marple Eqns (2.42-2.46) + ref = zeros(p,1); + g = -bcf(2)/bcf(1); + a = [ g ]; + v = real( ( 1 - g*conj(g)) * bcf(1) ); + ref(1) = g; + for t = 2 : p + g = -(bcf(t+1) + a * bcf(t:-1:2)) / v; + a = [ a+g*conj(a(t-1:-1:1)), g ]; + v = v * ( 1 - real(g*conj(g)) ) ; + ref(t) = g; + end + a = [1, a]; + end + end endfunction diff --git a/macros/lpc.sci b/macros/lpc.sci index 02ab1a5..70c64be 100644 --- a/macros/lpc.sci +++ b/macros/lpc.sci @@ -9,35 +9,53 @@ function [a,g] = lpc(x,varargin) // // Description // [a,g] = lpc(x,p) - // Determines the coefficients of a pth order forward linear predictor - // filter by minimizing the squared error. If p is unspecified, a + // Determines the coefficients of a pth order forward linear predictor + // filter by minimizing the squared error. If p is unspecified, a // default value of length(x)-1 is used. // // Parameters // x: double - // The input signal. If x is a matrix, each column in treated as an + // The input signal. If x is a matrix, each column in treated as an // independent computation // p: int, natural number, scalar // The order of the linear prediction filter to be inferred. Value must - // be a scalar and a positive natural number. p must be less than or + // be a scalar and a positive natural number. p must be less than or // equal to the length of the signal vector // a: double - // The coefficients of the forward linear predictor. Coefficient for + // The coefficients of the forward linear predictor. Coefficient for // each signal input is returned as a row vector. // g: double // Column vector of averaged square prediction error // // // Examples - // 1) - // noise = randn(20000,1); - // x = filter(1,[1 1/5 1/3 1/4],noise); - // x = x(15904:20000); - // [a,g] = lpc(x,3); + //noise = rand(50000,1,"normal"); + //x = filter(1,[1 1/2 1/3 1/4],noise); + //x = x(45904:50000); + //[a,g]= lpc(x,3) + //est_x = filter([0 -a(2:$)],1,x); + //e = x-est_x; + //[acs,lags] = xcorr(e,'coeff'); + //plot(1:97,x(4001:4097),1:97,est_x(4001:4097),'--'); + //a = gca(); + //a.grid = [1,1]; + //title 'Original Signal vs. LPC Estimate'; + //xlabel 'Sample number', ylabel 'Amplitude'; + //legend('Original signal','LPC estimate'); + + //Output : + // g = + // + // 1.0117019 + // a = + // + // 1. 0.51533 0.3313039 0.2783268 + // + // // // References - // [1] Hayes, Monson H. Statistical digital signal processing and modeling. + // [1] Hayes, Monson H. Statistical digital signal processing and modeling. // John Wiley & Sons, 2009, pg. 220 // // See also @@ -49,7 +67,7 @@ function [a,g] = lpc(x,varargin) // ** Check on number of arguments ** [numOutArgs,numInArgs] = argn(0); - + if numInArgs<1 | numInArgs>2 then msg = "lpc: Wrong number of input argument; 1-2 expected"; error(77,msg); @@ -58,10 +76,10 @@ function [a,g] = lpc(x,varargin) msg = "lpc: Wrong number of output argument; 2 expected"; error(78,msg); end - + // ** Parsing input arguments ** // 1) check on x - + // check on dimensions if size(x,1)==1 | size(x,2)==1 then // x is a single signal @@ -71,7 +89,7 @@ function [a,g] = lpc(x,varargin) msg = "lpc: Wrong size for argument #1 (x): a vector or 2D matrix expected" error(60,msg); end - + // check on data type if type(x)==8 then // convert int to double @@ -80,7 +98,7 @@ function [a,g] = lpc(x,varargin) msg = "lpc: Wrong type for argument #1 (x): Real or complex matrix expected"; error(53,msg); end - + if length(varargin)==0 then p = size(x,1)-1; else @@ -90,53 +108,53 @@ function [a,g] = lpc(x,varargin) msg = "lpc: Wrong size for argument #2 (p): Scalar expected"; error(60,msg); end - + if type(p)~=1 & type(p)~=8 then msg = "lpc: Wrong type for argument #2 (p): Natural number expected"; error(53,msg); end - + if p~=round(p) | p<=0 then - msg = "lpc: Wrong type for argument #2 (p): Natural number expected"; + msg = "lpc: Wrong type for argument #2 (p): Natural number expected"; error(53,msg); end - + if p>size(x,1) then - msg = "lpc: Wrong value for argument #2 (p): Must be less than or equal to the length of the signal vector"; + msg = "lpc: Wrong value for argument #2 (p): Must be less than or equal to the length of the signal vector"; error(53,msg); end - + if ~isreal(p) then msg = "lpc: Wrong type for argument #2 (p): Real scalar expected"; error(53,msg); end end - + num_signals = size(x,2); // ** Processing ** N = size(x,1); - + // zero pad x x = [x; zeros(2^nextpow2(2*N-1)-N,size(x,2))]; X = fft(x,-1,1); R = fft(abs(X).^2,1,1); R = R./N; // Biased autocorrelation estimate - + // change ieee mode to handle division by zero ieee_prev = ieee(); ieee(2); [a,g] = ld_recursion(R,p); ieee(int(ieee_prev)); - - + + // filter coeffs should be real if input is real for signal_idx=1:num_signals if isreal(x(:,signal_idx)) then - a(signal_idx,:) = real(a(signal_idx,:)); + a(signal_idx,:) = real(a(signal_idx,:)); end end - + endfunction function [a,e] = ld_recursion(R,p) @@ -144,30 +162,30 @@ function [a,e] = ld_recursion(R,p) // // Paramaters // R: double - // Autocorrelation matrix where column corresponds to autocorrelation + // Autocorrelation matrix where column corresponds to autocorrelation // to be treated independently // a: double - // Matrix where rows denote filter cofficients of the corresponding + // Matrix where rows denote filter cofficients of the corresponding // autocorrelation values // e: double // Column vector denoting error variance for each filter computation - - + + num_filters = size(R,2); - - + + // Initial filter (order 0) a = zeros(num_filters,p+1); a(:,1) = 1; e = R(1,:).'; - - + + // Solving in a bottom-up fashion (low to high filter coeffs) for m=1:p k_m = -sum(a(:,m:-1:1).*R(2:m+1,:).',2)./e; a(:,2:m+1) = a(:,2:m+1) + k_m(:,ones(1,m)).*conj(a(:,m:-1:1)); - + e = (1-abs(k_m).^2).*e; end - + endfunction diff --git a/macros/medfilt1.sci b/macros/medfilt1.sci index b81a03a..f87aaa9 100644 --- a/macros/medfilt1.sci +++ b/macros/medfilt1.sci @@ -1,70 +1,81 @@ function y = medfilt1(x, varargin) - // 1D median filtering - // - // Calling sequence - // y = medfilt1(x) - // y = medfilt1(x, n) - // y = medfilt1(x, n, dim) - // y = medfitl1(__, nanflag, padding) - // - // Description - // y = medfilt1(x) - // Applies a 3rd order 1-dimensional median filter to input x along the - // first non-zero dimension. The function appropriately pads the signal - // with zeros at the endings. For a segment, a median is calculated as - // the middle value (average of two middle values) for odd number - // number (even number) of data points. - // y = medfilt1(x,n) - // Applies a nth order 1-dimensional median filter. - // y = medfilt1(x,n,dim) - // Applies the median filter along the n-th dimension - // y = medfilt1(__, nanflag, padding) - // nanflag specifies how NaN values are treated. padding specifies the - // type of filtering to be performed at the signal edges. - // - // Parameters - // x: int | double - // Input signal. - // n: positive integer scalar - // Filter order. - // Defaults to 3.The order of the median filter. Must be less than - // (length of the signal) where signals are 1D vectors along the - // dimension of x to be filtered - // dim: positive integer scalar - // Dimension to filter along. - // Defaults to first non-singleton dimension of x - // nanflag: 'includenan' (default) | 'omitnan' - // NaN condition. - // * includenan: Filtering such that the median of any segment - // containing a NaN is also a NaN. - // * omitnan: Filtering with NaNs omitted in each segment. If a segment - // contains all NaNs, the result is NaN - // y: int | double - // The filtered signal. - // y has the same size as x - // - // Examples - // 1) Noise supression using median filtering - // fs = 1e3; - // t = 1:1/fs:1; - // s = sin(2*%pi*2*t)+ cos(2*%pi*5*t); - // // Adding noise - // x = s + 0.1*randn(size(s)); - // y = medfilt1(x); - // - // See also - // filter | hampel | median | sgolayfilt - // - // Authors - // Ayush Baid - - - - // ************************************************************************* - // Checking number of arguments +// 1D median filtering +// +// Calling sequence +// y = medfilt1(x) +// y = medfilt1(x, n) +// y = medfilt1(x, n, dim) +// y = medfitl1(__, nanflag, padding) +// +// Description +// y = medfilt1(x) +// Applies a 3rd order 1-dimensional median filter to input x along the +// first non-zero dimension. The function appropriately pads the signal +// with zeros at the endings. For a segment, a median is calculated as +// the middle value (average of two middle values) for odd number +// number (even number) of data points. +// y = medfilt1(x,n) +// Applies a nth order 1-dimensional median filter. +// y = medfilt1(x,n,dim) +// Applies the median filter along the n-th dimension +// y = medfilt1(__, nanflag, padding) +// nanflag specifies how NaN values are treated. padding specifies the +// type of filtering to be performed at the signal edges. +// +// Parameters +// x: int | double +// Input signal. +// n: positive integer scalar +// Filter order. +// Defaults to 3.The order of the median filter. Must be less than +// (length of the signal) where signals are 1D vectors along the +// dimension of x to be filtered +// dim: positive integer scalar +// Dimension to filter along. +// Defaults to first non-singleton dimension of x +// nanflag: 'includenan' (default) | 'omitnan' +// NaN condition. +// * includenan: Filtering such that the median of any segment +// containing a NaN is also a NaN. +// * omitnan: Filtering with NaNs omitted in each segment. If a segment +// contains all NaNs, the result is NaN +// y: int | double +// The filtered signal. +// y has the same size as x +// +// +// Examples : Noise supression using 10th order (n =10) median filtering +// +////Generate a sinusoidal signal sampled for 1 second at 100 Hz. Add a higher-frequency sinusoid to simulate noise. +//fs = 100; +//t = 0:1/fs:1; +//x = sin(2*%pi*t*3)+0.25*sin(2*%pi*t*40); +// +////Use a 10th-order median filter to smooth the signal. Plot the result. +//y = medfilt1(x,10); +//plot(t,x,t,y) +//legend('Original','Filtered'); +//y = round(y*10000)/10000; +//y = y' +// +//Output : +// Output is a plot of x versus t and y versus t +// samples of y is stored in medfilt1op.txt +// +// +// See also +// filter | hampel | median | sgolayfilt +// +// Authors +// Ayush Baid + + + + // ************************************************************************* + // Checking number of arguments // ************************************************************************* [numOutArgs, numInArgs] = argn(0); - + if numInArgs<1 | numInArgs>5 then msg = "medfilt1: Wrong number of input argument; 1-5 expected"; error(77, msg); @@ -73,31 +84,31 @@ function y = medfilt1(x, varargin) msg = "medfilt1: Wrong number of output argument; 1 expected"; error(78, msg); end - - - + + + // ************************************************************************* // Parsing input arguments // ************************************************************************* - + // * Parsing x * temp = x(:); if type(temp)~=1 & type(temp)~=8 then msg = "medfilt1: Wrong type for argument #1 (x): Int/double expected" error(53, msg); end - - + + // * Parsing nanflag and padding * // Getting all the string arguments - stringIndices = list(); + stringIndices = list(); for i=1:length(varargin); e = varargin(i); if type(e)==10 then stringIndices($+1)=i; end end - + nanflag = %f; // 0->includenan (default); 1->omitnan padflag = %t; // 1->zeropad (default); 0->truncate if ~isempty(stringIndices) then @@ -105,15 +116,15 @@ function y = medfilt1(x, varargin) if or(strcmpi(varargin(stringIndices), 'omitnan')) then nanflag = %t; end - + // checking for 'truncate' if or(strcmpi(varargin(stringIndices), 'truncate')) then padflag = %f; end varargin(stringIndices) = []; end - - + + // setting default value for n and dim n = 3; dim = 1; @@ -123,7 +134,7 @@ function y = medfilt1(x, varargin) dim = i; end end - + // * Parsing n and dim * if length(varargin)==1 then if ~isempty(varargin(1)) then @@ -140,20 +151,20 @@ function y = medfilt1(x, varargin) msg = "medfilt1: Wrong type of input arguments; Atmost 3 numerical input expected"; error(53, msg); end - + // check on n if length(n)~=1 then msg = "medfilt1: Wrong size for argument #2 (n): Scalar expected"; error(60,msg); end - + if type(n)~=1 & type(n)~=8 then msg = "medfilt1: Wrong type for argument #2 (n): Natural number expected"; error(53,msg); end - + if n~=round(n) | n<=0 then - msg = "medfilt1: Wrong type for argument #2 (n): Natural number expected"; + msg = "medfilt1: Wrong type for argument #2 (n): Natural number expected"; error(53,msg); end @@ -161,20 +172,20 @@ function y = medfilt1(x, varargin) msg = "medfilt1: Wrong type for argument #2 (n): Real scalar expected"; error(53,msg); end - + // check on dim if length(dim)~=1 then msg = "medfilt1: Wrong size for argument #3 (dim): Scalar expected"; error(60,msg); end - + if type(dim)~=1 & type(dim)~=8 then msg = "medfilt1: Wrong type for argument #3 (dim): Natural number expected"; error(53,msg); end - + if dim~=round(dim) | dim<=0 then - msg = "medfilt1: Wrong type for argument #3 (dim): Natural number expected"; + msg = "medfilt1: Wrong type for argument #3 (dim): Natural number expected"; error(53,msg); end @@ -183,103 +194,103 @@ function y = medfilt1(x, varargin) error(53,msg); end - + // ************************************************************************* // Processing for median filtering column by column // ************************************************************************* inp_size = size(x); - + // Permuting x to bring the dimension to be acted upon as the first dimesnion perm_vec = [2:dim, 1, dim+1:length(inp_size)]; reverse_perm_vec = [dim, 1:dim-1, dim+1:length(inp_size)]; x = permute(x, perm_vec); size_vec = size(x); - + y = x; // just initialization for i=1:prod(size_vec(2:$)) temp = medfilt_colvector(x(:,i), n, padflag, nanflag); y(:,i) = temp; end - - - + + + y = permute(y, reverse_perm_vec); - - + + endfunction function med = medfilt_colvector(x, n, zeropadflag, nanflag) // Performs median filtering (of order n) on a column vector (x) // zeropadflag -> zero pad instead of truncation // nanflag -> discard all blocks containing nan, else do not consider nan values - + med = zeros(size(x,1),1); - disp('here1'); - - + //disp('here1'); + + // ** zero pad the signal ** pad_length = floor(n/2); // padding on a size x = [zeros(pad_length,1); x; zeros(pad_length,1)]; - + nx = length(x); // Arrange data in blocks top_row = 1:(nx-n); - + idx = zeros(n,length(top_row)); - + for i=1:n idx(i,:) = top_row + (i-1); end - + blocks = matrix(x(idx), size(idx)); - - + + if nanflag then disp('here2'); med = median(blocks, 1)'; - + // set result of all the blocks containing nan to nan nanpresent = or(isnan(blocks), 1); med(nanpresent) = %nan; else - disp('here3'); + //disp('here3'); // we have to neglect nans sorted_blocks = gsort(blocks, 'r', 'i'); - + // get the count of non-nan elements num_elems = n - sum(isnan(sorted_blocks), 1); - + // find the median offset = (0:size(blocks,2)-1)*size(blocks,1); idx1 = offset+ceil(num_elems/2); idx2 = offset+ceil((num_elems/2)+0.25); - + // temporarily setting idx1 to 1 so as to not give errors in median calc. // Will later replace values at such indices with Nan idx1(idx1==0)=1; med = (sorted_blocks(idx1) + sorted_blocks(idx2))./2; - + med(idx1==0) = %nan; end if ~zeropadflag then // ** recalculate boundary blocks with truncation truncate at the boundaries ** - + // divide the input signal into 3 parts; 1st and last part have truncation for i=ceil(n/2):n // ** first part ** block = x(1:i); - + // * median calc for a block * if nanflag then med(i-ceil(n/2)+1) = median(block, 1); - + // set result of all the blocks containing nan to nan nanpresent = or(isnan(block), 1); if nanpresent then @@ -288,15 +299,15 @@ function med = medfilt_colvector(x, n, zeropadflag, nanflag) else // we have to neglect nans sorted_block = gsort(block, 'r', 'i'); - + // get the count of non-nan elements num_elems = length(block) - sum(isnan(sorted_block), 1); - + // find the median idx1 = ceil(num_elems/2); idx2 = ceil(num_elems/2+0.25); - - + + // temporarily setting idx1 to 1 so as to not give errors in median calc. // Will later replace values at such indices with Nan if idx1==0 then @@ -304,33 +315,33 @@ function med = medfilt_colvector(x, n, zeropadflag, nanflag) else med(i-ceil(n/2)+1) = (sorted_block(idx1, :)+sorted_block(idx2, :))./2; end - end - - + end + + // ** last part ** block = x($:-1:$-i); - + // * median calc for a block * if nanflag then med($+ceil(n/2)-i) = median(block, 1); - + // set result of all the blocks containing nan to nan nanpresent = or(isnan(block), 1); if nanpresent then med($-ceil(n/2)+i) = %nan; end - med($+ceil(n/2)-i) = %nan; + med($+ceil(n/2)-i) = %nan; else // we have to neglect nans sorted_block = gsort(block, 'r', 'i'); - + // get the count of non-nan elements num_elems = length(block) - sum(isnan(sorted_block), 1); - + // find the median idx1 = ceil(num_elems/2); idx2 = ceil(num_elems/2+0.25); - + // temporarily setting idx1 to 1 so as to not give errors in median calc. // Will later replace values at such indices with Nan if idx1==0 then diff --git a/macros/medfilt1op.txt b/macros/medfilt1op.txt new file mode 100644 index 0000000..86f5d53 --- /dev/null +++ b/macros/medfilt1op.txt @@ -0,0 +1,101 @@ +0.000000 +0.065200 +0.232300 +0.436000 +0.634200 +0.752200 +0.791300 +0.827100 +0.827100 +0.860200 +0.860200 +0.860200 +0.788000 +0.689000 +0.433800 +0.321900 +0.290600 +0.130700 +-0.155700 +-0.436600 +-0.577400 +-0.584900 +-0.639900 +-0.763700 +-0.763700 +-0.855600 +-0.855600 +-0.855600 +-0.763700 +-0.721000 +-0.597200 +-0.537100 +-0.382600 +-0.150200 +0.076700 +0.242000 +0.354300 +0.514200 +0.679000 +0.744800 +0.759100 +0.784600 +0.820300 +0.820300 +0.784600 +0.784600 +0.759100 +0.681900 +0.452000 +0.169200 +0.020200 +-0.020200 +-0.169200 +-0.452000 +-0.681900 +-0.759100 +-0.784600 +-0.784600 +-0.820300 +-0.820300 +-0.784600 +-0.759100 +-0.744800 +-0.679000 +-0.514200 +-0.354300 +-0.242000 +-0.076700 +0.150200 +0.382600 +0.537100 +0.597200 +0.721000 +0.763700 +0.855600 +0.855600 +0.855600 +0.763700 +0.763700 +0.639900 +0.584900 +0.577400 +0.436600 +0.155700 +-0.130700 +-0.290600 +-0.321900 +-0.433800 +-0.689000 +-0.788000 +-0.860200 +-0.860200 +-0.860200 +-0.827100 +-0.827100 +-0.791300 +-0.752200 +-0.634200 +-0.436000 +-0.232300 +-0.065200 diff --git a/macros/movingrms.sci b/macros/movingrms.sci index 231a9f1..07e6f87 100644 --- a/macros/movingrms.sci +++ b/macros/movingrms.sci @@ -1,33 +1,113 @@ -function [rmsx,w]=movingrms(x,w,rc,Fs) +function [rmsx, w] = movingrms(x, width, risetime, varargin) // Find moving RMS value of signal in x + // Calling Sequence -// [rmsx,w]=movingrms(x,w,rc,Fs=1) +//[rmsx,w]=movingrms(x,width,risetime) +//[rmsx,w]=movingrms(x,width,risetime,Fs) + // Parameters -// x: Real or complex valued vector or matrix -// w: Real or complex scalar value -// rc: Real or complex scalar value -// Fs: Real or complex scalar value +// x: (Real or complex valued vector or matrix) Input Signal +// width: Real or complex scalar value +// risetime: Real or complex scalar value +// Fs: (Real or complex scalar value) Sampling frequency + // Description -// This is an Octave function. -// The signal is convoluted against a sigmoid window of width w and risetime rc with the units of these parameters relative to the value of the sampling frequency given in Fs (Default value=1). -// Examples -// 1. [a,b]=movingrms ([4.4 94 1;-2 5i 5],1,-2) -// a = 0.91237 17.71929 0.96254 -// 0.91237 17.71929 0.96254 -// b = 0.18877 -// 0.18877 -// 2. [a,b]=movingrms ([4.4 94 1;-2 5i 5],1,-2,2) -// a = 4.8332 93.8669 5.0990 -// 4.8332 93.8669 5.0990 -// b = 1 -// 1 +// In this function signal is convoluted against a sigmoid window of width w and risetime rc with the units of these parameters relative to the value of the sampling frequency given in Fs (Default value=1). + +// Example : 1 +//[a,b]=movingrms ([4.4 94 1;-2 5*%i 5],1,-2) +// Output: +// b = +// +// 0.1887703 +// 0.1887703 +// a = +// +// 0.9123683 17.719291 0.9625436 +// 0.9123683 17.719291 0.9625436 + +//Example : 2 +// [a,b]=movingrms ([4.4 94 1;-2 5*%i 5],1,-2,2) +//Output : +// b = +// +// 1. +// 1. +// a = +// +// 4.8332184 93.866927 5.0990195 +// 4.8332184 93.866927 5.0990195 funcprot(0); -rhs=argn(2); -if (rhs<3) then - error("Wrong number of input arguments.") -elseif (rhs==3) then Fs=1; + +//************************************************************************************************** +//______________________________________________version1 code (not working)_________________________ +//__________________________________________________________________________________________________ +//************************************************************************************************** + +//rhs=argn(2); +//if (rhs<3) then +// error("Wrong number of input arguments.") +//elseif (rhs==3) then Fs=1; +//end +//[rmsx,w]=callOctave("movingrms",x,w,rc,Fs) + +//************************************************************************************************** +//______________________________________________version2 code ( working)____________________________ +//__________________________________________________________________________________________________ +//************************************************************************************************** +if argn(2) > 4 | argn(2) < 3 then + error("movingrms : wrong number of inputs ") end -[rmsx,w]=callOctave("movingrms",x,w,rc,Fs) + + if length(varargin)==0 then + Fs = 1; + else + Fs = varargin(1); + end + + [N nc] = size (x); + if width*Fs > N/2 + idx = [1 N]; + w = ones(N,1); + else + idx = round ((N + width*Fs*[-1 1])/2); + w = sigmoid_train((1:N)', idx, risetime*Fs); + end + fw = fft (w.^2); + //fx = fft (x.^2); itdoes columwise fft in Octave but in scilab it does 2D fft + + //Evaluating columnwise fft using for loop + fx = []; + for k = 1:nc + fx = [fx fft(x(:,k).^2)]; + k = k + 1; + end + //end of Evaluating columnwise fft using for loop + + // in octave fx.*fw does row element wise multiplication but it is inconsistance in scilab + //doing it using for loop + fxw = []; + for k = 1:N + fxw = [fxw ; fx(k,:).*fw(k,:)] + end + //end of fxw computation + + //rmsx = real(ifft (fxw)/(N-1)); itdoes columwise ifft in Octave but in scilab it does 2D ifft + //Evaluating columnwise ifft using for loop + ifxw = []; + for k = 1:nc + ifxw = [ifxw ifft(fxw(:,k))]; + k = k + 1; + end + + rmsx = real(ifxw/(N-1)) + //end of Evaluating columnwise ifft using for loop + + rmsx (rmsx < %eps*max(rmsx(:))) = 0; + + rmsx = circshift (sqrt (rmsx), round(mean(idx))); + //##w = circshift (w, -idx(1)); + endfunction diff --git a/macros/ncauer.sci b/macros/ncauer.sci index c76eb65..d9a0684 100644 --- a/macros/ncauer.sci +++ b/macros/ncauer.sci @@ -1,21 +1,35 @@ +// 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 +// Author:Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + function [Zz, Zp, Zg] = ncauer(Rp, Rs, n) -//Analog prototype for Cauer filter. +//Analog prototype for Cauer filter (Cauer filter and elliptic filters are same). + //Calling Sequence //[Zz, Zp, Zg] = ncauer(Rp, Rs, n) -//[Zz, Zp] = ncauer(Rp, Rs, n) -//Zz = ncauer(Rp, Rs, n) -//Parameters + +//Parameters //n: Filter Order -//Rp: Peak-to-peak passband ripple -//Rs: Stopband attenuation +//Rp: Peak-to-peak passband ripple in dB +//Rs: Stopband attenuation in dB + //Description -//This is an Octave function. -//It designs an analog prototype for Cauer filter of nth order, with a Peak-to-peak passband ripple of Rp and a stopband attenuation of Rs. +//It gives an analog prototype for Cauer filter of nth order, with a Peak-to-peak passband ripple of Rp dB and a stopband attenuation of Rs dB. + + //Examples //n = 5; //Rp = 5; //Rs = 5; //[Zz, Zp, Zg] = ncauer(Rp, Rs, n) + //Zz = // // 0.0000 + 2.5546i 0.0000 + 1.6835i -0.0000 - 2.5546i -0.0000 - 1.6835i @@ -26,24 +40,14 @@ function [Zz, Zp, Zg] = ncauer(Rp, Rs, n) // //Zg = 0.0030628 + funcprot(0); lhs = argn(1) rhs = argn(2) if (rhs < 3 | rhs > 3) -error("Wrong number of input arguments.") +error("ncauer : Wrong number of input arguments.") end -select(rhs) - - case 3 then - if(lhs==1) - Zz = callOctave("ncauer", Rp, Rs, n) - elseif(lhs==2) - [Zz, Zp] = callOctave("ncauer", Rp, Rs, n) - elseif(lhs==3) - [Zz, Zp, Zg] = callOctave("ncauer", Rp, Rs, n) - else - error("Wrong number of output argments.") - end - end +[Zz, Zp, Zg] = ellipap(n, Rp, Rs) ; + endfunction diff --git a/macros/postpad.sci b/macros/postpad.sci new file mode 100644 index 0000000..f8042be --- /dev/null +++ b/macros/postpad.sci @@ -0,0 +1,49 @@ +// 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 +// Author:Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +// This is a supporting function + +function y = postpad(x, n, varargin) + + //Calling Sequences + // Y = postpad (X, L) + // Y = postpad (X, L, C) + + // Description : + // Append the scalar value C to the vector X until it is of length L. + // If C is not given, a value of 0 is used. + // + // If 'length (X) > L', elements from the end of X are removed until a + // vector of length L is obtained. + + //Example : + //x = [1 2 3]; + //L = 6; + //y = postpad(x, L) + //Output : + // y = + // + // 1. 2. 3. 0. 0. 0. + + funcprot(0); + if argn(2) > 3 | argn(2) < 2 then + error("postpad : wrong number of input argument ") + elseif argn(2) == 2 + c = 0 ; + else + c = varargin(1); + end + + y = x; + for i = 1:(n-length(x)) + y = [y c]; + end +endfunction diff --git a/macros/pulsedata_t.txt b/macros/pulsedata_t.txt new file mode 100644 index 0000000..cc9dcc6 --- /dev/null +++ b/macros/pulsedata_t.txt @@ -0,0 +1 @@ +0.000000 0.025000 0.050000 0.075000 0.100000 0.125000 0.150000 0.175000 0.200000 0.225000 0.250000 0.275000 0.300000 0.325000 0.350000 0.375000 0.400000 0.425000 0.450000 0.475000 0.500000 0.525000 0.550000 0.575000 0.600000 0.625000 0.650000 0.675000 0.700000 0.725000 0.750000 0.775000 0.800000 0.825000 diff --git a/macros/pulsedata_x.txt b/macros/pulsedata_x.txt new file mode 100644 index 0000000..800ef63 --- /dev/null +++ b/macros/pulsedata_x.txt @@ -0,0 +1 @@ +0.000000 0.010800 0.036700 -0.045200 0.017200 0.006400 -0.026200 -0.008700 0.006900 0.071600 0.055400 -0.027000 0.060700 5.014500 4.998700 5.014300 4.995900 4.997500 5.029800 0.028200 0.028300 0.013400 -0.024100 0.014300 0.032600 0.009800 0.020700 0.014500 -0.006100 0.005900 -0.015700 0.017800 -0.022900 4.978600 diff --git a/macros/pulseperiod.sci b/macros/pulseperiod.sci index aa43455..0e986a1 100644 --- a/macros/pulseperiod.sci +++ b/macros/pulseperiod.sci @@ -1,6 +1,7 @@ function [p, initialcross, finalcross, nextcross, midreference]= pulseperiod(x, varargin) - + // This function estimate pulse period of real vector X. + // Calling Sequence // p=pulseperiod(x) // p=pulseperiod(x, Fs) @@ -9,7 +10,6 @@ function [p, initialcross, finalcross, nextcross, midreference]= pulseperiod(x, // p=pulseperiod(x, t, 'MidPercentReferenceLevel', N ) // p=pulseperiod(x, t, 'Tolerance', M) // p=pulseperiod(x, t,'StateLevels', O) - // [p initialcross finalcross nextcross midreference]=pulseperiod(x) // [p initialcross finalcross nextcross midreference]=pulseperiod(x, t) // [p initialcross finalcross nextcross midreference]=pulseperiod(x, t) @@ -17,8 +17,8 @@ function [p, initialcross, finalcross, nextcross, midreference]= pulseperiod(x, // [p initialcross finalcross nextcross midreference]=pulseperiod(x, t, 'MidPercentReferenceLevel', N ) // [p initialcross finalcross nextcross midreference]= pulseperiod(x, t, 'Tolerance', M) // [p initialcross finalcross nextcross midreference]= pulseperiod(x, t,'StateLevels', O) - // [p initialcross finalcross nextcross midreference]= pulseperiod(x, t,'StateLevels', O, 'fig', on or off) - // + // [p initialcross finalcross nextcross midreference]= pulseperiod(x, t,'StateLevels', O, 'fig', 'on' or 'off') + // // Parameters // x: real vector. // Fs: specifies the sample rate, Fs, as a positive scalar, where the first sample instant corresponds to a time of zero. @@ -27,28 +27,37 @@ function [p, initialcross, finalcross, nextcross, midreference]= pulseperiod(x, // MidPercentReferenceLevel: specify the mid percent reference leves as a percentage, default value of N is 50. // Tolerance: define the tolerance value as real scaler value, where default value of M is 2.0. // StateLevels: define the lower and upper state levels as two element real vector. - // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'. + // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'. // p: returns a vector of difference between the mid-crossings of the initial transition of each positive-polarity pulse and the next positive-going transition // initialcross: returns a vector of initial cross values of bilevel waveform transitions X // finalcross: returns a vector of final cross values of bilevel waveform transitions X // nextcross: returns a vector of next cross values of bilevel waveform transitions X - // midreference: return mid reference value corrosponding to mid percenr reference value. - + // midreference: return mid reference value corrosponding to mid percent reference value. + // Examples - // x=[1.2, 5, 10, -20, 12] - //t=1:length(x) - //p=pulseperiod(x, t) + //x = fscanfMat("macros/pulsedata_x.txt"); + //t = fscanfMat("macros/pulsedata_t.txt"); + //clf + //p = pulseperiod(x,t,'fig','ON') + + //Output + // p = + // + // 0.5002996 + //also it generates a pulse plot with pulse period + + // See also // Authors // Jitendra Singh - - - // run statelevels and midcross function before running risetime function. + + + // run statelevels and midcross function before running risetime function. if or(type(x)==10) then error ('Input arguments must be double.') -end - +end + if length(varargin)==0 then varargin=varargin; end @@ -56,13 +65,13 @@ end sindex=[]; if length(varargin)>=1 then a=1; -for i=1:length(varargin) +for i=1:length(varargin) if type(varargin(i))==10 then sindex(a)=i; a=a+1; - end + end +end end -end pol='POSITIVE'; @@ -72,206 +81,206 @@ index_on=[]; if (~isempty(sindex)) then for j=1:length(sindex) select convstr(varargin(sindex(j)), 'u') // validating input variable names - case {'STATELEVELS'} - + case {'STATELEVELS'} + if length(varargin) <=sindex(j) then error(strcat(['parameter StateLevels required a value'])); end - + if type(varargin(sindex(j)+1))==1 then - levels=varargin(sindex(j)+1); - + levels=varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - - error('parameter StateLevels required a value.') - - + + error('parameter StateLevels required a value.') + + elseif type(varargin(sindex(j)+1))==10 then - + error('Expected STATELEVELS to be one of these types: double, Instead its type was char.') end - - case {'MIDPERCENTREFERENCELEVEL'} - + + case {'MIDPERCENTREFERENCELEVEL'} + if length(varargin) <=sindex(j) then - error(strcat(['parameter MidPercentRefernceLevel required a value.'])); + error(strcat(['parameter MidPercentRefernceLevel required a value.'])); end - + if type(varargin(sindex(j)+1))==1 then - midpercentval= varargin(sindex(j)+1); - elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - error('parameter MidPercentRefernceLevel required a value.') - - elseif type(varargin(sindex(j)+1))==10 then - error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.') - end - - - case {'TOLERANCE'} - + midpercentval= varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then + error('parameter MidPercentRefernceLevel required a value.') + + elseif type(varargin(sindex(j)+1))==10 then + error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.') + end + + + case {'TOLERANCE'} + if length(varargin) <=sindex(j) then - + error(strcat(['parameter Tolerance required a value"])); - + elseif type(varargin(sindex(j)+1))==1 then - tolerance= varargin(sindex(j)+1); - + tolerance= varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - + error('parameter Tolerance required a value.'); - + elseif type(varargin(sindex(j)+1))==10 then - + error('Expected Tolerance to be one of these types: double, Instead its type was char.'); - end - - + end + + case {'FIG'} - + if length(varargin) <=sindex(j) then error(strcat(['parameter fig required a value.'])); end - + if type(varargin(sindex(j)+1))==1 then error ('Expected fig to match one of these strings: on or off'); - - elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - error('parameter fig required a value.') - else + + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then + error('parameter fig required a value.') + else fig= convstr(varargin(sindex(j)+1), 'u'); - - end - - - if fig == 'OFF' | fig == 'ON' then - else + + end + + + if fig == 'OFF' | fig == 'ON' then + else error('Expected fig to match one of these strings: on or off'); - end - - - - case{'ON'} + end + + + + case{'ON'} index_on=sindex(j) if length(varargin) == 1 then - error ('Unexpected input.') - - + error ('Unexpected input.') + + elseif type(varargin(sindex(j)-1))==1 then - error ('Unexpected input.'); + error ('Unexpected input.'); elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then error('Unexpected input'); end - + case{'OFF'} - + if length(varargin) == 1 then - error ('Unexpected input.') - - + error ('Unexpected input.') + + elseif type(varargin(sindex(j)-1))==1 then - error ('Unexpected input.'); + error ('Unexpected input.'); elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then error('Unexpected input'); - end - - - - + end + + + + case{'POLARITY'} if length(varargin)<=sindex(j) then error ('Parameter polarity requires a value.') end - + if type( varargin(sindex(j)+1))==1 then error ('POLARITY must be either ''Positive'' or ''Negative''.') - + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' then - + error ('Parameter polarity requires a value.') - - + + elseif convstr(varargin(sindex(j)+1), 'u') ~= 'POSITIVE' & convstr(varargin(sindex(j)+1), 'u')~= 'NEGATIVE' then - + error ('POLARITY must be either ''Positive'' or ''Negative''.'); - - else - polidx=sindex(j); - end - - + + else + polidx=sindex(j); + end + + case {'POSITIVE'} - + if j==1 then error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY' error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); else polinputidx= sindex(j); - - pol= convstr(varargin (sindex(j)), 'u') ; + + pol= convstr(varargin (sindex(j)), 'u') ; end - + case {'NEGATIVE'} - + if j==1 then error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY' error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); else polinputidx= sindex(j); - - pol= convstr(varargin (sindex(j)), 'u') ; - end - - else + + pol= convstr(varargin (sindex(j)), 'u') ; + end + + else error(strcat(['Invalid optional argument'," ", varargin(sindex(j))])); end // switch end // for end // if -// +// if length(index_on)>0 then - varargin(index_on)='OFF'; + varargin(index_on)='OFF'; end if length(polidx)>0 then - varargin(polidx)=null(); + varargin(polidx)=null(); varargin(polinputidx-1)=null(); end - [crossval midref levels t tolerance]= midcross(x, varargin(:)); - + [crossval midref levels t tolerance]= midcross(x, varargin(:)); + upperbound= levels(2)- (tolerance/100)*(levels(2)-levels(1)); mostupperbound=levels(2)+ (tolerance/100)*(levels(2)-levels(1)); lowerbound= levels(1)+ (tolerance/100)*(levels(2)-levels(1)); - mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1)); + mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1)); int_pos=[]; final_pos=[]; int_neg=[]; - final_neg=[]; + final_neg=[]; nextcross_pos=[]; nextcross_neg=[]; if length(crossval)>=2 then if x(1)>midref then - + int_pos=crossval(2:2:$); final_pos=crossval(3:2:$); int_neg=crossval(1:2:$); final_neg=crossval(2:2:$); else - + int_pos=crossval(1:2:$); final_pos=crossval(2:2:$); int_neg=crossval(2:2:$); final_neg-crossval(3:2:$); - + end @@ -281,8 +290,8 @@ if length(int_pos)>=2 then end if length(int_neg)>=2 then - nextcross_neg=int_neg(2:$); - end + nextcross_neg=int_neg(2:$); + end @@ -304,113 +313,113 @@ elseif length(int_neg)>length(final_neg) then end if length(final_pos)>length(nextcross_pos) final_pos=final_pos(1:($-1)) - + end - + if length(int_neg)>length(nextcross_neg) then int_neg=int_neg(1:($-1)); end if length(final_neg)>length(nextcross_neg) then final_neg=final_neg(1:($-1)); end - + end - + p=[]; - + if pol=='POSITIVE' then // checking the input variable polarity - + p= nextcross_pos-int_pos; - - + + initialcross=int_pos; finalcross=final_pos; - nextcross=nextcross_pos; + nextcross=nextcross_pos; else p= nextcross_neg-int_neg; - - + + initialcross=int_neg; finalcross=final_neg; - nextcross=nextcross_neg; - + nextcross=nextcross_neg; + end - + midreference=midref; // return midreference value if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels - + if length(p)==0 then - + plot(t,x, 'LineWidth',1, 'color', 'black') // xtitle('', 'Time (second)','Level (Volts)' ); plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5) - + plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - - plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) - + + plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) + plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - + plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5) - + plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5) - - plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) - + + plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) + xlabel("Time (second)", "fontsize",3, "color", "black" ) - ylabel("Level (Volts)", "fontsize",3, "color", "black" ) - + ylabel("Level (Volts)", "fontsize",3, "color", "black" ) + + + legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?') + - legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?') - + else - else - plot(t,x, 'LineWidth',1, 'color', 'black') - + plot(t,midreference * ones(1, length(t)),'-g', 'LineWidth',0.5) - - + + //n=length(finalcross); - - + + rects=[initialcross(1:2:$); levels(2)*ones(p(1:2:$)); p(1:2:$); (levels(2)-levels(1))*ones(p(1:2:$))] - + col=-10*ones(p(1:2:$)); midc=[nextcross, initialcross, finalcross]; midcross=gsort(midc, 'c','i' ) - + plot(midcross, midreference*ones(midcross), "r*", 'MarkerSize',15); plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - - plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) - + + plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) + plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - + plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5) - + plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5) - + plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5) - - plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) - + + plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) + xrects(rects, col); - + xlabel("Time (second)", "fontsize",3, "color", "black" ) - ylabel("Level (Volts)", "fontsize",3, "color", "black" ) - + ylabel("Level (Volts)", "fontsize",3, "color", "black" ) + - legends(["pulse period"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;5], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?') + legends(["pulse period"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;5], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]],1) - end - end -// + end + end +// // endfunction diff --git a/macros/pulsesep.sci b/macros/pulsesep.sci index f64494b..df85e80 100644 --- a/macros/pulsesep.sci +++ b/macros/pulsesep.sci @@ -1,6 +1,7 @@ function [s, initialcross, finalcross, nextcross, midreference]= pulsesep(x, varargin) - + // This function estimate pulse separation between bilevel waveform pulses. + // Calling Sequence // s=pulsesep(x) // s=pulsesep(x, Fs) @@ -9,7 +10,7 @@ function [s, initialcross, finalcross, nextcross, midreference]= pulsesep(x, var // s=pulsesep(x, t, 'MidPercentReferenceLevel', N ) // s=pulsesep(x, t, 'Tolerance', M) // s=pulsesep(x, t,'StateLevels', [O 1]) - + // [s initialcross finalcross nextcross midreference]=pulsesep(x) // [s initialcross finalcross nextcross midreference]=pulsesep(x, Fs) // [s initialcross finalcross nextcross midreference]=pulsesep(x, t) @@ -18,7 +19,7 @@ function [s, initialcross, finalcross, nextcross, midreference]= pulsesep(x, var // [s initialcross finalcross nextcross midreference]= pulsesep(x, t, 'Tolerance', M) // [s initialcross finalcross nextcross midreference]= pulsesep(x, t,'StateLevels', O) // [s initialcross finalcross nextcross midreference]= pulsesep(x, t,'StateLevels', O, 'fig', on or off) - // + // // Parameters // x: real vector. // Fs: specifies the sample rate, Fs, as a positive scalar, where the first sample instant corresponds to a time of zero. @@ -26,29 +27,37 @@ function [s, initialcross, finalcross, nextcross, midreference]= pulsesep(x, var // Polarity: specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive' // MidPercentReferenceLevel: specify the mid percent reference leves as a percentage, default value of N is 50. // Tolerance: define the tolerance value as real scaler value, where default value of M is 2.0. - // StateLevels: define the lower and upper state levels as two element real vector. + // StateLevels: define the lower and upper state levels as two element real vector. // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'. // s: returns a vector of differences between the mid-crossings of each final negative-going transition of every positive-polarity pulse and the next positive-going transition. // initialcross: returns a vector of initial cross values of bilevel waveform transitions X // finalcross: returns a vector of final cross values of bilevel waveform transitions X // nextcross: returns a vector of next cross values of bilevel waveform transitions X // midreference: return mid reference value corrosponding to mid percenr reference value. - + // Examples - // x=[1.2, 5, 10, -20, 12] - //t=1:length(x) - //s=pulsesep(x, t) + //x = fscanfMat("macros/pulsedata_x.txt"); + //t = fscanfMat("macros/pulsedata_t.txt"); + //clf + //p = pulsesep(x,t,'fig','ON') + + //Output + // p = + // + // 0.3501425 + //also it generates a plot of pulse with pulse separation + // See also // Authors // Jitendra Singh - - - // run statelevels and midcross function before running risetime function. + + + // run statelevels and midcross function before running risetime function. if or(type(x)==10) then error ('Input arguments must be double.') -end - +end + if length(varargin)==0 then varargin=varargin; end @@ -56,13 +65,13 @@ end sindex=[]; if length(varargin)>=1 then a=1; -for i=1:length(varargin) +for i=1:length(varargin) if type(varargin(i))==10 then sindex(a)=i; a=a+1; - end + end +end end -end pol='POSITIVE'; @@ -72,203 +81,203 @@ index_on=[]; if (~isempty(sindex)) then for j=1:length(sindex) select convstr(varargin(sindex(j)), 'u') // validating input variable names - case {'STATELEVELS'} + case {'STATELEVELS'} if length(varargin) <=sindex(j) then error(strcat(['parameter StateLevels required a value'])); end - + if type(varargin(sindex(j)+1))==1 then - levels=varargin(sindex(j)+1); - + levels=varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - - error('parameter StateLevels required a value.') - - + + error('parameter StateLevels required a value.') + + elseif type(varargin(sindex(j)+1))==10 then - + error('Expected STATELEVELS to be one of these types: double, Instead its type was char.') end - - case {'MIDPERCENTREFERENCELEVEL'} + + case {'MIDPERCENTREFERENCELEVEL'} if length(varargin) <=sindex(j) then - error(strcat(['parameter MidPercentRefernceLevel required a value.'])); + error(strcat(['parameter MidPercentRefernceLevel required a value.'])); end - + if type(varargin(sindex(j)+1))==1 then - midpercentval= varargin(sindex(j)+1); - elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - error('parameter MidPercentRefernceLevel required a value.') - - elseif type(varargin(sindex(j)+1))==10 then - error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.') + midpercentval= varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then + error('parameter MidPercentRefernceLevel required a value.') + + elseif type(varargin(sindex(j)+1))==10 then + error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.') end - case {'TOLERANCE'} - + case {'TOLERANCE'} + if length(varargin) <=sindex(j) then error(strcat(['parameter Tolerance required a value"])); - + elseif type(varargin(sindex(j)+1))==1 then - tolerance= varargin(sindex(j)+1); - + tolerance= varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - + error('parameter Tolerance required a value.'); - + elseif type(varargin(sindex(j)+1))==10 then - + error('Expected Tolerance to be one of these types: double, Instead its type was char.'); - end - - - + end + + + case {'FIG'} - + if length(varargin) <=sindex(j) then error(strcat(['parameter fig required a value.'])); end - + if type(varargin(sindex(j)+1))==1 then error ('Expected fig to match one of these strings: on or off'); - - elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - error('parameter fig required a value.') - else + + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then + error('parameter fig required a value.') + else fig= convstr(varargin(sindex(j)+1), 'u'); - - end - - - if fig == 'OFF' | fig == 'ON' then - else + + end + + + if fig == 'OFF' | fig == 'ON' then + else error('Expected fig to match one of these strings: on or off'); - end - - - - case{'ON'} + end + + + + case{'ON'} index_on=sindex(j) if length(varargin) == 1 then - error ('Unexpected input.') - - + error ('Unexpected input.') + + elseif type(varargin(sindex(j)-1))==1 then - error ('Unexpected input.'); + error ('Unexpected input.'); elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then error('Unexpected input'); end - + case{'OFF'} - + if length(varargin) == 1 then - error ('Unexpected input.') - - + error ('Unexpected input.') + + elseif type(varargin(sindex(j)-1))==1 then - error ('Unexpected input.'); + error ('Unexpected input.'); elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then error('Unexpected input'); - end - - - - + end + + + + case{'POLARITY'} if length(varargin)<=sindex(j) then error ('Parameter polarity requires a value.') end - + if type( varargin(sindex(j)+1))==1 then error ('POLARITY must be either ''Positive'' or ''Negative''.') - + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' then - + error ('Parameter polarity requires a value.') - - + + elseif convstr(varargin(sindex(j)+1), 'u') ~= 'POSITIVE' & convstr(varargin(sindex(j)+1), 'u')~= 'NEGATIVE' then - + error ('POLARITY must be either ''Positive'' or ''Negative''.'); - - else - polidx=sindex(j); - end - - + + else + polidx=sindex(j); + end + + case {'POSITIVE'} - + if j==1 then error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY' error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); else polinputidx= sindex(j); - - pol= convstr(varargin (sindex(j)), 'u') ; + + pol= convstr(varargin (sindex(j)), 'u') ; end - + case {'NEGATIVE'} - + if j==1 then error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY' error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); else polinputidx= sindex(j); - - pol= convstr(varargin (sindex(j)), 'u') ; - end - - else + + pol= convstr(varargin (sindex(j)), 'u') ; + end + + else error(strcat(['Invalid optional argument'," ", varargin(sindex(j))])); end // switch end // for end // if -// +// if length(index_on)>0 then - varargin(index_on)='OFF'; + varargin(index_on)='OFF'; end if length(polidx)>0 then - varargin(polidx)=null(); + varargin(polidx)=null(); varargin(polinputidx-1)=null(); end - [crossval midref levels t tolerance]= midcross(x, varargin(:)); - + [crossval midref levels t tolerance]= midcross(x, varargin(:)); + upperbound= levels(2)- (tolerance/100)*(levels(2)-levels(1)); mostupperbound=levels(2)+ (tolerance/100)*(levels(2)-levels(1)); lowerbound= levels(1)+ (tolerance/100)*(levels(2)-levels(1)); - mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1)); + mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1)); int_pos=[]; final_pos=[]; int_neg=[]; - final_neg=[]; + final_neg=[]; nextcross_pos=[]; nextcross_neg=[]; if length(crossval)>=2 then if x(1)>midref then - + int_pos=crossval(2:2:$); final_pos=crossval(3:2:$); int_neg=crossval(1:2:$); final_neg=crossval(2:2:$); else - + int_pos=crossval(1:2:$); final_pos=crossval(2:2:$); int_neg=crossval(2:2:$); final_neg-crossval(3:2:$); - + end @@ -278,8 +287,8 @@ if length(int_pos)>=2 then end if length(int_neg)>=2 then - nextcross_neg=int_neg(2:$); - end + nextcross_neg=int_neg(2:$); + end @@ -301,112 +310,112 @@ elseif length(int_neg)>length(final_neg) then end if length(final_pos)>length(nextcross_pos) final_pos=final_pos(1:($-1)) - + end - + if length(int_neg)>length(nextcross_neg) then int_neg=int_neg(1:($-1)); end - + if length(final_neg)>length(nextcross_neg) then final_neg=final_neg(1:($-1)); end - + end - - + + s=[]; - - + + if pol=='POSITIVE' then s=nextcross_pos-final_pos; initialcross=int_pos; finalcross=final_pos; nextcross=nextcross_pos; - + else - + s=nextcross_neg-final_neg; initialcross=int_neg; finalcross=final_neg; nextcross=nextcross_neg; - + end - + midreference=midref; if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels - + if length(s)==0 then - + plot(t,x, 'LineWidth',1, 'color', 'black') // xtitle('', 'Time (second)','Level (Volts)' ); plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5) - + plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - - plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) - + + plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) + plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - + plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5) - + plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5) - - plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) - + + plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) + xlabel("Time (second)", "fontsize",3, "color", "black" ) - ylabel("Level (Volts)", "fontsize",3, "color", "black" ) - + ylabel("Level (Volts)", "fontsize",3, "color", "black" ) + + + legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?') + - legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?') - + else - else - plot(t,x, 'LineWidth',1, 'color', 'black') - + plot(t,midreference * ones(1, length(t)),'-g', 'LineWidth',0.5) - - + + //n=length(finalcross); - - + + rects=[finalcross; levels(2)*ones(s); s; (levels(2)-levels(1))*ones(s)] - + col=-10*ones(s); midc=[nextcross, finalcross, initialcross]; midcross=gsort(midc, 'c','i' ) - + plot(midcross, midreference*ones(midcross), "r*", 'MarkerSize',15); plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - - plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) - + + plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) + plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - + plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5) - + plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5) - + plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5) - - plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) - + + plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) + xrects(rects, col); - + xlabel("Time (second)", "fontsize",3, "color", "black" ) - ylabel("Level (Volts)", "fontsize",3, "color", "black" ) - + ylabel("Level (Volts)", "fontsize",3, "color", "black" ) + - legends(["pulse seperation"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;5], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?') + legends(["pulse seperation"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;5], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], 1) - end - end -// + end + end +// // endfunction diff --git a/macros/pulsewidth.sci b/macros/pulsewidth.sci index dad4a66..6e46484 100644 --- a/macros/pulsewidth.sci +++ b/macros/pulsewidth.sci @@ -1,6 +1,7 @@ function [w, initialcross, finalcross, midreference]=pulsewidth(x, varargin) - + // This function estimate pulse width of real vector X. + // Calling Sequence // w=pulsewidth(x) // w=pulsewidth(x, Fs) @@ -9,7 +10,7 @@ function [w, initialcross, finalcross, midreference]=pulsewidth(x, varargin) // w=pulsewidth(x, t, 'MidPercentReferenceLevel', N ) // w=pulsewidth(x, t, 'Tolerance', M) // w=pulsewidth(x, t,'StateLevels', O) - + // [w initialcross finalcross midreference]=pulsewidth(x) // [w initialcross finalcross midreference]=pulsewidth(x, Fs) // [w initialcross finalcross midreference]=pulsewidth(x, t) @@ -18,7 +19,7 @@ function [w, initialcross, finalcross, midreference]=pulsewidth(x, varargin) // [w initialcross finalcross midreference]= pulsewidth(x, t, 'Tolerance', M) // [w initialcross finalcross midreference]= pulsewidth(x, t,'StateLevels', O) // [w initialcross finalcross midreference]= pulsewidth(x, t,'StateLevels', O, 'fig', on or off) - // + // // Parameters // x: real vector. // Fs: specifies the sample rate, Fs, as a positive scalar, where the first sample instant corresponds to a time of zero. @@ -26,29 +27,38 @@ function [w, initialcross, finalcross, midreference]=pulsewidth(x, varargin) // Polarity: specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive'. // MidPercentReferenceLevel: specify the mid percent reference leves as a percentage, default value of N is 50. // Tolerance: define the tolerance value as real scaler value, where default value of M is 2.0. - // StateLevels: define the lower and upper state levels as two element real vector. + // StateLevels: define the lower and upper state levels as two element real vector. // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'. // w: returns a vector of difference between the mid-crossings of the initial and final transitions of each positive-polarity pulse found in the input signal. // initialcross: returns a vector of initial cross values of bilevel waveform transitions X. // finalcross: returns a vector of final cross values of bilevel waveform transitions X. // midreference: return mid reference value corrosponding to mid percenr reference value. - + // Examples - // x=[1.2, 5, 10, -20, 12] - //t=1:length(x) - //w=pulsewidth(x, t) + //x = fscanfMat("macros/pulsedata_x.txt"); + //t = fscanfMat("macros/pulsedata_t.txt"); + //clf + //p = pulsewidth(x,t,'fig','ON') + + //Output + // p = + // + // 0.1501572 + // it also generates a pulse with pulse width and annotations + + // See also // Authors // Jitendra Singh - - - // run statelevels and midcross function before running risetime function. - + + + // run statelevels and midcross function before running risetime function. + if or(type(x)==10) then error ('Input arguments must be double.') -end - - +end + + if length(varargin)==0 then varargin=varargin; end @@ -56,13 +66,13 @@ end sindex=[]; if length(varargin)>=1 then a=1; -for i=1:length(varargin) +for i=1:length(varargin) if type(varargin(i))==10 then sindex(a)=i; a=a+1; - end + end +end end -end pol='POSITIVE'; @@ -72,206 +82,206 @@ index_on=[]; if (~isempty(sindex)) then for j=1:length(sindex) select convstr(varargin(sindex(j)), 'u') // validating input variable names - case {'STATELEVELS'} - + case {'STATELEVELS'} + if length(varargin) <=sindex(j) then error(strcat(['parameter StateLevels required a value'])); end - + if type(varargin(sindex(j)+1))==1 then - levels=varargin(sindex(j)+1); - + levels=varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - - error('parameter StateLevels required a value.') - - + + error('parameter StateLevels required a value.') + + elseif type(varargin(sindex(j)+1))==10 then - + error('Expected STATELEVELS to be one of these types: double, Instead its type was char.') end - - - case {'MIDPERCENTREFERENCELEVEL'} - + + + case {'MIDPERCENTREFERENCELEVEL'} + if length(varargin) <=sindex(j) then - error(strcat(['parameter MidPercentRefernceLevel required a value.'])); + error(strcat(['parameter MidPercentRefernceLevel required a value.'])); end - + if type(varargin(sindex(j)+1))==1 then - midpercentval= varargin(sindex(j)+1); - elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - error('parameter MidPercentRefernceLevel required a value.') - - elseif type(varargin(sindex(j)+1))==10 then - error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.') + midpercentval= varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then + error('parameter MidPercentRefernceLevel required a value.') + + elseif type(varargin(sindex(j)+1))==10 then + error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.') end - - - - case {'TOLERANCE'} - + + + + case {'TOLERANCE'} + if length(varargin) <=sindex(j) then error(strcat(['parameter Tolerance required a value"])); - + elseif type(varargin(sindex(j)+1))==1 then - tolerance= varargin(sindex(j)+1); - + tolerance= varargin(sindex(j)+1); + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - + error('parameter Tolerance required a value.'); - + elseif type(varargin(sindex(j)+1))==10 then - + error('Expected Tolerance to be one of these types: double, Instead its type was char.'); - end - - + end + + case {'FIG'} - + if length(varargin) <=sindex(j) then error(strcat(['parameter fig required a value.'])); end - + if type(varargin(sindex(j)+1))==1 then error ('Expected fig to match one of these strings: on or off'); - - elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then - error('parameter fig required a value.') - else + + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then + error('parameter fig required a value.') + else fig= convstr(varargin(sindex(j)+1), 'u'); - - end - - - if fig == 'OFF' | fig == 'ON' then - else + + end + + + if fig == 'OFF' | fig == 'ON' then + else error('Expected fig to match one of these strings: on or off'); - end - - - - case{'ON'} + end + + + + case{'ON'} index_on=sindex(j) if length(varargin) == 1 then - error ('Unexpected input.') - - + error ('Unexpected input.') + + elseif type(varargin(sindex(j)-1))==1 then - error ('Unexpected input.'); + error ('Unexpected input.'); elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then error('Unexpected input'); end - + case{'OFF'} - + if length(varargin) == 1 then - error ('Unexpected input.') - - + error ('Unexpected input.') + + elseif type(varargin(sindex(j)-1))==1 then - error ('Unexpected input.'); + error ('Unexpected input.'); elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then error('Unexpected input'); - end - - - - + end + + + + case{'POLARITY'} if length(varargin)<=sindex(j) then error ('Parameter polarity requires a value.') end - + if type( varargin(sindex(j)+1))==1 then error ('POLARITY must be either ''Positive'' or ''Negative''.') - + elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' then - + error ('Parameter polarity requires a value.') - - + + elseif convstr(varargin(sindex(j)+1), 'u') ~= 'POSITIVE' & convstr(varargin(sindex(j)+1), 'u')~= 'NEGATIVE' then - + error ('POLARITY must be either ''Positive'' or ''Negative''.'); - - else - polidx=sindex(j); - end - - + + else + polidx=sindex(j); + end + + case {'POSITIVE'} - + if j==1 then error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY' error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); else polinputidx= sindex(j); - - pol= convstr(varargin (sindex(j)), 'u') ; + + pol= convstr(varargin (sindex(j)), 'u') ; end - + case {'NEGATIVE'} - + if j==1 then error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY' error(strcat(['Unexpected option:', " ", varargin(sindex(j))])); else polinputidx= sindex(j); - - pol= convstr(varargin (sindex(j)), 'u') ; - end - - else + + pol= convstr(varargin (sindex(j)), 'u') ; + end + + else error(strcat(['Invalid optional argument'," ", varargin(sindex(j))])); end // switch end // for end // if -// +// if length(index_on)>0 then - varargin(index_on)='OFF'; + varargin(index_on)='OFF'; end if length(polidx)>0 then - varargin(polidx)=null(); + varargin(polidx)=null(); varargin(polinputidx-1)=null(); end - [crossval midref levels t tolerance]= midcross(x, varargin(:)); - + [crossval midref levels t tolerance]= midcross(x, varargin(:)); + upperbound= levels(2)- (tolerance/100)*(levels(2)-levels(1)); mostupperbound=levels(2)+ (tolerance/100)*(levels(2)-levels(1)); lowerbound= levels(1)+ (tolerance/100)*(levels(2)-levels(1)); - mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1)); + mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1)); int_pos=[]; final_pos=[]; int_neg=[]; - final_neg=[]; - + final_neg=[]; + if length(crossval)>=2 then if x(1)>midref then - + int_pos=crossval(2:2:$); final_pos=crossval(3:2:$); int_neg=crossval(1:2:$); final_neg=crossval(2:2:$); else - + int_pos=crossval(1:2:$); final_pos=crossval(2:2:$); int_neg=crossval(2:2:$); final_neg=crossval(3:2:$); - + end if length(int_pos)>length(final_pos) then @@ -282,11 +292,11 @@ elseif length(int_neg)>length(final_neg) then end - + ////////////////////////////////////////////////////////////////////////////////////////// - + w=[]; - + if pol=='POSITIVE' then w=final_pos-int_pos; initialcross=int_pos; @@ -295,77 +305,77 @@ w=[]; w=final_neg-int_neg; initialcross=int_neg; finalcross=final_neg; - + end - + midreference=midref; // return midreference value if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels - + if length(w)==0 then - + plot(t,x, 'LineWidth',1, 'color', 'black') // xtitle('', 'Time (second)','Level (Volts)' ); plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5) - + plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - - plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) - + + plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) + plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - + plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5) - + plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5) - - plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) - + + plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) + xlabel("Time (second)", "fontsize",3, "color", "black" ) - ylabel("Level (Volts)", "fontsize",3, "color", "black" ) - + ylabel("Level (Volts)", "fontsize",3, "color", "black" ) + + + legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?') + - legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?') - + else - else - plot(t,x, 'LineWidth',1, 'color', 'black') - + plot(t,midreference * ones(1, length(t)),'-g', 'LineWidth',0.5) - + rects=[initialcross; levels(2)*ones(w); w; (levels(2)-levels(1))*ones(w)] col=-10*ones(w); midc=[initialcross, finalcross]; midcross=gsort(midc, 'c','i' ) - + plot(midcross, midreference*ones(midcross), "r*", 'MarkerSize',15); plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - - plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) - + + plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5) + plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5) - + plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5) - + plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5) - + plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5) - - plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) - + + plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5) + xrects(rects, col); - + xlabel("Time (second)", "fontsize",3, "color", "black" ) - ylabel("Level (Volts)", "fontsize",3, "color", "black" ) - + ylabel("Level (Volts)", "fontsize",3, "color", "black" ) + - legends(["pulsewidth"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;3], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?') + legends(["pulsewidth"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;3], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], 1) - end - end -// + end + end +// // endfunction diff --git a/macros/resample.sci b/macros/resample.sci index 3e0e878..e2d9f79 100644 --- a/macros/resample.sci +++ b/macros/resample.sci @@ -1,18 +1,22 @@ function [y, h] = resample( x, p, q, h ) //This function resamples in the input sequence x supplied by a factor of p/q. + //Calling Sequence //y = resample(x, p, q) //y = resample(x, p, q, h) //[y, h] = resample(...) -//Parameters + +//Parameters //x: scalar, vector or matrix of real or complex numbers //p: positive integer value //q: positive integer value //h: scalar, vector or matrix of real or complex numbers + //Description //This is an Octave function. -//This function resamples in the input sequence x supplied by a factor of p/q. If x is a matrix, then every column is resampled.hange the sample rate of x by a factor of p/q. -//This is performed using a polyphase algorithm. The impulse response h, given as parameter 4, of the antialiasing filter is either specified or designed with a Kaiser-windowed sinecard. +//This function resamples in the input sequence x supplied by a factor of p/q. If x is a matrix, then every column is resampled.hange the sample rate of x by a factor of p/q. +//This is performed using a polyphase algorithm. The impulse response h, given as parameter 4, of the antialiasing filter is either specified or designed with a Kaiser-windowed sinecard. + //Examples //resample(1,2,3) //ans = 0.66667 @@ -41,4 +45,115 @@ end endfunction +//************************************************************************************************** +//Tried to impement without callOctave but fot this it requires ufirdn function which implemented in .cc file in octave, simple implementation of upfirdn doesn't work for resample function +//************************************************************************************************** + + +//function [y, h] = resample( x, p, q, h ) +// nargin = argn(2); +// +// [rows, columns] = size(x) ; +// +// if nargin < 3 | nargin > 4 +// error("resample.sci : invalid number of inputs"); +// elseif or([p q]<=0) | or([p q]~=floor([p q])), +// error("resample.sci: p and q must be positive integers"); +// end +// +//// ## simplify decimation and interpolation factors +// +// great_common_divisor=gcd([p,q]); +// if (great_common_divisor>1) +// p = double(p) / double (great_common_divisor); +// q = double(q) / double (great_common_divisor); +// else +// p = double(p); +// q = double(q); +// end +// +//// ## filter design if required +// +// if (nargin < 4) +// +//// ## properties of the antialiasing filter +// +// log10_rejection = -3.0; +// stopband_cutoff_f = 1 / (2 * max (p, q)); +// roll_off_width = stopband_cutoff_f / 10.0; +// +//// ## determine filter length +//// ## use empirical formula from [2] Chap 7, Eq. (7.63) p 476 +// +// rejection_dB = -20.0*log10_rejection; +// L = ceil((rejection_dB-8.0) / (28.714 * roll_off_width)); +// +//// ## ideal sinc filter +// +// t=(-L:L)'; +// ideal_filter=2*p*stopband_cutoff_f*sinc(2*stopband_cutoff_f*t); +// +//// ## determine parameter of Kaiser window +//// ## use empirical formula from [2] Chap 7, Eq. (7.62) p 474 +// +// if ((rejection_dB>=21) & (rejection_dB<=50)) +// beta = 0.5842 * (rejection_dB-21.0)^0.4 + 0.07886 * (rejection_dB-21.0); +// elseif (rejection_dB>50) +// beta = 0.1102 * (rejection_dB-8.7); +// else +// beta = 0.0; +// end +// +//// ## apodize ideal filter response +// +// h=kaiser(2*L+1,beta).*ideal_filter; +// +// end +// +//// ## check if input is a row vector +// isrowvector=%F; +// if ((rows==1) & (columns>1)) +// x=x(:); +// isrowvector=%T; +// end +// +//// ## check if filter is a vector +// if ~isvector(h) +// error("resample.sci: the filter h should be a vector"); +// end +// +// Lx = rows; +// Lh = length(h); +// L = ( Lh - 1 )/2.0; +// Ly = ceil(Lx*p/q); +// +//// ## pre and postpad filter response +// +// nz_pre = floor(q-pmodulo(L,q)); +//// hpad = prepad(h,Lh+nz_pre); +// hpad = h ; +// for i = 1:Lh+nz_pre-length(h) +// hpad = [0;hpad]; +// end +// +// offset = floor((L+nz_pre)/q); +// nz_post = 0; +// while ceil( ( (Lx-1)*p + nz_pre + Lh + nz_post )/q ) - offset < Ly +// nz_post = nz_post + 1; +// end +// +// //hpad = postpad(hpad,Lh + nz_pre + nz_post); +// for i = 1:Lh + nz_pre + nz_post-length(hpad) +// hpad = [hpad;0]; +// end +// +//// ## filtering +// xfilt = upfirdn(x,hpad,p,q); +// y = xfilt(offset+1:offset+Ly,:); +// +// if isrowvector, +// y=y.'; +// end +// +//endfunctio diff --git a/macros/sftrans.sci b/macros/sftrans.sci index 916d44d..2dfd2bb 100644 --- a/macros/sftrans.sci +++ b/macros/sftrans.sci @@ -1,74 +1,180 @@ -function [Sz, Sp, Sg] = sftrans (Sz, Sp, Sg, W, stop) -//Transform band edges of a generic lowpass filter (cutoff at W=1) represented in splane zero-pole-gain form. -//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 of target filter. -//stop: True for high pass and band stop filters or false for low pass and band pass filters. -//Description -//This is an Octave function. -//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 -// S -> C S/Fc gain: C/Fc gain: Fc/C -// ---------------- ------------------------- ------------------------ -// High Pass zero: Fc C/x pole: Fc C/x -// S -> C Fc/S pole: 0 zero: 0 -// gain: -x gain: -1/x -// ---------------- ------------------------- ------------------------ -// Band Pass zero: b +- sqrt(b^2-FhFl) pole: b +- sqrt(b^2-FhFl) -// S^2+FhFl pole: 0 zero: 0 -// S -> C -------- gain: C/(Fh-Fl) gain: (Fh-Fl)/C -// S(Fh-Fl) b=x/C (Fh-Fl)/2 b=x/C (Fh-Fl)/2 -// ---------------- ------------------------- ------------------------ -// Band Stop zero: b +- sqrt(b^2-FhFl) pole: b +- sqrt(b^2-FhFl) -// S(Fh-Fl) pole: +-sqrt(-FhFl) zero: +-sqrt(-FhFl) -// S -> C -------- gain: -x gain: -1/x -// S^2+FhFl b=C/x (Fh-Fl)/2 b=C/x (Fh-Fl)/2 -// ---------------- ------------------------- ------------------------ -// Bilinear zero: (2+xT)/(2-xT) pole: (2+xT)/(2-xT) -// 2 z-1 pole: -1 zero: -1 -// S -> - --- gain: (2-xT)/T gain: (2-xT)/T -// T z+1 -// ---------------- ------------------------- ------------------------ -// -//where C is the cutoff frequency of the initial lowpass filter, Fc is the edge of the target low/high pass filter and [Fl,Fh] are the edges of the target band pass/stop filter. With abundant tedious -//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: +// Copyright (C) 2018 - IIT Bombay - FOSSEE // -// H(S)=g prod(S-Xi)/prod(S-Xj) -//Examples -//[Sz, Sp, Sg] = sftrans (5, 10, 15, 20, 30) -//Sz = 4 -//Sp = 2 -//Sg = 7.5000 +// 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 +// 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 + // S -> C S/Fc gain: C/Fc gain: Fc/C + // ---------------- ------------------------- ------------------------ + // High Pass zero: Fc C/x pole: Fc C/x + // S -> C Fc/S pole: 0 zero: 0 + // gain: -x gain: -1/x + // ---------------- ------------------------- ------------------------ + // Band Pass zero: b +- sqrt(b^2-FhFl) pole: b +- sqrt(b^2-FhFl) + // S^2+FhFl pole: 0 zero: 0 + // S -> C -------- gain: C/(Fh-Fl) gain: (Fh-Fl)/C + // S(Fh-Fl) b=x/C (Fh-Fl)/2 b=x/C (Fh-Fl)/2 + // ---------------- ------------------------- ------------------------ + // Band Stop zero: b +- sqrt(b^2-FhFl) pole: b +- sqrt(b^2-FhFl) + // S(Fh-Fl) pole: +-sqrt(-FhFl) zero: +-sqrt(-FhFl) + // S -> C -------- gain: -x gain: -1/x + // S^2+FhFl b=C/x (Fh-Fl)/2 b=C/x (Fh-Fl)/2 + // ---------------- ------------------------- ------------------------ + // Bilinear zero: (2+xT)/(2-xT) pole: (2+xT)/(2-xT) + // 2 z-1 pole: -1 zero: -1 + // S -> - --- gain: (2-xT)/T gain: (2-xT)/T + // T z+1 + // ---------------- ------------------------- ------------------------ + // + //where C is the cutoff frequency of the initial lowpass filter, Fc is the edge of the target low/high pass filter and [Fl,Fh] are the edges of the target band pass/stop filter. With abundant tedious + //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 + // Sg = + // + // 0.75 + // Sp = + // + // 5. 4. 3.3333333 + // Sz = + // + // 20. 10. 6.6666667 + + funcprot(0); + [nargout nargin]= argn(); + + if (nargin ~= 5) + error("sftrans: Wrong number of input arguments.") + end -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 5 | rhs > 5) -error("Wrong number of input arguments.") -end + if stop == %T then + elseif stop == %F + elseif stop == 1 + elseif stop == 0 + else + error("sftrans: stop must be true (%T or 1) or false (%F or 0)") + end -select(rhs) - - case 5 then - if(lhs==1) - Sz = callOctave("sftrans",Sz, Sp, Sg, W, stop) - elseif(lhs==2) - [Sz, Sp] = callOctave("sftrans",Sz, Sp, Sg, W, stop) - elseif(lhs==3) - [Sz, Sp, Sg] = callOctave("sftrans",Sz, Sp, Sg, W, stop) - else - error("Wrong number of output argments.") - end + C = 1; + p = length(Sp); + z = length(Sz); + if z > p | p == 0 + error("sftrans: must have at least as many poles as zeros in s-plane"); + end - end + if length(W)==2 + Fl = W(1); + Fh = W(2); + if stop + // ---------------- ------------------------- ---------------------- + // Band Stop zero: b ± sqrt(b^2-FhFl) pole: b ± sqrt(b^2-FhFl) + // S(Fh-Fl) pole: ±sqrt(-FhFl) zero: ±sqrt(-FhFl) + // S -> C -------- gain: -x gain: -1/x + // S^2+FhFl b=C/x (Fh-Fl)/2 b=C/x (Fh-Fl)/2 + // ---------------- ------------------------- ---------------------- + if (isempty(Sz)) + Sg = Sg * real (1 ./ prod(-Sp)); + elseif (isempty(Sp)) + Sg = Sg * real(prod(-Sz)); + else + Sg = Sg * real(prod(-Sz)/prod(-Sp)); + end + b = (C*(Fh-Fl)/2)./Sp; + 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))]; + 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))]; + end + end + else + // ---------------- ------------------------- ---------------------- + // Band Pass zero: b ± sqrt(b^2-FhFl) pole: b ± sqrt(b^2-FhFl) + // S^2+FhFl pole: 0 zero: 0 + // S -> C -------- gain: C/(Fh-Fl) gain: (Fh-Fl)/C + // S(Fh-Fl) b=x/C (Fh-Fl)/2 b=x/C (Fh-Fl)/2 + // ---------------- ------------------------- ---------------------- + Sg = Sg * (C/(Fh-Fl))^(z-p); + b = Sp*((Fh-Fl)/(2*C)); + Sp = [b+sqrt(b.^2-Fh*Fl), b-sqrt(b.^2-Fh*Fl)]; + if isempty(Sz) + Sz = zeros(1,p); + else + b = Sz*((Fh-Fl)/(2*C)); + Sz = [b+sqrt(b.^2-Fh*Fl), b-sqrt(b.^2-Fh*Fl)]; + if (p>z) + Sz = [Sz, zeros(1, (p-z))]; + end + end + end + else + Fc = W; + if stop + // ---------------- ------------------------- ---------------------- + // High Pass zero: Fc C/x pole: Fc C/x + // S -> C Fc/S pole: 0 zero: 0 + // gain: -x gain: -1/x + // ---------------- ------------------------- ---------------------- + if (isempty(Sz)) + Sg = Sg * real (1 ./ prod(-Sp)); + elseif (isempty(Sp)) + Sg = Sg * real(prod(-Sz)); + else + Sg = Sg * real(prod(-Sz)/prod(-Sp)); + end + Sp = C * Fc ./ Sp; + if isempty(Sz) + Sz = zeros(1,p); + else + Sz = [C * Fc ./ Sz]; + if (p > z) + Sz = [Sz, zeros(1,p-z)]; + end + end + else + // ---------------- ------------------------- ---------------------- + // Low Pass zero: Fc x/C pole: Fc x/C + // S -> C S/Fc gain: C/Fc gain: Fc/C + // ---------------- ------------------------- ---------------------- + Sg = Sg * (C/Fc)^(z-p); + Sp = Fc * Sp / C; + Sz = Fc * Sz / C; + end + end endfunction diff --git a/macros/sigmoid_train.sci b/macros/sigmoid_train.sci index 181584a..6f67d4b 100644 --- a/macros/sigmoid_train.sci +++ b/macros/sigmoid_train.sci @@ -1,24 +1,88 @@ -function y =sigmoid_train(t, ranges, rc) +function y = sigmoid_train(t, ranges, rc) // Evaluate a train of sigmoid functions at T. + //Calling Sequence //y = sigmoid_train(t, ranges, rc) + //Parameters //t: integer //ranges: matrix +//rc:timeconstant + //Description //The number and duration of each sigmoid is determined from RANGES. Each row of RANGES represents a real interval, e.g. if sigmoid 'i' starts at 't=0.1' and ends at 't=0.5', then 'RANGES(i,:) = [0.1 0.5]'. The input RC is an array that defines the rising and falling time constants of each sigmoid. Its size must equal the size of RANGES. + //Examples //sigmoid_train(0.1,[1:3],4) -//ans = -// 0.27375 + +//Output : +// ans = +// +// 0.2737470 + + + funcprot(0); -rhs=argn(2); -if (rhs<3 | rhs>3) then - error("Wrong number of input arguments"); -end - -select(rhs) -case 3 then - y=callOctave("sigmoid_train", t, ranges, rc) -end + +//************************************************************************************************** +//______________________________________________version1 code (not working)_________________________ +//__________________________________________________________________________________________________ +//************************************************************************************************** + + +//rhs=argn(2); +//if (rhs<3 | rhs>3) then +// error("Wrong number of input arguments"); +//end +// +//select(rhs) +//case 3 then +// y=callOctave("sigmoid_train", t, ranges, rc) +//end + + +//************************************************************************************************** +//______________________________________________version2 code ( working)____________________________ +//__________________________________________________________________________________________________ +//************************************************************************************************** + + nRanges = size (ranges, 1); + if isscalar (rc) + + rc = rc * ones (nRanges,2); + + elseif or( size(rc) ~= [1 1]) + + if length(rc) ~= nRanges + error('signalError','Length of time constant must equal number of ranges.') + end + if isrow (rc) + rc = rc'; + end + rc = repmat (rc,1,2); + + end + + + flag_transposed = %F; + if iscolumn (t) + t = t.'; + flag_transposed = %T; + end + [ncol nrow] = size (t); + + T = repmat (t, nRanges, 1); + RC1 = repmat (rc(:,1), 1, nrow); + RC2 = repmat (rc(:,2), 1, nrow); + a_up = (repmat (ranges(:,1), 1 ,nrow) - T)./RC1; + a_dw = (repmat (ranges(:,2), 1 ,nrow) - T)./RC2; + + + Y = 1 ./ ( 1 + exp (a_up) ) .* (1 - 1 ./ ( 1 + exp (a_dw) ) ) + y = max(Y,'r'); + + if flag_transposed + y = y.'; + end + endfunction diff --git a/macros/stmcb.sci b/macros/stmcb.sci index 938bc77..97bdea8 100644 --- a/macros/stmcb.sci +++ b/macros/stmcb.sci @@ -1,4 +1,5 @@ //Compute linear model using Steiglitz-McBride iteration + //calling syntax //[b,a] = stmcb(h,nb,na) //[b,a] = stmcb(y,x,nb,na) @@ -6,14 +7,27 @@ //[b,a] = stmcb(y,x,nb,na,niter) //[b,a] = stmcb(h,nb,na,niter,ai) //[b,a] = stmcb(y,x,nb,na,niter,ai) -//b,a : coefficients of the system b(z)/a(z) + +//Parameters : +//b,a : coefficients of the system function,nb is number of zeros and na is number of poles //h:impulse response of the system //x,y: input and output of same length given to the system //niter: no of iterations //ai:initial estimate of the denominator coefficients //Accepts only real i/ps , imaginary i/ps are not accepted due to limitations of the 'filter' function in Scilab + +//Example +//h = fscanfMat("macros/stmcb_h_data.txt"); +//stmcb(h,4,4) +//Output : +// ans = +// +// 0.0003 0.0010284 0.0147159 - 0.0077914 0.0316548 + + + function [b,a] = stmcb( x, u_in, q, p, niter, a_in ) - + narginchk(3, 6, argn(2)); //modify stmcb to handle exceptions when i/p is char if(type(x)==10 | type(u_in)==10) then @@ -25,68 +39,68 @@ function [b,a] = stmcb( x, u_in, q, p, niter, a_in ) p = q; q = u_in; a_in = prony(x, 0, p); - + elseif argn(2) == 4 niter = p; p = q; q = u_in; a_in = prony(x, 0, p); - + elseif argn(2) == 5 a_in = niter; niter = p; p = q; q = u_in; - + end [x_row, x_col] = size(x); - u_in = zeros(x_row, x_col); + u_in = zeros(x_row, x_col); u_in(1) = 1; - + else if length(u_in) ~= length(x) then error('Input Signal x and Output Signal Y must have the same length'); end - + if argn(2) < 6 then [b, a_in] = prony(x, 0, p); end - + if argn(2) < 5 then - niter = 5; + niter = 5; end - + end - + a = a_in; N = length(x); - + for i = 1:niter u = filter(1, a, x); v = filter(1, a, u_in); C1 = convmtx(u(:),p+1); C2 = convmtx(v(:),q+1); T = [ -C1(1:N,:) C2(1:N,:)]; - c = T(:,2:p+q+2)\(-T(:,1)); + c = T(:,2:p+q+2)\(-T(:,1)); a = [1; c(1:p)]; - b = c(p+1:p+q+1); - + b = c(p+1:p+q+1); + end - + a = a.'; - b = b.'; - - - + b = b.'; + + + endfunction function narginchk(min_argin, max_argin, num_of_argin) if num_of_argin < min_argin then error('Not enough input arguments') end - + if num_of_argin > max_argin then error('Too many input arguments') end - + endfunction diff --git a/macros/stmcb_h_data.txt b/macros/stmcb_h_data.txt new file mode 100644 index 0000000..2fdeae3 --- /dev/null +++ b/macros/stmcb_h_data.txt @@ -0,0 +1,64 @@ +0.000300 +0.003300 +0.014900 +0.043200 +0.091100 +0.149300 +0.198500 +0.219000 +0.200700 +0.147900 +0.076400 +0.007000 +-0.042900 +-0.064900 +-0.060100 +-0.037500 +-0.009200 +0.014200 +0.026500 +0.026700 +0.018000 +0.005700 +-0.005200 +-0.011500 +-0.012300 +-0.008800 +-0.003300 +0.001800 +0.005000 +0.005700 +0.004300 +0.001800 +-0.000600 +-0.002100 +-0.002600 +-0.002100 +-0.001000 +0.000100 +0.000900 +0.001200 +0.001000 +0.000500 +0.000000 +-0.000400 +-0.000500 +-0.000500 +-0.000300 +-0.000000 +0.000200 +0.000200 +0.000200 +0.000100 +0.000000 +-0.000100 +-0.000100 +-0.000100 +-0.000100 +-0.000000 +0.000000 +0.000000 +0.000000 +0.000000 +0.000000 +-0.000000 diff --git a/macros/tf2zp.sci b/macros/tf2zp.sci index 7c482d5..ca10fd4 100644 --- a/macros/tf2zp.sci +++ b/macros/tf2zp.sci @@ -1,72 +1,100 @@ -// Transfer function to zero pole conversion -//[z,p,k]= tf2zp(b,a); -//z=zeros of the corrsponding tf -//p=poles of the corresponding tf -//k=gain of the tf -//b=vector containing the numerator coefficients of the transfer function in descending powers of s -//a=vector containing the denominator coefficients of the transfer function in descending powers of s -//For discrete-time transfer functions, it is highly recommended to -//make the length of the numerator and denominator equal to ensure -//correct results. You can do this using the function EQTFLENGTH in -//the Signal Processing Toolbox. +// Copyright (C) 2018 - IIT Bombay - FOSSEE // -// -//Author -//Debdeep Dey +// 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 contribution: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in function [z,p,k]=tf2zp(num,den) -numop=argn(1); -//take only the first row of numerator into consideration -num=num(1,:); -//remove leading columns of zeros from numerator -if ~isempty(num) then - while(num(:,1)==0 & length(num)>1) - num(:,1)=[]; - end -end -[rd,cod]=size(den); -[ny,np]=size(num); -if(rd>1) then - error("Denominator must be row vector"); -elseif np>cod then - error("Improper transfer function"); -end -if (~isempty(den)) then - coef=den(1); -else - coef=1; -end -if coef ==0 then - error("Denominator must have non zero leading coefficient"); -end -//remove leading columns of zeros from numerator -if ~isempty(num) then - while(num(:,1)==0 & length(num)>1) - num(:,1)=[]; - end -end + // Transfer function to zero pole conversion -if (find(den==%inf) ~= [] | find(num==%inf) ~= []) then - error("Input to ROOTS must not contain NaN or Inf") -end -//poles + //Calling Sequence + //[z,p,k]= tf2zp(b,a); -p=roots(den); -//zeros and gain + //Parameters + //z=zeros of the corrsponding tf + //p=poles of the corresponding tf + //k=gain of the tf + //b=vector containing the numerator coefficients of the transfer function in descending powers of s/z + //a=vector containing the denominator coefficients of the transfer function in descending powers of s/z -k=zeros(ny,1); -linf=%inf; + //For discrete-time transfer functions, it is highly recommended to + //make the length of the numerator and denominator equal to ensure + //correct results. You can do this using the function EQTFLENGTH in + //the Signal Processing Toolbox. -z=linf(ones(np-1,1),ones(ny,1)); -for i=1:ny - zz=roots(num(i,:)); - if ~isempty(zz), z(1:length(zz), i) = zz; end - ndx = find(num(i,:)~=0); - if ~isempty(ndx), k(i,1) = num(i,ndx(1))./coef; end -end -z=roots(num); -endfunction + //Author : Debdeep Dey + + //Example : + //b = [1 2 3]; + //a = [4 5 6]; + //[z p k] = tf2zp(b,a) + //Output: + //k = + // + // 0.25 + // p = + // + // - 0.625 + 1.0532687i + // - 0.625 - 1.0532687i + // z = + // + // - 1. + 1.4142136i + // - 1. - 1.4142136i + + numop=argn(1); + //take only the first row of numerator into consideration + num=num(1,:); + //remove leading columns of zeros from numerator + if ~isempty(num) then + while(num(:,1)==0 & length(num)>1) + num(:,1)=[]; + end + end + [rd,cod]=size(den); + [ny,np]=size(num); + if(rd>1) then + error("Denominator must be row vector"); + elseif np>cod then + error("Improper transfer function"); + end + if (~isempty(den)) then + coef=den(1); + else + coef=1; + end + if coef ==0 then + error("Denominator must have non zero leading coefficient"); + end + //remove leading columns of zeros from numerator + if ~isempty(num) then + while(num(:,1)==0 & length(num)>1) + num(:,1)=[]; + end + end + if (find(den==%inf) ~= [] | find(num==%inf) ~= []) then + error("Input to ROOTS must not contain NaN or Inf") + end + //poles + p=roots(den); + //zeros and gain + + k=zeros(ny,1); + linf=%inf; + + z=linf(ones(np-1,1),ones(ny,1)); + for i=1:ny + zz=roots(num(i,:)); + if ~isempty(zz), z(1:length(zz), i) = zz; end + ndx = find(num(i,:)~=0); + if ~isempty(ndx), k(i,1) = num(i,ndx(1))./coef; end + end + z=roots(num); +endfunction diff --git a/macros/ultrwin.sci b/macros/ultrwin.sci index 91119eb..fb49f1c 100644 --- a/macros/ultrwin.sci +++ b/macros/ultrwin.sci @@ -1,22 +1,26 @@ function [w, xmu] = ultrwin (m, mu, par, key, norm) //This function returns the coefficients of an Ultraspherical window. + //Calling Sequence //w = ultrwin (m, mu, par) //w = ultrwin (m, mu, par, key) //w = ultrwin (m, mu, par, key, norm) //[w, xmu] = ultrwin (...) + //Parameters //m: positive integer value //mu: //par: //key: //norm: + //Description //This is an Octave function. //This function returns the coefficients of an Ultraspherical window of length m supplied as input, to the output vector w. //The second parameter controls the ratio between side lobe to side lobe of the window's Fourier transform. //The third parameter controls the ratio between main lobe width to side lobe. The default value is beta. //The value of xmu is also returned for given beta, att or latt. + //Examples //ultrwin(3,-0.4,0.5) //ans = diff --git a/macros/validate_filter_bands.sci b/macros/validate_filter_bands.sci new file mode 100644 index 0000000..cba3dc0 --- /dev/null +++ b/macros/validate_filter_bands.sci @@ -0,0 +1,39 @@ +// 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 +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +// Supporting function + +function validate_filter_bands (func, wp, ws) + funcprot(); + nargin = argn(2); + + if (nargin ~= 3) + error("validate_filter_bands: invalid number of inputs") + elseif (~ (type(func) == 10)) + error ("validate_filter_bands: FUNC must be a string"); + elseif (~ ((isvector (wp) | length(wp) == 1) & (isvector (ws) | length(ws) == 1) & (length (wp) == length (ws)))) + error (msprintf( "%s: WP and WS must both be scalars or vectors of length 2", func)); + elseif (~ ((length (wp) == 1) | (length (wp) == 2))) + error (msprintf("%s: WP and WS must both be scalars or vectors of length 2", func)); + elseif (~ (isreal (wp) & and (wp >= 0) & and (wp <= 1))) + error (msprintf("%s: and elements of WP must be in the range [0,1]",func )); + elseif (~ (isreal (ws) & and (ws >= 0) & and (ws <= 1))) + error (msprintf("%s: and elements of WS must be in the range [0,1]",func )); + elseif ((length (wp) == 2) & (wp(2) <= wp(1))) + error (msprintf("%s: WP(1) must be less than WP(2)",func )) + elseif ((length (ws) == 2) & (ws(2) <= ws(1))) + error (msprintf("%s: WS(1) must be less than WS(2)",func )) + elseif ((length (wp) == 2) & (and (wp > ws) | and (ws > wp))) + error (msprintf("%s: WP must be contained by WS or WS must be contained by WP",func )); + end + +endfunction diff --git a/macros/wconv.sci b/macros/wconv.sci index a0682a6..985c429 100644 --- a/macros/wconv.sci +++ b/macros/wconv.sci @@ -1,33 +1,82 @@ -function y = wconv (type, x, f, shape) -//Performs 1D or 2D convolution. -//Calling Sequence -//y = wconv (type, x, f) -// y = wconv (type, x, f, shape) -//Parameters -//type: convolution type. -//x: Signal vector or matrix. -//f: FIR filter coefficients. -//shape: Shape. -//Description -//This is an Octave function. -//It performs 1D or 2D convolution between the signal x and the filter coefficients f. -//Examples -//a = [1 2 3 4 5] -//b = [7 8 9 10] -//wconv(1,a,b) -//ans = -// 7 22 46 80 114 106 85 50 - -funcprot(0); -rhs = argn(2) -if(rhs<3 | rhs>4) -error("Wrong number of input arguments.") -end - -select (rhs) - case 3 then - y = callOctave("wconv",type, x, f) - case 4 then - y = callOctave("wconv",type, x, f, shape) - end +// 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 +// Author:Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function y = wconv (typ, x, f, shape) + //Performs 1D or 2D convolution. + + //Calling Sequence + //y = wconv (type, x, f) + // y = wconv (type, x, f, shape) + + //Parameters + //type: convolution type. + // 1 or "1" for 1D + // 2 or "2" for 2D + //x: Signal vector or matrix. + //f: FIR filter coefficients. + //shape: Shape. + // "full", computes the full one/two-dimensional convolution. It is the default value. + // "same", computes the central part of the convolution of the same size as x. + // "valid", computes the convolution parts without the zero-padding of x. + + //Description + //It performs 1D or 2D convolution between the signal x and the filter coefficients f. + + //Examples + //a = [1 2 3 4 5] + //b = [7 8 9 10] + //wconv(1,a,b) + //ans = + // 7 22 46 80 114 106 85 50 + + funcprot(0); + rhs = argn(2) + if(rhs<3 | rhs>4) + error("wconv: wrong number of inputs.") + end + + if (or(~ type(x) == [1 5 8]) & ~ or(type(f) == [1 5 8])) then + error("wconv:Arg #2 and #3 must be real or complex matrices/vectors") + end + + if argn(2) == 3 then + shape = "full" + end + + select (typ) + case 1 + if (isvector(x) & isvector(f)) + y = conv2 (x, f, shape); + if ( ~ isrow (x)) + y = y.'; + end + else + error("wconv: Arg #2 and #3 must be vector for 1D convolution") + end + + case "1" + if (isvector(x) & isvector(f)) + y = conv2 (x, f, shape); + if ( ~ isrow (x)) + y = y.'; + end + else + error("wconv: Arg #2 and #3 must be vector for 1D convolution") + end + case 2 + y = conv2 (x, f, shape); + case "2" + y = conv2 (x, f, shape); + else + error('wconv: type must be 1 for 1D convolution and 2 for 2D convolution') + end + endfunction diff --git a/macros/xcorr1.sci b/macros/xcorr1.sci deleted file mode 100644 index 6ae884d..0000000 --- a/macros/xcorr1.sci +++ /dev/null @@ -1,86 +0,0 @@ -function [R, lag] = xcorr1 (X, Y, maxlag, scale) -//Estimates the cross-correlation. -//Calling Sequence -//[R, lag] = xcorr1 (X, Y, maxlag, scale) -//[R, lag] = xcorr1 (X, Y, maxlag) -//[R, lag] = xcorr1 (X, Y) -//Parameters -//X: [non-empty; real or complex; vector or matrix] data. -//Y: [real or complex vector] data. -// If X is a matrix (not a vector), Y must be omitted. Y may be omitted if X is a vector; in this case xcorr estimates the autocorrelation of X. -//maxlag: [integer scalar] maximum correlation lag If omitted, the default value is N-1, where N is the greater of the lengths of X and Y or, if X is a matrix, the number of rows in X. -//scale: [character string] specifies the type of scaling applied to the correlation vector (or matrix). is one of: -// ‘none’ - return the unscaled correlation, R, -//‘biased’ - return the biased average, R/N, -//‘unbiased’ - return the unbiased average, R(k)/(N-|k|), -//‘coeff’ - return the correlation coefficient, R/(rms(x).rms(y)), where "k" is the lag, and "N" is the length of X. If omitted, the default value is "none". If Y is supplied but does not have the same -// length as X, scale must be "none". -//Description -//This is an Octave function. -//Estimate the cross correlation R_xy(k) of vector arguments X and Y or, if Y is omitted, estimate autocorrelation R_xx(k) of vector X, for a range of lags k specified by argument "maxlag". If X is a -//matrix, each column of X is correlated with itself and every other column. -// -//The cross-correlation estimate between vectors "x" and "y" (of length N) for lag "k" is given by -// -// N -// R_xy(k) = sum x_{i+k} conj(y_i), -// i=1 -// -//where data not provided (for example x(-1), y(N+1)) is zero. Note the definition of cross-correlation given above. To compute a cross-correlation consistent with the field of statistics, see xcov. -//Examples -//[R, lag] = xcorr1 ( [5 5], [2 2], 2, 'biased' ) -// -//R = -// -// 0 5 10 5 0 -// -//lag = -// -// -2 -1 0 1 2 - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 1 | rhs > 4) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 2 then - if(lhs==1) - R = callOctave("xcorr", X) - elseif(lhs==2) - [R, lag] = callOctave("xcorr", X) - else - error("Wrong number of output argments.") - end - - case 2 then - if(lhs==1) - R = callOctave("xcorr", X, Y) - elseif(lhs==2) - [R, lag] = callOctave("xcorr", X, Y) - else - error("Wrong number of output argments.") - end - - case 3 then - if(lhs==1) - R = callOctave("xcorr", X, Y, maxlag) - elseif(lhs==2) - [R, lag] = callOctave("xcorr", X, Y, maxlag) - else - error("Wrong number of output argments.") - end - case 4 then - if(lhs==1) - R = callOctave("xcorr", X, Y, maxlag, scale) - elseif(lhs==2) - [R, lag] = callOctave("xcorr", X, Y, maxlag, scale) - else - error("Wrong number of output argments.") - end - - end -endfunction diff --git a/macros/xcov1.sci b/macros/xcov1.sci deleted file mode 100644 index b0bff93..0000000 --- a/macros/xcov1.sci +++ /dev/null @@ -1,35 +0,0 @@ -function [R,lag] = xcov1(X, Y, biasflag) -// Compute covariance at various lags [=correlation(x-mean(x),y-mean(y))]. -//Calling Sequence -//[R, lag] = xcov (X) -//... = xcov (X, Y) -//... = xcov (..., maxlag) -//... = xcov (..., scale) -//Parameters -//X: Input vector -//Y: if specified, compute cross-covariance between X and Y, otherwise compute autocovariance of X. -//maxlag: is specified, use lag range [-maxlag:maxlag], otherwise use range [-n+1:n-1]. -//scale: -// 'biased': for covariance=raw/N, -// 'unbiased': for covariance=raw/(N-|lag|), -// 'coeff': for covariance=raw/(covariance at lag 0), -// 'none': for covariance=raw -// 'none': is the default. -//Description -//Compute covariance at various lags [=correlation(x-mean(x),y-mean(y))]. Returns the covariance for each lag in the range, plus an optional vector of lags. - -funcprot(0); -rhs = argn(2) -if(rhs<1 | rhs>3) -error("Wrong number of input arguments."); -end - - select(rhs) - case 1 then - [R,lag] = callOctave("xcov",X); - case 2 then - [R,lag] = callOctave("xcov",X,Y); - case 3 then - [R,lag] = callOctave("xcov",X,Y,biasflag); - end -endfunction diff --git a/macros/zp2ss.sci b/macros/zp2ss.sci index ab14bfd..1007b9d 100644 --- a/macros/zp2ss.sci +++ b/macros/zp2ss.sci @@ -1,65 +1,54 @@ function [a, b, c, d] = zp2ss (z, p, k) -//Converts zeros / poles to state space. -//Calling Sequence -//[a, b, c, d] = zp2ss (z, p, k) -//[a, b, c] = zp2ss (z, p, k) -//[a, b] = zp2ss (z, p, k) -//a = zp2ss (z, p, k) -//Parameters -//z: Zeros -//p: Poles -//k: Leading coefficient -//a: State space parameter -//a: State space parameter -//b: State space parameter -//c: State space parameter -//d: State space parameter -//Description -//This is an Octave function. -//It converts zeros / poles to state space. -//Examples -//z = [1 2 3] -// p = [4 5 6] -//k = 5 -//[a, b, c, d] = zp2ss (z, p, k) -//a = -// -// -0.00000 0.00000 -1.20000 -// -10.00000 0.00000 -7.40000 -// 0.00000 10.00000 15.00000 -// -//b = -// -// -5.7000 -// -31.5000 -// 45.0000 -// -//c = -// -// 0.00000 0.00000 1.00000 -// -//d = 5 + //Converts zeros / poles to state space. + //Calling Sequence + //[a, b, c, d] = zp2ss (z, p, k) + //[a, b, c] = zp2ss (z, p, k) + //[a, b] = zp2ss (z, p, k) + //a = zp2ss (z, p, k) + //Parameters + //z: Zeros + //p: Poles + //k: Leading coefficient + //a: State space parameter + //a: State space parameter + //b: State space parameter + //c: State space parameter + //d: State space parameter + //Description + //This is an Octave function. + //It converts zeros / poles to state space. + //Examples + //z = [1 2 3] + // p = [4 5 6] + //k = 5 + //[a, b, c, d] = zp2ss (z, p, k) + //a = + // + // -0.00000 0.00000 -1.20000 + // -10.00000 0.00000 -7.40000 + // 0.00000 10.00000 15.00000 + // + //b = + // + // -5.7000 + // -31.5000 + // 45.0000 + // + //c = + // + // 0.00000 0.00000 1.00000 + // + //d = 5 -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 3 | rhs > 3) -error("Wrong number of input arguments.") -end + funcprot(0); + lhs = argn(1) + rhs = argn(2) + if (rhs < 3 | rhs > 3) + error("zp2ss: Wrong number of input arguments.") + end + [num den] = zp2tf(z,p,k); + h = poly(num, "s", "c")/poly(den, "s", "c"); + sys = tf2ss(num, den) + [a b c d] = abcd(sys) -select(rhs) - - case 3 then - if(lhs==1) - a = callOctave("zp2ss", z, p, k) - elseif(lhs==2) - [a, b] = callOctave("zp2ss", z, p, k) - elseif(lhs==3) - [a, b, c] = callOctave("zp2ss", z, p, k) - elseif(lhs==4) - [a, b, c, d] = callOctave("zp2ss", z, p, k) - else - error("Wrong number of output argments.") - end - end endfunction diff --git a/macros/zp2tf.sci b/macros/zp2tf.sci index c830e3d..da3e8b1 100644 --- a/macros/zp2tf.sci +++ b/macros/zp2tf.sci @@ -1,46 +1,56 @@ -function [num, den] = zp2tf (z, p, k) -//Converts zeros / poles to a transfer function. -//Calling Sequence -//[num, den] = zp2tf (z, p, k) -//num = zp2tf (z, p, k) -//Parameters -//z: Zeros -//p: Poles -//k: Leading coefficient -//Num: Numerator of the transfer function -//den: Denomenator of the transfer function -//Description -//This is an Octave function. -//It converts zeros / poles to a transfer function. -//Examples -//z = [1 2 3] -// p = [4 5 6] -//k = 5 -//[num, den] = zp2tf (z, p, k) -//num = -// -// 5 -30 55 -30 -// -//den = +// Copyright (C) 2018 - IIT Bombay - FOSSEE // -// 1 -15 74 -120 - -funcprot(0); -lhs = argn(1) -rhs = argn(2) -if (rhs < 3 | rhs > 3) -error("Wrong number of input arguments.") -end - -select(rhs) - - case 3 then - if(lhs==1) - num = callOctave("zp2tf", z, p, k) - elseif(lhs==2) - [num, den] = callOctave("zp2tf", z, p, k) - else - error("Wrong number of output argments.") - end - end +// 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 +// Author:Sonu Sharma, RGIT Mumbai +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +function [num, den] = zp2tf (z, p, k) + //Converts zeros / poles to a transfer function. + + //Calling Sequence + //[num, den] = zp2tf (z, p, k) + //num = zp2tf (z, p, k) + + //Parameters + //z: Zeros + //p: Poles + //k: Leading coefficient (Gain) + //Num: Numerator coefficients of the transfer function + //den: Denomenator coefficients of the transfer function + + //Description + //It converts zeros / poles representation to transfer function representation. + + //Examples + //z = [1 2 3] + //p = [4 5 6] + //k = 5 + //[num, den] = zp2tf (z, p, k) + //Output : + // den = + // + // 1. - 15. 74. - 120. + // num = + // + // 5. - 30. 55. - 30. + + funcprot(0); + lhs = argn(1) + rhs = argn(2) + if (rhs < 3 | rhs > 3) + error("zp2tf : Wrong number of input arguments.") + end + + n = k*real(poly(z,"x")); + d = real(poly(p, "x")); + num = coeff(n); + num = flipdim(num,2); + den = coeff(d); + den = flipdim(den,2); + endfunction diff --git a/macros/zplane.sci b/macros/zplane.sci index bfa9285..696fef0 100644 --- a/macros/zplane.sci +++ b/macros/zplane.sci @@ -1,16 +1,137 @@ -function [y] = zplane(z,p) -funcprot(0); - -rhs = argn(2) - -if(rhs<1 | rhs>2) -error("Wrong number of input arguments.") -end - select(rhs) - case 1 then - callOctave("zplane",z) - case 2 then - callOctave("zplane",z,p) - end +//Pole-Zero plot for Discrete time systems + +//Calling Sequence +//zplane(z) +//zpalne(z,p) + +//Parameters: +//z: vector containing numerator coefficients +//p: vector containing denumerator coefficients + +//Description: +//This function gives pole zero plote of discrete time systems + +//Example : +//zplane([1 2 3],[4 5 6]) +//Output : +//Output is pole zero plot of respective discrete time system. + + + +//************************************************************************************************** +//______________________________________version1 code (not working)_________________________________ +//__________________________________________________________________________________________________ +//************************************************************************************************** + +//function [y] = zplane(z,p) +//funcprot(0); +// +//rhs = argn(2) +// +//if(rhs<1 | rhs>2) +//error("Wrong number of input arguments.") +//end +// select(rhs) +// case 1 then +// callOctave("zplane",z) +// case 2 then +// callOctave("zplane",z,p) +// end +//endfunction + +//************************************************************************************************** +//______________________________________________version2 code ( working)____________________________ +//__________________________________________________________________________________________________ +//************************************************************************************************** + +function zplane(z,varargin) + + funcprot(0); + + [nargout nargin] = argn(); + if nargin == 1 then + p = []; + else + p = varargin(1); + end + +[rows_z columns_z] = size(z); +[rows_p columns_p] = size(p); + if (nargin < 1 | nargin > 2) + error("Invalid inputs") + end + if columns_z>1 | columns_p>1 + if rows_z>1 | rows_p>1 +// ## matrix form: columns are already zeros/poles + else +// ## z -> b +// ## p -> a + if isempty(z), z=1; end + if isempty(p), p=1; end + + M = length(z) - 1; + N = length(p) - 1; + z = [ roots(z); zeros(N - M, 1) ]; + p = [ roots(p); zeros(M - N, 1) ]; + end + end + + + xmin = min([-1; real(z(:)); real(p(:))]); + xmax = max([ 1; real(z(:)); real(p(:))]); + ymin = min([-1; imag(z(:)); imag(p(:))]); + ymax = max([ 1; imag(z(:)); imag(p(:))]); + xfluff = max([0.05*(xmax-xmin), (1.05*(ymax-ymin)-(xmax-xmin))/10]); + yfluff = max([0.05*(ymax-ymin), (1.05*(xmax-xmin)-(ymax-ymin))/10]); + xmin = xmin - xfluff; + xmax = xmax + xfluff; + ymin = ymin - yfluff; + ymax = ymax + yfluff; + +// text(); +// plot_with_labels(z, "o"); +// plot_with_labels(p, "x"); +// refresh; + + r = exp(2*%i*%pi*[0:100]/100); + plot(real(r), imag(r),'k'); //hold on; +// axis equal; +// grid on; + xgrid ; + mtlb_axis(1.05*[xmin, xmax, ymin, ymax]); + if (~isempty(p)) + h = plot(real(p), imag(p), "bx"); + //set (h, 'MarkerSize', 7); + end + if (~isempty(z)) + h = plot(real(z), imag(z), "bo"); + //set (h, 'MarkerSize', 7); + end + legend('unit circle','poles','zeros'); +// hold off; + endfunction +//function plot_with_labels(x, symbol) +// +// [rows_x columns_x] = size(x); +// +// if ( ~isempty(x) ) +// +// x_u = unique(x(:)); +// +// for i = 1:length(x_u) +// n = sum(x_u(i) == x(:)); +// if (n > 1) +// xstring(real(x_u(i)), imag(x_u(i)), [" " msprintf('string', n)]); +// end +// end +// +// col = "rgbcmy"; +// for c = 1:columns_x +// plot(real( x(:,c) ), imag( x(:,c) ), [col(pmodulo(c,6)),symbol ";;"]); +// end +// +// end +// +//endfunction diff --git a/test1.sce b/test1.sce new file mode 100644 index 0000000..a15ae82 --- /dev/null +++ b/test1.sce @@ -0,0 +1,732 @@ +//exec FOSSEE_Scilab_Octave_Interface_Toolbox/loader.sce + +exec loader.sce +exec builder.sce +exec unloader.sce +exec loader.sce +//cd macros +//getd . + +test_pass=[] +res=[] + + +/////////Test case for 2) arburg ////////// + +a = arburg([1,2,3,4,5],2); +a = round(a*10000)/10000; + +if(a == [1. -1.8639 0.9571]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("arburg test failed") +end + +/////////Test case for 4) aryule ////////// + +a = aryule([1,2,3,4,5],2); +a = round(a*10000)/10000; + +if(a == [1. -0.814 0.1193]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("aryule test failed") +end + +/////////Test case for 5) bitrevorder ////////// + +x = [%i,1,3,6*%i] ; +[y i]=bitrevorder(x); + +if(y == [%i 3 1 6*%i] & i == [1 3 2 4]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("bitrevorder test failed") +end + +/////////Test case for **) digitrevorder ////////// + +x = [%i,1,3,6*%i] ; +b = 2; +[y i]=digitrevorder(x,b); + +if(y == [%i 3 1 6*%i] & i == [1 3 2 4]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("digitrevorder test failed") +end + +/////////Test case for 28) isfir ////////// + +fir = isfir([1 -1 1], 1) + +if(fir == 1) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("isfir test failed") +end + +///////////////////////////////////////////// + + +/////////Test case for 29) islinearphase ////////// + +flag = islinphase([0 1 2 2 1 0],1) + +if(flag == 1) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("islinearphase Test failed") +end + + +///////////////////////////////////////////// + + +/////////Test case for 30) ismaxphase ////////// + +flag = ismaxphase([1 -5 6],1) + +if(flag == 1) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("ismaxphase Test failed") +end + + + +///////////////////////////////////////////// + + +/////////Test case for 31) isminphase ////////// +flag = isminphase([1 -0.3 0.02],1) + +if(flag == 1) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("isminphase Test failed") +end + +///////////////////////////////////////////// + + +/////////Test case for 32) isstable ////////// + +flag = isstable([1 2],[1 -0.7 0.1]) + +if(flag == 1) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("isstable Test failed") +end + +///////////////////////////////////////////// + + +/////////Test case for 33)lar2rc ////////// + +g = [0.6389 4.5989 0.0063 0.0163 -0.0163]; +k = lar2rc(g) + +k=round(k*10000)/10000 + +if(k == [0.3090 0.9801 0.0031 0.0081 -0.0081]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("lar2rc Test failed") +end + + + +///////////////////////////////////////////// + + +/////////Test case for 38)levinson ////////// + +a = [1 0.1 -0.8]; +v = 0.4; +w = sqrt(v)*rand(15000,1,"normal"); +x = filter(1,a,w); + +[r,lg] = xcorr(x,'biased'); +r(lg<0) = []; + +ar = levinson(r,length(a)-1) + +ar = round(ar*10000)/10000 + +if(ar == [1 0.1043 -0.8010]) + test_pass=[test_pass,1] + else + test_pass=[test_pass,0] + disp("levinson Test failed") +end + +///////////////////////////////////////////// + + +/////////Test case for 39) lpc ////////// + +noise = rand(50000,1,"normal"); +x = filter(1,[1 1/2 1/3 1/4],noise); +x = x(45904:50000); +[a,g]= lpc(x,3) +a = round(a*10000)/10000 + +if(a == [1 0.5177 0.3310 0.2572]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("lpc Test failed") +end + +///////////////////////////////////////////// + + +/////////Test case for 40) medfilt1 ////////// + + +fs = 100; +t = 0:1/fs:1; +x = sin(2*%pi*t*3)+0.25*sin(2*%pi*t*40); + +y = medfilt1(x,10); +y = round(y*10000)/10000 ; +y = y' + +if(y == fscanfMat("macros/medfilt1op.txt")) + test_pass=[test_pass,1] + else + test_pass=[test_pass,0] + disp("medfilt1 Test failed") +end + +///////////////////////////////////////////// + + +/////////Test case for 41) movingrms ////////// + + +[a,b]=movingrms ([4.4 94 1;-2 5*%i 5],1,-2) + +b = round(b*10000)/10000 + +if(b == [0.1888 ; 0.1888]) + test_pass=[test_pass,1] + else + test_pass=[test_pass,0] + disp("movingrms Test failed") +end + + + +///////////////////////////////////////////// + + +/////////Test case for 58) pulseperiod ////////// + +x = fscanfMat("macros/pulsedata_x.txt"); +t = fscanfMat("macros/pulsedata_t.txt"); +p = pulseperiod(x,t); +p = round(p*10000)/10000 + +if(p == 0.5003) + test_pass=[test_pass,1] + else + test_pass=[test_pass,0] + disp("pulseperiod Test failed") +end + +/////////////////////////////////////// + +/////////Test case for 59) pulsesep ////////// + +x = fscanfMat("macros/pulsedata_x.txt"); +t = fscanfMat("macros/pulsedata_t.txt"); +p = pulsesep(x,t); +p = round(p*10000)/10000 + +if(p == 0.3501) + test_pass=[test_pass,1] + else + test_pass=[test_pass,0] + disp("pulsesep Test failed") +end + +/////////////////////////////////////// + +/////////Test case for 60) pulsewidth ////////// + +x = fscanfMat("macros/pulsedata_x.txt"); +t = fscanfMat("macros/pulsedata_t.txt"); +p = pulsewidth(x,t); +p = round(p*10000)/10000 + +if(p == 0.1502) + test_pass=[test_pass,1] + else + test_pass=[test_pass,0] + disp("pulsewidth Test failed") +end + + + +///////////////////////////////////////////// + + +/////////Test case for **)sigmoid_train ////////// + +s = sigmoid_train(0.1,[1:3],4) +s = round(s*10000)/10000 + +if(s == 0.2737) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("sigmoid_train Test failed") +end + +///////////////////////////////////////////// + + + +/////////Test case for **)circshift ///////// + + M = [1 2 3 4]; + R = circshift(M, [0 1]) + +if(R == [4 1 2 3]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("circshift failed") +end + +///////////////////////////////////////////// + + + +/////////Test case for **)kaiser ////////// + +win = kaiser(6, 0.2) ; +win = round(win*10000)/10000; + +if(win == [ 0.9901; 0.9964; 0.9996; 0.9996; 0.9964; 0.9901 ]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("kaiser Test failed") +end + +///////////////////////////////////////////// + + +/////////Test case for 78)stmcb ////////// + + +h = fscanfMat("macros/stmcb_h_data.txt"); +H = stmcb(h,4,4); +H = round(H*10000)/10000; + +if(H == [0.0003 0.001 0.0147 -0.0078 0.0317]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("stmcb Test failed") +end + +///////////////////////////////////////////// + + +/////////Test case for autoreg_matrix ////////// +m = autoreg_matrix([1,2,3],2); + +if(m == [1 0 0; 1 1 0; 1 2 1]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("autoreg_matrix test failed") +end + +///////////////////////////////////////////// + + + +/////////Test case for arch_rnd ////////// + +a = [1 2 3 4 5]; +b = [7 8 9 10]; +t = 5 ; +m = arch_rnd (a, b, t); +m = round(m*1000)/1000 + +if(m == [ 7.476 + 67.124 + 671.105 + 7382.441 + 80409.121 ]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("arch_rnd Test failed") +end + +///////////////////////////////////////////// + + + +/////////Test case for arma_rnd ////////// + +a = [1 2 3 4 5]; +b = [7; 8; 9; 10; 11]; +t = 5 ; +v = 10 ; +n = 100 ; +m = arma_rnd (a, b, v, t, n); +m = round(m) ; + +if(m == [ 60562. + 156019. + 401911. + 1035344. + 2667081. ]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("arma_rnd Test failed") +end + +/////////Test case for buttap ////////// + +n = 5 ; +[z p g] = buttap(n); +g = round(g*10000)/10000; + +if(g == 1) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("buttap Test failed") +end + + +/////////Test case for cheb1ap ////////// + +[z p g] = cheb1ap(10, 3); +g = round(g*10000)/10000; + +if(g == 0.002) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("cheb1ap Test failed") +end + +/////////Test case for cheb2ap ////////// + +[z p g] = cheb2ap(4, 10); +g = round(g*10000)/10000; + +if(g == 0.3162) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("cheb2ap Test failed") +end + +/////////Test case for ellipap ////////// + +[z p g] = ellipap(4, 3, 10); +g = round(g*10000)/10000; + +if(g == 0.3162) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("ellipap Test failed") +end + +/////////Test case for ncauer ////////// + +[z p g] = ncauer(3, 10, 4); +g = round(g*10000)/10000; + +if(g == 0.3162) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("ncauer Test failed") +end + +/////////Test case for besselap ////////// + +[z p g] = besselap(5); +g = round(g*10000)/10000; +p = round(p*10000)/10000; + +if(g == 1 & p == [-0.5906+0.9072*%i; -0.5906-0.9072*%i; -0.9264; -0.8516+0.4427*%i; -0.8516-0.4427*%i]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("besselap Test failed") +end + +/////////Test case for zp2tf ////////// + +[num, den] = zp2tf ([1 2 3], [4 5 6], 5); +num = round(num*10000)/10000; +den = round(den*10000)/10000; + +if(num == [5 -30 55 -30] & den == [1. -15. 74. -120]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("zp2tf Test failed") +end + +/////////Test case for tf2zp ////////// + +[z p k] = tf2zp ([1 2 3], [4 5 6]); +k = round(k*10000)/10000; +p = round(p*10000)/10000; +z = round(z*10000)/10000; + +if(k == 0.25 & p == [-0.625+1.0533*%i; -0.625-1.0533*%i] & z == [-1+1.4142*%i; -1-1.4142*%i]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("tf2zp Test failed") +end + +/////////Test case for sftrans ////////// + +[Sz, Sp, Sg] = sftrans([1 2 3], [4 5 6], 15, 20, %T); +Sg = round(Sg*10000)/10000; +Sp = round(Sp*10000)/10000; +Sz = round(Sz*10000)/10000; + +if(Sg == 0.75 & Sp == [5 4 3.3333] & Sz == [20 10 6.6667]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("sftrans Test failed") +end + +/////////Test case for bilinear ////////// + +[b a] = bilinear ([1 2 3], [4 5 6], 1, 1); +b = round(b*10000)/10000; +a = round(a*10000)/10000; + + +if(b == [0 -0.1667 -0.3333 2.5] & a == [1 7.3333 17.6667 14]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("bilinear Test failed") +end + +/////////Test case for postpad ////////// + +y = postpad([1 2 3], 6); + +if(y == [1 2 3 0 0 0 ] ) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("postpad Test failed") +end + +/////////Test case for buttord ////////// + +[n, Wn] = buttord(40/500, 150/500, 3, 60); +Wn = round(Wn*10000)/10000; + +if(n == 5 & Wn == 0.08) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("buttord Test failed") +end + +/////////Test case for butter ////////// + +[b a] = butter(4,0.3,"high"); +b = round(b*10000)/10000; +a = round(a*10000)/10000; + +if(b == [0.2754 -1.1017 1.6525 -1.1017 0.2754] & a == [1 -1.5704 1.2756 -0.4844 0.0762]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("butter Test failed") +end + +/////////Test case for besself ////////// + +[b, a]=besself(2,.3,"high","z"); +b = round(b*10000)/10000; +a = round(a*10000)/10000; + +if(b == [0.4668 -0.9336 0.4668 ] & a == [1. -0.6913 0.176 ]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("besself Test failed") +end + +/////////Test case for cheb1ord ////////// + +[n, Wn]=cheb1ord([0.25 0.3],[0.24 0.31],3,10); +Wn = round(Wn*10000)/10000; + +if(n == 3 & Wn == [0.25 0.3]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("cheb1ord Test failed") +end + +/////////Test case for cheby1 ////////// + +[z, p, k]=cheby1(2,6,0.7,"high"); +z = round(z*10000)/10000; +p = round(p*10000)/10000; +k = round(k*10000)/10000; + +if(z == [1 1] & p == [-0.6292+0.5537*%i -0.6292-0.5537*%i] & k == 0.0556) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("cheby1 Test failed") +end + +/////////Test case for cheb2ord ////////// + +Wp = 40/500; +Ws = 150/500; +Rp = 3; +Rs = 60; +[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); +Ws = round(Ws*10000)/10000; + +if(n == 4 & Ws == 0.3) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("cheb2ord Test failed") +end + +/////////Test case for cheby2 ////////// + +[z, p, k]=cheby2(2,5,0.7,"high"); +z = round(z*10000)/10000; +p = round(p*10000)/10000; +k = round(k*10000)/10000; + +if(z == [-0.3165-0.9486*%i -0.3165+0.9486*%i ] & p == [-0.3939+0.5314*%i -0.3939-0.5314*%i ] & k == 0.4753) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("cheby2 Test failed") +end + +/////////Test case for ellipord ////////// + +Wp = [60 200]/500; +Ws = [50 250]/500; +Rp = 3; +Rs = 40; +[n,Wp] = ellipord(Wp,Ws,Rp,Rs); +Wp = round(Wp*10000)/10000; + +if(n == 5 & Wp == [0.12 0.4]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("ellipord Test failed") +end + +/////////Test case for ellip ////////// + +[b, a]=ellip(2, 3, 40, [0.3,0.4]); +b = round(b*10000)/10000; +a = round(a*10000)/10000; + +if(b == [0.0203 -0.0164 0.0027 -0.0164 0.0203] & a == [1. -1.7259 2.5097 -1.5593 0.8188 ]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("ellip Test failed") +end + +/////////Test case for wconv ////////// +a = [1 2 3 4 5]; +b = [7 8 9 10]; +y = wconv(1,a,b); + +if(y == [7. 22. 46. 80. 114. 106. 85. 50.]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("wconv Test failed") +end + +/////////Test case for chirp ////////// +t = [4,3,2,1]; +f0 = 4; +t1 = 5; +f1 = 0.9; +form = "quadratic"; +y = chirp(t, f0, t1, f1, form); +y = round(y*10000)/10000; +if(y == [-0.6113 0.7459 -0.4854 0.9665]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("chirp Test failed") +end + +/////////Test case for dftmtx ////////// +d = dftmtx(4); +if(d == [1 1 1 1; 1 -%i -1 %i; 1 -1 1 -1; 1 %i -1 -%i]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("dftmtx Test failed") +end + +/////////Test case for dctmtx ////////// +T = dctmtx(3); +T = round(T*10000)/10000; +if(T == [0.5774 0.5774 0.5774; 0.7071 0 -0.7071; 0.4082 -0.8165 0.4082]) + test_pass=[test_pass,1] +else + test_pass=[test_pass,0] + disp("dctmtx Test failed") +end + +///////////////////////////////////////////// + +///////////////////////////////////////////// + + +res=find(test_pass==0) + +if(res~=[]) + disp("One or more tests failed") + //exit(1) +else + disp("All test cases passed") + exit +end |