summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2018-07-25 17:32:17 +0530
committerSunil Shetye2018-07-26 23:50:17 +0530
commitcdd55940b7a287810e423017c42e7c965815c468 (patch)
treed802563d2d507039354a3cf48e75465b7e7a8d76
parent1251f70aa3442736ce6fd9c4fb7fbce412af5a52 (diff)
downloadFOSSEE-Signal-Processing-Toolbox-cdd55940b7a287810e423017c42e7c965815c468.tar.gz
FOSSEE-Signal-Processing-Toolbox-cdd55940b7a287810e423017c42e7c965815c468.tar.bz2
FOSSEE-Signal-Processing-Toolbox-cdd55940b7a287810e423017c42e7c965815c468.zip
code changes by Shashikiran Yadalam during FOSSEE Fellowship 2018
-rw-r--r--help/en_US/deconv.xml68
-rw-r--r--help/en_US/gausswin.xml10
-rw-r--r--help/en_US/gmonopuls.xml21
-rw-r--r--help/en_US/mexihat.xml10
-rw-r--r--help/en_US/mpoles.xml78
-rw-r--r--help/en_US/pchip.xml60
-rw-r--r--help/en_US/peak2rms.xml18
-rw-r--r--help/en_US/peig.xml135
-rw-r--r--help/en_US/periodogram.xml32
-rw-r--r--help/en_US/pmusic.xml145
-rw-r--r--help/en_US/poly2lsf.xml40
-rw-r--r--help/en_US/polyreduce.xml58
-rw-r--r--help/en_US/polyscale.xml72
-rw-r--r--help/en_US/polyval.xml49
-rw-r--r--help/en_US/prepad.xml73
-rw-r--r--help/en_US/prony.xml62
-rw-r--r--help/en_US/rc2ac.xml41
-rw-r--r--help/en_US/rc2poly.xml46
-rw-r--r--help/en_US/rcosdesign.xml61
-rw-r--r--help/en_US/resample.xml2
-rw-r--r--help/en_US/residue.xml71
-rw-r--r--help/en_US/residued.xml30
-rw-r--r--help/en_US/residuez.xml23
-rw-r--r--help/en_US/rlevinson.xml109
-rw-r--r--help/en_US/rooteig.xml78
-rw-r--r--help/en_US/rootmusic.xml88
-rw-r--r--help/en_US/sampled2continuous.xml16
-rw-r--r--help/en_US/schurrc.xml47
-rw-r--r--help/en_US/slewrate.xml47
-rw-r--r--help/en_US/sos2ss.xml81
-rw-r--r--help/en_US/sos2tf.xml18
-rw-r--r--help/en_US/sosbreak.xml49
-rw-r--r--help/en_US/specgram.xml80
-rw-r--r--help/en_US/subspaceMethodsInputPars.xml (renamed from help/en_US/subspaceMethodsInputParser.xml)0
-rw-r--r--help/en_US/upfirdn.xml14
-rw-r--r--help/en_US/wind.xml (renamed from help/en_US/window.xml)0
-rw-r--r--help/en_US/wkeep.xml6
-rw-r--r--help/en_US/yulewalker.xml15
-rw-r--r--help/en_US/zerocrossing.xml31
-rw-r--r--macros/convmtx.sci64
-rw-r--r--macros/deconv.sci104
-rw-r--r--macros/downsample.sci91
-rw-r--r--macros/fftfilt.sci9
-rw-r--r--macros/gausswin.sci55
-rw-r--r--macros/gmonopuls.sci58
-rw-r--r--macros/mexihat.sci39
-rw-r--r--macros/mpoles.sci124
-rw-r--r--macros/musicBase.sci6
-rw-r--r--macros/nnls.sci2
-rw-r--r--macros/pchip.sci16
-rw-r--r--macros/pchips.sci37
-rw-r--r--macros/peak2rms.sci214
-rw-r--r--macros/peig.sci101
-rwxr-xr-xmacros/periodogram.sci225
-rw-r--r--macros/pmusic.sci129
-rw-r--r--macros/poly2lsf.sci26
-rw-r--r--macros/polyreduce.sci43
-rw-r--r--macros/polyscale.sci20
-rwxr-xr-xmacros/polyval.sci36
-rw-r--r--macros/prepad.sci80
-rw-r--r--macros/prony.sci21
-rw-r--r--macros/rc2ac.sci41
-rw-r--r--macros/rc2poly.sci18
-rw-r--r--macros/rcosdesign.sci86
-rw-r--r--macros/residue.sci286
-rw-r--r--macros/residued.sci127
-rw-r--r--macros/residuez.sci81
-rw-r--r--macros/rlevinson.sci118
-rw-r--r--macros/rooteig.sci180
-rw-r--r--macros/rootmusic.sci167
-rw-r--r--macros/sampled2continuous.sci46
-rw-r--r--macros/schurrc.sci41
-rw-r--r--macros/slewrate.sci330
-rw-r--r--macros/sos2ss.sci34
-rw-r--r--macros/sos2tf.sci7
-rw-r--r--macros/sosbreak.sci28
-rw-r--r--macros/specgram.sci139
-rw-r--r--macros/ss2sos.sci37
-rw-r--r--macros/subspaceMethodsInputPars.sci (renamed from macros/subspaceMethodsInputParser.sci)38
-rw-r--r--macros/text4_peig.txt257
-rw-r--r--macros/txt4_pchip.txt1
-rw-r--r--macros/txt4_periodogram.txt129
-rw-r--r--macros/txt4specgram_imag.txt768
-rw-r--r--macros/txt4specgram_real.txt768
-rw-r--r--macros/upfirdn.sci77
-rw-r--r--macros/upsample.sci99
-rw-r--r--macros/upsamplefill.sci87
-rw-r--r--macros/wkeep.sci70
-rw-r--r--macros/wrev.sci34
-rw-r--r--macros/yulewalker.sci54
-rw-r--r--macros/zerocrossing.sci70
-rw-r--r--test3.sce841
92 files changed, 7181 insertions, 1262 deletions
diff --git a/help/en_US/deconv.xml b/help/en_US/deconv.xml
new file mode 100644
index 0000000..c056db2
--- /dev/null
+++ b/help/en_US/deconv.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * This help file was generated from deconv.sci using help_from_sci().
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="deconv" 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>deconv</refname>
+ <refpurpose>Deconvolve two vectors.</refpurpose>
+ </refnamediv>
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ [b,r]= deconv (y, a)
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>y:</term>
+ <listitem><para>Input vector. The convolution of a and b.</para></listitem></varlistentry>
+ <varlistentry><term>a:</term>
+ <listitem><para>The input vector.</para></listitem></varlistentry>
+ <varlistentry><term>b:</term>
+ <listitem><para> The quotient polynomial coeffecients vector.</para></listitem></varlistentry>
+ <varlistentry><term>r:</term>
+ <listitem><para>The remainder polynomial coefficients vector. </para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+[b, r] = deconv (y, a) solves for b and r such that
+ y = conv (a, b) + r.</para>
+<para>
+If y and a are polynomial coefficient vectors, b will
+ contain the coefficients of the polynomial quotient and r will be
+ a remainder polynomial of lowest order.
+
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+[b, r] = deconv ([3, 6, 9, 9], [1, 2, 3])
+//Output:
+//b=[3, 0]
+//r=[0, 0, 0, 9]
+ ]]></programlisting>
+</refsection>
+
+</refentry>
diff --git a/help/en_US/gausswin.xml b/help/en_US/gausswin.xml
index 9d1af4a..a128a08 100644
--- a/help/en_US/gausswin.xml
+++ b/help/en_US/gausswin.xml
@@ -44,7 +44,7 @@
<refsection>
<title>Description</title>
<para>
-This is an Octave function.
+
This function returns the filter coefficients of a Gaussian window of length m supplied as input, to the output vector w.
The second parameter is the width measured in sample rate/number of samples and should be f for time domain and 1/f for frequency domain. The width is inversely proportional to a.
</para>
@@ -54,10 +54,10 @@ The second parameter is the width measured in sample rate/number of samples and
<title>Examples</title>
<programlisting role="example"><![CDATA[
gausswin(3)
-ans =
-0.2493522
-1.
-0.2493522
+//ans =
+//0.2493522
+//1.
+//0.2493522
]]></programlisting>
</refsection>
</refentry>
diff --git a/help/en_US/gmonopuls.xml b/help/en_US/gmonopuls.xml
index 72436d9..f514aa4 100644
--- a/help/en_US/gmonopuls.xml
+++ b/help/en_US/gmonopuls.xml
@@ -34,18 +34,27 @@
<refsection>
<title>Description</title>
<para>
-This is an Octave function
+
This function returns samples of the Gaussian monopulse of amplitude unity.
</para>
</refsection>
<refsection>
- <title>Examples</title>
+ <title>Example 1.</title>
<programlisting role="example"><![CDATA[
-1. gmonopuls([1 2 3],0.1)
-ans= 0.85036 0.94070 0.52591
-2. gmonopuls([1 2 3])
-ans= 0 0 0
+ gmonopuls([1 2 3],0.1)
+//ans= 0.85036 0.94070 0.52591
+
]]></programlisting>
</refsection>
+
+<refsection>
+ <title>Example 2.</title>
+ <programlisting role="example"><![CDATA[
+
+ gmonopuls([1 2 3],[])
+//ans= 0 0 0
+ ]]></programlisting>
+</refsection>
+
</refentry>
diff --git a/help/en_US/mexihat.xml b/help/en_US/mexihat.xml
index 3306e6f..81f77a1 100644
--- a/help/en_US/mexihat.xml
+++ b/help/en_US/mexihat.xml
@@ -43,7 +43,7 @@
<refsection>
<title>Description</title>
<para>
-This is an Octave function
+This is an Octave function which is built in scilab.
This function returns values of the Mexican hat wavelet in the specified interval at all the sample points.
</para>
</refsection>
@@ -52,11 +52,11 @@ This function returns values of the Mexican hat wavelet in the specified interva
<title>Examples</title>
<programlisting role="example"><![CDATA[
1. [a,b]= mexihat(1,2,3)
-a = [0.00000 -0.35197 -0.35214]
-b = [1.0000 1.5000 2.0000]
+//a = [0.00000 -0.35197 -0.35214]
+//b = [1.0000 1.5000 2.0000]
2. [a,b]= mexihat([1 2 3],1,1)
-a = [0;0;0]
-b = [1;1;1]
+//a = [0;0;0]
+//b = [1;1;1]
]]></programlisting>
</refsection>
</refentry>
diff --git a/help/en_US/mpoles.xml b/help/en_US/mpoles.xml
new file mode 100644
index 0000000..99ff1d2
--- /dev/null
+++ b/help/en_US/mpoles.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * This help file was generated from mpoles.sci using help_from_sci().
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="mpoles" 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>mpoles</refname>
+ <refpurpose>Identifies unique poles in p and their associated multiplicity.</refpurpose>
+ </refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ [multp, idxp] = mpoles (p)
+ [multp, idxp] = mpoles (p, tol)
+ [multp, idxp] = mpoles (p, tol, reorder)
+ </synopsis>
+</refsynopsisdiv>
+
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>p:</term>
+ <listitem><para> Real vector whose poles has to be calculated</para></listitem></varlistentry>
+ <varlistentry><term>tol:</term>
+ <listitem><para> tolerence,by default, tol=0.001</para></listitem></varlistentry>
+ <varlistentry><term>reorder:</term>
+ <listitem><para> the optional parameter, if reorder is zero, poles are not sorted.</para></listitem></varlistentry>
+ <varlistentry><term>multp:</term>
+ <listitem><para> is a vector specifying the multiplicity of the poles.</para></listitem></varlistentry>
+<varlistentry><term>indxp:</term>
+ <listitem><para> indices of the poles</para></listitem></varlistentry>
+
+</variablelist>
+</refsection>
+<refsection>
+ <title>Description</title>
+ <para>
+The output is ordered from largest to the smallest poles. If the relative difference between the poles is less than the tolerance(tol), then those poles are considered as multiples. By default, the tolerance value is 0.001.
+</para>
+
+<para>
+If the optional parameter, reorder is 0, then the poles are not sorted.
+</para>
+</refsection>
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+ p = [2 3 1 1 2];
+ [m, n] = mpoles (p)
+// n =
+// 2.
+// 5.
+// 1.
+// 4.
+// 3.
+// m =
+// 1.
+// 1.
+// 2.
+// 1.
+// 2.
+ ]]></programlisting>
+</refsection>
+
+</refentry>
diff --git a/help/en_US/pchip.xml b/help/en_US/pchip.xml
index c9aaa34..059f02e 100644
--- a/help/en_US/pchip.xml
+++ b/help/en_US/pchip.xml
@@ -17,7 +17,65 @@
<refnamediv>
<refname>pchip</refname>
- <refpurpose></refpurpose>
+ <refpurpose>This function returns piecewise cubic hermite interpolating polynomial.</refpurpose>
</refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ d=pchip(x,y)
+ d= pchip(x,y,xx)
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>x:</term>
+ <listitem><para> points at which the function is defined</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+ <varlistentry><term>y:</term>
+ <listitem><para> function of variable x</para><para>Note that the lengths of x and y should be the same.</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+ <varlistentry><term>xx:</term>
+ <listitem><para> points of interpolation</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+ <varlistentry><term>d:</term>
+ <listitem><para> vector of interpolantant at xx
+</para></listitem></varlistentry>
+ </variablelist>
+
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+ x=[0 1 2 3 4 5]
+ y=[1 0 1 0 1 0]
+ xx=linspace(0,5,800)
+ v=pchip(x, y)
+ v=pchip(x,y,xx)
+ plot(x,y,xx,v,'o')
+ ]]></programlisting>
+
+<scilab:image>
+
+ x=[0 1 2 3 4 5]
+ y=[1 0 1 0 1 0]
+ xx=linspace(0,5,800)
+ v=pchip(x, y)
+ v=pchip(x,y,xx)
+ plot(x,y,xx,v,'o')
+</scilab:image>
+
+</refsection>
+
+
+
+
+
+
</refentry>
diff --git a/help/en_US/peak2rms.xml b/help/en_US/peak2rms.xml
index dd21dae..4e1e4e0 100644
--- a/help/en_US/peak2rms.xml
+++ b/help/en_US/peak2rms.xml
@@ -73,13 +73,13 @@ If the elements of matrix are complex the absolute values are considered in the
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
-To calculate peak2rms of a vector:
+//To calculate peak2rms of a vector:
IN=[6 19 10 25]
OUT=peak2rms(IN)
-The output is OUT=
-1.4638501
-1.3887301
-1.119186
+//The output is OUT=
+//1.4638501
+//1.3887301
+//1.119186
]]></programlisting>
</refsection>
@@ -90,8 +90,8 @@ The output is OUT=
To calculate peak2rms of rows of matrix:
IN=[1 3 5;2 4 6;7 8 9]
OUT=peak2rms(IN,2)
-The output is
-OUT= 1.3719887
+//The output is
+//OUT= 1.3719887
]]></programlisting>
</refsection>
@@ -104,8 +104,8 @@ To calculate peak magnitude to RMS value of sinusoid:
t=0:0.6:9
IN=cos(6*%pi*t);
OUT= peak2rms(IN)
-The output is
-OUT= 1.3719887
+//The output is
+//OUT= 1.3719887
]]></programlisting>
</refsection>
diff --git a/help/en_US/peig.xml b/help/en_US/peig.xml
index 8c85698..b19c370 100644
--- a/help/en_US/peig.xml
+++ b/help/en_US/peig.xml
@@ -33,52 +33,121 @@
[S,f] = peig(x,p,nfft,fs,nwin,noverlap)
[...] = peig(...,freqrange)
[...,v,e] = peig(...)
-
- Parameters:
- x - int|double - vector|matrix
- Input signal. In case of a matrix, each row of x represents a
+
+
+
+
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>x:</term>
+ <listitem><para> int|double - vector|matrix</para>
+<para>Input signal. In case of a matrix, each row of x represents a
seperate observation of the signal. If 'corr' flag is specified,
then x is the correlation matrix.
If w is not specified in the input, it is determined by the
algorithm. If x is real valued, then range of w is [0, pi].
- Otherwise, the range of w is [0, 2pi)
- p - int|double - scalar|vector
- p(1) is the dimension of the signal subspace
+ Otherwise, the range of w is [0, 2pi)</para>
+</listitem></varlistentry>
+ </variablelist>
+
+<variablelist>
+ <varlistentry><term>p:</term>
+ <listitem><para> int|double - scalar|vector</para>
+<para>p(1) is the dimension of the signal subspace
p(2), if specified, represents a threshold that is multiplied by
- the smallest estimated eigenvalue of the signal's correlation matrix.
- w - int|double - vector
- w is the vector of normalized frequencies over which the
- pseuspectrogram is to be computed.
- nfft - int - scalar (Default = 256)
- Length of the fft used to compute pseudospectrum. The length of S
+ the smallest estimated eigenvalue of the signal's correlation matrix.</para>
+
+</listitem></varlistentry>
+ </variablelist>
+
+<variablelist>
+<varlistentry><term>w:</term>
+ <listitem><para> int|double - vector</para>
+<para>w is the vector of normalized frequencies over which the
+ pseuspectrogram is to be computed.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+
+<variablelist>
+<varlistentry><term>nfft:</term>
+ <listitem><para> int - scalar (Default = 256)</para>
+<para>Length of the fft used to compute pseudospectrum. The length of S
(and hence w/f) depends on the type of values in x and nfft.
If x is real, length of s is (nfft/2 + 1) {Range of w = [0, pi]} if
nfft is even and (nfft+1)/2 {Range of w = [0, pi)} otherwise.
- If x is complex, length of s is nfft.
- fs - int|double - scalar (Default = 1)
- Sampling rate. Used to convert the normalized frequencies (w) to
- actual values (f) and vice-versa.
- nwin - int|double - scalar (int only)|vector (Default = 2*p(1))
- If nwin is scalar, it is the length of the rectangular window.
+ If x is complex, length of s is nfft.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+<variablelist>
+<varlistentry><term>fs:</term>
+ <listitem><para> int|double - scalar (Default = 1)</para>
+<para>Sampling rate. Used to convert the normalized frequencies (w) to
+ actual values (f) and vice-versa.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+<variablelist>
+<varlistentry><term>nwin:</term>
+ <listitem><para> int|double - scalar (int only)|vector (Default = 2*p(1))</para>
+<para> If nwin is scalar, it is the length of the rectangular window.
Otherwise, the vector input is considered as the window coefficients.
- Not used if 'corr' flag present.
- If x is a vector, windowing not done in nwin in scalar. If x is a
- matrix,
- noverlap - int - scalar (Default = nwin-1)
- number of points by which successive windows overlap. noverlap not
- used if x is a matrix
- freqrange - string
- The range of frequencies over which the pseudospetrogram is
+ Not used if 'corr' flag present.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+<variablelist>
+<varlistentry><term>noverlap:</term>
+ <listitem><para> int - scalar (Default = nwin-1)</para>
+<para> number of points by which successive windows overlap. noverlap not
+ used if x is a matrix</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+<variablelist>
+<varlistentry><term>freqrange:</term>
+ <listitem><para> string</para>
+<para>The range of frequencies over which the pseudospetrogram is
computed. Three possible values - 'onesided', 'twosided', 'centered'
'corr' flag
Presence indicates that the primary input x is actually a
correlation matrix
-
- Examples:
- TODO:
-
- </synopsis>
-</refsynopsisdiv>
+ </para>
+
+</listitem></varlistentry>
+
+</variablelist>
+</refsection>
+
+
+
+
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+
+ fs = 100;
+ t = 0:1/fs:1-1/fs;
+ s = 2*sin(2*%pi*25*t)+sin(2*%pi*35*t)+rand(1,100,"normal");
+ [S,w]=peig(s,2,512,fs,'half');
+ plot(w,S);
+ ]]></programlisting>
+</refsection>
<refsection>
<title>See also</title>
diff --git a/help/en_US/periodogram.xml b/help/en_US/periodogram.xml
index 5ad8738..5566e39 100644
--- a/help/en_US/periodogram.xml
+++ b/help/en_US/periodogram.xml
@@ -24,9 +24,7 @@
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>
- [PXX, W] = periodogram (X)
- [PXX, W] = periodogram (X, WIN)
- [PXX, W] = periodogram (X, WIN, NFFT)
+
[PXX, W] = periodogram (X, WIN, NFFT, FS)
[PXX, W] = periodogram (..., "RANGE")
</synopsis>
@@ -56,8 +54,30 @@ The optional second output W are the normalized angular frequencies. For a one-
<para>
If a sampling frequency is specified, FS, then the output frequencies F will be in the range [0, FS/2] or [0, FS/2) for one-sided calculations. For two-sided calculations the range will be [0, FS).
</para>
- <para>
-When called with no outputs the periodogram is immediately plotted in the current figure window.
-</para>
+
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+n=0:319;
+x=cos(%pi/4*n)+rand(size(n,"r"),"normal");
+[pxx,w]=periodogram(x,ones(1,320),256,2000,"onesided");
+plot2d(w,10*log10(pxx))
+xtitle('periodogram','frequency','magnitude(db)')
+xgrid()
+ ]]></programlisting>
+<scilab:image>
+n=0:319;
+x=cos(%pi/4*n)+rand(size(n,"r"),"normal");
+[pxx,w]=periodogram(x,ones(1,320),256,2000,"onesided");
+plot2d(w,10*log10(pxx))
+xtitle('periodogram','frequency','magnitude(db)')
+xgrid()
+</scilab:image>
+
+
</refsection>
+
+
</refentry>
diff --git a/help/en_US/pmusic.xml b/help/en_US/pmusic.xml
index d299b3a..b445409 100644
--- a/help/en_US/pmusic.xml
+++ b/help/en_US/pmusic.xml
@@ -17,7 +17,7 @@
<refnamediv>
<refname>pmusic</refname>
- <refpurpose>Psuedospectrum using MUSIC algorithm</refpurpose>
+ <refpurpose>Computes Psuedospectrum using MUSIC algorithm</refpurpose>
</refnamediv>
@@ -33,57 +33,132 @@
[S,f] = pmusic(x,p,nfft,fs,nwin,noverlap)
[...] = pmusic(...,freqrange)
[...,v,e] = pmusic(...)
-
- Parameters:
- x - int|double - vector|matrix
- Input signal. In case of a matrix, each row of x represents a
+
+
+
+
+
+ </synopsis>
+</refsynopsisdiv>
+
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>x:</term>
+ <listitem><para> int|double - vector|matrix</para>
+<para>Input signal. In case of a matrix, each row of x represents a
seperate observation of the signal. If 'corr' flag is specified,
then x is the correlation matrix.
If w is not specified in the input, it is determined by the
algorithm. If x is real valued, then range of w is [0, pi].
- Otherwise, the range of w is [0, 2pi)
- p - int|double - scalar|vector
- p(1) is the dimension of the signal subspace
+ Otherwise, the range of w is [0, 2pi)</para>
+</listitem></varlistentry>
+ </variablelist>
+
+<variablelist>
+ <varlistentry><term>p:</term>
+ <listitem><para> int|double - scalar|vector</para>
+<para>p(1) is the dimension of the signal subspace
p(2), if specified, represents a threshold that is multiplied by
- the smallest estimated eigenvalue of the signal's correlation matrix.
- w - int|double - vector
- w is the vector of normalized frequencies over which the
- pseuspectrogram is to be computed.
- nfft - int - scalar (Default = 256)
- Length of the fft used to compute pseudospectrum. The length of S
+ the smallest estimated eigenvalue of the signal's correlation matrix.</para>
+
+</listitem></varlistentry>
+ </variablelist>
+
+<variablelist>
+<varlistentry><term>w:</term>
+ <listitem><para> int|double - vector</para>
+<para>w is the vector of normalized frequencies over which the
+ pseuspectrogram is to be computed.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+
+<variablelist>
+<varlistentry><term>nfft:</term>
+ <listitem><para> int - scalar (Default = 256)</para>
+<para>Length of the fft used to compute pseudospectrum. The length of S
(and hence w/f) depends on the type of values in x and nfft.
If x is real, length of s is (nfft/2 + 1) {Range of w = [0, pi]} if
nfft is even and (nfft+1)/2 {Range of w = [0, pi)} otherwise.
- If x is complex, length of s is nfft.
- fs - int|double - scalar (Default = 1)
- Sampling rate. Used to convert the normalized frequencies (w) to
- actual values (f) and vice-versa.
- nwin - int|double - scalar (int only)|vector (Default = 2*p(1))
- If nwin is scalar, it is the length of the rectangular window.
+ If x is complex, length of s is nfft.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+<variablelist>
+<varlistentry><term>fs:</term>
+ <listitem><para> int|double - scalar (Default = 1)</para>
+<para>Sampling rate. Used to convert the normalized frequencies (w) to
+ actual values (f) and vice-versa.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+<variablelist>
+<varlistentry><term>nwin:</term>
+ <listitem><para> int|double - scalar (int only)|vector (Default = 2*p(1))</para>
+<para> If nwin is scalar, it is the length of the rectangular window.
Otherwise, the vector input is considered as the window coefficients.
- Not used if 'corr' flag present.
- If x is a vector, windowing not done in nwin in scalar. If x is a
- matrix,
- noverlap - int - scalar (Default = nwin-1)
- number of points by which successive windows overlap. noverlap not
- used if x is a matrix
- freqrange - string
- The range of frequencies over which the pseudospetrogram is
+ Not used if 'corr' flag present.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+<variablelist>
+<varlistentry><term>noverlap:</term>
+ <listitem><para> int - scalar (Default = nwin-1)</para>
+<para> number of points by which successive windows overlap. noverlap not
+ used if x is a matrix</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+<variablelist>
+<varlistentry><term>freqrange:</term>
+ <listitem><para> string</para>
+<para>The range of frequencies over which the pseudospetrogram is
computed. Three possible values - 'onesided', 'twosided', 'centered'
'corr' flag
Presence indicates that the primary input x is actually a
correlation matrix
-
- Examples:
- TODO:
-
- </synopsis>
-</refsynopsisdiv>
+ </para>
+
+</listitem></varlistentry>
+
+</variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+<para>[S,w] = pmusic(x,p) implements the MUSIC (Multiple Signal Classification) algorithm and returns S, the pseudospectrum estimate of the input signal x, and a vector w of normalized frequencies (in rad/sample) at which the pseudospectrum is evaluated. The pseudospectrum is calculated using estimates of the eigenvectors of a correlation matrix associated with the input data x, where x is specified as either:</para>
+
+ <para> A row or column vector representing one observation of the signal
+
+ </para>
+<para>A rectangular array for which each row of x represents a separate observation of the signal (for example, each row is one output of an array of sensors, as in array processing), such that x'*x is an estimate of the correlation matrix</para>
+</refsection>
+
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+ n = 0:199;
+ x = cos(0.257*%pi*n) + sin(0.2*%pi*n) ;
+ [S,w]=pmusic(x,2,16,1)
+ ]]></programlisting>
+</refsection>
+
<refsection>
<title>See also</title>
<simplelist type="inline">
- <member><link linkend="pburg">| peig | periodogram | pmtm | prony | pwelch | rooteig | rootmusic</link></member>
+ <member><link linkend="pburg">pburg| peig | periodogram | pmtm | prony | pwelch | rooteig | rootmusic</link></member>
</simplelist>
</refsection>
diff --git a/help/en_US/poly2lsf.xml b/help/en_US/poly2lsf.xml
index 27ca6a2..e3cc732 100644
--- a/help/en_US/poly2lsf.xml
+++ b/help/en_US/poly2lsf.xml
@@ -17,7 +17,45 @@
<refnamediv>
<refname>poly2lsf</refname>
- <refpurpose></refpurpose>
+ <refpurpose>Calculates the line spectral frequencies for the given prediction polynomial</refpurpose>
</refnamediv>
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ lsf = poly2lsf(a)
+poly2lsf maps Prediction polynomial coefficients to line spectral frequencies.
+
+ </synopsis>
+</refsynopsisdiv>
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>a:</term>
+ <listitem><para> Coefficients of prediction polynomial(the roots of the polynomial has to be inside the unity circle)</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+ <varlistentry><term>lsf:</term>
+ <listitem><para> Line spectral frequencies</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Example</title>
+ <programlisting role="example"><![CDATA[
+X=[1 0.6149 0.9899 0 0.0031 -0.0082]
+lsf = poly2lsf(X)
+//EXPECTED OUTPUT:
+//lsf =0.7841731 1.5605415 1.8776459 1.8984313 2.3592523
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Jitnder Singh</member>
+ </simplelist>
+</refsection>
+
</refentry>
diff --git a/help/en_US/polyreduce.xml b/help/en_US/polyreduce.xml
new file mode 100644
index 0000000..13e759a
--- /dev/null
+++ b/help/en_US/polyreduce.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * This help file was generated from polyreduce.sci using help_from_sci().
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="polyreduce" 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>polyreduce</refname>
+ <refpurpose></refpurpose>
+ </refnamediv>
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ p= polyreduce (c)
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>c:</term>
+ <listitem><para>polynomial coefficients vector.</para></listitem></varlistentry>
+ <varlistentry><term>p:</term>
+ <listitem><para>Reduced polynomial coefficients.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Reduce a polynomial coefficient vector to a minimum number of terms by
+stripping off any leading zeros. This function is used in residue().
+
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+polyreduce ([0, 0, 1, 2, 3])
+//Output: [1, 2, 3]
+ ]]></programlisting>
+</refsection>
+
+
+</refentry>
diff --git a/help/en_US/polyscale.xml b/help/en_US/polyscale.xml
index f689e36..cc62663 100644
--- a/help/en_US/polyscale.xml
+++ b/help/en_US/polyscale.xml
@@ -17,7 +17,77 @@
<refnamediv>
<refname>polyscale</refname>
- <refpurpose>errcheck1</refpurpose>
+ <refpurpose> scales the roots of a polynomial in the z plane</refpurpose>
</refnamediv>
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ b = polyscale(a,alpha)
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+<title>Description</title>
+<para>
+b = polyscale(a,alpha) scales the roots of a polynomial in the z-plane, where a is a vector containing the polynomial coefficients and alpha is the scaling factor.
+</para>
+<para>
+If alpha is a real value in the range [0 1], then the roots of a are radially scaled toward the origin in the z-plane. Complex values for alpha allow arbitrary changes to the root locations.
+</para>
+
+
+</refsection>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>a:</term>
+ <listitem><para> vector containing the polynomial coefficients</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+ <varlistentry><term>alpha:</term>
+ <listitem><para> the scaling vector</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+<varlistentry><term>b:</term>
+ <listitem><para>vector of scaled roots. </para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+p=[1 0 0 0 0 0 0 -1]
+b=polyscale(p,0.95)
+//EXPECTED OUTPUT:b=1. 0. 0. 0. 0. 0. 0. - 0.6983373
+
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+t
+p=[1 0 0 0 0 0 0 -1]
+b=polyscale(p,0.85)
+//EXPECTED OUTPUT:b=1. 0. 0. 0. 0. 0. 0. - 0.3205771
+
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+<title>Author</title>
+<simplelist type="vert">
+ <member>Debdeep Dey</member>
+ </simplelist>
+</refsection>
+
+
+
</refentry>
diff --git a/help/en_US/polyval.xml b/help/en_US/polyval.xml
index f041227..8150805 100644
--- a/help/en_US/polyval.xml
+++ b/help/en_US/polyval.xml
@@ -17,7 +17,54 @@
<refnamediv>
<refname>polyval</refname>
- <refpurpose></refpurpose>
+ <refpurpose>returns the value of a polynomial of degree n evaluated at x. y = polyval(p,x,[],mu) or [y,delta] = polyval(p,x,S,mu) use x^=(x−μ1)/μ2 in place of x.
+In this equation, μ1=mean(x)and μ2=std(x). The centering and scaling parameters mu = [μ1,μ2] is optional </refpurpose>
</refnamediv>
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ y= polyval(p,x)
+ [y,delta] = polyval(p,x,S)
+ </synopsis>
+</refsynopsisdiv>
+
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>p:</term>
+ <listitem><para> vector of length n+1 whose elements are the coefficients in descending powers of the polynomial to be evaluated.</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+ <varlistentry><term>x:</term>
+ <listitem><para> -can be a matrix or a vector. In either case, polyval evaluates p at each element of x.</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+<varlistentry><term>delta:</term>
+ <listitem><para>-is an estimate of the standard deviation of the error in predicting a future observation at x by p(x). </para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+p = [3 2 1];
+y=polyval(p,[5 7 9])
+//EXPECTED OUTPUT:
+//y= 86 162 262
+
+
+ ]]></programlisting>
+</refsection>
+
+
+
+
+
+
+
+
</refentry>
diff --git a/help/en_US/prepad.xml b/help/en_US/prepad.xml
new file mode 100644
index 0000000..81797e0
--- /dev/null
+++ b/help/en_US/prepad.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * This help file was generated from prepad.sci using help_from_sci().
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="prepad" 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>prepad</refname>
+ <refpurpose></refpurpose>
+ </refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ y= prepad (x, l)
+ y= prepad (x, l, c)
+ y= prepad (x, l, c, dim)
+ </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 prepadded sequence.</para></listitem></varlistentry>
+ <varlistentry><term>c:</term>
+ <listitem><para>number used for prepadding.</para></listitem></varlistentry>
+ <varlistentry><term>dim:</term>
+ <listitem><para>The dimension along which the prepadding should happen.</para></listitem></varlistentry>
+ <varlistentry><term>y:</term>
+ <listitem><para>Output</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Prepend 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 beginning of x
+ are removed until a vector of length l is obtained.
+
+ If x is a matrix, elements are prepended or removed from each row.
+
+ If the optional argument dim is given, operate along this dimension.
+
+ If dim is larger than the dimensions of x, the result will have
+ dim dimensions.
+
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+prepad ([1,2], 4,0,2)
+//Output: [0,0,1,2]
+ ]]></programlisting>
+</refsection>
+</refentry>
diff --git a/help/en_US/prony.xml b/help/en_US/prony.xml
index 25734a1..42ca98a 100644
--- a/help/en_US/prony.xml
+++ b/help/en_US/prony.xml
@@ -17,7 +17,67 @@
<refnamediv>
<refname>prony</refname>
- <refpurpose></refpurpose>
+ <refpurpose>Prony's method for time-domain design of IIR Filters</refpurpose>
</refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ [b,a] = prony(h,nb,na)
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+<title>Description</title>
+<para>
+The system function has numerator order,nb and denominator order,na. The lengths of Num and Den are num_ord+1 and denom_ord+1. If the length of impulse_resp is less than the largest order (num_ord or denom_ord), impulse_resp is padded with zeros.
+</para>
+
+
+
+</refsection>
+
+
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>b:</term>
+ <listitem><para> coefficients of the numerator of the TF</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+ <varlistentry><term>a:</term>
+ <listitem><para> coefficients of the denominator of the TF</para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+<varlistentry><term>h:</term>
+ <listitem><para>impulse response of the digital filter </para></listitem></varlistentry>
+ </variablelist>
+<variablelist>
+<varlistentry><term>nb:</term>
+ <listitem><para>number of zeros(order of numerator) </para></listitem></varlistentry>
+ </variablelist>
+
+<variablelist>
+<varlistentry><term>na:</term>
+ <listitem><para>number of poles(order of denominator) </para></listitem></varlistentry>
+ </variablelist>
+
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+V=filter([1,1],[1,1,2],[1 zeros(1,31)]);
+[b,a]=prony(V,1,2)
+
+//OUTPUT:a = 1. 1. 2.//denominator coefficients
+ //b = 1. 1. //numerator coefficients
+
+ ]]></programlisting>
+</refsection>
+
+
+
</refentry>
diff --git a/help/en_US/rc2ac.xml b/help/en_US/rc2ac.xml
index acfe121..1462720 100644
--- a/help/en_US/rc2ac.xml
+++ b/help/en_US/rc2ac.xml
@@ -27,4 +27,45 @@
a = rc2ac(k, R0)
</synopsis>
</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>k:</term>
+ <listitem><para>Lattice form reflection coefficients.</para></listitem></varlistentry>
+ <varlistentry><term>r0:</term>
+ <listitem><para> Initial zero lag autocorrelation.</para></listitem></varlistentry>
+ <varlistentry><term>a:</term>
+ <listitem><para>Autocorrelation coefficients.</para></listitem></varlistentry>
+
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Uses rlevinson to function convert reflection coefficients to autocorrelation sequence.
+</para>
+<para>
+r = rc2ac(k,r0) finds the autocorrelation coefficients, r, of the output of the discrete-time prediction error filter from the lattice-form reflection coefficients k and initial zero-lag autocorrelation r0
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
+r0 = 0.1;
+R=rc2ac(k,r0)
+//Output:
+//R =
+// 0.1
+// - 0.0309
+// - 0.0790948
+// 0.0786627
+// 0.0293629
+// - 0.0950000
+
+ ]]></programlisting>
+</refsection>
</refentry>
diff --git a/help/en_US/rc2poly.xml b/help/en_US/rc2poly.xml
index f8c66a4..a2f2993 100644
--- a/help/en_US/rc2poly.xml
+++ b/help/en_US/rc2poly.xml
@@ -3,7 +3,11 @@
<!--
*
* This help file was generated from rc2poly.sci using help_from_sci().
- *
+ *kr: Refelection coefficient.
+// R0: the zero lag autocorrelation, R0.
+// a: Return the prediction polynomial.
+// efinal: Return the final prediction error.
+
-->
<refentry version="5.0-subset Scilab" xml:id="rc2poly" xml:lang="en"
@@ -17,7 +21,7 @@
<refnamediv>
<refname>rc2poly</refname>
- <refpurpose></refpurpose>
+ <refpurpose>Convert reflection coefficients to prediction filter polynomial</refpurpose>
</refnamediv>
@@ -28,4 +32,42 @@
[a, efinal] = rc2poly(kr,R0)
</synopsis>
</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>kr:</term>
+ <listitem><para>Reflection coefficients.</para></listitem></varlistentry>
+ <varlistentry><term>R0:</term>
+ <listitem><para>The zero-lag autocorrelation.</para></listitem></varlistentry>
+ <varlistentry><term>a:</term>
+ <listitem><para>Prediciton polynomial.</para></listitem></varlistentry>
+
+<varlistentry><term>efinal:</term>
+ <listitem><para>the final prediction error.</para></listitem></varlistentry>
+</variablelist>
+</refsection>
+
+<refsection>
+<title>Description</title>
+<para>a = rc2poly(k) converts the reflection coefficients k corresponding to the lattice structure to the prediction filter polynomial a, with a(1) = 1.</para>
+<para>The output a is row vector of length length(k) + 1.</para>
+
+<para>[a,efinal] = rc2poly(k,r0) returns the final prediction error efinal based on the zero-lag autocorrelation, r0.</para>
+</refsection>
+
+
+<refsection>
+<title>Example</title>
+ <programlisting role="example"><![CDATA[
+k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
+a = rc2poly(k)
+//EXPECTED OUTPUT:a= 1. 0.6148162 0.9898814 0.0000243 0.0031580 - 0.0082
+ ]]></programlisting>
+
+
+</refsection>
+
+
+
</refentry>
diff --git a/help/en_US/rcosdesign.xml b/help/en_US/rcosdesign.xml
index e586d0d..397be44 100644
--- a/help/en_US/rcosdesign.xml
+++ b/help/en_US/rcosdesign.xml
@@ -17,7 +17,66 @@
<refnamediv>
<refname>rcosdesign</refname>
- <refpurpose>RCOSDESIGN computes the raised cosine FIR filter</refpurpose>
+ <refpurpose><para>RCOSDESIGN computes the raised cosine FIR filter.</para>
+<para>The output result for the input parameter of shape 'normal' is not equivalent to the matlab output because of the use of sinc function in the computation. Matlab and scilab sinc functions seem to not be equivalent.
+</para>
+</refpurpose>
</refnamediv>
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ h = rcosdesign(rollof_factor, num_of_symb, samp_per_symb, varargin)
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>rollof_factor:</term>
+ <listitem><para> roll-off factor of the designed filter</para></listitem></varlistentry>
+ </variablelist>
+
+
+ <variablelist>
+ <varlistentry><term>num_of_symb:</term>
+ <listitem><para>filter truncated to these many number of symbols</para></listitem></varlistentry>
+ </variablelist>
+
+
+ <variablelist>
+ <varlistentry><term>samp_of_symb:</term>
+ <listitem><para> each symbol represented by these many samples</para></listitem></varlistentry>
+ </variablelist>
+
+
+
+ <variablelist>
+ <varlistentry><term>shape:</term>
+ <listitem><para> returns a normal raised-cosine FIR filter when set to 'normal'.</para>
+<para>returns a square-root raised cosing filter when set to 'sqrt'.</para></listitem></varlistentry>
+ </variablelist>
+
+
+ <variablelist>
+ <varlistentry><term>h:</term>
+ <listitem><para> returned filter coefficients</para></listitem></varlistentry>
+ </variablelist>
+
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+rolloff = 0.25;
+span = 3;
+sample per symbol=sps=2;
+b=rcosdesign(rolloff,span,sps);
+//OUTPUT:
+//b=- 0.1210006 - 0.0456421 0.4418023 0.7590604 0.4418023 - 0.0456421 - 0.1210006
+ ]]></programlisting>
+</refsection>
+
</refentry>
diff --git a/help/en_US/resample.xml b/help/en_US/resample.xml
index aab50da..809b4ff 100644
--- a/help/en_US/resample.xml
+++ b/help/en_US/resample.xml
@@ -48,7 +48,7 @@
<title>Description</title>
<para>
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 function resamples in the input sequence x supplied by a factor of p/q. If x is a matrix, then every column is resampled changing 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.
</para>
</refsection>
diff --git a/help/en_US/residue.xml b/help/en_US/residue.xml
new file mode 100644
index 0000000..0d969a8
--- /dev/null
+++ b/help/en_US/residue.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * This help file was generated from residue.sci using help_from_sci().
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="residue" 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>residue</refname>
+ <refpurpose></refpurpose>
+ </refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ [r, p, k, e] = residue (b, a)
+ [b, a] = residue (r, p, k)
+ [b, a] = residue (r, p, k, e)
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>b:</term>
+ <listitem><para> Real or complex valued vector or matrix</para></listitem></varlistentry>
+ <varlistentry><term>a:</term>
+ <listitem><para> Real or complex valued vector or matrix</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+The first calling form computes the partial fraction expansion for the quotient of the polynomials, b and a.
+This function works for transfer functions which are proper fractions.
+NOTE that the polynomials 'b' and 'a' should have real coefficients(because of the function 'filter' used in polyval)
+</para>
+<para>The second and the third calling forms perform the inverse operation of the first calling form.</para>
+<para>
+<latex>
+\begin{eqnarray}
+\frac{B(s)}{A(s)}=\sum_{m=1}^{M}\frac{r(m)}{(s-p(m))^{e(m)}}+\sum_{i=1}^{N}k(i)*{s^{N-i}}
+\end{eqnarray}
+</latex>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+1.
+b = [1, 1, 1];
+a = [1, -5, 8, -4];
+ [r, p, k, e] = residue (b, a)
+// result r = [-2; 7; 3]
+// result p = [2; 2; 1]
+// result k = [](0x0)
+// result e = [1; 2; 1]
+ ]]></programlisting>
+</refsection>
+</refentry>
diff --git a/help/en_US/residued.xml b/help/en_US/residued.xml
index 8bdecc5..1aa9f3c 100644
--- a/help/en_US/residued.xml
+++ b/help/en_US/residued.xml
@@ -41,19 +41,35 @@
<refsection>
<title>Description</title>
<para>
-This is an Octave function.
-Similar to the "residuez" function. The difference being in the function "residuez", the IIR part (poles p and residues r) is driven in parallel with the FIR part(f) whereas in the function "residued", the IIR part is driven by the output of the FIR part. In signal modeling applications, this structure can be more accurate.
+Similar to the "residuez" function. The difference being in the function "residuez", the IIR part (poles p and residues r) is driven in parallel with the FIR part(f) whereas in the function "residued", the IIR part is driven by the output of the FIR part. In signal modeling applications, this structure can be more accurate.NOTE that the polynomials 'b' and 'a' should have real coefficients(because of the function 'filter' used in polyval). This function works for transfer functions which are proper fractions.
+</para>
+<para>
+<latex>
+\begin{eqnarray}
+\frac{B(s)}{A(s)}=\sum_{m=1}^{M}\frac{r(m)}{(s-p(m))^{e(m)}}+\sum_{i=1}^{N}k(i)*{s^{N-i}}
+\end{eqnarray}
+</latex>
</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
-1. [a,b,c,d]=residued([1 i;3 -4],[1 2; 3 4])
-a = [ 0.19405 - 1.31377i; 0.08329 + 0.99163i; -0.27734 + 0.32215i]
-b = [ -0.10184 - 1.19167i; -0.10184 + 1.19167i; -2.79632 - 0.00000i]
-c = 1
-d = [ 1 ; 1 ; 1]
+1.
+B=[1 1 ]; A=[1 -2 1];
+ [r,p,f,m] = residued(B,A)
+//OUTPUT
+//r =
+// -1
+// 2
+//p =
+// 1
+// 1
+//
+//f = [](0x0)
+//e =
+// 1
+// 2
]]></programlisting>
</refsection>
</refentry>
diff --git a/help/en_US/residuez.xml b/help/en_US/residuez.xml
index 4655c59..b004fea 100644
--- a/help/en_US/residuez.xml
+++ b/help/en_US/residuez.xml
@@ -41,19 +41,28 @@
<refsection>
<title>Description</title>
<para>
-This is an Octave function
-It compute the PFE of filter H(z)= B(z)/A(z) where inputs b and a are vectors specifying the digital filter.
+It computes the partial fraction expansion of filter H(z)= B(z)/A(z) where inputs b and a are vectors specifying the digital filter.NOTE that the polynomials 'b' and 'a' should have real coefficients(because of the function 'filter' used in polyval). This function works for transfer functions which are proper fractions.
</para>
+<para>
+<latex>
+\begin{eqnarray}
+H(z)=\frac{r(1)}{[1-\frac{p(1)}{z}]^{m(1)}}+..........+\frac{r(N)}{[1-\frac{p(N)}{z}]^{m(N)}}
+\end{eqnarray}
+</latex>
+</para>
+
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
-1. [a,b,c,d]=residuez([i 2i 3i; -4 1 4i],[1 2 3])
-a = [0.6262 - 1.4412i; -0.4039 + 1.4658i]
-b = [-1.0000 - 1.4142i; -1.0000 + 1.4142i]
-c = [-0.22222 - 0.97531i 0.33333 + 0.51852i 0.00000 - 0.11111i; 0.00000 - 1.33333i]
-d = 1
+1.B=[1 1 1]; A=[1 -2 1];
+ [r,p,f,m] = residuez(B,A)
+ //OUTPUT:
+ //r=[0;3]
+ //p=[1;1]
+ //f=1
+ //e=[1;2]
]]></programlisting>
</refsection>
</refentry>
diff --git a/help/en_US/rlevinson.xml b/help/en_US/rlevinson.xml
index 799fcb1..5017af8 100644
--- a/help/en_US/rlevinson.xml
+++ b/help/en_US/rlevinson.xml
@@ -17,17 +17,116 @@
<refnamediv>
<refname>rlevinson</refname>
- <refpurpose></refpurpose>
+ <refpurpose>This function computes the autocorrelation coefficients using prediction polynomial method.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>
- a = rlevinson(a, efinal)
- [a, U] = rlevinson(a, efinal)
- [a, U, kr] = rlevinson(a, efinal)
- [a, U, kr, e] = rlevinson(a, efinal)
+ R = rlevinson(a, efinal)
+ [R, U] = rlevinson(a, efinal)
+ [R, U, kr] = rlevinson(a, efinal)
+ [R, U, kr, e] = rlevinson(a, efinal)
</synopsis>
</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>a:</term>
+ <listitem><para>Input argument ,prediction polynomial coefficients.</para></listitem></varlistentry>
+ <varlistentry><term>efinal:</term>
+ <listitem><para>Input argument, final prediction error.</para></listitem></varlistentry>
+ <varlistentry><term>R:</term>
+ <listitem><para>Returns the auto-correlation coefficients.</para></listitem></varlistentry>
+
+<varlistentry><term>U:</term>
+ <listitem><para>Returns upper triangular matrix of order length(a)*length(a).</para></listitem></varlistentry>
+ <varlistentry><term>kr:</term>
+ <listitem><para>Reflection coefficients.</para></listitem></varlistentry>
+
+<varlistentry><term>e:</term>
+ <listitem><para>Prediction error.</para></listitem></varlistentry>
+ </variablelist>
+
+</refsection>
+
+<refsection>
+ <title>Description
+ </title>
+<para>The reverse Levinson-Durbin recursion implements the step-down algorithm for solving the following symmetric Toeplitz system of linear equations for r, where r = [r(1) … r(p + 1)] and r(i)* denotes the complex conjugate of r(i).</para>
+<para>
+<latex>
+\begin{eqnarray}
+\begin{bmatrix}
+ r(1) r(2)* - - r(p)* \\
+ r(2) r(1) - - r(p-1)* \\
+ - - - - - \\
+ - - - - - \\
+ - - - - - \\
+ r(p) r(p-1) - r(2) r(1)
+\end{bmatrix}\begin{bmatrix}
+a(2)\\
+a(3)\\
+.\\
+.\\
+.\\
+a(p+1)
+\end{bmatrix}=\begin{bmatrix}
+-r(2)\\
+-r(3)\\
+.\\
+.\\
+.\\
+-r(p+1)
+\end{bmatrix}
+\end{eqnarray}
+
+</latex>
+</para>
+
+<para>
+Input vector a represents the polynomial coefficients of this prediction error filter in descending powers of z.
+<para>
+<latex>
+\begin{eqnarray}
+A(z)=1+a(2)^{z-1}+.............+a(n+1)^{z-p}
+\end{eqnarray}
+</latex></para>
+</para>
+<para>[r,u] = rlevinson(a,efinal) returns upper triangular matrix U from the UDU* decomposition
+
+</para>
+<latex>
+\begin{eqnarray}
+R^{-1}=UE^{-1}U*
+\end{eqnarray}
+</latex>
+<para>
+<latex>
+
+</latex>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+X=[1 6/7 5/7 8/7 3/7 6/7];
+[R U kr e] = rlevinson(X, 0.3)
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>See also</title>
+ <simplelist type="inline">
+ <member><link linkend="levinson">abs</link></member>
+ <member><link linkend="levdown">mean</link></member>
+
+ </simplelist>
+</refsection>
+
+
+
</refentry>
diff --git a/help/en_US/rooteig.xml b/help/en_US/rooteig.xml
index 9b2abe2..b8ad409 100644
--- a/help/en_US/rooteig.xml
+++ b/help/en_US/rooteig.xml
@@ -24,26 +24,86 @@
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>
- w = rooteig(x,p)
[w,pow] = rooteig(x,p)
- [f,pow] = rooteig(...,fs)
+ [w,pow] = rooteig(...,fs)
[w,pow] = rooteig(...,'corr')
-
+
</synopsis>
</refsynopsisdiv>
<refsection>
<title>Parameters</title>
<variablelist>
- <varlistentry><term>Examples:</term>
- <listitem><para> </para></listitem></varlistentry>
- <varlistentry><term>1) 3 complex exponentials:</term>
- <listitem><para> </para></listitem></varlistentry>
- <varlistentry><term>n=0:</term>
- <listitem><para>99;</para></listitem></varlistentry>
+ <varlistentry><term>x:</term>
+ <listitem><para> int|double - vector|matrix</para>
+<para>Input signal. In case of a matrix, each row of x represents a
+ seperate observation of the signal. If 'corr' flag is specified,
+ then x is the correlation matrix.
+ If w is not specified in the input, it is determined by the
+ algorithm. If x is real valued, then range of w is [0, pi].
+ Otherwise, the range of w is [0, 2pi)</para>
+</listitem></varlistentry>
+ </variablelist>
+
+<variablelist>
+ <varlistentry><term>p:</term>
+ <listitem><para> int|double - scalar|vector</para>
+<para>p(1) is the dimension of the signal subspace
+ p(2), if specified, represents a threshold that is multiplied by
+ the smallest estimated eigenvalue of the signal's correlation matrix.</para>
+
+</listitem></varlistentry>
</variablelist>
+
+<variablelist>
+<varlistentry><term>w:</term>
+ <listitem><para> int|double - vector</para>
+<para>w is the vector of normalized frequencies over which the
+ pseuspectrogram is to be computed.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+
+
+
+<variablelist>
+<varlistentry><term>fs:</term>
+ <listitem><para> int|double - scalar (Default = 1)</para>
+<para>Sampling rate. Used to convert the normalized frequencies (w) to
+ actual values (f) and vice-versa.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+
</refsection>
+
+
+
+
+
+
+<refsection>
+<title>Description</title>
+[w,pow] = rooteig(x,p) estimates the frequency content in the time samples of a signal x, and returns w, a vector of frequencies in rad/sample, and the corresponding signal power in the vector pow in units of power, such as volts^2. The input signal x is specified either as:
+ <para> A row or column vector representing one observation of the signal
+
+ </para>
+<para>A rectangular array for which each row of x represents a separate observation of the signal (for example, each row is one output of an array of sensors, as in array processing), such that x'*x is an estimate of the correlation matrix</para>
+</refsection>
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+ n=0:99;
+ s=exp(1*%i*%pi/2*n)+2*exp(1*%i*%pi/4*n)+exp(1*%i*%pi/3*n)+rand(1,100,"normal");
+ X = corrmtx(s,12,'mod');
+ [W,P] = rooteig(X,3);
+ ]]></programlisting>
+</refsection>
<refsection>
<title>See also</title>
<simplelist type="inline">
diff --git a/help/en_US/rootmusic.xml b/help/en_US/rootmusic.xml
index 82178e1..19aa883 100644
--- a/help/en_US/rootmusic.xml
+++ b/help/en_US/rootmusic.xml
@@ -28,20 +28,94 @@
[w,pow] = rootmusic(x,p)
[f,pow] = rootmusc(...,fs)
[w,pow] = rootmusic(...,'corr')
-
+
</synopsis>
</refsynopsisdiv>
<refsection>
<title>Parameters</title>
<variablelist>
- <varlistentry><term>Examples:</term>
- <listitem><para> </para></listitem></varlistentry>
- <varlistentry><term>1) 3 complex exponentials:</term>
- <listitem><para> </para></listitem></varlistentry>
- <varlistentry><term>n=0:</term>
- <listitem><para>99;</para></listitem></varlistentry>
+ <varlistentry><term>x:</term>
+ <listitem><para> int|double - vector|matrix</para>
+<para>Input signal. In case of a matrix, each row of x represents a
+ seperate observation of the signal. If 'corr' flag is specified,
+ then x is the correlation matrix.
+ If w is not specified in the input, it is determined by the
+ algorithm. If x is real valued, then range of w is [0, pi].
+ Otherwise, the range of w is [0, 2pi)</para>
+</listitem></varlistentry>
+ </variablelist>
+
+<variablelist>
+ <varlistentry><term>p:</term>
+ <listitem><para> int|double - scalar|vector</para>
+<para>p(1) is the dimension of the signal subspace
+ p(2), if specified, represents a threshold that is multiplied by
+ the smallest estimated eigenvalue of the signal's correlation matrix.</para>
+
+</listitem></varlistentry>
</variablelist>
+
+<variablelist>
+<varlistentry><term>w:</term>
+ <listitem><para> int|double - vector</para>
+<para>w is the vector of normalized frequencies over which the
+ pseuspectrogram is to be computed.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+
+<variablelist>
+<varlistentry><term>pow:</term>
+ <listitem><para> the estimated absolute value squared amplitudes of the sinusoids at the frequencies w.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+<variablelist>
+<varlistentry><term>fs:</term>
+ <listitem><para> int|double - scalar (Default = 1)</para>
+<para>Sampling rate. Used to convert the normalized frequencies (w) to
+ actual values (f) and vice-versa.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+
+
+<variablelist>
+<varlistentry><term>corr:</term>
+ <listitem><para> If specified, x is interpreted as a correlation matrix rather than a matrix of the signal data. For x to be a correlation matrix, x must be a square matrix and all its eigenvalues must be nonnegative.</para>
+
+</listitem></varlistentry>
+
+</variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+<para>W = rootmusic(X,P) returns the frequencies in radians/sample for the P complex exponentials (sinusoids) that make up the signal X.
+
+The input X is specified either as:</para>
+
+ <para> A row or column vector representing one observation of the signal
+
+ </para>
+<para>A rectangular array for which each row of x represents a separate observation of the signal (for example, each row is one output of an array of sensors, as in array processing), such that x'*x is an estimate of the correlation matrix</para>
+</refsection>
+
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+n=0:99;
+s=exp(1*%i*%pi/2*n)+2*exp(1*%i*%pi/4*n)+exp(1*%i*%pi/3*n)+rand(1,100,"normal");
+[A,R]=corrmtx(s,12,'mod');
+[W,P] = rootmusic(R,3,'corr');
+ ]]></programlisting>
</refsection>
<refsection>
diff --git a/help/en_US/sampled2continuous.xml b/help/en_US/sampled2continuous.xml
index a08d04a..8d3d2df 100644
--- a/help/en_US/sampled2continuous.xml
+++ b/help/en_US/sampled2continuous.xml
@@ -31,20 +31,18 @@
<refsection>
<title>Parameters</title>
<variablelist>
- <varlistentry><term>n:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <varlistentry><term>xn:</term>
+ <listitem><para> sampled signal</para></listitem></varlistentry>
<varlistentry><term>s:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para> sampling rate</para></listitem></varlistentry>
<varlistentry><term>t:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para>all instants of time t at which we need x(t) from x[n] </para></listitem></varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
- <para>
-This is an Octave function.
-This function calculates the output reconstructed from the samples n supplied as input, at a rate of 1/s samples per unit time.
+ <para>This function calculates the output reconstructed from the samples n supplied as input, at a rate of 1/s samples per unit time.
The third parameter t is all the instants where output x is needed from intput n and this time is relative to x(0).
</para>
</refsection>
@@ -53,8 +51,8 @@ The third parameter t is all the instants where output x is needed from intput n
<title>Examples</title>
<programlisting role="example"><![CDATA[
sampled2continuous([1,2,3],5,6)
-ans =
-2.4166806
+//ans =
+//2.4166806
]]></programlisting>
</refsection>
</refentry>
diff --git a/help/en_US/schurrc.xml b/help/en_US/schurrc.xml
index b269840..481430a 100644
--- a/help/en_US/schurrc.xml
+++ b/help/en_US/schurrc.xml
@@ -17,7 +17,52 @@
<refnamediv>
<refname>schurrc</refname>
- <refpurpose>narginchk(1,1,argn(2));</refpurpose>
+ <refpurpose>Computes reflection coefficients from auto-correlation sequence using Schrur algorithm.</refpurpose>
</refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ k = schurrc(r)
+[k,e] = schurrc(r)
+ </synopsis>
+</refsynopsisdiv>
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>k:</term>
+ <listitem><para> reflection coefficients or lattice parameters of prediction filter</para></listitem></varlistentry>
+ <varlistentry><term>e:</term>
+ <listitem><para> prediction error variance</para></listitem></varlistentry>
+ <varlistentry><term>r:</term>
+ <listitem><para>auto correltion sequence </para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+
+<refsection>
+ <title>Description</title>
+ <para>k = schurrc(r) uses the Schur algorithm to compute a vector k of reflection coefficients from a vector r representing an autocorrelation sequence. k and r are the same size. The reflection coefficients represent the lattice parameters of a prediction filter for a signal with the given autocorrelation sequence, r. When r is a matrix, schurrc treats each column of r as an independent autocorrelation sequence, and produces a matrix k, the same size as r. Each column of k represents the reflection coefficients for the lattice filter for predicting the process with the corresponding autocorrelation sequence r.</para>
+
+<para>[k,e] = schurrc(r) also computes the scalar e, the prediction error variance. When r is a matrix, e is a column vector. The number of rows of e is the same as the number of columns of r.
+
+</para>
+</refsection>
+
+
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+m=linspace(1,100);
+r = xcorr(m(1:5),'unbiased');
+[k,e] = schurrc(r(5:$))
+
+//EXPECTED OUTPUT
+//e =1.6212406
+ //k = - 0.9090909 0.2222222 0.2244898 0.2434211
+
+
+ ]]></programlisting>
+</refsection>
</refentry>
diff --git a/help/en_US/slewrate.xml b/help/en_US/slewrate.xml
index 97afbfb..c2a9002 100644
--- a/help/en_US/slewrate.xml
+++ b/help/en_US/slewrate.xml
@@ -17,7 +17,52 @@
<refnamediv>
<refname>slewrate</refname>
- <refpurpose></refpurpose>
+ <refpurpose> returns the slew rate for all transitions found in the bilevel waveform</refpurpose>
</refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ s=slewrate(x)
+ s=slewrate(x, t)
+ s=slewrate(x, Fs)
+ s=slewrate(x, t, 'PercentReferenceLevels', N )
+ s=slewrate(x, t, 'Tolerance', M)
+ s=slewrate(x, t,'StateLevels', O)
+
+ [s lowercrossvalue uppercrossvalue lowerreference upperreference]=slewrate(x)
+ [s lowercrossvalue uppercrossvalue lowerreference upperreference]=slewrate(x, t)
+ [s lowercrossvalue uppercrossvalue lowerreference upperreference]=slewrate(x, Fs)
+ [s lowercrossvalue uppercrossvalue lowerreference upperreference]=slewrate(x, t, 'PercentReferenceLevels', N )
+ [s lowercrossvalue uppercrossvalue lowerreference upperreference]= slewrate(x, t, 'Tolerance', M)
+ [s lowercrossvalue uppercrossvalue lowerreference upperreference]= slewrate(x, t,'StateLevels', O)
+ [s lowercrossvalue uppercrossvalue lowerreference upperreference]= slewrate(x, t,'StateLevels', O, 'fig', on or off)
+
+ </synopsis>
+</refsynopsisdiv>
+
+
+
+
+<refsection>
+ <title>Description</title>
+ returns the slew rate for all transitions found in the bilevel waveform, X. The slew rate is the slope of the line connecting the 10% and 90% reference levels. The sample instants of X are the indices of the vector. To determine the transitions, slewrate estimates the state levels of the input waveform by a histogram method. slewrate identifies all regions that cross the upper-state boundary of the low state and the lower-state boundary of the high state. The low-state and high-state boundaries are expressed as the state level plus or minus a multiple of the difference between the state levels.
+</refsection>
+
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+ x=[ones(1,25) -ones(1,25) ones(1,25) ]
+ t=1:length(x)
+ s=slewrate(x,t)
+ //EXPECTED OUTPUT:
+ //s = - 2 2
+
+ ]]></programlisting>
+</refsection>
+
+
+
+
</refentry>
diff --git a/help/en_US/sos2ss.xml b/help/en_US/sos2ss.xml
index 99a5812..d69c4c7 100644
--- a/help/en_US/sos2ss.xml
+++ b/help/en_US/sos2ss.xml
@@ -17,7 +17,86 @@
<refnamediv>
<refname>sos2ss</refname>
- <refpurpose>[nargout,nargin]=argn();</refpurpose>
+ <refpurpose>Converts Digital Filter Second order section parameters to steady state form. </refpurpose>
</refnamediv>
+
+<refsection>
+<title>Calling Sequence</title>
+
+[A,B,C,D] = sos2ss(sos)
+[A,B,C,D] = sos2ss(sos,g)
+
+</refsection>
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>[A,B,C,D]:</term>
+ <listitem><para>Steady state parameters.</para></listitem></varlistentry>
+ <varlistentry><term>sos:</term>
+ <listitem><para> Second order sectional matrix.</para></listitem></varlistentry>
+ <varlistentry><term>g:</term>
+ <listitem><para>gain of the system.</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+
+<refsection>
+<title>Description</title>
+<para>sos2ss converts a second-order section representation of a digital filter to an equivalent state-space representation.</para>
+<para>
+[A,B,C,D] = sos2ss(sos) converts sos, a system expressed in second-order section form, to a single-input, single-output state-space representation:
+
+x(n+1)=Ax(n)+Bu(n),
+y(n)=Cx(n)+Du(n).</para>
+
+<para>
+
+ <latex>
+ \begin{eqnarray}
+ f(x,a,r) = \frac{1}{r^{-a}\Gamma(a)} \int_0^x t^{a-1} \exp\left(-rt\right) dt
+ \end{eqnarray}
+ </latex>
+
+</para>
+
+
+
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+sos = [1 1 1 1 0 -1 ;
+ -2 3 1 1 10 1];
+[A,B,C,D] = sos2ss(sos,2);
+//EXPECTED OUTPUT:
+//D =- 4.
+//C =42. 4. - 32. - 2.
+//B =[1. 0. 0. 0. 0.]'
+//A =[- 10. 0. 10. 1. ; 1. 0. 0. 0. ; 0. 1. 0. 0. ; 0. 0. 1. 0. ]
+ ]]></programlisting>
+</refsection>
+
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Parthasrathi Panda</member>
+ </simplelist>
+</refsection>
+
+
+
+<refsection>
+ <title>See also</title>
+ <simplelist type="inline">
+ <member><link linkend="sos2tf">abs</link></member>
+ <member><link linkend="sosbreak">mean</link></member>
+ <member><link linkend="sos2ss">max</link></member>
+
+ </simplelist>
+</refsection>
+
+
</refentry>
diff --git a/help/en_US/sos2tf.xml b/help/en_US/sos2tf.xml
index 4d4e48e..972ba79 100644
--- a/help/en_US/sos2tf.xml
+++ b/help/en_US/sos2tf.xml
@@ -34,9 +34,15 @@
<title>Parameters</title>
<variablelist>
<varlistentry><term>sos:</term>
- <listitem><para> matrix of real or complex numbers</para></listitem></varlistentry>
+ <listitem><para> matrix of real or complex numbers</para><para>Second Order Sectional form of the system.</para></listitem></varlistentry>
<varlistentry><term>g:</term>
- <listitem><para> real or complex value, default value is 1</para></listitem></varlistentry>
+ <listitem><para> real or complex value, default value is 1</para><para>Gain of the system.</para></listitem></varlistentry>
+
+<varlistentry><term>B:</term>
+ <listitem><para>Vector of numerator coefficients.</para><para>Gain of the system.</para></listitem></varlistentry>
+
+<varlistentry><term>A:</term>
+ <listitem><para>Vector of denominator coefficients.</para><para>Gain of the system.</para></listitem></varlistentry>
</variablelist>
</refsection>
@@ -54,10 +60,10 @@ The output is a vector.
<title>Examples</title>
<programlisting role="example"><![CDATA[
[a,b]=sos2tf([1,2,3,4,5,6])
-a =
-1 2 3
-b =
-4 5 6
+//a =
+//1 2 3
+//b =
+//4 5 6
]]></programlisting>
</refsection>
</refentry>
diff --git a/help/en_US/sosbreak.xml b/help/en_US/sosbreak.xml
index 3957d94..383f449 100644
--- a/help/en_US/sosbreak.xml
+++ b/help/en_US/sosbreak.xml
@@ -19,5 +19,54 @@
<refname>sosbreak</refname>
<refpurpose>function for breaking a polynomial in second order polynomials (and an extra linear)</refpurpose>
</refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ [zerosort,g]=sosbreak(p)
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>p:</term>
+ <listitem><para>-the input polynomial.</para></listitem></varlistentry>
+ <varlistentry><term>zerosort:</term>
+ <listitem><para>-the array of the broken polynomials </para></listitem></varlistentry>
+ <varlistentry><term>g:</term>
+ <listitem><para>the interger multiple obtained after breaking the polynomial</para></listitem></varlistentry>
+
+
+
+</variablelist>
+
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+v=[1+4*%s+6*%s^2+4*%s^3+%s^4];
+[zerosort,g]=sosbreak(v);
+//OUTPUT:
+// g =1.
+ //zerosort =
+ // zerosort(1)
+// 2
+// 1 + 2s + s
+// zerosort(2)
+// 2
+//1.0000000 + 2s + s
+
+ ]]></programlisting>
+</refsection>
+
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Parthasarathi Panda</member>
+</simplelist>
+</refsection>
+
</refentry>
diff --git a/help/en_US/specgram.xml b/help/en_US/specgram.xml
index a0215bb..d603043 100644
--- a/help/en_US/specgram.xml
+++ b/help/en_US/specgram.xml
@@ -17,7 +17,83 @@
<refnamediv>
<refname>specgram</refname>
- <refpurpose></refpurpose>
- </refnamediv>
+ <refpurpose>Generate a spectrogram for the signal x.</refpurpose>
+ </refnamediv>
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ [S, f, t] = specgram (x,n,fs,win,overlap)
+ [S, f, t] =specgram(x)
+ </synopsis>
+</refsynopsisdiv>
+
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>S:</term>
+ <listitem><para>is the complex output of the FFT, one row per slice.</para></listitem></varlistentry>
+ <varlistentry><term>f:</term>
+ <listitem><para>is the frequency indices corresponding to the rows of S.</para></listitem></varlistentry>
+ <varlistentry><term>t:</term>
+ <listitem><para>is the time indices corresponding to the columns of S.</para></listitem></varlistentry>
+
+<varlistentry><term>x:</term>
+ <listitem><para>the input signal.</para></listitem></varlistentry>
+ <varlistentry><term>n:</term>
+ <listitem><para>length of the overlapping segments(default,n=256).</para></listitem></varlistentry>
+
+<varlistentry><term>fs:</term>
+ <listitem><para>sampling rate of input signal (if specified).</para></listitem></varlistentry>
+<varlistentry><term>win:</term>
+ <listitem><para>window vector,alternate window to apply rather than the default of hanning (n).</para></listitem></varlistentry>
+<varlistentry><term>overlap:</term>
+ <listitem><para>specifies the number of samples overlap between successive segments of the input signal. The default overlap is length (window)/2.</para></listitem></varlistentry>
+
+
+</variablelist>
+
+</refsection>
+
+
+<refsection>
+ <title>Description
+ </title>
+<para>Generates a spectrogram for the signal x. The signal is chopped into overlapping segments of length n, and each segment is windowed and transformed into the frequency domain using the FFT. The default segment size is 256. If fs is given, it specifies the sampling rate of the input signal. The argument window specifies an alternate window to apply rather than the default of hanning (n). The argument overlap specifies the number of samples overlap between successive segments of the input signal. The default overlap is length (window)/2.
+</para>
+
+</refsection>
+
+
+
+
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+N=1024;
+n=0:N-1;
+w=2*%pi/5;
+x=sin(w*n)+10*sin(2*w*n);
+[s,f,t]=specgram(x);
+//grayplot(f,t,s)
+//xlabel("frequency")
+//ylabel("time")
+ ]]></programlisting>
+<scilab:image>
+N=1024;
+n=0:N-1;
+w=2*%pi/5;
+x=sin(w*n)+10*sin(2*w*n);
+[s,f,t]=specgram(x);
+grayplot(f,t,s)
+xlabel("frequency")
+ylabel("time")
+
+</scilab:image>
+
+
+</refsection>
+
</refentry>
diff --git a/help/en_US/subspaceMethodsInputParser.xml b/help/en_US/subspaceMethodsInputPars.xml
index 908ead3..908ead3 100644
--- a/help/en_US/subspaceMethodsInputParser.xml
+++ b/help/en_US/subspaceMethodsInputPars.xml
diff --git a/help/en_US/upfirdn.xml b/help/en_US/upfirdn.xml
index 6688531..98da4ec 100644
--- a/help/en_US/upfirdn.xml
+++ b/help/en_US/upfirdn.xml
@@ -32,20 +32,20 @@
<title>Parameters</title>
<variablelist>
<varlistentry><term>x:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para> The input signal.</para></listitem></varlistentry>
<varlistentry><term>h:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para> The impulse response of the FIR filter.</para></listitem></varlistentry>
<varlistentry><term>p:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para>The upsampling factor(default=1) </para></listitem></varlistentry>
<varlistentry><term>q:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para>The downsampling factor(default=1) </para></listitem></varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
-This is an Octave function.
+
This function upsamples the input data in the matrix by a factor of n. Then the upsampled data is FIR filtered. After this, the resultant is downsampled.
</para>
</refsection>
@@ -54,9 +54,9 @@ This function upsamples the input data in the matrix by a factor of n. Then the
<title>Examples</title>
<programlisting role="example"><![CDATA[
upfirdn([1,2,3],2,3,5)
-ans =
+//ans =
-2. 0.
+//2. 0.
]]></programlisting>
</refsection>
</refentry>
diff --git a/help/en_US/window.xml b/help/en_US/wind.xml
index 19d4312..19d4312 100644
--- a/help/en_US/window.xml
+++ b/help/en_US/wind.xml
diff --git a/help/en_US/wkeep.xml b/help/en_US/wkeep.xml
index 3bac5e2..85c0692 100644
--- a/help/en_US/wkeep.xml
+++ b/help/en_US/wkeep.xml
@@ -44,7 +44,7 @@
<refsection>
<title>Description</title>
<para>
-This is an Octave function
+This function extracts a vector from the given vector of length l.
[y]=wkeep(x,l) extracts a vector of length l from the centre of input vector x.
[y]=wkeep(x,l,opt) extracts vector based on opt which could be 'l','r' or 'c' (left, right or central).
</para>
@@ -54,9 +54,9 @@ This is an Octave function
<title>Examples</title>
<programlisting role="example"><![CDATA[
1. [y]=wkeep([1 2 3;4 5 6],[2 2])
-y= 1 2
+//y= 1 2
2. [y]=wkeep([1 2 3 4 5 6],3,'r')
-y= 4 5 6
+//y= 4 5 6
]]></programlisting>
</refsection>
</refentry>
diff --git a/help/en_US/yulewalker.xml b/help/en_US/yulewalker.xml
index 5fdac3c..d4393fb 100644
--- a/help/en_US/yulewalker.xml
+++ b/help/en_US/yulewalker.xml
@@ -44,4 +44,19 @@ Fit an AR (p)-model with Yule-Walker estimates given a vector C of autocovarianc
Returns the AR coefficients, A, and the variance of white noise, V.
</para>
</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+ [A,V]=yulewalker([1 2 3])
+// V =
+// - 2.6666667
+// A =
+// 1.3333333
+// 0.3333333
+
+ ]]></programlisting>
+</refsection>
+
+
</refentry>
diff --git a/help/en_US/zerocrossing.xml b/help/en_US/zerocrossing.xml
index 5109f99..4d7da0f 100644
--- a/help/en_US/zerocrossing.xml
+++ b/help/en_US/zerocrossing.xml
@@ -17,14 +17,14 @@
<refnamediv>
<refname>zerocrossing</refname>
- <refpurpose>This function estimates the points at which a given waveform crosses the x-axis.</refpurpose>
+ <refpurpose>This function estimates the points at which a given waveform y=y(x) crosses the x-axis using linear interpolation. </refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>
- x = zerocrossing (w, y)
+ w = zerocrossing (x, y)
</synopsis>
</refsynopsisdiv>
@@ -32,25 +32,42 @@
<title>Parameters</title>
<variablelist>
<varlistentry><term>w:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para>vector of points at which the function y(x) crosses x-axis. </para></listitem></varlistentry>
<varlistentry><term>y:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para> The dependant variable,y(x)</para></listitem></varlistentry>
<varlistentry><term>x:</term>
- <listitem><para> </para></listitem></varlistentry>
+ <listitem><para> The independant variable</para></listitem></varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
-This is an Octave function.
-This function estimates the points at which a given waveform y = y(w) crosses the x-axis. It uses linear interpolation.
+This function estimates the points at which a given waveform y = y(x) crosses the x-axis. It uses linear interpolation.
</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
+x = linspace(0,1,100);
+y = 2*sin(2*%pi*x);
+x0= zerocrossing(x,y);
+//ans:
+// x0 = 0. 0.5 1.0 1.5
+y0=interp1(x,y,x0)
+plot(x,y,x0,y0,'x')
+
]]></programlisting>
+
+<scilab:image>
+x = linspace(0,2,200);
+y = 2*sin(2*%pi*x);
+x0= zerocrossing(x,y);
+y0=interp1(x,y,x0)
+plot(x,y,x0,y0,'x')
+
+</scilab:image>
+
</refsection>
</refentry>
diff --git a/macros/convmtx.sci b/macros/convmtx.sci
index c0aa891..c1f0109 100644
--- a/macros/convmtx.sci
+++ b/macros/convmtx.sci
@@ -1,36 +1,30 @@
-//Convolution Matrix
-//convmtx(h,n) returns the convolution matrix for vector h. If h is a
-//column vector and X is a column vector of length n, then convmtx(h,n)*X
-//gives the result of the convolution oof h and X.If R is a row vector and X//is a row vector of length N, then X*convmtx(R,N) gives the convolution of R and X.
-//Example:
-//Generate a simple convolution matrix.
-//
-// h = [%i 1 2 3];
-// convmtx(h,7) //Convolution matrix
-//
-//Author
-//Debdeep Dey
-function t=convmtx(v,n);
- n=double(n);
- [mv,nv]=size(v);
- v=v(:);
-
- //put Toeplitz code inline
- c = [v; zeros(n-1,1)];
- r = zeros(n,1);
- m = length(c);
- x = [r(n:-1:2) ; c(:)];
-
- cidx = (0:m-1)';
- ridx = n:-1:1;
- t = cidx(:,ones(n,1)) + ridx(ones(m,1),:); //Toeplitz subscripts
- t(:) = x(t); //actual data
-
- //t = single(t);
- // end of toeplitz code
-
-if mv < nv then
- t = t.';
- end
-
+function b = convmtx (a, n)
+//Calling sequence:
+//b=convmtx(a,n);
+//convmtx(a,n);
+
+//This function returns the convolution matrix 'b'.
+//If 'a' is a column vector and if we need the convolution of 'a' with another column vector 'x' of length 'n' then an operation "convmtx(a,n)*x" yeilds the convoluted sequence much faster.
+
+//Similarily, if 'a' is a row vector then to convolve with another row vector 'x' of length n , then convoluted sequence can be obtained by
+//x*convmtx(a,n)
+
+
+
+[nargout,nargin]=argn();
+ if (nargin ~= 2)
+ error("wrong number of input arguments");
+ end
+
+ [r, c] = size(a);
+
+ if ((r ~= 1) & (c ~= 1)) | (r*c == 0)
+ error("convmtx: expecting vector argument");
+ end
+
+ b = toeplitz([a(:); zeros(n-1,1)],[a(1); zeros(n-1,1)]);
+ if (c > r)
+ b = b.';
+ end
+
endfunction
diff --git a/macros/deconv.sci b/macros/deconv.sci
new file mode 100644
index 0000000..1c4d8fa
--- /dev/null
+++ b/macros/deconv.sci
@@ -0,0 +1,104 @@
+function [b, r] = deconv (y, a)
+// calling sequence:
+// [b,r]= deconv (y, a)
+// Deconvolve two vectors.
+//
+// [b, r] = deconv (y, a) solves for b and r such that
+// y = conv (a, b) + r.
+//
+// If y and a are polynomial coefficient vectors, b will
+// contain the coefficients of the polynomial quotient and r will be
+// a remainder polynomial of lowest order.
+
+//Test cases:
+//1.
+//[b, r] = deconv ([3, 6, 9, 9], [1, 2, 3])
+//Output:
+//b=[3, 0]
+//r=[0, 0, 0, 9]
+
+//2.
+//[b, r] = deconv ([3, 6], [1; 2; 3])
+//Output:
+//b = 0.
+//r= [- 2. ; 8]
+
+
+
+
+
+ [nargout,nargin]=argn();
+
+ if (nargin ~= 2)
+ error ("wrong number of input arguments");
+ end
+
+ if (~ (isvector (y) & isvector (a)))
+ error ("deconv: both arguments must be vectors");
+ end
+
+ la = length (a);
+ ly = length (y);
+
+ lb = ly - la + 1;
+
+ // Ensure A is oriented as Y.
+ if (diff (size (y)) * diff (size (a)) < 0)
+ a = permute (a, [2, 1]);
+ end
+
+ if (ly > la)
+ o=size (y) - size (a) + 1;
+ x = zeros (o(1),o(2));
+ x(1) = 1;
+ b = filter (real(y), real(a), x);
+ elseif (ly == la)
+ b = filter (real(y), real(a), 1);
+ else
+ b = 0;
+ end
+
+ lc = la + length (b) - 1;
+ if (ly == lc)
+ if (length(a)==length(b) | length(a)>length(b))
+ if isrow(a)
+ q=conv(a,b);
+
+ u=[];
+ for i=1:length(y)
+ u=[u;q];
+ end
+
+ w=[];
+ if (isrow(y))
+ for i=1:length(q)
+ w=[w;y];
+ end
+ else
+ for i=1:length(q)
+ w=[w,y];
+ end
+ end
+
+ r = w-u;
+
+ r=diag(r);
+ end
+ end
+ r=y-conv(a,b);
+
+
+elseif(la~=lc)
+ // Respect the orientation of Y"
+ if (size (y,"r") <= size (y,"c"))
+ r = [(zeros (1, lc - ly)), y] - conv (a, b);
+ else
+ r = [(zeros (lc - ly, 1)); y] - conv (a, b);
+ end
+ if (ly < la)
+ // Trim the remainder is equal to the length of Y.
+ r = r($-(length(y)-1):$);
+ end
+end
+
+endfunction
diff --git a/macros/downsample.sci b/macros/downsample.sci
index 9bd1591..e0bc508 100644
--- a/macros/downsample.sci
+++ b/macros/downsample.sci
@@ -1,31 +1,66 @@
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+//Function File vary = downsample (x, n)
+//Function File y = downsample (x, n, offset)
+// Downsample the signal, selecting every nth element. If x
+// is a matrix, downsample every column.
+//
+// If offset is defined, select every nth element starting at
+// sample offset.
+//
+//
+
+//Test cases:
+
+//1.downsample([1,2,3,4,5],2)
+//EXPECTED OUTPUT:[1,3,5]
+
+
+//2.downsample([1;2;3;4;5],2)
+//EXPECTED OUTPUT:[1;3;5]
+
+
+//3.downsample([1,2;3,4;5,6;7,8;9,10],2)
+//EXPECTED OUTPUT:[1,2;5,6;9,10]
+
+
+//4.downsample([1,2,3,4,5],2,1)
+//EXPECTED OUTPUT:[2,4]
+
+
+//5.downsample([1,2;3,4;5,6;7,8;9,10],2,1)
+//EXPECTED OUTPUT:[3,4;7,8]
+
+
+
function y = downsample (x, n, phase)
-//This function downsamples the signal by selecting every nth element.
-//Calling Sequence
-//y = downsample (x, n)
-//y = downsample (x, n, phase)
-//Parameters
-//x: scalar, vector or matrix of real or complex numbers
-//n: real number or vector
-//phase: integer value, 0 <= phase <= (n - 1), default value 0, or logical
-//Description
-//This is an Octave function.
-//This function downsamples the signal by selecting every nth element supplied as parameter 2. If x is a matrix, the function downsamples every column.
-//If the phase is specified, every nth element is selected starting from the sample phase. The default phase is 0.
-//Examples
-//downsample([1,2,4],2)
-//ans =
-// 1. 4.
-
-funcprot(0);
-rhs = argn(2)
-if(rhs<2 | rhs>3)
-error("Wrong number of input arguments.")
+[nargout,nargin]=argn();
+ if (nargin<2 | nargin>3)
+ error ("wrong no. of input arguments");
+ end
+
+if nargin==2
+ phase=0;
+ else
+ if phase > n-1
+ warning("This is incompatible with Matlab (phase = 0:n-1). See octave-forge signal package release notes for details." )
+ end
end
-
- select(rhs)
- case 2 then
- y = callOctave("downsample",x,n)
- case 3 then
- y = callOctave("downsample",x,n,phase)
- end
+
+ if isvector(x)
+ y = x(phase + 1:n:$);
+ else
+ y = x(phase + 1:n:$,:);
+ end
+
endfunction
diff --git a/macros/fftfilt.sci b/macros/fftfilt.sci
index 1fcd211..ab171ce 100644
--- a/macros/fftfilt.sci
+++ b/macros/fftfilt.sci
@@ -24,9 +24,9 @@ function y = fftfilt(b, x, varargin)
//
// Examples
// 1) Filtering a sine wave
- // x = sin(1:2000);
- // b = [1 1/2];
- // y = fftfilt(b,x);
+// x = sin(1:2000);
+// b = [1 1/2];
+// y = fftfilt(b,x);
// 2) Multiple filters (1,1/3) and (1/4,1/5);
// x = sin(1:2000);
// b = [1 1/4;1/3 1/5];
@@ -202,6 +202,3 @@ function y = fftfilt(b, x, varargin)
endfunction
-
-
-
diff --git a/macros/gausswin.sci b/macros/gausswin.sci
index eb3b3d8..4a65c14 100644
--- a/macros/gausswin.sci
+++ b/macros/gausswin.sci
@@ -1,32 +1,27 @@
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
function w = gausswin (m, a)
-//This function returns the filter coefficients of a Gaussian window.
-//Calling Sequence
-//w = gausswin (m)
-//w = gausswin (m, a)
-//Parameters
-//m: positive integer value
-//a:
-//w: output variable, vector of real numbers
-//Description
-//This is an Octave function.
-//This function returns the filter coefficients of a Gaussian window of length m supplied as input, to the output vector w.
-//The second parameter is the width measured in sample rate/number of samples and should be f for time domain and 1/f for frequency domain. The width is inversely proportional to a.
-//Examples
-//gausswin(3)
-//ans =
-// 0.2493522
-// 1.
-// 0.2493522
-
-funcprot(0);
-rhs = argn(2)
-if(rhs<1 | rhs>2)
-error("Wrong number of input arguments.")
-end
-if(rhs==1)
-w = callOctave("gausswin",m)
-elseif(rhs==2)
-w = callOctave("gausswin",m,a)
-end
-endfunction
+//This function is used to generate the gaussian window.
+[nargout,nargin]=argn();
+ if (nargin < 1 | nargin > 2)
+ error("wrong no. of input arguments");
+ elseif (~ (isscalar (m) & (m == fix (m)) & (m > 0)))
+ error ("gausswin: M must be a positive integer");
+ elseif (nargin == 1)
+ a = 2.5;
+ end
+
+ w = exp ( -0.5 * ( a/m * [ -(m-1) : 2 : m-1 ]' ) .^ 2 );
+
+endfunction
diff --git a/macros/gmonopuls.sci b/macros/gmonopuls.sci
index 6fa9db0..7265853 100644
--- a/macros/gmonopuls.sci
+++ b/macros/gmonopuls.sci
@@ -1,7 +1,33 @@
-function [y]=gmonopuls(t,fc)
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
-// Gaussian monopulse
-// Caling Sequence
+function y = gmonopuls(t, fc )
+
+
+//
+// This program is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 3 of the License, or (at your option) any later
+// version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, see <http://www.gnu.org/licenses/>.
+
+
+// Calling Sequence
// [y]=gmonopuls(t)
// [y]=gmonopuls(t,fc)
// Parameters
@@ -13,15 +39,23 @@ function [y]=gmonopuls(t,fc)
// Examples
// 1. gmonopuls([1 2 3],0.1)
// ans= 0.85036 0.94070 0.52591
-// 2. gmonopuls([1 2 3])
+// 2. gmonopuls([1 2 3],[])
// ans= 0 0 0
-funcprot(0);
-rhs=argn(2);
-if ( rhs<1 ) then
- error ("Wrong number of input arguments.")
-elseif (rhs==1)
- y=callOctave("gmonopuls",t)
-else y=callOctave("gmonopuls",t,fc)
-end
+
+
+ [nargout,nargin]=argn();
+
+ if (nargin<1 | nargin > 2)
+ error("wrong number of input arguments");
+ end
+ if(isempty(fc))
+ fc=1e3;
+ end
+
+ if fc < 0
+ error("fc must be positive");
+ end
+ y = 2*sqrt(exp(1)) .* %pi.*t.*fc.*exp(-2 .* (%pi.*t.*fc).^2);
+
endfunction
diff --git a/macros/mexihat.sci b/macros/mexihat.sci
index 3f2ed48..5f94988 100644
--- a/macros/mexihat.sci
+++ b/macros/mexihat.sci
@@ -1,3 +1,16 @@
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+
function [psi,x]=mexihat(lb,ub,n)
// Generates Mexican Hat wavelet
@@ -8,7 +21,7 @@ function [psi,x]=mexihat(lb,ub,n)
// ub: Real or complex valued vector or matrix
// n: Real strictly positive scalar number
// Description
-// This is an Octave function
+// This is an Octave function which is built in scilab.
// This function returns values of the Mexican hat wavelet in the specified interval at all the sample points.
// Examples
// 1. [a,b]= mexihat(1,2,3)
@@ -19,9 +32,25 @@ function [psi,x]=mexihat(lb,ub,n)
// b = [1;1;1]
funcprot(0);
-rhs=argn(2);
-if (rhs<3) then
- error ("Wrong number of input arguments.")
-else [psi,x]=callOctave("mexihat",lb,ub,n)
+
+[nargout,nargin]=argn();
+
+ if (nargin < 3)
+ error("wrong number of input arguments");
+ end
+
+ if (n <= 0)
+ error("n must be strictly positive");
+ end
+
+ if(isvector(lb))
+ for(i=1:length(lb))
+ x(i) = linspace(lb(i),ub,n);
+ psi(i) = (1-x(i).^2).*(2/(sqrt(3)*%pi^0.25)) .* exp(-x(i).^2/2) ;
+ end
+
+else
+ x = linspace(lb,ub,n);
+ psi = (1-x.^2).*(2/(sqrt(3)*%pi^0.25)) .* exp(-x.^2/2) ;
end
endfunction
diff --git a/macros/mpoles.sci b/macros/mpoles.sci
new file mode 100644
index 0000000..bba9997
--- /dev/null
+++ b/macros/mpoles.sci
@@ -0,0 +1,124 @@
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+function [multp, indx] = mpoles (p, tol, reorder)
+
+//Calling sequence:
+// [multp, idxp] = mpoles (p)
+// [multp, idxp] = mpoles (p, tol)
+// [multp, idxp] = mpoles (p, tol, reorder)
+// Identify unique poles in p and their associated multiplicity.
+//
+// The output is ordered from largest pole to smallest pole.
+//
+// If the relative difference of two poles is less than tol then they are
+// considered to be multiples. The default value for tol is 0.001.
+//
+// If the optional parameter reorder is zero, poles are not sorted.
+//
+// The output multp is a vector specifying the multiplicity of the poles.
+// multp(n) refers to the multiplicity of the Nth pole
+// p(idxp(n)).
+//
+//
+//
+
+// test case:
+
+// p = [2 3 1 1 2];
+// [m, n] = mpoles (p)
+// n =
+// 2.
+// 5.
+// 1.
+// 4.
+// 3.
+// m =
+// 1.
+// 1.
+// 2.
+// 1.
+// 2.
+//
+
+
+[nargout,nargin]=argn();
+
+ if (nargin < 1 | nargin > 3)
+ error("wrong number of input arguments");
+ end
+
+ if (nargin < 2 | isempty (tol))
+ tol = 0.001;
+ end
+
+ if (nargin < 3 | isempty (reorder))
+ reorder = %t;
+ end
+
+ Np = length (p);
+
+ // Force the poles to be a column vector.
+
+ p = p(:);
+
+ // Sort the poles according to their magnitidues, largest first.
+
+ if (reorder)
+ // Sort with smallest magnitude first.
+ [p, ordr] = gsort (p,"r","i");
+ // Reverse order, largest maginitude first.
+ n = Np:-1:1;
+ p = p(n);
+ ordr = ordr(n);
+ else
+ ordr = 1:Np;
+ end
+
+ // Find pole multiplicty by comparing the relative differnce in the
+ // poles.
+
+ multp = zeros (Np, 1);
+ indx = [];
+ n = find (multp == 0, 1);
+
+
+
+
+
+
+ while (n)
+ dp = abs (p-p(n));
+ if (p(n) == 0.0)
+ if (or (abs (p) > 0 & (abs(p)<%inf)))
+ p0 = mean (abs (p(abs (p) > 0 & abs(p)<%inf)));
+ else
+ p0 = 1;
+ end
+ else
+ p0 = abs (p(n));
+ end
+ k = find (dp < tol * p0)';
+ // Poles can only be members of one multiplicity group.
+// if (length(indx))
+// mk=members(k,indx);
+// k = (~ bool2s(mk~=0));
+// end
+ m = 1:length (k);
+ multp(k) = m';
+ indx = [indx; k];
+ n = find (multp == 0, 1);
+ end
+ multp = multp(indx);
+ indx = ordr(indx);
+
+endfunction
diff --git a/macros/musicBase.sci b/macros/musicBase.sci
index f915bbe..757834a 100644
--- a/macros/musicBase.sci
+++ b/macros/musicBase.sci
@@ -1,4 +1,6 @@
// Date of creation: 19 Dec, 2015
+
+
function [outputData,msg] = musicBase(inputData)
// Implements the core of the MUSIC algorithm
// Used by pmusic and rootmusic algorithm
@@ -14,7 +16,7 @@ function [outputData,msg] = musicBase(inputData)
inputData.isWindowSpecified);
- // disp("eigenvects in musicBase");
+ //disp("eigenvects in musicBase");
// disp(eigenvects);
// disp("eigenvals in musicBase");
// disp(eigenvals);
@@ -66,7 +68,7 @@ function [eigenvects,eigenvals,msg] = computeEig(x,isCorrFlag, windowLength, nov
eigenvects = eigenvects(:,order);
else
if xIsMatrix then
- // TODO: check for dimenion constraints
+ // TODO: check for dimension constraints
else
// x is vector
Lx = length(x);
diff --git a/macros/nnls.sci b/macros/nnls.sci
index 3e77d65..46554e9 100644
--- a/macros/nnls.sci
+++ b/macros/nnls.sci
@@ -1,4 +1,4 @@
-function x = nnls(E,f,x)
+function [x,w] = nnls(E,f)
// Non Negative Least Squares (nnls) for Ex=f with the constraint x>=0
// Reference
diff --git a/macros/pchip.sci b/macros/pchip.sci
index 4674929..184fb8b 100644
--- a/macros/pchip.sci
+++ b/macros/pchip.sci
@@ -9,21 +9,22 @@ function v = pchip(x,y,xx)
// Parameters
// x: a vector
-// y: is Y is vector then it must have the same length as x and Y is matrix then the last dimension of Y must equal length(X).
+// y: if Y is vector then it must have the same length as x and Y is matrix then the last dimension of Y must equal length(X).
// xx: Points for interpolation
// v: vector of interpolantant at xx
-// Examples
+//// Examples
// x=[0 1 2 3 4 5]
// y=[1 0 1 0 1 0]
-// xx=linspace(0:10,800)
+// xx=linspace(0,5,800)
// v=pchip(x, y)
// v=pchip(x,y,xx)
-// See also
+//plot(x,y,xx,v,'o')
+
// Authors
// Jitendra Singh
-// execute function "pchips" prior executing this function
+// NOTE:execute function "pchips" prior executing this function
if argn(2)==3 & ~isreal(xx)
@@ -132,7 +133,4 @@ v = matrix(v,[dd,sizexx]);
end
- endfunction
-
-
-
+endfunction
diff --git a/macros/pchips.sci b/macros/pchips.sci
index 78c7473..c639ca2 100644
--- a/macros/pchips.sci
+++ b/macros/pchips.sci
@@ -1,27 +1,40 @@
function d = pchips(x,y,delta)
+//Piecewise Cubic Hermite Interpolating Polynomial (PCHIP)
+//Parameters
+// x: a vector
+// y: is Y is vector then it must have the same length as x and Y is matrix then the last dimension of Y must equal
+//length(X).
+// delta: Points for interpolation
+// d: vector of interpolantant at delta
+//Examples:
+//x = -3:3;
+//y = [-1 -1 -1 0 1 1 1];
+//xq1 = -3:.01:3;
+//v=pchips(x,y,xq1)
+//
n = length(x);
- if n==2
+ if n==2
d = repmat(delta(1),size(y));
-
+
else
d = zeros(size(y));
-
+
k = find(sign(delta(1:n-2)).*sign(delta(2:n-1)) > 0);
-
+
h = diff(x);
hs = h(k)+h(k+1);
w1 = (h(k)+hs)./(3*hs);
w2 = (hs+h(k+1))./(3*hs);
-
+
if ~isempty (k) then
-
-
+
+
del_mx = max(abs(delta(k)), abs(delta(k+1)));
del_mn = min(abs(delta(k)), abs(delta(k+1)));
d(k+1) = del_mn./conj(w1.*(delta(k)./del_mx) + w2.*(delta(k+1)./del_mx));
@@ -40,10 +53,10 @@ function d = pchips(x,y,delta)
d(n) = 3*delta(n-1);
end
end
-
-
-
-
+
+
+
+
end
-
+
endfunction
diff --git a/macros/peak2rms.sci b/macros/peak2rms.sci
index 3a8df40..8b61024 100644
--- a/macros/peak2rms.sci
+++ b/macros/peak2rms.sci
@@ -1,106 +1,108 @@
-function out = peak2rms(in,orientation)
-//This function calculates the ratio of peak magnitude to the Root Mean Square(RMS) value.
-//
-//Calling Sequence
-//OUT=peak2rms(IN)
-//OUT=peak2rms(IN,orientation)
-//
-//Parameters
-//in:Vector or Matrix of real or complex elements.
-//orientation: A string with possible values "r", "c" or "m" giving the dimension along which the peak2rms value is to be calculated.
-//out:A scalar with real value when input is a vector.When input is a matrix, out is the peak magnitude to RMS value along the orientation specified or the default one when not specified.
-//
-//Description
-//For vector as input, the output is the ratio of peak value to the RMS value. The RMS value can be calculated by taking the square root of mean value of the squared sum of the elements.
-//
-//When a matrix is given as input the output is peak to RMS ratio in the orientation specified.
-//The orientation can be given as string with values "r","c" or "m".
-//
-//peak2rms(in, 1) calculates the values of ratio of peak to RMS of columns of matrix. The output in this case is a row vector with peak2rms value of each column of in.
-//
-//peak2rms(in, 2) calculates the values of ratio of peak to RMS of rows of matrix, where the output would be a column vector having peak2rms value of each row of in.
-//
-//The default orientation is chosen to be the index of first dimension of input greater than 1.Hence peak2rms(in) is equivalent to peak2rms(in, "m").
-//
-//For an N dimensional array the orientation is the index of first non singleton dimension of the array.
-//
-//If the elements of matrix are complex the absolute values are considered in the calculation of RMS value.
-//
-//Examples
-//To calculate peak2rms of a vector:
-//IN=[6 19 10 25]
-//OUT=peak2rms(IN)
-//The output is OUT=
- // 1.4638501
- //1.3887301
- //1.119186
-//
-//Examples
-//To calculate peak2rms of rows of matrix:
-//IN=[1 3 5;2 4 6;7 8 9]
-//OUT=peak2rms(IN,2)
-//The output is
- //OUT= 1.3719887
-//
-//Examples
-//To calculate peak magnitude to RMS value of sinusoid:
-//
-//t=0:0.6:9
-//IN=cos(6*%pi*t);
-//OUT= peak2rms(IN)
-//The output is
- //OUT= 1.3719887
-//See also
-//abs
-//mean
-// max
-//sqrt
-//isempty
-//
-//Authors
-//Indira Askaukar
-//
-//Bibliography
-//Matlab help document.
-//Modified to accept char i/p
-//MOdified function to match MATLAB input arguments
-//Now for calculating the values of ratio of peak to RMS of columns of matrix use peak2rms(in,1)
-//And for calculates the values of ratio of peak to RMS of rows of matrix. use peak2rms(in,2)
-//Updated help comments accordingly
-//MOdifications done by by Debdeep Dey
- if(type(in)=10) then //if i/p is of type char convert it to its ascii value
- in=ascii(in);
- end
-
- if argn(2)==1
- //calculating the Root Mean Square value
- a=abs(in)
- a=a.^2
- s=mean(a,"m")
- rmsvalue=sqrt(s)
- peak = max(abs(in),"m")
- rmsq = rmsvalue
-
-else
- //Calculation of the RMS value
- if orientation==1 then
- orient='r';
- else
- orient='c';
- end
-
- a=abs(in)
- a=a.^2
- s=mean(a,orient)
- rmsvalue=sqrt(s)
- [peak,k] = max(abs(in),orient)
- rmsq = rmsvalue
-
-end
- //Calculation of Ratio of peak to the Root Mean square value
-if isempty(peak)
- out = rmsq;
-else
- out = peak ./ rmsq;
-end
-endfunction
+function out = peak2rms(in,orientation)
+//This function calculates the ratio of peak magnitude to the Root Mean Square(RMS) value.
+//
+//Calling Sequence
+//OUT=peak2rms(IN)
+//OUT=peak2rms(IN,orientation)
+//
+//Parameters
+//in:Vector or Matrix of real or complex elements.
+//orientation: A string with possible values "r", "c" or "m" giving the dimension along which the peak2rms value is to be calculated.
+//out:A scalar with real value when input is a vector.When input is a matrix, out is the peak magnitude to RMS value along the orientation specified or the default one when not specified.
+//
+//Description
+//For vector as input, the output is the ratio of peak value to the RMS value. The RMS value can be calculated by taking the square root of mean value of the squared sum of the elements.
+//
+//When a matrix is given as input the output is peak to RMS ratio in the orientation specified.
+//The orientation can be given as string with values "r","c" or "m".
+//
+//peak2rms(in, 1) calculates the values of ratio of peak to RMS of columns of matrix. The output in this case is a row vector with peak2rms value of each column of in.
+//
+//peak2rms(in, 2) calculates the values of ratio of peak to RMS of rows of matrix, where the output would be a column vector having peak2rms value of each row of in.
+//
+//The default orientation is chosen to be the index of first dimension of input greater than 1.Hence peak2rms(in) is equivalent to peak2rms(in, "m").
+//
+//For an N dimensional array the orientation is the index of first non singleton dimension of the array.
+//
+//If the elements of matrix are complex the absolute values are considered in the calculation of RMS value.
+//
+//Examples
+//To calculate peak2rms of a vector:
+//IN=[6 19 10 25]
+//OUT=peak2rms(IN)
+//The output is OUT=
+ // 1.4927036
+//
+//Examples
+////To calculate peak2rms of rows of matrix:
+//IN=[1 3 5;2 4 6;7 8 9]
+//OUT=peak2rms(IN,2)
+//The output is
+ //OUT= 1.4638501
+ //1.3887301
+ //1.119186
+
+//
+//Examples
+//To calculate peak magnitude to RMS value of sinusoid:
+//
+//t=0:0.6:9
+//IN=cos(6*%pi*t);
+//OUT= peak2rms(IN)
+//The output is
+ //OUT= 1.3719887
+//See also
+//abs
+//mean
+// max
+//sqrt
+//isempty
+//
+//Authors
+//Indira Askaukar
+//
+//Bibliography
+//Matlab help document.
+//Modified to accept char i/p
+//MOdified function to match MATLAB input arguments
+//Now for calculating the values of ratio of peak to RMS of columns of matrix use peak2rms(in,1)
+//And for calculates the values of ratio of peak to RMS of rows of matrix. use peak2rms(in,2)
+//Updated help comments accordingly
+//MOdifications done by by Debdeep Dey
+ //if(type(in)=10) then //condition checking error,for equality it is '=='
+ if(type(in)==10)
+ in=ascii(in);
+ end
+
+ if argn(2)==1
+ //calculating the Root Mean Square value
+ a=abs(in)
+ a=a.^2
+ s=mean(a,"m")
+ rmsvalue=sqrt(s)
+ peak = max(abs(in),"m")
+ rmsq = rmsvalue
+
+else
+ //Calculation of the RMS value
+ if orientation==1 then
+ orient='r';
+ else
+ orient='c';
+ end
+
+ a=abs(in)
+ a=a.^2
+ s=mean(a,orient)
+ rmsvalue=sqrt(s)
+ [peak,k] = max(abs(in),orient)
+ rmsq = rmsvalue
+
+end
+ //Calculation of Ratio of peak to the Root Mean square value
+if isempty(peak)
+ out = rmsq;
+else
+ out = peak ./ rmsq;
+end
+endfunction
diff --git a/macros/peig.sci b/macros/peig.sci
index 7529edc..b4157d7 100644
--- a/macros/peig.sci
+++ b/macros/peig.sci
@@ -14,47 +14,62 @@ function [S,f,v,e] = peig(varargin)
//
// Parameters:
// x - int|double - vector|matrix
- // Input signal. In case of a matrix, each row of x represents a
- // seperate observation of the signal. If 'corr' flag is specified,
+ // Input signal. In case of a matrix, each row of x represents a
+ // seperate observation of the signal. If 'corr' flag is specified,
// then x is the correlation matrix.
- // If w is not specified in the input, it is determined by the
- // algorithm. If x is real valued, then range of w is [0, pi].
+ // If w is not specified in the input, it is determined by the
+ // algorithm. If x is real valued, then range of w is [0, pi].
// Otherwise, the range of w is [0, 2pi)
// p - int|double - scalar|vector
// p(1) is the dimension of the signal subspace
- // p(2), if specified, represents a threshold that is multiplied by
+ // p(2), if specified, represents a threshold that is multiplied by
// the smallest estimated eigenvalue of the signal's correlation matrix.
// w - int|double - vector
- // w is the vector of normalized frequencies over which the
+ // w is the vector of normalized frequencies over which the
// pseuspectrogram is to be computed.
// nfft - int - scalar (Default = 256)
// Length of the fft used to compute pseudospectrum. The length of S
// (and hence w/f) depends on the type of values in x and nfft.
- // If x is real, length of s is (nfft/2 + 1) {Range of w = [0, pi]} if
+ // If x is real, length of s is (nfft/2 + 1) {Range of w = [0, pi]} if
// nfft is even and (nfft+1)/2 {Range of w = [0, pi)} otherwise.
// If x is complex, length of s is nfft.
// fs - int|double - scalar (Default = 1)
- // Sampling rate. Used to convert the normalized frequencies (w) to
+ // Sampling rate. Used to convert the normalized frequencies (w) to
// actual values (f) and vice-versa.
// nwin - int|double - scalar (int only)|vector (Default = 2*p(1))
// If nwin is scalar, it is the length of the rectangular window.
// Otherwise, the vector input is considered as the window coefficients.
// Not used if 'corr' flag present.
- // If x is a vector, windowing not done in nwin in scalar. If x is a
- // matrix,
+ // If x is a vector, windowing not done in nwin in scalar. If x is a
+ // matrix,
// noverlap - int - scalar (Default = nwin-1)
- // number of points by which successive windows overlap. noverlap not
+ // number of points by which successive windows overlap. noverlap not
// used if x is a matrix
// freqrange - string
- // The range of frequencies over which the pseudospetrogram is
+ // The range of frequencies over which the pseudospetrogram is
// computed. Three possible values - 'onesided', 'twosided', 'centered'
// 'corr' flag
- // Presence indicates that the primary input x is actually a
+ // Presence indicates that the primary input x is actually a
// correlation matrix
//
// Examples:
- // TODO:
- //
+//1.
+// fs = 100;
+// t = 0:1/fs:1-1/fs;
+// s = 2*sin(2*%pi*25*t)+sin(2*%pi*35*t)+rand(1,100,"normal");
+// [S,w]=peig(s,2,512,fs,'half');
+// plot(w,S);
+ //OUTPUT: gives the plot of power vs normalised frequencies
+////2.
+// fs = 100;
+//t = 0:1/fs:1-1/fs;
+//s = 2*sin(2*%pi*25*t)+sin(2*%pi*35*t);
+//[S,w]=peig(s,2,512,fs,'half');
+//plot(w,S);
+
+ //EXECUTE FUNCTIONS subspaceMethodsInputPars.sci, musicBase.sci PRIOR THE EXECUTION OF THIS FUNCTION
+
+
// See also
// rooteig | pmusic | pmtm | pcov | pmcov | pburg | pyulear | pwelch | corrmtx
//
@@ -64,16 +79,16 @@ function [S,f,v,e] = peig(varargin)
// References
// [1] Petre Stoica and Randolph Moses, Introduction To Spectral
// Analysis, Prentice-Hall, 1997, pg. 15
- // [2] S. J. Orfanidis, Optimum Signal Processing. An Introduction.
+ // [2] S. J. Orfanidis, Optimum Signal Processing. An Introduction.
// 2nd Ed., Macmillan, 1988.
-
+
funcprot(0);
-
- exec('subspaceMethodsInputParser.sci',-1);
- exec('musicBase.sci',-1);
- [data, msg, err_num] = subspaceMethodsInputParser(varargin);
-
+ //exec('/home/shashi/Desktop/FOSSEE-Signal-Processing-Toolbox-master/macros/subspaceMethodsInputParser.sci',-1);
+ // exec('/home/shashi/Desktop/FOSSEE-Signal-Processing-Toolbox-master/macros/musicBase.sci',-1);
+
+ [data, msg, err_num] = subspaceMethodsInputPars(varargin);
+
if length(msg)==0 then
// no error occured
else
@@ -90,7 +105,7 @@ function [S,f,v,e] = peig(varargin)
// computing the pseudospectrum
[S,f] = pseudospectrum(musicData.noiseEigenvects, ...
musicData.eigenvals,data.w,data.nfft, data.fs, data.freqrange,data.isFsSpecified);
-
+
v = musicData.noiseEigenvects;
e = musicData.eigenvals;
@@ -100,15 +115,15 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
nfft, fs, freqrange,isFsSpecified)
// disp("noise eigenvects in pseudospectrum - ");
// disp(noiseEigenvects);
-
+
// NOTE: the only difference from the pmusic code
// Using the noise subspace eigenvalues as weights
- weights = eigenvals(($-size(noiseEigenvects,2)+1):$);
+ weights = eigenvals(($-size(noiseEigenvects,2)+1):$);
denominator = 0;
-
+
isFreqGiven = %F;
-
+
for i=1:size(noiseEigenvects,2);
// disp("looping in pseudospectrum");
@@ -129,7 +144,7 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
pspec = pspec(:);
-
+
if ~isFreqGiven then
// correcting the range of pspec according to the user specification
if strcmpi(freqrange, 'onesided')==0 then
@@ -141,11 +156,11 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
end
pspec = pspec(range);
w = w(range);
-
+
elseif strcmpi(freqrange,'centered')==0 then
// convert two sided spectrum to centered
rem = modulo(nfft,2);
-
+
if rem then
idx = [((nfft+1)/2+1):nfft 1:(nfft+1)/2];
else
@@ -153,7 +168,7 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
end
pspec = pspec(idx);
w = w(idx);
-
+
if rem then
w(1:(nfft-1)/2) = - w(nfft:-1:((nfft+1)/2+1));
else
@@ -165,8 +180,8 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
endfunction
function [h,w] = computeFreqResponseByFFT(b,n,fs,isFsSpecified)
- // returns the frequency response (h) and the corresponding frequency
- // values (w) for a digital filter with numerator b. The evaluation of the
+ // returns the frequency response (h) and the corresponding frequency
+ // values (w) for a digital filter with numerator b. The evaluation of the
// frequency response is done at n points in [0,fs) using fft algorithm
//
// Similar to MATLAB's freqz(b,a,n,'whole',fs)
@@ -176,10 +191,10 @@ function [h,w] = computeFreqResponseByFFT(b,n,fs,isFsSpecified)
w = linspace(0,2*%pi,n+1)';
w($) = [];
w(1) = 0; // forcing the first frequency to be 0
-
+
// forcing b and a to be column vectors
b = b(:);
-
+
// zero padding for fft
zeroPadLength = n - length(b);
zeroPad = zeros(zeroPadLength,1);
@@ -187,34 +202,34 @@ function [h,w] = computeFreqResponseByFFT(b,n,fs,isFsSpecified)
h = fft(b);
-
+
if isFsSpecified then
w = w*fs/(2*%pi);
end
-
+
endfunction
function [h,w] = computeFreqResponseByPolyEval(b,f,fs,isFsSpecified)
// returns the frequency response (h) for a digital filter with numerator b.
// The evaluation of the frequency response is done at frequency values f
-
+
// disp(f);
// disp(isFsSpecified);
-
+
f = f(:);
b = b(:);
-
+
n = length(b);
powerMatrix = zeros(length(f),n);
powerMatrix(:,1) = 1;
for i=2:n
powerMatrix(:,i) = exp(f*(-i+1)*%i);
end
-
+
h = powerMatrix*b;
-
+
if isFsSpecified then
w = f * fs/(2*%pi);
end
-
+
endfunction
diff --git a/macros/periodogram.sci b/macros/periodogram.sci
index ca8995e..11971d6 100755
--- a/macros/periodogram.sci
+++ b/macros/periodogram.sci
@@ -1,46 +1,187 @@
-function [d,n]=periodogram(a,b,c,d,e)
-//Return the periodogram (Power Spectral Density) of X
-//Calling Sequence
-// [PXX, W] = periodogram (X)
-// [PXX, W] = periodogram (X, WIN)
-// [PXX, W] = periodogram (X, WIN, NFFT)
-// [PXX, W] = periodogram (X, WIN, NFFT, FS)
-// [PXX, W] = periodogram (..., "RANGE")
-//Parameters
-// X:data vector. If X is real-valued a one-sided spectrum is estimated. If X is complex-valued, or "RANGE" specifies "twosided", the full spectrum is estimated.
-//WIN: window weight data. If window is empty or unspecified a default rectangular window is used. Otherwise, the window is applied to the signal ('X .* WIN') before computing th periodogram. The window data must be a vector of the same length as X.
-//NFFT:number of frequency bins. The default is 256 or the next higher power of 2 greater than the length of X ('max (256,2.^nextpow2 (length (x)))'). If NFFT is greater than the length of the input then X will be zero-padded to the length of NFFT.
-//FS:sampling rate. The default is 1.
-//RANGE:range of spectrum. "onesided" computes spectrum from [0..nfft/2+1]."twosided" computes spectrum from [0..nfft-1].
-//Description
-//The optional second output W are the normalized angular frequencies. For a one-sided calculation W is in the range [0, pi]. If NFFT is even and [0, pi) if NFFT is odd. Similarly, for a two-sided calculation W is in the range [0, 2*pi] or [0, 2*pi)depending on NFFT.
-//
-//If a sampling frequency is specified, FS, then the output frequencies F will be in the range [0, FS/2] or [0, FS/2) for one-sided calculations. For two-sided calculations the range will be [0, FS).
-//
-//When called with no outputs the periodogram is immediately plotted in the current figure window.
- funcprot(0);
- lhs= argn(1);
- rhs= argn(2);
- if(rhs<1 | rhs>5)
- error("Wrong number of input arguments");
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+
+
+
+
+function [pxx, f] = periodogram (x, varargin)
+//Calling Sequence:
+//[PXX, F] = periodogram (X, WIN, NFFT, FS)
+//[PXX, F] = periodogram (..., "RANGE")
+
+// The possible inputs are:
+//
+// X
+//
+// data vector. If X is real-valued a one-sided spectrum is
+// estimated. If X is complex-valued, or "RANGE" specifies
+// "twosided", the full spectrum is estimated.
+//
+// WIN
+// window weight data. If window is empty or unspecified a
+// default rectangular window is used. Otherwise, the window is
+// applied to the signal ('X .* WIN') before computing the
+// periodogram. The window data must be a vector of the same
+// length as X.
+//
+// NFFT
+// number of frequency bins. The default is 256 or the next
+// higher power of 2 greater than the length of X ('max (256,
+// 2.^nextpow2 (length (x)))'). If NFFT is greater than the
+// length of the input then X will be zero-padded to the length
+// of NFFT.
+//
+// FS
+// sampling rate. The default is 1.
+//
+// RANGE
+// range of spectrum. "onesided" computes spectrum from
+// [0..nfft/2+1]. "twosided" computes spectrum from [0..nfft-1].
+//
+//
+
+
+//Test cases:
+////1.
+//n=0:319;
+//x=cos(%pi/4*n)+rand(size(n,"r"),"normal");
+//[pxx,w]=periodogram(x,ones(1,320),256,2000,"onesided");
+//plot2d(w,10*log10(pxx))
+//xtitle('periodogram','frequency','magnitude(db)')
+//xgrid()
+//
+//
+
+[nargout,nargin]=argn();
+ // check input arguments
+ if (nargin < 1 | nargin > 5)
+ error("wrong no. of input arguments")
+ end
+
+ nfft = [];
+ fs = [];
+ ran = [];
+ win = [];
+ j = 2;
+ for k = 1:length (varargin)
+ if (type (varargin(k))==10)
+ ran = varargin(k);
+ else
+ select (j)
+ case 2
+ win = varargin(k);
+ case 3
+ nfft = varargin(k);
+ case 4
+ fs = varargin(k);
+ end
+ j=j+1;
end
- if(lhs>2 | lhs< 2)
- error("Wrong number of output arguments");
+ end
+
+ if (~ isvector (x))
+ error ("periodogram: X must be a real or complex vector");
+ end
+ x = x(:); // Use column vectors from now on
+
+ n = size(x,"r");
+
+ if (~isempty (win))
+ if (~ isvector (win) | length (win) ~= n)
+ error ("periodogram: WIN must be a vector of the same length as X");
end
- select(rhs)
- case 1 then
- [d,n]= callOctave('periodogram',a);
- case 2 then
- [d,n]= callOctave('periodogram',a,b);
-
- case 3 then
- [d,n]= callOctave('periodogram',a,b,c);
-
- case 4 then
- [d,n]= callOctave('periodogram',a,b,c,d);
-
- case 5 then
- [d,n]= callOctave('periodogram',a,b,c,d,e);
+ win = win(:);
+ x =x.* win;
+else
+ win=window("re",length(x));
+ win=win(:);
+ x=x.*win;
+
+ end
+
+ if (isempty (nfft))
+ nfft = max (256, 2.^nextpow2 (n));
+ elseif (~ isscalar (nfft))
+ error ("periodogram: NFFT must be a scalar");
+ end
+
+ use_w_freq = isempty (fs);
+ if (~use_w_freq & ~ isscalar (fs))
+ error ("periodogram: FS must be a scalar");
+ end
+
+ if (~strcmpi (ran, "onesided"))
+ ran = 1;
+ elseif (~strcmpi (ran, "twosided"))
+ ran = 2;
+ elseif (~strcmpi (ran, "centered"))
+ error ('periodogram: centered ran type is not implemented');
+ else
+ ran = 2-isreal (x);
+ end
+
+ // compute periodogram
+
+ if (n > nfft)
+ Pxx = 0;
+ rr = modulo(length (x), nfft);
+ if (rr)
+ x = [x(:); zeros(nfft-rr, 1)];
end
-endfunction
+ x = sum (matrix (x, nfft,length(x)/nfft), 2);
+ end
+
+ if (~ isempty (win))
+ n = sum(win.*conj(win));
+ end;
+ Pxx = (abs (fft (x))) .^ 2 / n;
+ if (use_w_freq)
+ Pxx =Pxx/ 2*%pi;
+ else
+ Pxx =Pxx/ fs;
+ end
+
+ // generate output arguments
+
+ if (ran == 1) // onesided
+ if (modulo (nfft,2)==0) // nfft is even
+ psd_len = nfft/2+1;
+ Pxx = Pxx(1:psd_len) + [0; Pxx(nfft:-1:psd_len+1); 0];
+ else // nfft is odd
+ psd_len = (nfft+1)/2;
+ Pxx = Pxx(1:psd_len) + [0; Pxx(nfft:-1:psd_len+1)];
+ end
+ end
+
+ if (nargout ~= 1)
+ if (ran == 1)
+ f = (0:nfft/2)' / nfft;
+ elseif (ran == 2)
+ f = (0:nfft-1)' / nfft;
+ end
+ if (use_w_freq)
+ f =f* 2*pi; // generate w=2*pi*f
+ else
+ f =f* fs;
+ end
+ end
+
+
+
+ pxx = Pxx;
+
+
+
+
+endfunction
diff --git a/macros/pmusic.sci b/macros/pmusic.sci
index 0891bb9..7cc788a 100644
--- a/macros/pmusic.sci
+++ b/macros/pmusic.sci
@@ -16,47 +16,61 @@ function varargout = pmusic(varargin)
//
// Parameters:
// x - int|double - vector|matrix
- // Input signal. In case of a matrix, each row of x represents a
- // seperate observation of the signal. If 'corr' flag is specified,
+ // Input signal. In case of a matrix, each row of x represents a
+ // seperate observation of the signal. If 'corr' flag is specified,
// then x is the correlation matrix.
- // If w is not specified in the input, it is determined by the
- // algorithm. If x is real valued, then range of w is [0, pi].
+ // If w is not specified in the input, it is determined by the
+ // algorithm. If x is real valued, then range of w is [0, pi].
// Otherwise, the range of w is [0, 2pi)
// p - int|double - scalar|vector
// p(1) is the dimension of the signal subspace
- // p(2), if specified, represents a threshold that is multiplied by
+ // p(2), if specified, represents a threshold that is multiplied by
// the smallest estimated eigenvalue of the signal's correlation matrix.
// w - int|double - vector
- // w is the vector of normalized frequencies over which the
+ // w is the vector of normalized frequencies over which the
// pseuspectrogram is to be computed.
// nfft - int - scalar (Default = 256)
// Length of the fft used to compute pseudospectrum. The length of S
// (and hence w/f) depends on the type of values in x and nfft.
- // If x is real, length of s is (nfft/2 + 1) {Range of w = [0, pi]} if
+ // If x is real, length of s is (nfft/2 + 1) {Range of w = [0, pi]} if
// nfft is even and (nfft+1)/2 {Range of w = [0, pi)} otherwise.
// If x is complex, length of s is nfft.
// fs - int|double - scalar (Default = 1)
- // Sampling rate. Used to convert the normalized frequencies (w) to
+ // Sampling rate. Used to convert the normalized frequencies (w) to
// actual values (f) and vice-versa.
// nwin - int|double - scalar (int only)|vector (Default = 2*p(1))
// If nwin is scalar, it is the length of the rectangular window.
// Otherwise, the vector input is considered as the window coefficients.
// Not used if 'corr' flag present.
- // If x is a vector, windowing not done in nwin in scalar. If x is a
- // matrix,
+ // If x is a vector, windowing not done in nwin in scalar. If x is a
+ // matrix,
// noverlap - int - scalar (Default = nwin-1)
- // number of points by which successive windows overlap. noverlap not
+ // number of points by which successive windows overlap. noverlap not
// used if x is a matrix
// freqrange - string
- // The range of frequencies over which the pseudospetrogram is
+ // The range of frequencies over which the pseudospetrogram is
// computed. Three possible values - 'onesided', 'twosided', 'centered'
// 'corr' flag
- // Presence indicates that the primary input x is actually a
+ // Presence indicates that the primary input x is actually a
// correlation matrix
//
// Examples:
- // TODO:
//
+ //Ex1:
+ //n = 0:199;
+ //x = cos(0.257*%pi*n) + sin(0.2*%pi*n) + 0.01*rand(size(n,"r"),"normal");
+ //[S,w]=pmusic(x,[%inf,1.1],[],8000,2) ;//where x: [1x200 constant] p:-infinite signal space and threshold value is 1.1 window length:-7 Fs:-8000Hz........fftlength:-256
+ //plot(w,S);.........to see the plot of psuedospectrum estimate of x vs frequencies w
+
+// //Ex2:
+// n = 0:199;
+// x = cos(0.257*%pi*n) + sin(0.2*%pi*n) ;
+// [S,w]=pmusic(x,2,16,1) //where x: [1x200 constant] p: 2 w: [0x0 constant] nfft: 16 fs: 1
+ // OUTPUT:
+//S=[2.6425624,5.7475005,77.148221,1.5296243,0.4725347,0.2848481,0.2508128,0.2731036,0.2950648];
+//w=[0,0.0625,0.125,0.1875,0.25,0.3125,0.375,0.4375,0.5];
+ //NOTE EXECUTE FUNCTIONS subspaceMethodsInputParser.sci AND musicBase.sci PRIOR EXECUTING THIS FUNCTION
+ //
// See also
// pburg | peig | periodogram | pmtm | prony | pwelch | rooteig | rootmusic
//
@@ -66,16 +80,16 @@ function varargout = pmusic(varargin)
// References
// [1] Petre Stoica and Randolph Moses, Introduction To Spectral
// Analysis, Prentice-Hall, 1997, pg. 15
- // [2] S. J. Orfanidis, Optimum Signal Processing. An Introduction.
+ // [2] S. J. Orfanidis, Optimum Signal Processing. An Introduction.
// 2nd Ed., Macmillan, 1988.
-
+
funcprot(0);
-
- exec('subspaceMethodsInputParser.sci',-1);
- exec('musicBase.sci',-1);
-
+
+ //exec /home/shashi/Desktop/FOSSEE-Signal-Processing-Toolbox-master/macros/subspaceMethodsInputParser.sci
+ //exec('/home/shashi/Desktop/FOSSEE-Signal-Processing-Toolbox-master/macros/musicBase.sci',-1);
+
[numOutArgs,numInArgs] = argn(0);
-
+
// check number of output arguments
if numOutArgs~=2 & numOutArgs~=4 then
msg = "pmusic: Wrong number of output argument; 2 or 4 expected";
@@ -84,20 +98,20 @@ function varargout = pmusic(varargin)
// ("**start**");
[data, msg, err_num] = subspaceMethodsInputParser(varargin);
-
+
if length(msg)==0 then
// no error occured
else
error(err_num, "pmusic: " + msg);
end
-
- //disp(data);
+
+ // disp(data);
[musicData,msg] = musicBase(data);
-
+
//disp(musicData);
//disp(musicData.noiseEigenvects);
- //disp(musicData.signalEigenvects);
+ //disp(musicData.signalEigenvects);
if length(msg)~=0 then
error(msg);
@@ -107,24 +121,24 @@ function varargout = pmusic(varargin)
// computing the pseudospectrum
[S,f] = pseudospectrum(musicData.noiseEigenvects, ...
musicData.eigenvals,data.w,data.nfft, data.fs, data.freqrange,data.isFsSpecified);
-
+
v = musicData.noiseEigenvects;
e = musicData.eigenvals;
-
+
varargout = list(S,f,v,e);
-
+
// plot if requested
if numOutArgs==0 then
pow = 10*log10(S);
figure()
plot(f,pow);
-
+
if data.isFsSpecified then
xlabel('Frequency (Hz)');
else
xlabel('Normalized Frequency (*pi rad/sample)');
end
-
+
ylabel('Power (dB)');
title('Pseudospectrum Estimate via MUSIC');
end
@@ -133,16 +147,16 @@ endfunction
function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
nfft, fs, freqrange,isFsSpecified)
- // disp("noise eigenvects in pseudospectrum - ");
- // disp(noiseEigenvects);
+ // disp("noise eigenvects in pseudospectrum - ");
+ //disp(noiseEigenvects);
weights = ones(1,size(noiseEigenvects,2));
denominator = 0;
-
+
isFreqGiven = %F;
for i=1:size(noiseEigenvects,2);
- // disp("looping in pseudospectrum");
+ // disp("looping in pseudospectrum");
if isempty(freqvector) then
[h,w] = computeFreqResponseByFFT(noiseEigenvects(:,i),nfft,fs,...
isFsSpecified);
@@ -152,15 +166,15 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
isFreqGiven = %T;
end
denominator = denominator + (abs(h).^2)./weights(i);
- // disp(h(1:10));
+ //disp(h(1:10));
end
-
- // disp(denominator(1:5));
+
+ // disp(denominator(1:5));
// computing pseudospectrum pspec
pspec = 1.0 ./ denominator;
// converting to column vector
pspec = pspec(:);
-
+
if ~isFreqGiven then
// correcting the range of pspec according to the user specification
if strcmpi(freqrange, 'onesided')==0 then
@@ -172,11 +186,11 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
end
pspec = pspec(range);
w = w(range);
-
+
elseif strcmpi(freqrange,'centered')==0 then
// convert two sided spectrum to centered
rem = modulo(nfft,2);
-
+
if rem then
idx = [(nfft+1)/2+1:nfft 1:(nfft+1)/2];
else
@@ -184,7 +198,7 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
end
pspec = pspec(idx);
w = w(range);
-
+
if rem then
w(1:(nfft-1)/2) = w(1:(nfft-1)/2) - fs;
else
@@ -196,8 +210,8 @@ function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
endfunction
function [h,w] = computeFreqResponseByFFT(b,n,fs,isFsSpecified)
- // returns the frequency response (h) and the corresponding frequency
- // values (w) for a digital filter with numerator b. The evaluation of the
+ // returns the frequency response (h) and the corresponding frequency
+ // values (w) for a digital filter with numerator b. The evaluation of the
// frequency response is done at n points in [0,fs) using fft algorithm
//
// Similar to MATLAB's freqz(b,a,n,'whole',fs)
@@ -207,10 +221,10 @@ function [h,w] = computeFreqResponseByFFT(b,n,fs,isFsSpecified)
w = linspace(0,2*%pi,n+1)';
w($) = [];
w(1) = 0; // forcing the first frequency to be 0
-
+
// forcing b and a to be column vectors
b = b(:);
-
+
// zero padding for fft
zeroPadLength = n - length(b);
zeroPad = zeros(zeroPadLength,1);
@@ -218,36 +232,35 @@ function [h,w] = computeFreqResponseByFFT(b,n,fs,isFsSpecified)
h = fft(b);
-
+
if isFsSpecified then
w = w*fs/(2*%pi);
end
-
+
endfunction
+
function [h,w] = computeFreqResponseByPolyEval(b,f,fs,isFsSpecified)
// returns the frequency response (h) for a digital filter with numerator b.
// The evaluation of the frequency response is done at frequency values f
-
- // disp(f);
- // disp(isFsSpecified);
-
+
+ //disp(f);
+ //disp(isFsSpecified);
+
f = f(:);
b = b(:);
-
+
n = length(b);
powerMatrix = zeros(length(f),n);
powerMatrix(:,1) = 1;
for i=2:n
powerMatrix(:,i) = exp(f*(-i+1)*%i);
end
-
+
h = powerMatrix*b;
-
+
if isFsSpecified then
w = f * fs/(2*%pi);
end
-
-endfunction
-
+endfunction
diff --git a/macros/poly2lsf.sci b/macros/poly2lsf.sci
index 69288f3..3140992 100644
--- a/macros/poly2lsf.sci
+++ b/macros/poly2lsf.sci
@@ -9,9 +9,13 @@ function lsf=poly2lsf(a)
// k: define the prediction polynomial.
// lsf: returns corresponding line spectral frequencies.
// Examples
-//X = [0.5 0.3 0.8 0.9 0.4 0.05];
+//
+//EXAMPLE
+//X=[1 0.6149 0.9899 0 0.0031 -0.0082]
// lsf = poly2lsf(X)
-// See also
+//EXPECTED OUTPUT:
+//lsf =0.7841731 1.5605415 1.8776459 1.8984313 2.3592523
+
//
// Author
// Jitendra Singh
@@ -59,17 +63,17 @@ if (p-fix(p./2).*2)~=0 then // Odd order
na = length(aa);
if na > n
P = 0;
-
+
else
P= filter(pp, aa, [1 zeros(1,n-na)]);
if m ~= 1
P = P(:);
end
end
-
+
Q = qq;
else // Even order
-
+
aa=[1 -1];
[m,n] = size(pp);
n = max(m,n);
@@ -77,29 +81,29 @@ else // Even order
(aa);
if na > n
P = 0;
-
+
else
P= filter(pp, aa, [1 zeros(1,n-na)]);
- if m ~= 1
+ if m ~= 1
P = P(:);
end
end
-
+
aa=[1 1];
[m,n] = size(qq);
n = max(m,n);
na = length(aa);
-
+
if na > n
Q = 0;
-
+
else
Q= filter(qq, aa, [1 zeros(1,n-na)]);
if m ~= 1
Q = Q(:);
end
end
-
+
end
r_p = roots(P); r_q = roots(Q);
diff --git a/macros/polyreduce.sci b/macros/polyreduce.sci
new file mode 100644
index 0000000..265b969
--- /dev/null
+++ b/macros/polyreduce.sci
@@ -0,0 +1,43 @@
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+
+function p = polyreduce (c)
+//Calling sequence
+//p= polyreduce (c)
+// Reduce a polynomial coefficient vector to a minimum number of terms by
+// stripping off any leading zeros.
+
+//Test cases:
+//polyreduce ([0, 0, 1, 2, 3])
+//Output: [1, 2, 3]
+
+
+
+[nargout,nargin]=argn();
+
+ if (nargin ~= 1)
+ error("wrong number of input arguments");
+
+ elseif (~isvector (c) | isempty (c))
+ error ("polyreduce: C must be a non-empty vector");
+ end
+
+ idx = find (c ~= 0, 1);
+
+ if (isempty (idx))
+ p = 0;
+ else
+ p = c(idx:$);
+ end
+
+endfunction
diff --git a/macros/polyscale.sci b/macros/polyscale.sci
index 9073e7a..019c08a 100644
--- a/macros/polyscale.sci
+++ b/macros/polyscale.sci
@@ -5,13 +5,31 @@
// where
//a is the vector containing the polynomial coefficients
// alpha is the scaling vector
+//
+//EXAMPLES:
+//to scale the seventh roots of unity ,x^7=1,
+////we represent
+//p=[1 0 0 0 0 0 0 -1] and changing the scaling factor,
+//b=polyscale(p,0.85)
+//EXPECTED OUTPUT:b=1. 0. 0. 0. 0. 0. 0. - 0.3205771
+
+
+//p=[1 0 0 0 0 0 0 -1] and changing the scaling factor,
+//b=polyscale(p,0.95)
+//EXPECTED OUTPUT:b=1. 0. 0. 0. 0. 0. 0. - 0.6983373
+//
+
+//p=[1 0 0 0 0 0 0 -1] and changing the scaling factor,
+//b=polyscale(p,1)
+//EXPECTED OUTPUT:b=1. 0. 0. 0. 0. 0. -1
+
// Author
//Debdeep Dey
function b = polyscale(a,alpha)
//errcheck1
if(min(size(a))>1) then
- error('Input polynomial must be an array')
+ error('Input polynomial must be an array')
end
if type(a)==10 then
error("Input cannot be of type char");
diff --git a/macros/polyval.sci b/macros/polyval.sci
index bcd5dfb..0ec7a82 100755
--- a/macros/polyval.sci
+++ b/macros/polyval.sci
@@ -1,15 +1,28 @@
function [y, delta] = polyval(p,x,S,mu)
+//y = polyval(p,x) returns the value of a polynomial of degree n evaluated at x. The input argument p is a vector of length n+1 whose elements are the coefficients in descending powers of the polynomial to be evaluated.
+//x --can be a matrix or a vector. In either case, polyval evaluates p at each element of x.
+//[y,delta] = polyval(p,x,S) uses the optional output structure S generated by polyfit to generate error estimates delta.
+//delta --is an estimate of the standard deviation of the error in predicting a future observation at x by p(x).
+// If the coefficients in p are least squares estimates computed by polyfit, and the errors in the data input to poly// if it are independent, normal, and have constant variance, then y±delta contains at least 50% of the
+// predictions of future observations at x.
-// Check input is a vector
-if ~(isvector(p) | isempty(p))
- error(message('polyval:InvalidP'));
+//y = polyval(p,x,[],mu) or [y,delta] = polyval(p,x,S,mu) use ˆx=(x−μ1)/μ2 in place of x. In this equation, μ1=mean(x) // and μ2=std(x). The centering and scaling parameters mu = [μ1,μ2] is optional
+
+//EXAMPLES:
+//p = [3 2 1];
+//y=polyval(p,[5 7 9])
+//EXPECTED OUTPUT:
+//y= 86 162 262
+
+if ~(isvector(p) | isempty(p)) // Check input is a vector
+ error('polyval:InvalidP');
end
nc = length(p);
-if isscalar(x) & (argn(2) < 3) & nc>0 & isfinite(x) & all(isfinite(p(:)))
+if isscalar(x) & (argn(2) < 3) & nc>0 & (abs(x)<%inf) & and(abs(p(:))<%inf)
// Make it scream for scalar x. Polynomial evaluation can be
// implemented as a recursive digital filter.
- y = filter(1,[1 -x],p);
+ y = filter(1,[1 -real(x)],p);
y = y(nc);
return
end
@@ -28,9 +41,9 @@ end
if argn(1) > 1
if argn(2) < 3 | isempty(S)
- error(message('polyval:RequiresS'));
+ error('polyval:Requires S');
end
-
+
// Extract parameters from S
if isstruct(S), // Use output structure from polyfit.
R = S.R;
@@ -39,7 +52,7 @@ if argn(1) > 1
else // Use output matrix from previous versions of polyfit.
[ms,ns] = size(S);
if (ms ~= ns+2) | (nc ~= ns)
- error(message('polyval:SizeS'));
+ error('polyval:SizeS');
end
R = S(1:nc,1:nc);
df = S(nc+1,1);
@@ -59,12 +72,11 @@ if argn(1) > 1
E = V/R;
e = sqrt(1+sum(E.*E,2));
if df == 0
- warning(message('polyval:ZeroDOF'));
- delta = Inf(size(e));
+ warning('polyval:ZeroDOF');
+ delta = %inf(size(e));
else
delta = normr/sqrt(df)*e;
end
- delta = reshape(delta,siz_x);
+ delta = matrix(delta,siz_x);
end
endfunction
-
diff --git a/macros/prepad.sci b/macros/prepad.sci
new file mode 100644
index 0000000..ccbbddd
--- /dev/null
+++ b/macros/prepad.sci
@@ -0,0 +1,80 @@
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+function y = prepad (x, l, c, dim)
+// Calling sequence:
+// y= prepad (x, l)
+// y= prepad (x, l, c)
+// y= prepad (x, l, c, dim)
+// Prepend 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 beginning of x
+// are removed until a vector of length l is obtained.
+//
+// If x is a matrix, elements are prepended or removed from each row.
+//
+// If the optional argument dim is given, operate along this dimension.
+//
+// If dim is larger than the dimensions of x, the result will have
+// dim dimensions.
+
+//Test cases:
+//prepad ([1,2], 4,0,2)
+//Output: [0,0,1,2]
+
+
+[nargout,nargin]=argn();
+ if (nargin < 2 | nargin > 4)
+ error("wrong number of input arguments");
+ end
+
+ if (nargin < 3 | isempty (c))
+ c = 0;
+ else
+ if (~ isscalar (c))
+ error ("prepad: pad value C must be empty or a scalar");
+ end
+ end
+//dim=1;
+ nd = ndims (x);
+ sz = size (x);
+ if (argn(2) < 4)
+ // Find the first non-singleton dimension.
+ (dim == find (sz > 1, 1)) | (dim == 1);
+ else
+ if (~(isscalar (dim) & dim == fix (dim) & dim >= 1))
+ error ("prepad: DIM must be an integer and a valid dimension");
+ end
+ end
+
+ if (~ isscalar (l) | l < 0)
+ error ("prepad: length L must be a positive scalar");
+ end
+
+ if (dim > nd)
+ sz(nd+1:dim) = 1;
+ end
+
+ d = sz(dim);
+
+ if (d >= l)
+// idx = repmat ({':'}, nd, 1);
+// idx(dim) = (d-l+1) : d;
+// y = x(idx(:));
+ y=x;
+ else
+ sz(dim) = l - d;
+ y = cat (dim, c(ones (sz(1),sz(2))), x);
+ end
+
+endfunction
diff --git a/macros/prony.sci b/macros/prony.sci
index 9f0fb9c..9df6a43 100644
--- a/macros/prony.sci
+++ b/macros/prony.sci
@@ -7,15 +7,31 @@
// na=number of poles
//Reference : T.W. Parks and C.S. Burrus, Digital Filter Design,
// John Wiley and Sons, 1987, p226.
-//Author
+//Author
//Debdeep Dey
+//EXAMPLE 1:
+//V=filter([1,1],[1,1,2],[1 zeros(1,31)]);//gives the impulse response of filter with the mentioned coefficients
+//[b,a]=prony(V,1,2)
+//
+//OUTPUT:a = 1. 1. 2.//denominator coefficients
+ //b = 1. 1. //numerator coefficients
+
+//EXAMPLE2:
+//V=filter([1,2],[1,2,3,4],[1 zeros(1,31)]);
+ //[b,a]=prony(V,1,3)
+//a = 1. 2. 3. 4. //denominato coefficients
+//b = 1. 2. //numerator coefficients
+
+
+
+
function [b,a]=prony(h,nb,na)
K = length(h)-1;
M=double(nb);
N=double(na);
//zero-pad input if necessary
-if K <= max(M,N) then
+if K <= max(M,N) then
K = max(M,N)+1;
h(K+1) = 0;
end
@@ -36,4 +52,3 @@ a = [1; -H2\h1].';
b = c*a*H1.';
endfunction
-
diff --git a/macros/rc2ac.sci b/macros/rc2ac.sci
index 7d59af5..124de0b 100644
--- a/macros/rc2ac.sci
+++ b/macros/rc2ac.sci
@@ -9,36 +9,45 @@ function R=rc2ac(k, R0)
// R0: input argument zero lag autocorrelation
// R: return autocorrelation sequence.
-// Examples
-//X = [7 6 5 8 3 6]
-// R = rc2ac(X, 0.3)
+// Test cases
+//k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
+//r0 = 0.1;
+//Output:
+//R =
+// 0.1
+// - 0.0309
+// - 0.0790948
+// 0.0786627
+// 0.0293629
+// - 0.0950000
+//
// See also
//
// Author
// Jitendra Singh
-//
-
- // load rc2poly and rlevinson before running this function
-
+//
+
+ // load rc2poly and rlevinson before running this function
+
if or(type(k)==10) then
error ('Input arguments must be double.')
-end
-
+end
+
if (size(k,1) > 1) & (size(k,2) > 1)
error ('The reflection coefficients must be stored in a vector.')
end
-
-
+
+
if argn(2)<2 then // checking of number of input arguments, if argn(2)<2 execute error.
error ('Not enough input argument, define zero lag autocorrelation, R0.')
- end
+ end
if or(k(2:$)==1) then
error('Algorithm failed for this case. At least one of the reflection coefficients is equal to one.')
end
-
+
[a, efinal]=rc2poly (k, R0);
- R=rlevinson(a, efinal)
-
-
+ R=rlevinson(a, efinal)
+
+
endfunction
diff --git a/macros/rc2poly.sci b/macros/rc2poly.sci
index 19eed2a..a3665f2 100644
--- a/macros/rc2poly.sci
+++ b/macros/rc2poly.sci
@@ -1,28 +1,32 @@
function [a, efinal] = rc2poly(kr, R0)
-
+
//rc2poly function convert reflection coefficients to prediction polynomial.
// Calling Sequence
// a = rc2poly(kr)
// [a, efinal] = rc2poly(kr,R0)
// Parameters
-// kr: Refelection coefficient.
+// kr: Refelection coefficient.
// R0: the zero lag autocorrelation, R0.
// a: Return the prediction polynomial.
// efinal: Return the final prediction error.
// Examples
//X = [7 6 5 8 3 6]
-// [a, efinal] = rc2poly(X)
+// [a, efinal] = rc2poly(X) //error as only one input parameter is specified.(R0 is not mentioned)
+//
+//k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
+//a = rc2poly(k)
+//EXPECTED OUTPUT:a= 1. 0.6148162 0.9898814 0.0000243 0.0031580 - 0.0082
//
// See also
//
// Author
// Jitendra Singh
-//
+//
if or(type(kr)==10) then
error ('Input arguments must be double.')
-end
+end
if (size(kr,1) > 1) & (size(kr,2) > 1)
error ('The reflection coefficients must be stored in a vector.')
@@ -47,10 +51,10 @@ a=kr(1);
for i=2:length(kr)
a = [a + a(i-1:-1:1)*kr(i) kr(i)]
- ee=ee.*(1-kr(i)'.*kr(i));
+ ee=ee.*(1-kr(i)'.*kr(i));
end
a=[1 a];
-efinal=ee;
+efinal=ee;
endfunction
diff --git a/macros/rcosdesign.sci b/macros/rcosdesign.sci
index b3218c1..ba20ee2 100644
--- a/macros/rcosdesign.sci
+++ b/macros/rcosdesign.sci
@@ -1,19 +1,29 @@
function h = rcosdesign(rollof_factor, num_of_symb, samp_per_symb, varargin)
// RCOSDESIGN computes the raised cosine FIR filter
-// Inputs:
+// Inputs:
// rollof_fact: roll-off factor of the designed filter
// num_of_symb: filter truncated to these many number of symbols
// samp_per_symb: each symbol represented by these many samples
// shape: returns a normal raised-cosine FIR filter when set to 'normal'.
// returns a square-root raised cosing filter when set to 'sqrt'.
-// Output:
+// Output:
// h: returned filter coefficients
//The output result for the input parameter of shape 'normal' is not equivalent to the matlab output because of the use of sinc function in the computation. Matlab and scilab sinc functions seem to not be equivalent.
+////EXAMPLE:
+//rolloff = 0.25;
+//span = 3;
+//sample per symbol=sps=2;
+//b=rcosdesign(rolloff,span,sps);
+//OUTPUT:
+//b=- 0.1210006 - 0.0456421 0.4418023 0.7590604 0.4418023 - 0.0456421 - 0.1210006
- // Check validity of number of inout arguments
+
+
+
+// Check validity of number of inout arguments
checkNArgin(3, 4, argn(2));
-
+
// Check validity of input arguments
valid_class_ROF = ['single', 'double'];
properties_ROF = ['scalar', 'real', 'nonNegative'];
@@ -21,7 +31,7 @@ function h = rcosdesign(rollof_factor, num_of_symb, samp_per_symb, varargin)
if rollof_factor > 1 then
error('roll-off factor should be <= 1');
end
-
+
if rollof_factor == 0 then
rollof_factor = number_peroperties("tiny");
end
@@ -29,81 +39,81 @@ function h = rcosdesign(rollof_factor, num_of_symb, samp_per_symb, varargin)
valid_class_NOS = ['single', 'double'];
properties_NOS = ['scalar', 'real', 'positive', 'finite'];
checkIpValidity(num_of_symb, valid_class_NOS, properties_NOS);
-
+
valid_class_SPS = ['single', 'double'];
properties_SPS = ['scalar', 'real', 'positive', 'finite', 'integer'];
checkIpValidity(samp_per_symb, valid_class_SPS, properties_SPS);
-
+
if pmodulo((num_of_symb*samp_per_symb), 2) ~= 0 then
error('product of number_of_symbols and samples_per_symbol should be even');
end
-
-
+
+
if argn(2) > 3 then
shape = varargin(1);
else
shape = 'sqrt';
end
-
+
valid_string_shape = ['sqrt', 'normal'];
checkStringValidity(shape, valid_string_shape);
-
+
// Designing the raised cosine filter
-
+
pr = (samp_per_symb*num_of_symb)/2;
ax = (-pr:pr)/samp_per_symb;
-
+
if ~strcmpi(shape, 'normal') then
den = (1-(2*rollof_factor*ax).^2);
id1 = find(abs(den) > sqrt(%eps));
for idx = 1:length(id1)
filt_resp(id1(idx)) = sinc(ax(id1(idx))).*(cos(%pi*rollof_factor*ax(id1(idx)))./den(id1(idx)))/samp_per_symb;
end
-
+
id2 = 1:length(ax);
id2(id1) = [];
for idx = 1:length(id2)
filt_resp(id2(idx)) = rollof_factor*sin(%pi/(2*rollof_factor))/(samp_per_symb);
end
-
-
+
+
else
id1 = find(ax == 0);
if ~isempty(id1) then
filt_resp(id1) = (-1)./(%pi.*samp_per_symb).*(%pi.*(rollof_factor-1) - 4.*rollof_factor);
end
-
+
id2 = find(abs(abs(4.*rollof_factor.*ax) - 1.0) < sqrt(%eps));
if ~isempty(id2) then
filt_resp(id2) = 1 ./ (2.*%pi.*samp_per_symb) * (%pi.*(rollof_factor+1) .* sin(%pi.*(rollof_factor+1)./(4.*rollof_factor)) - 4.*rollof_factor .* sin(%pi.*(rollof_factor-1)./(4.*rollof_factor)) + %pi.*(rollof_factor-1) .* cos(%pi.*(rollof_factor-1)./(4.*rollof_factor)) );
end
-
+
id = 1:length(ax);
id([id1 id2]) = [];
nid = ax(id);
a = (-4.*rollof_factor./samp_per_symb);
b = ( cos((1+rollof_factor).*%pi.*nid) + sin((1-rollof_factor).*%pi.*nid) ./ (4.*rollof_factor.*nid) );
c = (%pi .* ((4.*rollof_factor.*nid).^2 - 1));
-
+
for idx = 1:length(id)
filt_resp(id(idx)) = a*b(idx)/c(idx);
idx
end
-
-
+
+
end
-
+
filt_resp = filt_resp / sqrt(sum(filt_resp.^2));
-
+
h = filt_resp';
-
+
endfunction
function checkNArgin(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
@@ -112,7 +122,7 @@ endfunction
function checkIpValidity(variable, valid_class, properties)
// Function to check the validity of the input variable
-// Inputs:
+// Inputs:
// valid_class: vector of valid classes for the input variable
// properties: vector of necessary properties of the input variable
@@ -122,9 +132,9 @@ function checkIpValidity(variable, valid_class, properties)
error('input variable should be of type double ');
end
end
-
+
end
-
+
for jdx = 1:length(length(properties))
if ~strcmpi(properties(jdx), 'scalar') then
if length(variable) > 1 then
@@ -137,43 +147,43 @@ function checkIpValidity(variable, valid_class, properties)
error('Input variable is empty. It is invalid');
end
end
-
+
if ~strcmpi(properties(jdx), 'nonNan') then
if isnan(variable) then
error('Input variable is not a number (Nan). It is invalid');
end
end
-
+
if ~strcmpi(properties(jdx), 'real') then
if ~isreal(variable) then
error('Input should be real');
end
end
-
+
if ~strcmpi(properties(jdx), 'positive') then
if variable <= 0 then
error('Input should be positive');
end
end
-
+
if ~strcmpi(properties(jdx), 'integer') then
if (int(variable)-variable) ~= 0 then
error('Input should be an integer');
end
end
-
+
if ~strcmpi(properties(jdx), 'nonNegative') then
if variable < 0 then
error('Input should be non-negative');
end
end
-
+
if ~strcmpi(properties(jdx), 'finite') then
if ~(abs(variable) < %inf) then
error('Input should be finite');
end
end
-
+
end
endfunction
@@ -181,9 +191,9 @@ endfunction
function checkStringValidity(variable, valid_strings)
if ~strcmpi(valid_strings(1), variable) | ~strcmpi(valid_strings(2), variable) then
-
+
else
error('Input string is not recognized')
- end
-
+ end
+
endfunction
diff --git a/macros/residue.sci b/macros/residue.sci
new file mode 100644
index 0000000..70dc91f
--- /dev/null
+++ b/macros/residue.sci
@@ -0,0 +1,286 @@
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+function [r, p, k, e] = residue (b, a, varargin)
+
+
+// [r, p, k, e] = residue (b, a)
+// [b, a] = residue (r, p, k)
+// [b, a] = residue (r, p, k, e)
+// The first calling form computes the partial fraction expansion for the
+// quotient of the polynomials, b and a.
+//
+// The quotient is defined as
+
+// B(s) M r(m) N
+// ---- = SUM ------------- + SUM k(i)*s^(N-i)
+// A(s) m=1 (s-p(m))^e(m) i=1
+
+// where M is the number of poles (the length of the r, p,
+// and e), the k vector is a polynomial of order N-1
+// representing the direct contribution, and the e vector specifies the
+// multiplicity of the m-th residue's pole.
+//
+//NOTE that the polynomials 'b' and 'a' should have real coefficients(because of the function 'filter' used in polyval)
+//
+//Test case
+//1.
+// b = [1, 1, 1];
+// a = [1, -5, 8, -4];
+// [r, p, k, e] = residue (b, a)
+// result r = [-2; 7; 3]
+// result p = [2; 2; 1]
+// result k = [](0x0)
+// result e = [1; 2; 1]
+//
+
+//2.
+//[r,p,k,e]=residue([1 2 1],[1 -5 8 -4])
+//OUTPUT
+//r =
+// -3.0000
+// 9.0000
+// 4.0000
+//
+//p =
+// 2.0000
+// 2.0000
+// 1.0000
+//
+//f = [](0x0)
+//e =
+// 1
+// 2
+// 1
+//
+
+
+ [nargout,nargin]=argn();
+
+ if (nargin < 2 | nargin > 4)
+ error ("wrong umber of input arguments");
+ end
+
+ toler = .001;
+
+ if (nargin >= 3)
+ if (nargin >= 4)
+ e = varargin(2);
+ else
+ e = [];
+ end
+ // The inputs are the residue, pole, and direct part. Solve for the
+ // corresponding numerator and denominator polynomials
+ [r, p] = rresidue (b, a, varargin(1), toler, e);
+ return;
+ end
+
+ // Make sure both polynomials are in reduced form.
+
+ a = polyreduce (a);
+ b = polyreduce (b);
+
+ b = b / a(1);
+ a = a / a(1);
+
+ la = length (a);
+ lb = length (b);
+
+ // Handle special cases here.
+
+ if (la == 0 | lb == 0)
+ k =[];
+ r = [];
+ p = [];
+ e = [];
+ return;
+ elseif (la == 1)
+ k = b / a;
+ r = [];
+ p = [];
+ e = [];
+ return;
+ end
+
+ // Find the poles.
+
+ p = roots (a);
+ lp = length (p);
+
+ // Sort poles so that multiplicity loop will work.
+
+ [e, indx] = mpoles (p, toler, 0);
+ p = p(indx);
+
+ // For each group of pole multiplicity, set the value of each
+ // pole to the average of the group. This reduces the error in
+ // the resulting poles.
+
+ p_group = cumsum (e == 1);
+ for ng = 1:p_group($)
+ m = find (p_group == ng);
+ p(m) = mean (p(m));
+ end
+
+ // Find the direct term if there is one.
+
+ if (lb >= la)
+ // Also return the reduced numerator.
+ [k, b] = deconv (b, a);
+ lb = length (b);
+ else
+ k = [];
+ end
+
+ // Determine if the poles are (effectively) zero.
+
+ small = max (abs (p));
+ if (type(a)==1 | type(b)==1)
+ small = max ([small, 1]) * 1.1921e-07 * 1e4 * (1 + length (p))^2;
+ else
+ small = max ([small, 1]) * %eps * 1e4 * (1 + length (p))^2;
+ end
+ p(abs (p) < small) = 0;
+
+ // Determine if the poles are (effectively) real, or imaginary.
+
+ index = (abs (imag (p)) < small);
+ p(index) = real (p(index));
+ index = (abs (real (p)) < small);
+ p(index) = 1*%i * imag (p(index));
+
+ // The remainder determines the residues. The case of one pole
+ // is trivial.
+
+ if (lp == 1)
+ r = polyval (b, p);
+ return;
+ end
+
+ // Determine the order of the denominator and remaining numerator.
+ // With the direct term removed the potential order of the numerator
+ // is one less than the order of the denominator.
+
+ aorder = length (a) - 1;
+ border = aorder - 1;
+
+ // Construct a system of equations relating the individual
+ // contributions from each residue to the complete numerator.
+
+ A = zeros (border+1, border+1);
+ B = prepad (matrix (b, [length(b), 1]), border+1, 0,2);
+ for ip = 1:length (p)
+ ri = zeros (size (p,1),size(p,2));
+ ri(ip) = 1;
+ A(:,ip) = prepad (rresidue (ri, p, [], toler), border+1, 0,2).';
+ end
+
+ // Solve for the residues.
+if(size(A,1)~=size(B,1))
+ if(size(A,1)<size(B,1))
+ A=[A;zeros((size(B,1)-size(A,1)),(size(A,2)))];
+ else
+ B=[zeros((size(A,1)-size(B,1)),(size(B,2)));B];
+ end
+
+ end
+ r = A \ B;
+ r=r(:,$);
+
+endfunction
+
+function [pnum, pden, e] = rresidue (rm, p, k, toler, e)
+
+ // Reconstitute the numerator and denominator polynomials from the
+ // residues, poles, and direct term.
+[nargout,nargin]=argn();
+ if (nargin < 2 | nargin > 5)
+ error ("wrong number of input arguments");
+ end
+
+ if (nargin < 5)
+ e = [];
+ end
+
+ if (nargin < 4)
+ toler = [];
+ end
+
+ if (nargin < 3)
+ k = [];
+ end
+
+ if (length (e))
+ indx = 1:length (p);
+ else
+ [e, indx] = mpoles (p, toler, 0);
+ p = p(indx);
+ rm = rm(indx);
+ end
+
+ indx = 1:length (p);
+
+ for n = indx
+ pn = [1, -p(n)];
+ if (n == 1)
+ pden = pn;
+ else
+ pden = conv (pden, pn);
+ end
+ end
+
+ // D is the order of the denominator
+ // K is the order of the direct polynomial
+ // N is the order of the resulting numerator
+ // pnum(1:(N+1)) is the numerator's polynomial
+ // pden(1:(D+1)) is the denominator's polynomial
+ // pm is the multible pole for the nth residue
+ // pn is the numerator contribution for the nth residue
+
+ D = length (pden) - 1;
+ K = length (k) - 1;
+ N = K + D;
+ pnum = zeros (1, N+1);
+ for n = indx(abs (rm) > 0)
+ p1 = [1, -p(n)];
+ for m = 1:e(n)
+ if (m == 1)
+ pm = p1;
+ else
+ pm = conv (pm, p1);
+ end
+ end
+ pn = deconv (real(pden),real(pm));
+ pn = rm(n) * pn;
+ pnum = pnum + prepad (real(pn), N+1, 0, 2);
+ end
+
+ // Add the direct term.
+
+ if (length (k))
+ pnum = pnum + conv (pden, k);
+ end
+
+ // Check for leading zeros and trim the polynomial coefficients.
+ if (type(rm)==1 | type(p)==1 | type(k)==1)
+ small = max ([max(abs(pden)), max(abs(pnum)), 1]) * 1.1921e-07;
+ else
+ small = max ([max(abs(pden)), max(abs(pnum)), 1]) *%eps;
+ end
+
+ pnum(abs (pnum) < small) = 0;
+ pden(abs (pden) < small) = 0;
+
+ pnum = polyreduce (pnum);
+ pden = polyreduce (pden);
+
+endfunction
diff --git a/macros/residued.sci b/macros/residued.sci
index 182b9ca..9b4a386 100644
--- a/macros/residued.sci
+++ b/macros/residued.sci
@@ -1,25 +1,108 @@
-function [r,p,f,m]=residued(b,a)
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
-// Finds the partial fraction expansion of filter H(z)= B(z)/A(z).
-// Calling Sequence
-// [r,p,f,m]=residued(b,a)
-// Parameters
-// b: Real or complex valued vector or matrix
-// a: Real or complex valued vector or matrix
-// Description
-// This is an Octave function.
-// Similar to the "residuez" function. The difference being in the function "residuez", the IIR part (poles p and residues r) is driven in parallel with the FIR part(f) whereas in the function "residued", the IIR part is driven by the output of the FIR part. In signal modeling applications, this structure can be more accurate.
-// Examples
-// 1. [a,b,c,d]=residued([1 i;3 -4],[1 2; 3 4])
-// a = [ 0.19405 - 1.31377i; 0.08329 + 0.99163i; -0.27734 + 0.32215i]
-// b = [ -0.10184 - 1.19167i; -0.10184 + 1.19167i; -2.79632 - 0.00000i]
-// c = 1
-// d = [ 1 ; 1 ; 1]
+// Function File [r, p, f, m] = residued (b, a)
+// Compute the partial fraction expansion (PFE) of filter
+// H(z) = B(z)/A(z). In the usual PFE function coderesiduez, the
+// IIR part (poles p and residues r) is driven in parallel
+// with the FIR part (f). In this variant, the IIR part is driven by
+// the output of the FIR part. This structure can be more accurate in
+// signal modeling applications.
+//
+// INPUTS:
+// b and a are vectors specifying the digital filter
+// H(z) = B(z)/A(z).
+//NOTE that the polynomials 'b' and 'a' should have real coefficients(because of the function 'filter' used in polyval)
+//
+// RETURNED:
+//
+// r = column vector containing the filter-pole residues
+// p = column vector containing the filter poles
+// f = row vector containing the FIR part, if any
+// m = column vector of pole multiplicities
+//
+//
+// Test cases:
+//1.
+//B=[1 1 ]; A=[1 -2 1];
+// [r,p,f,m] = residued(B,A);
+//r =
+// -1
+// 2
+//p =
+// 1
+// 1
+//
+//f = [](0x0)
+//e =
+// 1
+// 2
+//2.
+//B=[6,2]; A=[1 -2 1];
+//[r,p,k,e]=residued(B,A)
+//m =
+// 1.
+// 2.
+// f =[]
+// p =
+// 1.
+// 1.
+// r =
+// - 2.
+// 8.
+//
+
+function [r, p, f, m] = residued(b, a, toler)
+
+ // RESIDUED - return residues, poles, and FIR part of B(z)/A(z)
+ //
+ // Let nb = length(b), na = length(a), and N=na-1 = no. of poles.
+ // If nb<na, then f will be empty, and the returned filter is
+ //
+ // r(1) r(N)
+ // H(z) = ---------------- + ... + ----------------- = R(z)
+ // [ 1-p(1)/z ]^e(1) [ 1-p(N)/z ]^e(N)
+ //
+ // This is the same result as returned by RESIDUEZ.
+ // Otherwise, the FIR part f will be nonempty,
+ // and the returned filter is
+ //
+ // H(z) = f(1) + f(2)/z + f(3)/z^2 + ... + f(nf)/z^M + R(z)/z^M
+ //
+ // where R(z) is the parallel one-pole filter bank defined above,
+ // and M is the order of F(z) = length(f)-1 = nb-na.
+ //
+ // Note, in particular, that the impulse-response of the parallel
+ // (complex) one-pole filter bank starts AFTER that of the the FIR part.
+ // In the result returned by RESIDUEZ, R(z) is not divided by z^M,
+ // so its impulse response starts at time 0 in parallel with f(n).
+ //
+[nargout,nargin]=argn();
+
+ if nargin<3,
+ warning("tolerance ignored");
+ end
+ NUM = b(:)';
+ DEN = a(:)';
+ nb = length(NUM);
+ na = length(DEN);
+ f = [];
+ if na<=nb
+ f = filter(NUM,DEN,[1,zeros(nb-na)]);
+ NUM = NUM - conv(DEN,f);
+ NUM = NUM(nb-na+2:$);
+ end
+ [r,p,f2,m] = residuez(NUM,DEN);
+ if f2
+ error('f2 not empty as expected');
+ end
-funcprot(0);
-rhs=argn(2);
-if (rhs<2) then
- error ("Wrong number of input arguments.")
-else [r,p,f,m]=callOctave("residued",b,a)
-end
endfunction
diff --git a/macros/residuez.sci b/macros/residuez.sci
index ee67a21..f3a5172 100644
--- a/macros/residuez.sci
+++ b/macros/residuez.sci
@@ -1,25 +1,62 @@
-function [r,p,f,m]=residuez(b,a)
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
-// Compute the partial fraction expansion(PFE) of filter H(z) = B(z)/A(z).
-// Calling Sequence
-// [r,p,f,m]=residuez(b,a)
-// Parameters
-// b: Real or complex valued vector or matrix
-// a: Real or complex valued vector or matrix
-// Description
-// This is an Octave function
-// It compute the PFE of filter H(z)= B(z)/A(z) where inputs b and a are vectors specifying the digital filter.
-// Examples
-// 1. [a,b,c,d]=residuez([i 2i 3i; -4 1 4i],[1 2 3])
-// a = [0.6262 - 1.4412i; -0.4039 + 1.4658i]
-// b = [-1.0000 - 1.4142i; -1.0000 + 1.4142i]
-// c = [-0.22222 - 0.97531i 0.33333 + 0.51852i 0.00000 - 0.11111i; 0.00000 - 1.33333i]
-// d = 1
+ function [r, p, f, m] = residuez(B, A, tol)
+
+ // RESIDUEZ - return residues, poles, and FIR part of B(z)/A(z)
+ //
+ // Let nb = length(b), na = length(a), and N=na-1 = no. of poles.
+ // If nb<na, then f will be empty, and the returned filter is
+ //
+ // r(1) r(N)
+ // H(z) = ---------------- + ... + ----------------- = R(z)
+ // [ 1-p(1)/z ]^m(1) [ 1-p(N)/z ]^m(N)
+ //
+ // If, on the other hand, nb >= na, the FIR part f will not be empty.
+ // Let M = nb-na+1 = order of f = length(f)-1). Then the returned filter is
+ //
+ // H(z) = f(1) + f(2)/z + f(3)/z^2 + ... + f(M+1)/z^M + R(z)
+ //
+ // where R(z) is the parallel one-pole filter bank defined above.
+ // Note, in particular, that the impulse-response of the one-pole
+ // filter bank is in parallel with that of the the FIR part. This can
+ // be wasteful when matching the initial impulse response is important,
+ // since F(z) can already match the first N terms of the impulse
+ // response. To obtain a decomposition in which the impulse response of
+ // the IIR part R(z) starts after that of the FIR part F(z), use RESIDUED.
+ //
+
+ //NOTE that the polynomials 'b' and 'a' should have real coefficients(because of the function 'filter' used in polyval)
+ //Testcase
+ //B=[1 1 1]; A=[1 -2 1];
+ //[r,p,f,m] = residuez(B,A)
+ //OUTPUT:
+ //r=[0;3]
+ //p=[1;1]
+ //f=1
+ //e=[1;2]
+
+
+
+ [nargout,nargin]=argn();
+ if nargin<3
+ warning("tolerance ignored");
+ end
+ NUM = B(:)'; DEN = A(:)';
+ // Matlab's residue does not return m (since it is implied by p):
+ [r,p,f,m]=residue(conj(mtlb_fliplr(NUM)),conj(mtlb_fliplr(DEN)));
+ p = 1 ./ p;
+ r = r .* ((-p) .^m);
+ if f
+ f = conj(mtlb_fliplr(f));
+ end
-funcprot(0);
-rhs=argn(2);
-if (rhs<2) then
- error ("Wrong number of input arguments.")
-else [r,p,f,m]=callOctave("residuez",b,a)
-end
endfunction
diff --git a/macros/rlevinson.sci b/macros/rlevinson.sci
index 3007234..8a36b8b 100644
--- a/macros/rlevinson.sci
+++ b/macros/rlevinson.sci
@@ -1,5 +1,5 @@
function [R, U, kr, e] = rlevinson(a, efinal)
-
+
//rlevinson function computes the autocorrelation coefficients using prediction polynomial.
// Calling Sequence
// a = rlevinson(a, efinal)
@@ -12,36 +12,68 @@ function [R, U, kr, e] = rlevinson(a, efinal)
// efinal: input argument 'final prediction error'.
// R: returns the autocorrelation coefficients.
// U: return a upper triangular matrox of order (length(a)*length(a))
-// kr: return refelection coefficient.
+// kr: return refelection coefficient.
// e: Return the vector of prediction error.
// Examples
-//X = [7 6 5 8 3 6]
-// R = rlevinson(X, 0.3)
+//X = [7 6 5 8 3 6] //make the first prediction polynomial coefficient unity and check for standard Auto regressive model
+
+//X=[1 6/7 5/7 8/7 3/7 6/7];
+//
+// [R U kr e] = rlevinson(X, 0.3)
+
+////EXPECTED OUTPUT:
+//e =
+//
+// 0.3757546 0.0221076 - 3.4125 1.1307692 0.3
+// kr =
+//
+// - 0.2251908
+// 0.9701364
+// - 12.464286
+// - 1.1538462
+// 0.8571429
+// U =
+// 1. -0.2251908 0.9701364 -12.464286 -1.1538462 0.8571429
+// 0. 1. -0.4436567 6.5 2. 0.4285714
+// 0. 0. 1. -12.535714 - 1. 1.1428571
+// 0. 0. 0. 1. 1.8461538 0.7142857
+// 0. 0. 0. 0. 1. 0.8571429
+// 0. 0. 0. 0. 0 1
+//
+//
+//
+// R =
+//
+// 0.3958273
+// 0.0891367
+// - 0.3444604
+// 0.0362590
+// - 0.1329496
+// 0.1042446
//
-// See also
//
// Author
// Jitendra Singh
-//
-
-
+//
+
+
if or(type(a)==10) then
error ('Input arguments must be numeric.')
-end
+end
+
+
-
-
if argn(2)<2 then // checking of number of input arguments, if argn(2)<2 execute error.
error ('Not enough input argument, define final prediction error.')
- end
-
+ end
+
a=a(:);
if a(1)~=1 then
warning('First coefficient of the prediction polynomial was not unity.')
end
-
+
if a(1)==0 then
R=repmat(%nan,[length(a),1])
xx=length(a);
@@ -55,13 +87,13 @@ end
kr=[kr',%inf]
kr=kr'
else
-
-
-
+
+
+
a=a/a(1);
-
+
n=length(a);
-
+
if n<2 then // execute the error if the length of input vector in less than 2
error ('Polynomial should have at least two coefficients.')
end
@@ -69,59 +101,59 @@ end
if type(a)==1 then // checking for argument type
U=zeros(n,n);
end
-
+
U(:,n)=conj(a($:-1:1)); // store prediction coefficient of order p
-
+
n=n-1;
- e(n)=efinal;
+ e(n)=efinal;
Kr(n)=a($); // defining the input required for next step i.e. levinson down
-
+
a=a'
for i=n-1:-1:1 // start levinson down
-
+
ee=a($)
-
+
a = (a-Kr(i+1)*flipdim(a,2,1))/(1-Kr(i+1)^2);
-
+
a=a(1:$-1)
-
-
+
+
Kr(i)=a($);
-
+
econj=conj(ee) //conjugate
econj=econj'
- e(i) = e(i+1)/(1.-(econj.*ee));
-
+ e(i) = e(i+1)/(1.-(econj.*ee));
+
+
+
+ U(:,i+1)=[conj(a($:-1:1).'); zeros(n-i,1)]; //conjugate
-
- U(:,i+1)=[conj(a($:-1:1).'); zeros(n-i,1)]; //conjugate
-
end // end of levinson down estimation
e=e';
-
+
if abs(a(2))==1 then
e1=%nan
else
- e1=e(1)/(1-abs(a(2)^2));
+ e1=e(1)/(1-abs(a(2)^2));
end
-
-
+
+
U(1,1)=1;
kr=conj(U(1,2:$))
kr=kr';
-
+
R1=e1;
R(1)=-conj(U(1,2))*R1; //conjugate
for j=2:n
R(j)=-sum(conj(U(j-1:-1:1,j)).*R($:-1:1))- kr(j)*e(j-1);
R=R(:);
-
+
end
- R=[R1; R];
+ R=[R1; R];
end
-
-
+
+
endfunction
diff --git a/macros/rooteig.sci b/macros/rooteig.sci
index e4f59c0..1b3196e 100644
--- a/macros/rooteig.sci
+++ b/macros/rooteig.sci
@@ -14,12 +14,12 @@ function [w,pow] = rooteig(x,p,varargin)
// Input signal.
// If x is a vector, then it reprsenets one realization of the signal.
// If x is a matrix, then each row represents a separate observation of
- // the signal.
+ // the signal.
// p - int|double - scalar|2 element vector
- // p(1) is the signal subspace dimension and hence the number of
+ // p(1) is the signal subspace dimension and hence the number of
// complex exponentials in x.
- // p(2), if specified, represents a threshold that is multiplied by
- // the smallest estimated eigenvalue of the signal's correlation
+ // p(2), if specified, represents a threshold that is multiplied by
+ // the smallest estimated eigenvalue of the signal's correlation
// matrix.
// fs - int|double - scalar
// Sampling frequency (in Hz)
@@ -27,75 +27,91 @@ function [w,pow] = rooteig(x,p,varargin)
// to 1 Hz
// 'corr' flag
// If specified, x is interpreted as a correlation matrix rather than
- // a matrix of the signal data. For x to be a correlation matrix,
- // x must be a square matrix and all its eigenvalues must be
+ // a matrix of the signal data. For x to be a correlation matrix,
+ // x must be a square matrix and all its eigenvalues must be
// nonnegative
+ // Output arguments
+ // w - double - vector
+ // Estimated frequencies of the complex sinusoids
+ // pow - double - vector
+ // estimated absolute value squared amplitudes of the sinusoids at
+ // the frequencies w
//
+
+
// Examples:
// 1) 3 complex exponentials:
//
- // n=0:99;
- // s=exp(1i*pi/2*n)+2*exp(1i*pi/4*n)+exp(1i*pi/3*n)+randn(1,100);
+ // n=0:99;
+ // s=exp(1i*pi/2*n)+2*exp(1i*pi/4*n)+exp(1i*pi/3*n)+randn(1,100);
// [W,P] = rooteig(s,3);
//
+// n=0:99;
+// s=exp(1*%i*%pi/2*n)+2*exp(1*%i*%pi/4*n)+exp(1*%i*%pi/3*n)+rand(1,100,"normal");
+// exec('/home/shashi/Downloads/FOSSEE-Signal-Processing-Toolbox-master/macros/corrmtx.sci',-1);//EXECUTE CORRMTX FUNCTION PRIOR EXECUTING THIS FUNCTION
+// X = corrmtx(s,12,'mod');
+// [W,P] = rooteig(X,3);
+//
+ //EXPECTED OUTPUT:
+ //W = 0.7883
+ // 1.5674
+ // 1.0429
+//P=
+ // 4.1748
+ // 1.0572
+ // 1.2419
+
// Author
// Ayush
//
- // See also
- // corrmtx | peig | pmusic | rootmusic
+ //
//
// References
- // 1) Stoica, P. and R. Moses, INTRODUCTION TO SPECTRAL ANALYSIS,
+ // 1) Stoica, P. and R. Moses, INTRODUCTION TO SPECTRAL ANALYSIS,
// Prentice-Hall
//
//
- // Output arguments
- // w - double - vector
- // Estimated frequencies of the complex sinusoids
- // pow - double - vector
- // estimated absolute value squared amplitudes of the sinusoids at
- // the frequencies w
- //
-
+
+
funcprot(0);
-
- exec('musicBase.sci',-1);
- exec('nnls.sci',-1);
-
-
+
+ // exec('musicBase.sci',-1);
+ //exec('nnls.sci',-1);
+ //EXECUTE FUNCTIONS nnls.sci AND musicBase.sci PRIOR EXECUTING THIS FUNCTION
+
// **** checking the number of input and output arguments ****
-
+
[numOutArgs, numInArgs] = argn(0);
-
+
if numOutArgs~=1 & numOutArgs~=2 then
error(78,"rooteig");
end
-
+
if numInArgs<1 | numInArgs>4 then
error(77,"rooteig");
end
-
-
+
+
// **** parsing the input arguments ****
isFsSpecified = %F;
fs = [];
-
+
varargLength = length(varargin);
// searching for the 'corr' flag
isCorrFlag = %F;
-
+
if varargLength==0 then
stringIndices = [];
else
stringIndices = find(type(varargin(1:varargLength))==10);
end
-
+
if ~isempty(stringIndices) then
// ignoring all other strings except the corr flag
isCorrFlag = or(strcmpi(varargin(stringIndices),"corr")==0);
varargin(stringIndices) = [];
end
-
+
// varargin can have only an entry for fs
if length(varargin)==1 then
fs = varargin(1);
@@ -108,13 +124,13 @@ function [w,pow] = rooteig(x,p,varargin)
isFsSpecified = %T;
elseif length(fs)>1 then
msg = "rooteig: Wrong type for argument #4 (fs); Positive scalar expected";
- error(msg,10084);
+ error(msg,10084);
end
elseif length(varargin)>1 then
msg = "rooteig: Wrong type for argument #4 (fs); Positive scalar expected";
- error(msg,10084);
+ error(msg,10084);
end
-
+
// extracting primary input x/R
primaryInput = x;
@@ -143,7 +159,7 @@ function [w,pow] = rooteig(x,p,varargin)
end
// first argument of p must be an integer
if ~IsIntOrDouble(p(1),%T) then
- msg = "rooteig: Wrong input argument #2 p(1); " + ...
+ msg = "rooteig: Wrong input argument #2 p(1); " + ...
"positive integer expected";
error(msg,10036);
return
@@ -154,10 +170,10 @@ function [w,pow] = rooteig(x,p,varargin)
if length(p)==2 then
if ~IsIntOrDouble(p(2),%F) then
msg = "rooteig: Wrong type for argument #2 p(2); must be a scalar";
- error(msg,10053);
+ error(msg,10053);
end
end
-
+
isXReal = isreal(x)
if ~isCorrFlag then
// check that p(1) should be even if x is real
@@ -168,8 +184,8 @@ function [w,pow] = rooteig(x,p,varargin)
end
end
-
-
+
+
// **** calling pmusic ****
data= struct();
data.x = primaryInput;
@@ -185,7 +201,7 @@ function [w,pow] = rooteig(x,p,varargin)
data.isFsSpecified = isFsSpecified;
data.freqrange = "twosided";
-
+
[outData,msg] = musicBase(data);
if length(msg)~=0 then
@@ -193,52 +209,52 @@ function [w,pow] = rooteig(x,p,varargin)
msg = "rooteig: "+msg
error(msg);
end
-
+
pEffective = outData.pEffective;
eigenvals = outData.eigenvals;
-
+
w = computeFreqs(outData.noiseEigenvects,pEffective,%t,eigenvals);
-
+
if isempty(w) then
// assign all frequency and powers as -nan
w = %nan*(1:pEffective)';
pow = w;
return;
end
-
-
+
+
// **** Estimating the variance of the noise ****
// Estimate is the mean of the eigenvalues belonging to the noise subspace
sigma_noise = mean(eigenvals(pEffective+1:$));
-
+
pow = computePower(outData.signalEigenvects,eigenvals,w,pEffective,...
sigma_noise,isXReal);
-
-
+
+
// is fs is specified, convert normailized frequencies to actual frequencies
if isFsSpecified then
w = w*fs/(2*%pi);
end
-
-
+
+
endfunction
function w = computeFreqs(noiseEigenvects,pEffective,EVFlag,eigenvals)
- // Computes the frequencies of the complex sinusoids using the roots of
+ // Computes the frequencies of the complex sinusoids using the roots of
// the polynomial formed with the noise eigenvectors
//
// Parameters
- // noiseEigenvects -
+ // noiseEigenvects -
// A matrix where noise eigenvectors are represented by each column
- // pEffective -
+ // pEffective -
// The effective dimension of the signal subspace
- // EVFlag -
+ // EVFlag -
// Flag to indicate weighting to be used for rooteig
- // eigenvals -
+ // eigenvals -
// Eigenvals of the correlation matrix
//
// Output arguments
- // w -
+ // w -
// A vector with frequencies of the complex sinusoids
@@ -249,68 +265,68 @@ function w = computeFreqs(noiseEigenvects,pEffective,EVFlag,eigenvals)
else
weights = ones(numOfNoiseEigenvects,1);
end
-
+
// Form a polynomial consisting of a sum of polynomials given by the
- // product of the noise subspace eigenvectors and the reversed and
+ // product of the noise subspace eigenvectors and the reversed and
// conjugated version. (eq 8.163 from [1])
D = 0;
for i=1:numOfNoiseEigenvects
eigenvect = noiseEigenvects(:,i);
D = D + conv(eigenvect,conj(eigenvect($:-1:1)))./weights(i);
end
-
+
roots = roots(D);
-
+
// selecting the roots inside the unit circle
rootsSelected = roots(abs(roots)<1);
-
+
// sort the roots in order of increasing distance from the unit circle
[dist,indices] = gsort(abs(rootsSelected)-1);
-
+
sortedRoots = rootsSelected(indices);
-
+
if isempty(sortedRoots) then
w = [];
else
w = atan(imag(sortedRoots(1:pEffective)),real(sortedRoots(1:pEffective)));
end
-
-
+
+
endfunction
function power = computePower(signalEigenvects,eigenvals,w,pEffective,...
sigma_noise,isXReal)
-
+
if isXReal then
- // removing the negative frequencies as sinusoids will be present in
+ // removing the negative frequencies as sinusoids will be present in
// complex conjugate pairs
w = w(w>=0);
pEffective = length(w);
end
-
+
// Solving eq. 8.160 from [1] (Ap = b) where p is the power matrix
-
+
A = zeros(length(w),pEffective);
-
+
for i=1:pEffective
A(:,i) = computeFreqResponseByPolyEval(signalEigenvects(:,i), ...
w,1,%F);
end
-
+
A = (abs(A).^2)';
b = eigenvals(1:pEffective) - sigma_noise;
-
+
// Solving Ap=b with the constraint that all elements of p >=0
power = nnls(A,b+A*sqrt(%eps)*ones(pEffective,1));
-
-
+
+
endfunction
function h = computeFreqResponseByPolyEval(b,f,fs,isFsSpecified)
// returns the frequency response (h) for a digital filter with numerator b.
// The evaluation of the frequency response is done at frequency values f
-
+
f = f(:);
b = b(:);
if isFsSpecified then
@@ -319,18 +335,18 @@ function h = computeFreqResponseByPolyEval(b,f,fs,isFsSpecified)
else
w = f;
end
-
+
n = length(b);
powerMatrix = zeros(length(f),n);
powerMatrix(:,1) = 1;
for i=2:n
powerMatrix(:,i) = exp(w*(-i+1)*%i);
end
-
+
h = powerMatrix*b;
-
-endfunction
-
+
+endfunction
+
function result = IsIntOrDouble(inputNum, isPositiveCheck)
// Checks if The Input Is Integer Or Double
diff --git a/macros/rootmusic.sci b/macros/rootmusic.sci
index 34c3ff6..0efe89f 100644
--- a/macros/rootmusic.sci
+++ b/macros/rootmusic.sci
@@ -13,12 +13,12 @@ function [w,pow] = rootmusic(x,p,varargin)
// Input signal.
// If x is a vector, then it reprsenets one realization of the signal.
// If x is a matrix, then each row represents a separate observation of
- // the signal.
+ // the signal.
// p - int|double - scalar|2 element vector
- // p(1) is the signal subspace dimension and hence the number of
+ // p(1) is the signal subspace dimension and hence the number of
// complex exponentials in x.
- // p(2), if specified, represents a threshold that is multiplied by
- // the smallest estimated eigenvalue of the signal's correlation
+ // p(2), if specified, represents a threshold that is multiplied by
+ // the smallest estimated eigenvalue of the signal's correlation
// matrix.
// fs - int|double - scalar
// Sampling frequency (in Hz)
@@ -26,16 +26,31 @@ function [w,pow] = rootmusic(x,p,varargin)
// to 1 Hz
// 'corr' flag
// If specified, x is interpreted as a correlation matrix rather than
- // a matrix of the signal data. For x to be a correlation matrix,
- // x must be a square matrix and all its eigenvalues must be
+ // a matrix of the signal data. For x to be a correlation matrix,
+ // x must be a square matrix and all its eigenvalues must be
// nonnegative
//
// Examples:
// 1) 3 complex exponentials:
//
- // n=0:99;
- // s=exp(1i*pi/2*n)+2*exp(1i*pi/4*n)+exp(1i*pi/3*n)+randn(1,100);
- // [W,P] = rootmusic(s,3);
+// n=0:99;
+// s=exp(1*%i*%pi/2*n)+2*exp(1*%i*%pi/4*n)+exp(1*%i*%pi/3*n)+rand(1,100,"normal");
+// [A,R]=corrmtx(s,12,'mod');
+// [W,P] = rootmusic(R,3,'corr');
+
+
+// //2)
+// n=0:99;
+// s=exp(1*%i*%pi/2*n)+2*exp(1*%i*%pi/4*n)+exp(1*%i*%pi/3*n);
+// [A,R]=corrmtx(s,12,'mod');
+// [W,P] = rootmusic(R,3,'corr');
+
+ //EXPECTED OUTPUT:
+ //W = 0.7738111 1.5690374 1.0426234
+ //P =377.4255 103.18124 123.86659
+
+
+
//
// Author
// Ayush
@@ -44,7 +59,7 @@ function [w,pow] = rootmusic(x,p,varargin)
// corrmtx | peig | pmusic | rooteig
//
// References
- // 1) Monson H. Hayes, Statistical Digital Signal Processing And Modeling,
+ // 1) Monson H. Hayes, Statistical Digital Signal Processing And Modeling,
// Wiley & Sons, Inc, [Section 8.6.3]
//
//
@@ -52,49 +67,49 @@ function [w,pow] = rootmusic(x,p,varargin)
// w - double - vector
// Estimated frequencies of the complex sinusoids
// pow - double - vector
- // estimated absolute value squared amplitudes of the sinusoids at
- // the frequencies w
+ // estimated absolute value squared amplitudes of the sinusoids at
+ // the frequencies w
//
-
+
funcprot(0);
-
- exec('musicBase.sci',-1);
- exec('nnls.sci',-1);
-
-
+
+ //exec('/home/shashi/Desktop/FOSSEE-Signal-Processing-Toolbox-master/macros/musicBase.sci',-1);
+ //exec('/home/shashi/Desktop/FOSSEE-Signal-Processing-Toolbox-master/macros/nnls.sci',-1);
+
+
// **** checking the number of input and output arguments ****
-
+
[numOutArgs, numInArgs] = argn(0);
-
+
if numOutArgs~=1 & numOutArgs~=2 then
error(78,"rootmusic");
end
-
+
if numInArgs<1 | numInArgs>4 then
error(77,"rootmusic");
end
-
-
+
+
// **** parsing the input arguments ****
isFsSpecified = %F;
fs = [];
-
+
varargLength = length(varargin);
// searching for the 'corr' flag
isCorrFlag = %F;
-
+
if varargLength==0 then
stringIndices = [];
else
stringIndices = find(type(varargin(1:varargLength))==10);
end
-
+
if ~isempty(stringIndices) then
// ignoring all other strings except the corr flag
isCorrFlag = or(strcmpi(varargin(stringIndices),"corr")==0);
varargin(stringIndices) = [];
end
-
+
// varargin can have only an entry for fs
if length(varargin)==1 then
fs = varargin(1);
@@ -107,13 +122,13 @@ function [w,pow] = rootmusic(x,p,varargin)
isFsSpecified = %T;
elseif length(fs)>1 then
msg = "rootmusic: Wrong type for argument #4 (fs); Positive scalar expected";
- error(msg,10084);
+ error(msg,10084);
end
elseif length(varargin)>1 then
msg = "rootmusic: Wrong type for argument #4 (fs); Positive scalar expected";
- error(msg,10084);
+ error(msg,10084);
end
-
+
// extracting primary input x/R
primaryInput = x;
@@ -142,7 +157,7 @@ function [w,pow] = rootmusic(x,p,varargin)
end
// first argument of p must be an integer
if ~IsIntOrDouble(p(1),%T) then
- msg = "rootmusic: Wrong input argument #2 p(1); " + ...
+ msg = "rootmusic: Wrong input argument #2 p(1); " + ...
"positive integer expected";
error(msg,10036);
return
@@ -153,10 +168,10 @@ function [w,pow] = rootmusic(x,p,varargin)
if length(p)==2 then
if ~IsIntOrDouble(p(2),%F) then
msg = "rootmusic: Wrong type for argument #2 p(2); must be a scalar";
- error(msg,10053);
+ error(msg,10053);
end
end
-
+
isXReal = isreal(x)
if ~isCorrFlag then
// check that p(1) should be even if x is real
@@ -167,8 +182,8 @@ function [w,pow] = rootmusic(x,p,varargin)
end
end
-
-
+
+
// **** calling pmusic ****
data= struct();
data.x = primaryInput;
@@ -184,7 +199,7 @@ function [w,pow] = rootmusic(x,p,varargin)
data.isFsSpecified = isFsSpecified;
data.freqrange = "twosided";
-
+
[outData,msg] = musicBase(data);
if length(msg)~=0 then
@@ -192,52 +207,52 @@ function [w,pow] = rootmusic(x,p,varargin)
msg = "rootmusic: "+msg
error(msg);
end
-
+
pEffective = outData.pEffective;
eigenvals = outData.eigenvals;
-
+
w = computeFreqs(outData.noiseEigenvects,pEffective,%f,eigenvals);
-
+
if isempty(w) then
// assign all frequency and powers as -nan
w = %nan*(1:pEffective)';
pow = w;
return;
end
-
-
+
+
// **** Estimating the variance of the noise ****
// Estimate is the mean of the eigenvalues belonging to the noise subspace
sigma_noise = mean(eigenvals(pEffective+1:$));
-
+
pow = computePower(outData.signalEigenvects,eigenvals,w,pEffective,...
sigma_noise,isXReal);
-
-
+
+
// is fs is specified, convert normailized frequencies to actual frequencies
if isFsSpecified then
w = w*fs/(2*%pi);
end
-
-
+
+
endfunction
function w = computeFreqs(noiseEigenvects,pEffective,EVFlag,eigenvals)
- // Computes the frequencies of the complex sinusoids using the roots of
+ // Computes the frequencies of the complex sinusoids using the roots of
// the polynomial formed with the noise eigenvectors
//
// Parameters
- // noiseEigenvects -
+ // noiseEigenvects -
// A matrix where noise eigenvectors are represented by each column
- // pEffective -
+ // pEffective -
// The effective dimension of the signal subspace
- // EVFlag -
+ // EVFlag -
// Flag to indicate weighting to be used for rooteig
- // eigenvals -
+ // eigenvals -
// Eigenvals of the correlation matrix
//
// Output arguments
- // w -
+ // w -
// A vector with frequencies of the complex sinusoids
@@ -248,68 +263,68 @@ function w = computeFreqs(noiseEigenvects,pEffective,EVFlag,eigenvals)
else
weights = ones(numOfNoiseEigenvects,1);
end
-
+
// Form a polynomial consisting of a sum of polynomials given by the
- // product of the noise subspace eigenvectors and the reversed and
+ // product of the noise subspace eigenvectors and the reversed and
// conjugated version. (eq 8.163 from [1])
D = 0;
for i=1:numOfNoiseEigenvects
eigenvect = noiseEigenvects(:,i);
D = D + conv(eigenvect,conj(eigenvect($:-1:1)))./weights(i);
end
-
+
roots = roots(D);
-
+
// selecting the roots inside the unit circle
rootsSelected = roots(abs(roots)<1);
-
+
// sort the roots in order of increasing distance from the unit circle
[dist,indices] = gsort(abs(rootsSelected)-1);
-
+
sortedRoots = rootsSelected(indices);
-
+
if isempty(sortedRoots) then
w = [];
else
w = atan(imag(sortedRoots(1:pEffective)),real(sortedRoots(1:pEffective)));
end
-
-
+
+
endfunction
function power = computePower(signalEigenvects,eigenvals,w,pEffective,...
sigma_noise,isXReal)
-
+
if isXReal then
- // removing the negative frequencies as sinusoids will be present in
+ // removing the negative frequencies as sinusoids will be present in
// complex conjugate pairs
w = w(w>=0);
pEffective = length(w);
end
-
+
// Solving eq. 8.160 from [1] (Ap = b) where p is the power matrix
-
+
A = zeros(length(w),pEffective);
-
+
for i=1:pEffective
A(:,i) = computeFreqResponseByPolyEval(signalEigenvects(:,i), ...
w,1,%F);
end
-
+
A = (abs(A).^2)';
b = eigenvals(1:pEffective) - sigma_noise;
-
+
// Solving Ap=b with the constraint that all elements of p >=0
power = nnls(A,b+A*sqrt(%eps)*ones(pEffective,1));
-
-
+
+
endfunction
function h = computeFreqResponseByPolyEval(b,f,fs,isFsSpecified)
// returns the frequency response (h) for a digital filter with numerator b.
// The evaluation of the frequency response is done at frequency values f
-
+
f = f(:);
b = b(:);
if isFsSpecified then
@@ -318,18 +333,18 @@ function h = computeFreqResponseByPolyEval(b,f,fs,isFsSpecified)
else
w = f;
end
-
+
n = length(b);
powerMatrix = zeros(length(f),n);
powerMatrix(:,1) = 1;
for i=2:n
powerMatrix(:,i) = exp(w*(-i+1)*%i);
end
-
+
h = powerMatrix*b;
-
-endfunction
-
+
+endfunction
+
function result = IsIntOrDouble(inputNum, isPositiveCheck)
// Checks if The Input Is Integer Or Double
diff --git a/macros/sampled2continuous.sci b/macros/sampled2continuous.sci
index 25738c4..e14f96b 100644
--- a/macros/sampled2continuous.sci
+++ b/macros/sampled2continuous.sci
@@ -1,11 +1,24 @@
-function x = sampled2continuous (n, s, t)
-//This function calculates the output reconstructed from the samples n supplied as input, at a rate of 1/s samples per unit time.
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function xt = sampled2continuous( xn , T, t )
+
+
+ //This function calculates the output reconstructed from the samples n supplied as input, at a rate of 1/s samples per unit time.
//Calling Sequence
-//x = sampled2continuous (n, s, t)
-//Parameters
-//n:
-//s:
-//t:
+//x = sampled2continuous (xn, T, t)
+//Parameters
+//xn:sampled signal
+//T:sampling rate
+//t:all the instants of time when you need x(t) from x[n]
//Description
//This is an Octave function.
//This function calculates the output reconstructed from the samples n supplied as input, at a rate of 1/s samples per unit time.
@@ -13,12 +26,17 @@ function x = sampled2continuous (n, s, t)
//Examples
//sampled2continuous([1,2,3],5,6)
//ans =
-// 2.4166806
-funcprot(0);
-rhs = argn(2)
-if(rhs<3)
-error("Wrong number of input arguments.")
-end
-x = callOctave("sampled2continuous", n, s, t)
+// 2.4166806
+
+ if ( argn(2) < 3 )
+ error('wrong number of input parameters')
+ end
+
+ N = length( xn );//finding the length of input sequence
+ xn = matrix( xn, N, 1 );//stacking the matrix xn in columnwise manner
+ [TT,tt]= meshgrid(T*(0:N-1)',t);
+ S = sinc(%pi.*(tt -TT)./T);
+ xt = S*xn;//recontructing the samples
+ return
endfunction
diff --git a/macros/schurrc.sci b/macros/schurrc.sci
index 0a5e6ce..98448d6 100644
--- a/macros/schurrc.sci
+++ b/macros/schurrc.sci
@@ -3,28 +3,41 @@
//[K,E] = SCHURRC(R) returns the prediction error variance E. If R is a matrix, SCHURRC finds the error for each column of R, and returns them in the rows of E.
//Modified to match matlab i/p and o/p and handle exceptions
//Fixed bugs
-//by Debdeep Dey
+//by Debdeep Dey
+
+//////EXAMPLES:
+//m=linspace(1,100);
+//r = xcorr(m(1:5),'unbiased');.......autocorrelation vector
+//[k,e] = schurrc(r(5:$))
+
+//EXPECTED OUTPUT
+//e =1.6212406
+ //k = - 0.9090909 0.2222222 0.2244898 0.2434211
+
+
+
+
function [k,e] = schurrc(R)
narginchk(1,1,argn(2));
-if(type(R)==10) then
+if(type(R)==10) then// R is a matrix of character strings
w=R;
[nr,nc]=size(R);
if(nr==1 & nc==1) then
- R=ascii(R);
- R=matrix(R,length(w));
+ R=ascii(R);//conversion to the corresponding asci values
+ R=matrix(R,length(w));//reshaping the matrix
else
-
+
R=ascii(R);
- R=matrix(R,size(w));
+ R=matrix(R,size(w));//reshaping the matrix
end
-
+
end
-if(type(R) > 1) then
+if(type(R) > 1) then ///checking if R in not a matrix of real or complex numbers
error('Input R is not a matrix')
end
-if (min(size(R)) == 1) then
- R = R(:);
-end
+if (min(size(R)) == 1) then
+ R = R(:);
+end
[m,n] = size(R);
// Compute reflection coefficients for each column of the input matrix
for j = 1:n
@@ -33,11 +46,11 @@ for j = 1:n
U = [0 X(2:m); X(1:m)];
for i = 2:m,
- U(2,:) = [0 U(2,1:m-1)];
- k(i-1,j) = -U(1,i)/U(2,i);
+ U(2,:) = [0 U(2,1:m-1)];
+ k(i-1,j) = -U(1,i)/U(2,i);
U = [1 k(i-1,j); conj(k(i-1,j)) 1]*U;
end
-
+
e(j,1) = U(2,$);
end
endfunction
diff --git a/macros/slewrate.sci b/macros/slewrate.sci
index 5b83327..544bd28 100644
--- a/macros/slewrate.sci
+++ b/macros/slewrate.sci
@@ -1,6 +1,6 @@
function [s, lowercrossvalue, uppercrossvalue, lowerreference, upperreference]=slewrate(x, varargin)
-
-
+
+
// This function estimate slew rate of bilevel waveform transitions
// Calling Sequence
// s=slewrate(x)
@@ -9,7 +9,7 @@ function [s, lowercrossvalue, uppercrossvalue, lowerreference, upperreference]=s
// s=slewrate(x, t, 'PercentReferenceLevels', N )
// s=slewrate(x, t, 'Tolerance', M)
// s=slewrate(x, t,'StateLevels', O)
-
+
// [s lowercrossvalue uppercrossvalue lowerreference upperreference]=slewrate(x)
// [s lowercrossvalue uppercrossvalue lowerreference upperreference]=slewrate(x, t)
// // [s lowercrossvalue uppercrossvalue lowerreference upperreference]=slewrate(x, Fs)
@@ -17,7 +17,7 @@ function [s, lowercrossvalue, uppercrossvalue, lowerreference, upperreference]=s
// [s lowercrossvalue uppercrossvalue lowerreference upperreference]= slewrate(x, t, 'Tolerance', M)
// [s lowercrossvalue uppercrossvalue lowerreference upperreference]= slewrate(x, t,'StateLevels', O)
// [s lowercrossvalue uppercrossvalue lowerreference upperreference]= slewrate(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.
@@ -25,48 +25,58 @@ function [s, lowercrossvalue, uppercrossvalue, lowerreference, upperreference]=s
// PercentReferenceLevels: specify the mid percent reference leves as a percentage, default value of N is [10 90].
// 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'.
// s: returns a vector of the ratios of the level difference to the time duration between the points where each transition crosses the 10% and 90% reference levels.
// lowercrossvalue: return the lowerc cross value of bilevel waveform transitions X
// uppercrossvalue: return the upper cross value of bilevel waveform transitions X
// lowerreference: return lower reference value corrosponding to lower percent reference value.
// upperreference: return upper reference value corrosponding to upper percent reference value.
-
- // Examples
+
+ // Example1
// x=[1.2, 5, 10, -20, 12]
//t=1:length(x)
- //s=slewrate(x, t)
+ //s=slewrate(x, t)
+ //EXPECTED OUTPUT:
+ //s = - 30. 32.
+ //
+ //Example2
+ //x=[ones(1,25) -ones(1,25) ones(1,25) ]
+ //t=1:length(x)
+ //s=slewrate(x,t)
+ //EXPECTED OUTPUT:
+ //s = - 2 2
+
// 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 size(x,1)==1 | size (x,2)==1 then
else
error ('Argument X must be vector.')
end
-
-
+
+
if length(varargin)==0 then // if the no of input is 0, then specify the default values to input parameter.
[levels hist]=statelevels(x);
Lvarargin=list(1:length(x), 'StateLevels', levels(1), 'MidPercentReferenceLevel', 10, 'Tolerance', 2, 'fig', 'off')
Uvarargin=list(1:length(x), 'StateLevels', levels(2), 'MidPercentReferenceLevel', 90, 'Tolerance', 2, 'fig', 'off')
end
-
+
if length(varargin)>=1 & type(varargin(1))==1 then
if length(varargin(1))==1 then
t=(0:(length(x)-1));
-
+
elseif length(varargin(1))==length(x) then
t=varargin(1);
-
+
else
error('T must be a same length as X.')
end
@@ -86,11 +96,11 @@ 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
@@ -100,7 +110,7 @@ if length(sindex)>5 then
end
if length(varargin)==1 & (isempty(sindex)) then
-
+
[levels hist]=statelevels(x);
Lvarargin=list(t, 'StateLevels', levels(1), 'MidPercentReferenceLevel', 10, 'Tolerance', 2, 'fig', 'off')
Uvarargin=list(t, 'StateLevels', levels(2), 'MidPercentReferenceLevel', 90, 'Tolerance', 2, 'fig', 'off')
@@ -112,113 +122,113 @@ fig='OFF';
if (~isempty(sindex)) then
for j=1:length(sindex)
-
+
select convstr(varargin(sindex(j)),'u')
-
+
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')=='PERCENTREFERENCELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' 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 {'PERCENTREFERENCELEVELS'}
+
+ case {'PERCENTREFERENCELEVELS'}
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' 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' 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
-
+
if length( midpercentval)~=2 then
- error ('Expected MidPercentRefernceLevel to be of size 1x2')
- end
+ error ('Expected MidPercentRefernceLevel to be of size 1x2')
+ end
/////////////////////////////////
-
+
perval=varargin(sindex(j)+1);
disp(perval)
if perval(2)<= perval(1) then
error('The PercentReferenceLevels must be in increasing order.')
end
-
+
varargin(sindex(j))='MidPercentReferenceLevel';
varargin(sindex(j)+1)=perval(1);
Lvarargin= varargin;
-
+
varargin(sindex(j)+1)=perval(2);
Uvarargin=varargin;
-
-
-
+
+
+
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')=='PERCENTREFERENCELEVELS' 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')=='PERCENTREFERENCELEVELS' 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'}
+
+
+
case{'OFF'}
-
+
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')== 'PERCENTREFERENCELEVELs' | convstr(varargin(sindex(j)+1), 'u')=='FIG' 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
-
- else
+
+ else
error(strcat(['Invalid optional argument'," ", varargin(sindex(j))]));
end // switch
end // for
@@ -227,41 +237,41 @@ if (~isempty(sindex)) then
/////////////////////////////////////////////
-
+
indexx=[];
if length(sindex)>=1 then
a=1;
for i=1:length(sindex)
-
- indexx(a)=find(convstr(varargin(sindex(i)), 'u')=='MIDPERCENTREFERENCELEVEL')
+
+ indexx(a)=find(convstr(varargin(sindex(i)), 'u')=='MIDPERCENTREFERENCELEVEL')
a=a+1;
end
-end
+end
if sum(indexx)==0 then
-
+
varargin(length(varargin)+1)='MIDPERCENTREFERENCELEVEL';
varargin(length(varargin)+1)=10;
Lvarargin= varargin;
-
+
varargin(length(varargin))=90;
- Uvarargin=varargin;
+ Uvarargin=varargin;
end
-
+
index_on=[];
if length(sindex)>=1 then
a=1;
for i=1:length(sindex)
-
- index_on(a)=find(convstr(varargin(sindex(i)), 'u')=='ON')
-
+
+ index_on(a)=find(convstr(varargin(sindex(i)), 'u')=='ON')
+
a=a+1;
-
+
+end
end
-end
if sum(index_on)>0 then
Lvarargin(sindex(find(index_on>0)))='OFF';
@@ -270,118 +280,118 @@ end
-
- [lcrossval lref levels t tolerance]= midcross(x, Lvarargin(:));
-
+
+ [lcrossval lref levels t tolerance]= midcross(x, Lvarargin(:));
+
[ucrossval uref]=midcross(x, Uvarargin(:));
-
-
- if length(lcrossval)==length(ucrossval) then
+
+
+ if length(lcrossval)==length(ucrossval) then
ss=ucrossval-lcrossval
-
+
elseif length(lcrossval)>length(ucrossval)
n=length(ucrossval);
ss=ucrossval-lcrossval(1:n);
-
+
else
n=length(lcrossval);
ss=ucrossval(1:n)-lcrossval;
-
-
+
+
end
-
+
s=(uref-lref)./ss;
-
-
+
+
uppercrossvalue=ucrossval;
- lowercrossvalue=lcrossval;
-
+ lowercrossvalue=lcrossval;
+
lowerreference=lref;
- upperreference=uref;
-
+ upperreference=uref;
+
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));
+
+
+
+
+
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')
-
+
plot(t,upperreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
-
+
plot(t,lowerreference * ones(1, length(t)),'-g', '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"; "upper reference"; "lower reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;1], [3;2], [1;2], [3;2]], opt='?')
+
- legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "upper reference"; "lower reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;1], [3;2], [1;2], [3;2]], opt='?')
-
+ else
- else
-
plot(t,x, 'LineWidth',1, 'color', 'black')
-
+
plot(t,upperreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
-
+
plot(t,lowerreference * ones(1, length(t)),'-g', 'LineWidth',0.5)
-
+
rects=[lowercrossvalue; upperreference*ones(lowercrossvalue); ss; (upperreference-lowerreference)*ones(s)]
-
+
col=-10*ones(s);
-
+
xrects(rects, col);
-
+
plot(uppercrossvalue, upperreference*ones(uppercrossvalue), "r*", 'MarkerSize',15);
-
+
plot(lowercrossvalue, lowerreference*ones(lowercrossvalue), "g*", '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,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(["slewrate"; "Signal"; "upper cross"; "lower cross"; "upper boundary"; "upper state"; "lower boundary"; "upper reference"; "lower reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;5], [-10;3], [5;2], [1;2], [5;2], [5;1], [3;1], [3;2],[1;2], [3;2]], opt='?')
- end
- end
-
+ end
+ end
+
endfunction
diff --git a/macros/sos2ss.sci b/macros/sos2ss.sci
index c13f688..d629c29 100644
--- a/macros/sos2ss.sci
+++ b/macros/sos2ss.sci
@@ -1,5 +1,27 @@
//Author: Parthasarathi Panda
//parthasarathipanda314@gmail.com
+//Convert digital filter second-order section parameters to state-space form
+//Calling Sequence
+//[A,B,C,D] = sos2ss(sos)
+//[A,B,C,D] = sos2ss(sos,g)
+//
+//sos2ss converts a second-order section representation of a digital filter to an equivalent state-space representation.
+//A,B,C,D:Steady state parameters
+//sos:6 column second order section matrix
+//g:gain
+
+
+//EXAMPLES:
+//sos = [1 1 1 1 0 -1 ;
+// -2 3 1 1 10 1];
+//[A,B,C,D] = sos2ss(sos,2);
+//
+//EXPECTED OUTPUT:
+//D =- 4.
+ //C =42. 4. - 32. - 2.
+ //B =[1. 0. 0. 0. 0.]'
+ //A =[- 10. 0. 10. 1. ; 1. 0. 0. 0. ; 0. 1. 0. 0. ; 0. 0. 1. 0. ]
+
function [A,B,C,D]=sos2ss(sos,g)
[nargout,nargin]=argn();
if nargin==1 then
@@ -16,7 +38,7 @@ function [A,B,C,D]=sos2ss(sos,g)
if j~=6 then
error('sos should be a 6-column matrix');
end
-
+
num=[1];
den=[1];
//convolving the numerator and denominator to get the coefficient of the numerator and the denominator at the top and bottom
@@ -24,21 +46,21 @@ function [A,B,C,D]=sos2ss(sos,g)
num=convol(num,sos(i,1:3));
den=convol(den,sos(i,4:6));
end
-
+ t=2*d+1; //polynomial degree must be defined here
if den(t)==0 then
error('improper transfer function check input');
end
-
- t=2*d+1; //polynomial degree
+
+ // t=2*d+1; //polynomial degree
A=zeros(t-1,t-1);
if t>2 then
A(2:(t-1),1:(t-2))=eye(t-2,t-2);
end
- A(1,:)=-1*den(2:t)/den(1);
+ A(1,:)=-1*den(2:t)/den(1);
B=zeros(t,1);
B(1)=1/den(1); //constructing (A,B) in canonical controllable form
C=g*(num(2:t)-den(2:t)*num(1)/den(1));//appropiate C and D
D=g*num(1)/den(1);
-
+
endfunction
diff --git a/macros/sos2tf.sci b/macros/sos2tf.sci
index 0ee0d3e..d38a4f7 100644
--- a/macros/sos2tf.sci
+++ b/macros/sos2tf.sci
@@ -13,11 +13,12 @@ function [B,A] = sos2tf(sos, g)
//The input is the sos matrix and the second parameter is the overall gain, default value of which is 1.
//The output is a vector.
//Examples
-//[a,b]=sos2tf([1,2,3,4,5,6])
+//sos = [1 1 1 1 0 -1; -2 3 1 1 10 1];
+////[b,a] = sos2tf(sos)
//a =
-// 1 2 3
+// -2 1 2 4 1
//b =
-// 4 5 6
+// 1 10 0 -10 -1
funcprot(0);
rhs = argn(2)
if(rhs<1 | rhs>2)
diff --git a/macros/sosbreak.sci b/macros/sosbreak.sci
index dc78f95..c82935f 100644
--- a/macros/sosbreak.sci
+++ b/macros/sosbreak.sci
@@ -1,7 +1,28 @@
//Author: Parthasarathi Panda
//parthasarathipanda314@gmail.com
function [zerosort,g]=sosbreak(p)
-//function for breaking a polynomial in second order polynomials (and an extra linear)
+//function for breaking a polynomial in second order polynomials and an extra linear term (g)
+//where
+//g:-the interger multiple obtained after breaking the polynomial
+//zerosort:-the array of the broken polynomials
+//p:-the input polynomial
+
+
+//EXAMPLE:
+//v=[1+4*%s+6*%s^2+4*%s^3+%s^4];
+// [zerosort,g]=sosbreak(v);
+//OUTPUT:
+// g =1.
+ //zerosort =
+ // zerosort(1)
+// 2
+// 1 + 2s + s
+// zerosort(2)
+// 2
+//1.0000000 + 2s + s
+
+//NOTE :To verify the output use coeff(zerosort(1)) and coeff(zerosort(2))
+
[zero,g]=factors(p);//factorising into real coefficient polynomials
degn=degree(p);
zerosort=list();
@@ -16,7 +37,7 @@ function [zerosort,g]=sosbreak(p)
zerosort($+1)=q;
end
end
-
+
if (modulo(degn,2))==0 then
e=length(zerosort);
//leave the last linear element if an odd degree polynomial
@@ -28,7 +49,8 @@ function [zerosort,g]=sosbreak(p)
if degree(q)==2 then
break;
end
- zerosort(i)=q*zerosort(i-1);//combining 2 linear polynomial into one quadratic polynomial
+ zerosort(i)=q.*zerosort(i-1);//combining 2 linear polynomial into one quadratic polynomial
zerosort(i-1)=null();//removing leftover linear polynomial
+
end
endfunction
diff --git a/macros/specgram.sci b/macros/specgram.sci
index 3af24f1..e1ca6dc 100644
--- a/macros/specgram.sci
+++ b/macros/specgram.sci
@@ -1,21 +1,120 @@
-function [S_r, f_r, t_r] = specgram(x,n,fs,window,overlap)
-
-funcprot(0);
-rhs = argn(2)
-
-if(rhs<1 | rhs>5)
-error("Wrong number of input arguments.")
-end
- select(rhs)
- case 1 then
- [S_r, f_r, t_r] = callOctave("specgram",x)
- case 2 then
- [S_r, f_r, t_r] = callOctave("specgram",x,n)
- case 3 then
- [S_r, f_r, t_r] = callOctave("specgram",x,n,fs)
- case 4 then
- [S_r, f_r, t_r] = callOctave("specgram",x,n,fs,window)
- case 5 then
- [S_r, f_r, t_r] = callOctave("specgram",x,n,fs,window,overlap)
- 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+
+function [S_r, f_r, t_r] = specgram(x, n , Fs , win , overlap)
+//Generate a spectrogram for the signal x. The signal is chopped into overlapping segments of length n, and each segment is windowed and transformed into the frequency domain using the FFT. The default segment size is 256. If fs is given, it specifies the sampling rate of the input signal. The argument window specifies an alternate window to apply rather than the default of hanning (n). The argument overlap specifies the number of samples overlap between successive segments of the input signal. The default overlap is length (window)/2.
+
+//CALLING SEQUENCE:
+//[S, f, t] = specgram (x,n,fs,window,overlap)
+//where
+//S is the complex output of the FFT, one row per slice
+//f is the frequency indices corresponding to the rows of S
+// t is the time indices corresponding to the columns of S.
+
+
+
+//Test cases:
+//////1.
+//N=1024;
+//n=0:N-1;
+//w=2*%pi/5;
+//x=sin(w*n)+10*sin(2*w*n);
+//[s,f,t]=specgram(x);
+//grayplot(f,t,s)
+//xlabel("frequency")
+//ylabel("time")
+////
+[nargout,nargin]=argn();
+ if nargin < 1 | nargin > 5
+ error("wrong no. of input arguments");
+ // make sure x is a vector
+ elseif size(x,"c") ~= 1 & size(x,"r") ~= 1
+ error ("specgram data must be a vector");
+ end
+
+ if nargin==1 then
+ n=min(256,length(x));
+ Fs=2;
+ win = window("hn",n);
+ overlap=ceil(length(win)/2);
+ end
+
+
+
+
+ if size(x,"c") ~= 1
+ x = x';
+ end
+
+ // if only the win length is given, generate hanning win
+ if isscalar(win)
+ win = window("hn",win);
+
+ end
+
+ // should be extended to accept a vector of frequencies at which to
+ // evaluate the Fourier transform (via filterbank or chirp
+ // z-transform)
+ if ~isscalar(n)
+ error("specgram doesnot handle frequency vectors yet");
+ end
+
+ if (length (x) <= length (win))
+ error ("specgram: segment length must be less than the size of X");
+ end
+
+ // compute win offsets
+ win_size = length(win);
+ if (win_size > n)
+ n = win_size;
+ warning ("specgram fft size adjusted to %d", n);
+ end
+ step = win_size - overlap;
+
+ // build matrix of wined data slices
+ offset = [ 1 : step : length(x)-win_size ];
+ S = zeros (n, length(offset));
+ for i=1:length(offset)
+ S(:, i) =( x(offset(i):offset(i)+win_size-1).* win');
+ end
+
+ // compute Fourier transform
+ S = fft (S);
+
+ // extract the positive frequency components
+ if (n-fix(n/2)*2)==1
+ ret_n = (n+1)/2;
+ else
+ ret_n = n/2;
+ end
+ S = S(1:ret_n, :);
+
+ f = [0:ret_n-1]*Fs/n;
+ t = offset/Fs;
+// if nargout==0
+// //Matplot(20*log10(abs(S)));
+// //set (gca (), "ydir", "normal");
+// xlabel ("Time")
+// ylabel ("Frequency")
+// end
+ if nargout>0
+ S_r = S;
+ end
+ if nargout>1
+ f_r = f;
+ end
+ if nargout>2
+ t_r = t;
+ end
+
endfunction
diff --git a/macros/ss2sos.sci b/macros/ss2sos.sci
index caf2def..2664b24 100644
--- a/macros/ss2sos.sci
+++ b/macros/ss2sos.sci
@@ -1,5 +1,36 @@
//Author: Parthasarathi Panda
//parthasarathipanda314@gmail.com
+
+//ss2sos converts a state-space representation of a given digital filter to an equivalent second-order section representation.
+
+////Example:
+//a =[0.5095,0,0,0,0;
+//0.3007, 0.2260, -0.3984, 0, 0;
+//0.0977, 0.3984, 0.8706, 0, 0;
+//0.0243, 0.0991, 0.4652, 0.5309, -0.4974;
+//0.0079, 0.0322, 0.1512, 0.4974, 0.8384];
+//
+//
+//b =[0.6936 0.1382 0.0449 0.0112 0.0036]'
+//
+//
+//c =[0.0028 0.0114 0.0534 0.1759 0.6500]
+//
+//
+//d =0.0013
+
+//[sos,g]=ss2sos(a,b,c,d)
+//Expected output:
+//g =
+ // 0.0013
+// sos =
+// 1. 1.2679417 0.6443293 1. - 1.0966 0.3554782
+// 1. 3.1480112 3.2063892 1. - 1.3693 0.6925133
+// 1. 0.4742625 0. 1. - 0.5095 0.
+//
+
+
+
function [sos,g]=ss2sos(A,B,C,D)
//not taking if, order and scale as input since they do not seem useful
if (type(A)~=1 | type(B)~=1 | type(C)~=1 | type(D)~=1) then
@@ -23,7 +54,7 @@ function [sos,g]=ss2sos(A,B,C,D)
if n~=1 then
error('for single input single output, C must be row matrix');
end
- if size(A)~=[1,1] then
+ if size(A)==[1,1] then
error('A must be square matrix');
end
//obtaining the transfer function(continuous)
@@ -57,7 +88,7 @@ function [sos,g]=ss2sos(A,B,C,D)
v=[b,a];
sos=[sos;v]//adding the second order sub-system
end
-
+
g=gn/gd;//computing the gain
-
+
endfunction
diff --git a/macros/subspaceMethodsInputParser.sci b/macros/subspaceMethodsInputPars.sci
index 1396c86..35eb6f5 100644
--- a/macros/subspaceMethodsInputParser.sci
+++ b/macros/subspaceMethodsInputPars.sci
@@ -1,5 +1,5 @@
// Date of creation: 17 Dec, 2015
-function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
+function [data, msg, err_num] = subspaceMethodsInputParsS(inputArgsList)
// Input parser to be used by pmusic and peig
// primaryInput, p, w, nfft, fs, nwin, noverlap, freqrange, isCorrFlag
@@ -26,7 +26,7 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
// w/f - vector
// nfft - positive scalar
// fs - positive scalar
- // isWindowSpecified - boolean indicating if window specified in the
+ // isWindowSpecified - boolean indicating if window specified in the
// input params
// windowLength - positive scalar
// windowVector - vector
@@ -35,7 +35,7 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
// isCorrFlag - boolean
// isFsSpecified - boolean indicating if fs argument is present
// (fs can be empty)
- //
+ //
// msg - error message (if any)
// err_num - error number (if any; otherwise -1)
@@ -43,11 +43,11 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
msg = "";
err_num = -1;
data = struct();
-
+
numOfInputArgs = length(inputArgsList);
// ****getting indices of all string input arguments****
- stringIndices = list();
+ stringIndices = list();
for i=1:numOfInputArgs
e = inputArgsList(i);
if type(e)==10 then
@@ -60,7 +60,7 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
isOneSided = %F;
isTwoSided = %F;
isCentered = %F;
-
+
if ~isempty(stringIndices) then
// ****checking for corr flag****
isCorrFlag = or(strcmpi(inputArgsList(stringIndices),"corr")==0);
@@ -71,7 +71,7 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
| strcmpi(inputArgsList(stringIndices),"whole")==0);
isCentered = or(strcmpi(inputArgsList(stringIndices),"centered")==0);
end
-
+
freqrange = "";
if isTwoSided then
freqrange = "twosided";
@@ -144,7 +144,7 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
if ~IsIntOrDouble(p(2),%F) then
msg = "Wrong type for p(2); must be a scalar";
err_num = 84;
- return
+ return
end
end
@@ -168,7 +168,7 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
if L==3 then
// (x,p,w), and (x,p,nfft) are candidates
temp3 = inputArgsList(3);
-
+
// should be a vector or a scalar
if size(temp3, 1)~=1 & size(temp3, 2)~=1 then
@@ -271,9 +271,9 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
end
fs = double(temp4);
isFsSpecified = %T;
- end
+ end
end
-
+
elseif L>=5 then
// nfft, fs, nwin, noverlap
nfft = inputArgsList(3);
@@ -288,7 +288,7 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
elseif ~length(nfft)==1 | ~IsIntOrDouble(nfft,%T) then
msg = "Wrong type for argument #3 (nfft); must be a positive integer";
err_num = 84;
- return
+ return
end
if isempty(fs) then
@@ -331,21 +331,21 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
// noverlap
if isempty(noverlap) then
- noverlap = windowLength-1;
+ noverlap = windowLength-1;
elseif length(noverlap)==1 then
if ~(type(noverlap)==8 | type(noverlap)==1)| noverlap<0 then
msg = "Wrong type for argument #6 (noverlap); must be a non-negative integer";
err_num = 84;
return;
end
- noverlap = int(noverlap);
+ noverlap = int(noverlap);
else
msg = "Wrong type for argument #6 (noverlap); must be a non-negative integer";
err_num = 84;
return;
end
end
-
+
// assigning default value for freqrange if not already specified
if length(freqrange)==0 then
if isreal(x) then
@@ -354,14 +354,14 @@ function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
freqrange = "twosided";
end
end
-
-
+
+
// normalizing w if it exists
if ~isempty(w) & isFsSpecified then
w = w*2*%pi/fs;
end
-
-
+
+
data.x = primaryInput;
data.p = p;
data.w = w;
diff --git a/macros/text4_peig.txt b/macros/text4_peig.txt
new file mode 100644
index 0000000..4345884
--- /dev/null
+++ b/macros/text4_peig.txt
@@ -0,0 +1,257 @@
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+2.000000
+2.000000
+2.000000
+2.000000
+2.000000
+2.000000
+2.000000
+2.000000
+3.000000
+3.000000
+3.000000
+3.000000
+4.000000
+4.000000
+4.000000
+5.000000
+5.000000
+6.000000
+7.000000
+8.000000
+9.000000
+10.000000
+12.000000
+14.000000
+17.000000
+21.000000
+27.000000
+35.000000
+48.000000
+69.000000
+109.000000
+198.000000
+464.000000
+2047.000000
+20657.000000
+1193.000000
+349.000000
+163.000000
+94.000000
+61.000000
+43.000000
+32.000000
+24.000000
+19.000000
+16.000000
+13.000000
+11.000000
+9.000000
+8.000000
+7.000000
+6.000000
+6.000000
+5.000000
+4.000000
+4.000000
+4.000000
+3.000000
+3.000000
+3.000000
+3.000000
+2.000000
+2.000000
+2.000000
+2.000000
+2.000000
+2.000000
+2.000000
+2.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+1.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
+0.000000
diff --git a/macros/txt4_pchip.txt b/macros/txt4_pchip.txt
new file mode 100644
index 0000000..50abba8
--- /dev/null
+++ b/macros/txt4_pchip.txt
@@ -0,0 +1 @@
+1.000000 0.877423 0.762859 0.656305 0.557763 0.467233 0.384714 0.310207 0.243711 0.185227 0.134754 0.092293 0.057843 0.031405 0.012979 0.002564 0.000477 0.016429 0.052765 0.106442 0.174418 0.253651 0.341099 0.433718 0.528467 0.622304 0.712185 0.795069 0.867913 0.927675 0.971313 0.995783 0.998110 0.977837 0.937790 0.881009 0.810538 0.729419 0.640694 0.547405 0.452595 0.359306 0.270581 0.189462 0.118991 0.062210 0.022163 0.001890 0.004217 0.028687 0.072325 0.132087 0.204931 0.287815 0.377696 0.471533 0.566282 0.658901 0.746349 0.825582 0.893558 0.947235 0.983571 0.999523 0.997436 0.987021 0.968595 0.942157 0.907707 0.865246 0.814773 0.756289 0.689793 0.615286 0.532767 0.442237 0.343695 0.237141 0.122577 0.000000
diff --git a/macros/txt4_periodogram.txt b/macros/txt4_periodogram.txt
new file mode 100644
index 0000000..b8954a4
--- /dev/null
+++ b/macros/txt4_periodogram.txt
@@ -0,0 +1,129 @@
+0.000000
+0.000002
+0.000003
+0.000002
+0.000000
+0.000002
+0.000004
+0.000002
+0.000000
+0.000003
+0.000006
+0.000003
+0.000000
+0.000004
+0.000010
+0.000006
+0.000000
+0.000008
+0.000018
+0.000011
+0.000000
+0.000016
+0.000040
+0.000025
+0.000000
+0.000044
+0.000123
+0.000091
+0.000000
+0.000267
+0.001234
+0.002530
+0.080000
+0.002658
+0.001361
+0.000310
+0.000000
+0.000117
+0.000166
+0.000062
+0.000000
+0.000039
+0.000065
+0.000027
+0.000000
+0.000020
+0.000036
+0.000016
+0.000000
+0.000013
+0.000023
+0.000011
+0.000000
+0.000009
+0.000017
+0.000008
+0.000000
+0.000007
+0.000013
+0.000006
+0.000000
+0.000005
+0.000010
+0.000005
+0.000000
+0.000004
+0.000009
+0.000004
+0.000000
+0.000004
+0.000007
+0.000004
+0.000000
+0.000003
+0.000006
+0.000003
+0.000000
+0.000003
+0.000006
+0.000003
+0.000000
+0.000003
+0.000005
+0.000002
+0.000000
+0.000002
+0.000005
+0.000002
+0.000000
+0.000002
+0.000004
+0.000002
+0.000000
+0.000002
+0.000004
+0.000002
+0.000000
+0.000002
+0.000004
+0.000002
+0.000000
+0.000002
+0.000004
+0.000002
+0.000000
+0.000002
+0.000003
+0.000002
+0.000000
+0.000002
+0.000003
+0.000002
+0.000000
+0.000002
+0.000003
+0.000002
+0.000000
+0.000002
+0.000003
+0.000002
+0.000000
+0.000002
+0.000003
+0.000002
+0.000000
+0.000002
+0.000003
+0.000002
+0.000000
diff --git a/macros/txt4specgram_imag.txt b/macros/txt4specgram_imag.txt
new file mode 100644
index 0000000..fea4262
--- /dev/null
+++ b/macros/txt4specgram_imag.txt
@@ -0,0 +1,768 @@
+0.000000
+0.000007
+0.000014
+0.000021
+0.000029
+0.000037
+0.000045
+0.000053
+0.000062
+0.000071
+0.000082
+0.000093
+0.000104
+0.000117
+0.000132
+0.000147
+0.000165
+0.000184
+0.000205
+0.000229
+0.000256
+0.000287
+0.000322
+0.000362
+0.000407
+0.000460
+0.000522
+0.000594
+0.000679
+0.000780
+0.000902
+0.001048
+0.001227
+0.001448
+0.001724
+0.002073
+0.002522
+0.003109
+0.003891
+0.004956
+0.006447
+0.008595
+0.011809
+0.016835
+0.025151
+0.039952
+0.069026
+0.134854
+0.321577
+1.136663
+18.640061
+-50.357022
+33.382804
+-2.461783
+-0.519759
+-0.195382
+-0.094287
+-0.052452
+-0.031950
+-0.020685
+-0.013953
+-0.009659
+-0.006769
+-0.004732
+-0.003236
+-0.002093
+-0.001186
+-0.000438
+0.000202
+0.000772
+0.001297
+0.001799
+0.002295
+0.002800
+0.003327
+0.003890
+0.004504
+0.005184
+0.005950
+0.006823
+0.007830
+0.009007
+0.010396
+0.012056
+0.014060
+0.016512
+0.019551
+0.023373
+0.028259
+0.034620
+0.043077
+0.054601
+0.070760
+0.094219
+0.129745
+0.186467
+0.283443
+0.465184
+0.853312
+1.868525
+5.709807
+47.381014
+-180.320279
+152.070394
+-22.966610
+-3.672901
+-1.227116
+-0.546384
+-0.285251
+-0.164895
+-0.102316
+-0.066868
+-0.045459
+-0.031871
+-0.022896
+-0.016775
+-0.012485
+-0.009409
+-0.007160
+-0.005487
+-0.004221
+-0.003249
+-0.002489
+-0.001884
+-0.001392
+-0.000981
+-0.000626
+-0.000304
+-0.000000
+0.000013
+0.000027
+0.000041
+0.000056
+0.000072
+0.000088
+0.000105
+0.000124
+0.000143
+0.000163
+0.000185
+0.000208
+0.000232
+0.000258
+0.000286
+0.000315
+0.000347
+0.000381
+0.000417
+0.000456
+0.000498
+0.000544
+0.000594
+0.000649
+0.000709
+0.000776
+0.000850
+0.000933
+0.001027
+0.001133
+0.001256
+0.001399
+0.001568
+0.001769
+0.002014
+0.002315
+0.002696
+0.003186
+0.003833
+0.004713
+0.005950
+0.007758
+0.010529
+0.015032
+0.022917
+0.038182
+0.072278
+0.167767
+0.579516
+9.315158
+-24.705971
+16.075077
+-1.160487
+-0.238523
+-0.086463
+-0.039641
+-0.020473
+-0.011159
+-0.006067
+-0.003025
+-0.001073
+0.000258
+0.001216
+0.001941
+0.002514
+0.002986
+0.003388
+0.003741
+0.004059
+0.004350
+0.004618
+0.004866
+0.005094
+0.005299
+0.005477
+0.005620
+0.005716
+0.005749
+0.005698
+0.005533
+0.005210
+0.004673
+0.003840
+0.002595
+0.000774
+-0.001864
+-0.005672
+-0.011186
+-0.019232
+-0.031119
+-0.048988
+-0.076474
+-0.120022
+-0.191698
+-0.315637
+-0.544400
+-1.006031
+-2.065119
+-5.035145
+-17.062526
+-156.495645
+656.545571
+-609.076019
+101.022996
+17.721496
+6.489005
+3.164995
+1.809677
+1.145849
+0.779072
+0.558287
+0.416565
+0.320933
+0.253771
+0.205038
+0.168703
+0.140988
+0.119434
+0.102390
+0.088722
+0.077627
+0.068529
+0.061007
+0.054748
+0.049517
+0.045137
+0.041475
+-0.000000
+0.000004
+0.000008
+0.000011
+0.000014
+0.000016
+0.000018
+0.000020
+0.000022
+0.000023
+0.000024
+0.000025
+0.000027
+0.000028
+0.000029
+0.000031
+0.000033
+0.000035
+0.000037
+0.000040
+0.000043
+0.000047
+0.000052
+0.000057
+0.000063
+0.000069
+0.000077
+0.000086
+0.000096
+0.000108
+0.000121
+0.000136
+0.000152
+0.000170
+0.000189
+0.000210
+0.000232
+0.000252
+0.000270
+0.000280
+0.000273
+0.000235
+0.000133
+-0.000097
+-0.000592
+-0.001678
+-0.004212
+-0.010854
+-0.032252
+-0.136819
+-2.622048
+8.117958
+-6.078610
+0.501003
+0.117377
+0.048765
+0.025986
+0.016003
+0.010858
+0.007912
+0.006100
+0.004930
+0.004153
+0.003631
+0.003285
+0.003067
+0.002949
+0.002911
+0.002945
+0.003043
+0.003204
+0.003429
+0.003724
+0.004095
+0.004551
+0.005108
+0.005783
+0.006598
+0.007584
+0.008780
+0.010237
+0.012019
+0.014215
+0.016943
+0.020361
+0.024689
+0.030236
+0.037442
+0.046950
+0.059722
+0.077238
+0.101852
+0.137452
+0.190754
+0.274018
+0.411184
+0.653182
+1.121338
+2.153696
+4.942882
+15.847748
+138.133054
+-552.828591
+490.877201
+-78.155820
+-13.194353
+-4.659944
+-2.196513
+-1.215758
+-0.746237
+-0.492425
+-0.342795
+-0.248636
+-0.186280
+-0.143252
+-0.112533
+-0.089963
+-0.072965
+-0.059881
+-0.049612
+-0.041405
+-0.034735
+-0.029224
+-0.024596
+-0.020643
+-0.017205
+-0.014159
+-0.011401
+0.000000
+-0.000000
+-0.000000
+-0.000000
+-0.000000
+-0.000001
+-0.000002
+-0.000003
+-0.000004
+-0.000006
+-0.000008
+-0.000011
+-0.000015
+-0.000019
+-0.000025
+-0.000032
+-0.000041
+-0.000052
+-0.000065
+-0.000081
+-0.000100
+-0.000123
+-0.000152
+-0.000187
+-0.000229
+-0.000282
+-0.000346
+-0.000425
+-0.000522
+-0.000644
+-0.000797
+-0.000989
+-0.001234
+-0.001547
+-0.001953
+-0.002485
+-0.003192
+-0.004145
+-0.005453
+-0.007285
+-0.009916
+-0.013805
+-0.019762
+-0.029293
+-0.045406
+-0.074682
+-0.133341
+-0.268713
+-0.659883
+-2.398539
+-40.401544
+112.023452
+-76.196390
+5.766887
+1.250855
+0.483983
+0.241136
+0.139119
+0.088443
+0.060284
+0.043327
+0.032482
+0.025217
+0.020173
+0.016570
+0.013943
+0.011999
+0.010551
+0.009473
+0.008681
+0.008117
+0.007741
+0.007529
+0.007464
+0.007538
+0.007748
+0.008101
+0.008606
+0.009282
+0.010155
+0.011260
+0.012647
+0.014382
+0.016554
+0.019286
+0.022746
+0.027171
+0.032896
+0.040412
+0.050449
+0.064127
+0.083217
+0.110636
+0.151399
+0.214622
+0.318032
+0.499191
+0.847202
+1.609327
+3.654391
+11.596308
+100.066471
+-396.571556
+348.759244
+-55.004428
+-9.199162
+-3.218709
+-1.503023
+-0.824080
+-0.500970
+-0.327314
+-0.225513
+-0.161796
+-0.119814
+-0.090978
+-0.070474
+-0.055458
+-0.044173
+-0.035493
+-0.028672
+-0.023201
+-0.018723
+-0.014984
+-0.011794
+-0.009010
+-0.006523
+-0.004241
+-0.002089
+0.000000
+0.000005
+0.000011
+0.000018
+0.000026
+0.000035
+0.000046
+0.000058
+0.000073
+0.000089
+0.000108
+0.000130
+0.000155
+0.000184
+0.000217
+0.000256
+0.000300
+0.000351
+0.000411
+0.000480
+0.000561
+0.000655
+0.000765
+0.000895
+0.001049
+0.001231
+0.001448
+0.001708
+0.002023
+0.002404
+0.002871
+0.003448
+0.004165
+0.005067
+0.006214
+0.007691
+0.009620
+0.012182
+0.015647
+0.020436
+0.027224
+0.037137
+0.052146
+0.075902
+0.115655
+0.187183
+0.329176
+0.653975
+1.584533
+5.686700
+94.635967
+-259.367783
+174.428893
+-13.053811
+-2.799212
+-1.070220
+-0.526419
+-0.299425
+-0.187307
+-0.125295
+-0.088069
+-0.064282
+-0.048313
+-0.037148
+-0.029071
+-0.023052
+-0.018445
+-0.014833
+-0.011933
+-0.009551
+-0.007549
+-0.005825
+-0.004303
+-0.002923
+-0.001637
+-0.000402
+0.000817
+0.002058
+0.003356
+0.004752
+0.006290
+0.008025
+0.010024
+0.012375
+0.015190
+0.018623
+0.022885
+0.028276
+0.035225
+0.044372
+0.056690
+0.073717
+0.097971
+0.133776
+0.188962
+0.278719
+0.435140
+0.734151
+1.385889
+3.126751
+9.857014
+84.497679
+-332.666327
+290.636062
+-45.536122
+-7.565187
+-2.629127
+-1.219135
+-0.663507
+-0.400153
+-0.259154
+-0.176785
+-0.125383
+-0.091591
+-0.068411
+-0.051929
+-0.039835
+-0.030709
+-0.023638
+-0.018020
+-0.013442
+-0.009616
+-0.006332
+-0.003433
+-0.000798
+0.001669
+0.004050
+0.006420
+0.000000
+0.000013
+0.000025
+0.000037
+0.000049
+0.000061
+0.000072
+0.000084
+0.000096
+0.000108
+0.000120
+0.000134
+0.000147
+0.000162
+0.000179
+0.000196
+0.000216
+0.000237
+0.000262
+0.000289
+0.000321
+0.000357
+0.000399
+0.000448
+0.000506
+0.000574
+0.000655
+0.000751
+0.000867
+0.001007
+0.001179
+0.001390
+0.001653
+0.001982
+0.002400
+0.002936
+0.003634
+0.004558
+0.005804
+0.007519
+0.009940
+0.013461
+0.018769
+0.027132
+0.041065
+0.066018
+0.115324
+0.227583
+0.547718
+1.952458
+32.272771
+-87.852767
+58.685049
+-4.362507
+-0.929293
+-0.352972
+-0.172496
+-0.097483
+-0.060586
+-0.040259
+-0.028099
+-0.020352
+-0.015161
+-0.011534
+-0.008905
+-0.006937
+-0.005417
+-0.004207
+-0.003214
+-0.002372
+-0.001636
+-0.000968
+-0.000342
+0.000268
+0.000881
+0.001517
+0.002197
+0.002942
+0.003776
+0.004728
+0.005833
+0.007134
+0.008687
+0.010567
+0.012870
+0.015729
+0.019328
+0.023925
+0.029894
+0.037789
+0.048451
+0.063204
+0.084216
+0.115190
+0.162819
+0.240039
+0.374100
+0.629257
+1.182765
+2.653746
+8.310488
+70.703511
+-276.080492
+239.155483
+-37.159678
+-6.127301
+-2.116807
+-0.978246
+-0.532585
+-0.322964
+-0.211758
+-0.147533
+-0.108046
+-0.082600
+-0.065611
+-0.053975
+-0.045871
+-0.040188
+-0.036224
+-0.033522
+-0.031780
+-0.030795
+-0.030434
+-0.030606
+-0.031259
+-0.032364
+-0.033916
+-0.035927
diff --git a/macros/txt4specgram_real.txt b/macros/txt4specgram_real.txt
new file mode 100644
index 0000000..fdbcf3c
--- /dev/null
+++ b/macros/txt4specgram_real.txt
@@ -0,0 +1,768 @@
+-0.000000
+-0.000000
+-0.000000
+-0.000001
+-0.000001
+-0.000002
+-0.000003
+-0.000005
+-0.000006
+-0.000008
+-0.000010
+-0.000013
+-0.000015
+-0.000019
+-0.000023
+-0.000027
+-0.000033
+-0.000039
+-0.000046
+-0.000054
+-0.000064
+-0.000076
+-0.000089
+-0.000105
+-0.000124
+-0.000146
+-0.000172
+-0.000204
+-0.000243
+-0.000290
+-0.000348
+-0.000419
+-0.000508
+-0.000621
+-0.000764
+-0.000950
+-0.001193
+-0.001517
+-0.001958
+-0.002572
+-0.003446
+-0.004731
+-0.006689
+-0.009811
+-0.015075
+-0.024618
+-0.043710
+-0.087732
+-0.214871
+-0.779839
+-13.127812
+36.398018
+-24.758375
+1.873043
+0.405624
+0.156373
+0.077379
+0.044134
+0.027560
+0.018290
+0.012647
+0.008973
+0.006445
+0.004618
+0.003236
+0.002145
+0.001245
+0.000471
+-0.000223
+-0.000873
+-0.001504
+-0.002138
+-0.002796
+-0.003498
+-0.004263
+-0.005112
+-0.006072
+-0.007172
+-0.008448
+-0.009945
+-0.011719
+-0.013845
+-0.016418
+-0.019565
+-0.023458
+-0.028332
+-0.034513
+-0.042467
+-0.052869
+-0.066726
+-0.085580
+-0.111870
+-0.149610
+-0.205704
+-0.292699
+-0.434996
+-0.684291
+-1.163226
+-2.212127
+-5.026830
+-15.957840
+-137.726457
+545.837275
+-480.022416
+75.710768
+12.665412
+4.434229
+2.073017
+1.138785
+0.694340
+0.455633
+0.315858
+0.228539
+0.171176
+0.131954
+0.104253
+0.084165
+0.069279
+0.058056
+0.049478
+0.042859
+0.037725
+0.033741
+0.030671
+0.028345
+0.026642
+0.025480
+0.024804
+-0.000000
+-0.000008
+-0.000016
+-0.000026
+-0.000036
+-0.000047
+-0.000060
+-0.000074
+-0.000089
+-0.000105
+-0.000123
+-0.000143
+-0.000165
+-0.000189
+-0.000215
+-0.000244
+-0.000276
+-0.000312
+-0.000351
+-0.000394
+-0.000441
+-0.000494
+-0.000553
+-0.000619
+-0.000693
+-0.000776
+-0.000870
+-0.000977
+-0.001100
+-0.001241
+-0.001404
+-0.001596
+-0.001824
+-0.002096
+-0.002427
+-0.002834
+-0.003345
+-0.003999
+-0.004853
+-0.005999
+-0.007579
+-0.009835
+-0.013186
+-0.018410
+-0.027048
+-0.042457
+-0.072861
+-0.142140
+-0.340199
+-1.212427
+-20.119488
+55.125992
+-37.080708
+2.769566
+0.589440
+0.221446
+0.105324
+0.056488
+0.032010
+0.018116
+0.009415
+0.003487
+-0.000876
+-0.004327
+-0.007244
+-0.009865
+-0.012348
+-0.014804
+-0.017323
+-0.019979
+-0.022842
+-0.025982
+-0.029474
+-0.033400
+-0.037858
+-0.042961
+-0.048850
+-0.055696
+-0.063712
+-0.073170
+-0.084413
+-0.097888
+-0.114180
+-0.134064
+-0.158584
+-0.189165
+-0.227792
+-0.277279
+-0.341704
+-0.427123
+-0.542791
+-0.703317
+-0.932657
+-1.271920
+-1.795615
+-2.648239
+-4.135127
+-6.978673
+-13.178167
+-29.739973
+-93.772720
+-803.929738
+3165.122181
+-2765.202332
+433.264001
+71.996424
+25.034783
+11.621554
+6.337174
+3.833742
+2.494603
+1.713459
+1.227161
+0.908649
+0.691358
+0.538085
+0.426913
+0.344354
+0.281796
+0.233563
+0.195813
+0.165880
+0.141877
+0.122444
+0.106584
+0.093558
+0.082808
+0.073916
+0.000000
+-0.000008
+-0.000015
+-0.000021
+-0.000027
+-0.000033
+-0.000038
+-0.000043
+-0.000048
+-0.000052
+-0.000057
+-0.000062
+-0.000068
+-0.000073
+-0.000080
+-0.000088
+-0.000097
+-0.000107
+-0.000119
+-0.000134
+-0.000152
+-0.000173
+-0.000199
+-0.000230
+-0.000268
+-0.000315
+-0.000372
+-0.000443
+-0.000530
+-0.000637
+-0.000772
+-0.000940
+-0.001154
+-0.001425
+-0.001774
+-0.002228
+-0.002826
+-0.003625
+-0.004710
+-0.006215
+-0.008353
+-0.011478
+-0.016208
+-0.023685
+-0.036172
+-0.058576
+-0.102903
+-0.203907
+-0.492077
+-1.756822
+-29.057257
+79.104369
+-52.838758
+3.929642
+0.838501
+0.319732
+0.157397
+0.090040
+0.057021
+0.038942
+0.028241
+0.021541
+0.017173
+0.014246
+0.012258
+0.010909
+0.010015
+0.009458
+0.009164
+0.009085
+0.009190
+0.009462
+0.009895
+0.010487
+0.011248
+0.012191
+0.013339
+0.014722
+0.016381
+0.018370
+0.020758
+0.023636
+0.027126
+0.031388
+0.036637
+0.043170
+0.051395
+0.061893
+0.075502
+0.093463
+0.117667
+0.151091
+0.198599
+0.268510
+0.375859
+0.549703
+0.851244
+1.424807
+2.668509
+5.972928
+18.678761
+158.816408
+-620.072545
+537.167120
+-83.446120
+-13.745431
+-4.736823
+-2.178615
+-1.176610
+-0.704679
+-0.453701
+-0.308147
+-0.218048
+-0.159362
+-0.119538
+-0.091586
+-0.071400
+-0.056464
+-0.045175
+-0.036481
+-0.029671
+-0.024251
+-0.019875
+-0.016289
+-0.013310
+-0.010797
+-0.008645
+-0.006770
+0.000000
+-0.000001
+-0.000002
+-0.000005
+-0.000009
+-0.000014
+-0.000021
+-0.000029
+-0.000039
+-0.000051
+-0.000064
+-0.000080
+-0.000099
+-0.000120
+-0.000145
+-0.000173
+-0.000206
+-0.000244
+-0.000288
+-0.000339
+-0.000399
+-0.000468
+-0.000549
+-0.000644
+-0.000756
+-0.000889
+-0.001046
+-0.001234
+-0.001460
+-0.001733
+-0.002065
+-0.002473
+-0.002978
+-0.003609
+-0.004406
+-0.005426
+-0.006749
+-0.008492
+-0.010832
+-0.014041
+-0.018551
+-0.025083
+-0.034885
+-0.050261
+-0.075756
+-0.121201
+-0.210568
+-0.413042
+-0.987584
+-3.496020
+-57.365785
+154.985567
+-102.738939
+7.579550
+1.602823
+0.604718
+0.293825
+0.165337
+0.102530
+0.068176
+0.047804
+0.034966
+0.026487
+0.020674
+0.016570
+0.013605
+0.011424
+0.009802
+0.008586
+0.007676
+0.007001
+0.006514
+0.006179
+0.005974
+0.005883
+0.005895
+0.006008
+0.006221
+0.006537
+0.006967
+0.007524
+0.008228
+0.009107
+0.010200
+0.011560
+0.013257
+0.015392
+0.018106
+0.021601
+0.026175
+0.032279
+0.040616
+0.052327
+0.069346
+0.095135
+0.136329
+0.206772
+0.338803
+0.620786
+1.358375
+4.149226
+34.425128
+-131.009546
+110.486415
+-16.685411
+-2.667708
+-0.890737
+-0.396151
+-0.206421
+-0.118972
+-0.073501
+-0.047741
+-0.032183
+-0.022308
+-0.015786
+-0.011339
+-0.008226
+-0.005999
+-0.004378
+-0.003180
+-0.002285
+-0.001612
+-0.001105
+-0.000725
+-0.000443
+-0.000240
+-0.000104
+-0.000026
+0.000000
+0.000009
+0.000018
+0.000029
+0.000040
+0.000053
+0.000068
+0.000084
+0.000101
+0.000121
+0.000143
+0.000168
+0.000195
+0.000226
+0.000260
+0.000299
+0.000342
+0.000391
+0.000446
+0.000508
+0.000579
+0.000660
+0.000753
+0.000859
+0.000982
+0.001125
+0.001291
+0.001486
+0.001716
+0.001990
+0.002318
+0.002713
+0.003196
+0.003790
+0.004530
+0.005464
+0.006658
+0.008212
+0.010271
+0.013058
+0.016929
+0.022466
+0.030678
+0.043409
+0.064274
+0.101038
+0.172501
+0.332543
+0.781405
+2.718130
+43.815678
+-116.241586
+75.617703
+-5.469732
+-1.132731
+-0.417867
+-0.198130
+-0.108520
+-0.065296
+-0.041961
+-0.028297
+-0.019787
+-0.014225
+-0.010444
+-0.007790
+-0.005874
+-0.004460
+-0.003395
+-0.002577
+-0.001941
+-0.001438
+-0.001035
+-0.000710
+-0.000446
+-0.000229
+-0.000051
+0.000094
+0.000211
+0.000303
+0.000370
+0.000412
+0.000427
+0.000410
+0.000354
+0.000249
+0.000076
+-0.000187
+-0.000578
+-0.001153
+-0.001998
+-0.003250
+-0.005135
+-0.008033
+-0.012623
+-0.020173
+-0.033220
+-0.057287
+-0.105834
+-0.217179
+-0.529377
+-1.793545
+-16.448600
+69.005426
+-64.016818
+10.617535
+1.862126
+0.681468
+0.332017
+0.189474
+0.119600
+0.080935
+0.057601
+0.042562
+0.032350
+0.025111
+0.019787
+0.015742
+0.012573
+0.010018
+0.007900
+0.006091
+0.004500
+0.003058
+0.001710
+0.000410
+-0.000883
+-0.002208
+-0.003602
+-0.000000
+0.000007
+0.000014
+0.000020
+0.000025
+0.000030
+0.000035
+0.000039
+0.000043
+0.000047
+0.000051
+0.000055
+0.000058
+0.000062
+0.000066
+0.000069
+0.000073
+0.000077
+0.000082
+0.000086
+0.000092
+0.000097
+0.000104
+0.000110
+0.000118
+0.000126
+0.000136
+0.000146
+0.000158
+0.000171
+0.000185
+0.000200
+0.000218
+0.000236
+0.000256
+0.000277
+0.000298
+0.000317
+0.000333
+0.000339
+0.000325
+0.000275
+0.000154
+-0.000111
+-0.000672
+-0.001891
+-0.004720
+-0.012114
+-0.035899
+-0.152055
+-2.912207
+9.015749
+-6.751171
+0.556190
+0.130087
+0.053835
+0.028479
+0.017326
+0.011537
+0.008179
+0.006069
+0.004658
+0.003666
+0.002939
+0.002386
+0.001950
+0.001595
+0.001295
+0.001033
+0.000795
+0.000570
+0.000351
+0.000129
+-0.000105
+-0.000356
+-0.000636
+-0.000953
+-0.001319
+-0.001748
+-0.002260
+-0.002876
+-0.003627
+-0.004552
+-0.005704
+-0.007152
+-0.008996
+-0.011371
+-0.014474
+-0.018590
+-0.024147
+-0.031803
+-0.042607
+-0.058287
+-0.081833
+-0.118702
+-0.179552
+-0.287057
+-0.495232
+-0.954584
+-2.196101
+-7.050924
+-61.495484
+246.140860
+-218.546463
+34.803836
+5.881647
+2.082451
+0.986283
+0.550305
+0.342010
+0.229831
+0.164121
+0.123203
+0.096552
+0.078627
+0.066320
+0.057797
+0.051933
+0.048016
+0.045588
+0.044349
+0.044108
+0.044750
+0.046213
+0.048481
+0.051574
+0.055549
+0.060500
diff --git a/macros/upfirdn.sci b/macros/upfirdn.sci
index 7f0215d..9068db0 100644
--- a/macros/upfirdn.sci
+++ b/macros/upfirdn.sci
@@ -1,26 +1,57 @@
-function y = upfirdn (x, h, p, q)
-//This function upsamples the input data, applies the FIR filter and then downsamples it.
-//Calling Sequence
-//y = upfirdn (x, h, p, q)
-//Parameters
-//x:
-//h:
-//p:
-//q:
-//Description
-//This is an Octave function.
-//This function upsamples the input data in the matrix by a factor of n. Then the upsampled data is FIR filtered. After this, the resultant is downsampled.
-//Examples
-//upfirdn([1,2,3],2,3,5)
-//ans =
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
//
-// 2. 0.
-funcprot(0);
-rhs = argn(2)
-if(rhs~=4)
-error("Wrong number of input arguments.")
-end
-
-y = callOctave("upfirdn",x, h, p, q)
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+//Function y=upfirdn(xin,h,p,q)
+//
+//this function upsamples the input data xin by factor "p", filters it using fiter coefficients "h" and the downsamples this filtered data by a factor "q".
+//Esentially it is a cascade of three processes:
+//1)Upsampling(Interpolation)
+//2)Filtering
+//3)Downsampling(Decimation)
+
+
+//Test cases:
+
+//1.yout=upfirdn (1:100, 1, 1, 1)
+//Expected output: yout=1:100
+
+//2.yout=upfirdn (1:100, 1, 1, 2)
+//Expected outut: yout=1:2:100
+
+
+
+
+function yout = upfirdn(xin,h,p,q)
+
+[nargout,nargin]=argn();
+
+if(nargin < 2)
+ error("usage : yout = upfirdn(xin,h,p,q)");
+ end
+
+ if(nargin < 3)
+ p = 1;
+ q = 1;
+ end
+
+ if(nargin < 4)
+ q = 1;
+ end
+
+ if(floor(p) ~= p | floor(q) ~= q | p < 1 | q < 1)
+ error('p and q must be positive integer');
+ end
+
+ yout = upsample(xin,p);
+ yout = filter(h,1,yout);
+ yout = downsample(yout,q);
endfunction
diff --git a/macros/upsample.sci b/macros/upsample.sci
index cb5d7ae..98a9e6d 100644
--- a/macros/upsample.sci
+++ b/macros/upsample.sci
@@ -1,33 +1,70 @@
-function y = upsample (x, n, phase)
-//This function upsamples the signal, inserting n-1 zeros between every element.
-//Calling Sequence
-//y = upsample (x, n)
-//y = upsample (x, n, phase)
-//Parameters
-//x: scalar, vector or matrix of real or complex numbers
-//n: real number or vector
-//phase: integer value, 0 <= phase <= (n - 1 ), default value 0, or logical
-//Description
-//This is an Octave function.
-//This function upsamples the signal, inserting n-1 zeros between every element. If x is a matrix, every column is upsampled.
-//The phase determines the position of the inserted sample in the block of zeros. The default value is 0.
-//Examples
-//upsample(4,5,2)
-//ans =
-// 0. 0. 4. 0. 0.
-
-funcprot(0);
-rhs = argn(2)
-if(rhs<2 | rhs>3)
-error("Wrong number of input arguments.")
-end
-
- select(rhs)
- case 2 then
- y = callOctave("upsample",x,n)
- case 3 then
- y = callOctave("upsample",x,n,phase)
- 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+//Calling sequence:
+// y = upsample (x, n)
+// y = upsample (x, n, offset)
+// Upsample the signal, inserting n-1 zeros between every element.
+//
+// If x is a matrix, upsample every column.
+//
+// If offset is specified, control the position of the inserted sample in
+// the block of n zeros.
+//
+
+//Testcases:
+//1.upsample([1,3,5],2)
+//EXPECTED OUTPUT:[1,0,3,0,5,0]
+
+
+//2.upsample([1;3;5],2)
+//EXPECTED OUTPUT:[1;0;3;0;5;0]
+
+
+//3.upsample([1,2;5,6;9,10],2)
+//EXPECTED OUTPUT:[1,2;0,0;5,6;0,0;9,10;0,0]
+//
+//
-endfunction
+
+function y = upsample (x,n,phase )
+ [nargout,nargin]=argn()
+
+ if (nargin<2 | nargin>3),
+ error("wrong no. of input arguments")
+ end
+if nargin==2
+ phase=0;
+ else
+ if phase > n-1
+ warning("This is incompatible with Matlab (phase = 0:n-1). See octave-forge signal package release notes for details." )
+ end
+end
+
+ [nr,nc] = size(x);
+ if (nc==1 | nr==1) then
+
+ if ( nc==1)
+ y = zeros(n*nr*nc,1);
+ y(phase+1:n:$) = x;
+ end
+ if (nr==1)
+ y = zeros(n*nr*nc,1);
+ y(phase+1:n:$) = x';
+ y = y.';
+ end
+ else
+ y = zeros(n*nr,nc);
+ y(phase + 1:n:$,:) = x;
+ end
+
+endfunction
diff --git a/macros/upsamplefill.sci b/macros/upsamplefill.sci
index 60ca1da..6173e1f 100644
--- a/macros/upsamplefill.sci
+++ b/macros/upsamplefill.sci
@@ -1,10 +1,10 @@
-function y = upsamplefill (x, w, cpy)
+function y = upsamplefill (x, v, c)
//This function upsamples a vector interleaving given values or copies of the vector elements.
//Calling Sequence
-//y = upsamplefill (x, w)
+//
//y = upsamplefill (x, w, cpy)
-//Parameters
-//x: scalar, vector or matrix of real or complex numbers
+//Parameters
+//x: scalar, vector or matrix of real or complex numbers
//w: scalar or vector of real or complex values
//cpy: can take in "true" or "false", default is false
//Description
@@ -13,20 +13,67 @@ function y = upsamplefill (x, w, cpy)
//The second argument has the values in the vector w that are placed in between the elements of x.
//The third argument, if true, means that w should be scalar and that each value in x repeated w times.
//Examples
-//upsamplefill([0.4,0.5],7)
-//ans =
-// 0.4 7. 0.5 7.
-funcprot(0);
-rhs = argn(2)
-
-if(rhs<2 | rhs>3)
-error("Wrong number of input arguments.")
-end
-
- select(rhs)
- case 2 then
- y = callOctave("upsamplefill", x, w)
- case 3 then
- y = callOctave("upsamplefill", x, w, cpy)
- end
+
+//1.upsamplefill([1,3,5],2,%f)
+//ans:1. 1. 1. 3. 3. 3. 5. 5. 5.
+
+//2.upsamplefill([1,3,5],2,%t)
+//ans:1. 2. 3. 2. 5. 2.
+
+
+
+
+ if argn(2)<2
+ error("wrong no. of input arguments")
+ end
+
+ [nr,nc] = size (x);
+ if c==%f
+
+ if (nr==1 | nc==1)
+
+ y = kron (x(:), ones(v+1,1));
+ if nr == 1
+ y = y.';
+ end
+
+ else
+
+ y = kron (x, ones(v+1,1));
+
+ end
+
+ return
+
+ else
+
+ //Assumes 'v' row or column vector
+ n = length(v) + 1;
+ N = n*nr;
+
+ if (nr==1 | nc==1)
+
+ N = N*nc;
+ idx = 1:n:N;
+ idx_c = setdiff (1:N, 1:n:N);
+ y = zeros (N,1);
+ y(idx) = x';
+ y(idx_c) = repmat (v(:), max(nr,nc), 1);
+
+ if nr == 1
+ y = y.';
+ end
+
+ else
+
+ idx = 1:n:N;
+ idx_c = setdiff(1:N,1:n:N);
+ y = zeros (N,nc);
+ y(idx,:) = x';
+
+ y(idx_c,:) = repmat (v(:), nr, nc);
+
+ end
+ end
+
endfunction
diff --git a/macros/wkeep.sci b/macros/wkeep.sci
index e4e4506..31fda78 100644
--- a/macros/wkeep.sci
+++ b/macros/wkeep.sci
@@ -1,5 +1,15 @@
-function [y] = wkeep(x,l,opt)
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+function y = wkeep(x,l,opt )
// Extracts a vector from the given vector of length l
// Calling Sequence
// [y]=wkeep(x,l)
@@ -18,12 +28,54 @@ function [y] = wkeep(x,l,opt)
// 2. [y]=wkeep([1 2 3 4 5 6],3,'r')
// y= 4 5 6
-funcprot(0);
-rhs=argn(2);
-if (rhs<2) then
- error ("Wrong number of input arguments.")
-elseif (rhs==2)
- y=callOctave("wkeep",x,l)
-else y=callOctave("wkeep",x,l,opt)
-end
+
+[nargout,nargin]=argn();
+
+ if (nargin < 2 | nargin > 3)
+ error("wrong number of input arguments");
+ end
+ if(isvector(x))
+
+ if(l > length(x))
+ error('l must be less than or equal the size of x');
+ end
+
+ if(opt=='c')
+ s = (length(x)-l)./2;
+ y = x(1+floor(s):$-ceil(s));
+
+ elseif(opt=='l')
+ y=x(1:l);
+
+ elseif(opt=='r')
+ y = x($-l+1:$);
+
+ else
+ error('opt must be equal to c, l or r');
+ end
+ else
+ if(max(size(l,1),size(l,2)) == 2)
+ s1 = (max(size(x,1),size(x,2))-l(1))./2;
+ s2 = (max(size(x,1),size(x,2))-l(2))./2;
+ else
+ disp("entered the else" ) ///remove later
+ error('For a matrix l must be a 1x2 vector');
+ end
+
+ if(nargin==2)
+ y = x(1+floor(s1):$-ceil(s1),1+floor(s2):$-ceil(s2));
+ else
+ if(max(size(opt,1),size(opt,2)) == 2)
+ firstr=opt(1);
+ firstc=opt(2);
+ else
+ disp("entered the else2") ////remove later
+ error('For a matrix l must be a 1x2 vector');
+ end
+
+ y=x(firstr:firstr+l(1)-1,firstc:firstc+l(2)-1);
+ end
+
+ end
+
endfunction
diff --git a/macros/wrev.sci b/macros/wrev.sci
index a01ed77..343b24c 100644
--- a/macros/wrev.sci
+++ b/macros/wrev.sci
@@ -1,12 +1,25 @@
-function [y]= wrev(x)
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
-// Reverses order of elements of input vector
+
+function y = wrev(x)
+
+
+ // Reverses order of elements of input vector
// Calling Sequence
// [y]=wrev(x)
// Parameters
// x: Input vector of string, real or complex values
// Description
-// This is an Octave function.
+// This is an Octave function which is built in scilab.
// This function reverses the order of elements of the input vector x.
// Examples
// 1. wrev([1 2 3])
@@ -15,9 +28,16 @@ function [y]= wrev(x)
// ans= cba
funcprot(0);
-rhs=argn(2);
-if (rhs~=1) then
- error("Wrong number of input arguments.")
-else y=callOctave("wrev",x)
+ if (argn(2)< 1| argn(2) > 1) then
+ error("wrong number of input arguments"); //number of input arguments has to be 1
+ end
+ if(~isvector(x))//checks whether input is a vector
+ error('x must be a vector');
+ end
+ if(type(x)==10 | type(x)==1) then
+ //revers the vector
+ l = size(x,"c");
+ k = 0:l-1;
+ y = x(l-k);
end
endfunction
diff --git a/macros/yulewalker.sci b/macros/yulewalker.sci
index 40fcadb..22fbd77 100644
--- a/macros/yulewalker.sci
+++ b/macros/yulewalker.sci
@@ -1,32 +1,56 @@
-function [A,V]= yulewalker(C)
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function [A,V]= yulewalker(c)
// Fit an AR (p)-model with Yule-Walker estimates given a vector C of autocovariances '[gamma_0, ..., gamma_p]'.
//Calling Sequence
//A = yulewalker(C)
//[A,V]= yulewalker(C)
-//Parameters
+//Parameters
//C: Autocovariances
//Description
//Fit an AR (p)-model with Yule-Walker estimates given a vector C of autocovariances '[gamma_0, ..., gamma_p]'.
//Returns the AR coefficients, A, and the variance of white noise, V.
+
+//Test cases
+//[A,V]=yulewalker([1 2 3])
+// V = - 2.6666667
+// A =1.3333333
+// 0.3333333
+
+
funcprot(0);
lhs=argn(1);
rhs= argn(2);
-if(rhs<1 | rhs>1)
- error("Wrong number of input arguments");
-end
+ if (rhs ~= 1)
+ error ("wrong number of input arguments");
+ end
+
+ p = length (c) - 1;
-if(lhs<1 | lhs>2)
- error("Wrong number of output arguments");
-end
+ if (size (c,"c") > 1)
+ c = c';
+ end
-select(lhs)
+ cp = c(2 : p+1);
+ CP = zeros (p, p);
- case 1 then
- A= callOctave("yulewalker", C);
- case 2 then
- [A,V]= callOctave("yulewalker", C);
-end
-endfunction
+ for i = 1:p
+ for j = 1:p
+ CP (i, j) = c (abs (i-j) + 1);
+ end
+ end
+ A = inv (CP) * cp;
+ V = c(1) -A' * cp;
+endfunction
diff --git a/macros/zerocrossing.sci b/macros/zerocrossing.sci
index 41b51d6..ba14281 100644
--- a/macros/zerocrossing.sci
+++ b/macros/zerocrossing.sci
@@ -1,22 +1,66 @@
-function x = zerocrossing (w, y)
+// 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:[insert name]
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function r = zerocrossing (x,y)
+
//This function estimates the points at which a given waveform crosses the x-axis.
+//Estimates the points at which a given waveform y=y(x) crosses the
+//x-axis using linear interpolation.
//Calling Sequence
-//x = zerocrossing (w, y)
-//Parameters
-//w:
-//y:
-//x:
+//r = zerocrossing (w, y)
+//Parameters
+//r: zero crossing points
+//y:function y=y(x)...the dependant variable
+//x:the independant variable
//Description
-//This is an Octave function.
//This function estimates the points at which a given waveform y = y(w) crosses the x-axis. It uses linear interpolation.
//Examples
+////1.
+//x = linspace(0,1,100);
+// y = rand(1,100)-0.5;
+// x0= zerocrossing(x,y);
+//y0=interp1(x,y,x0)
+//plot(x,y,x0,y0,'x')
+
+//
+////////2.
+//x = linspace(0,1,100);
+// y = 2*sin(2*%pi*x);
+// x0= zerocrossing(x,y);
+//ans:
+//// x0 = 0. 0.5
+//y0=interp1(x,y,x0)
+//plot(x,y,x0,y0,'x')
+//
+
+
+ x = x(:);y = y(:);
+ crossing_intervals = (y(1:$-1).*y(2:$ )<= 0);//find for crossing intervals
+
+ left_ends = (x(1:$-1)).*(crossing_intervals);
+ right_ends = (x(2:$)).*(crossing_intervals);
+
+ left_vals = (y(1:$-1)).*(crossing_intervals);
+ right_vals = (y(2:$)).*(crossing_intervals);
+ mid_points = (left_ends+right_ends)./2;//finding the midpoints of crossing interval
+
+ zero_intervals = find(left_vals==right_vals);
+ retval1 = mid_points(zero_intervals);//finding the set of points where the function crosses the x-axis
-funcprot(0);
-rhs = argn(2)
-if(rhs~=2)
-error("Wrong number of input arguments.")
-end
-x = callOctave("zerocrossing", w, y)
+ left_ends(zero_intervals) = [];
+ right_ends(zero_intervals) = [];
+ left_vals(zero_intervals) = [];
+ right_vals(zero_intervals) = [];
+ retval2=left_ends-(right_ends-left_ends).*left_vals./(right_vals-left_vals);
+ r = union(retval1,retval2);//combining both retval1 and retval2 and removing redundancies
endfunction
diff --git a/test3.sce b/test3.sce
new file mode 100644
index 0000000..c3195d5
--- /dev/null
+++ b/test3.sce
@@ -0,0 +1,841 @@
+//exec FOSSEE_Scilab_Octave_Interface_Toolbox/loader.sce
+//exec("/home/shashi/Desktop/FOSSEE_Scilab_Octave_Interface_Toolbox/loader.sce")
+//getd macros/
+exec("loader.sce")
+exec("builder.sce")
+
+
+
+
+test_pass=[]
+res=[]
+
+
+
+
+
+
+/////////////////test case for pchip /////////////////////////
+
+ x=[0 1 2 3 4 5]
+ y=[1 0 1 0 1 0]
+ xx=linspace(0,5,80);
+
+ vp=pchip(x,y,xx);
+
+vi=fscanfMat("macros/txt4_pchip.txt");
+
+vi=roundn(vi,4);
+vp=roundn(vp,4);
+
+if(vp==vi)
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass, 0];
+ disp('pchip test failed.');
+end
+
+
+
+/////////Test case for peak2rms //////////
+
+IN=[6 19 10 25];
+OUT=peak2rms(IN);
+//m=1.4927036;
+OUT=(round(OUT*100)/100);
+if(OUT==1.49)
+ test_pass=[test_pass ,1];
+
+else
+ test_pass=[test_pass, 0];
+ disp('peak2rms test failed.');
+end
+
+
+
+
+
+/////////////// Test case for peig /////////
+
+//fs = 100;
+//t = 0:1/fs:1-1/fs;
+//s = 2*sin(2*%pi*25*t)+sin(2*%pi*35*t);
+//[S,w]=peig(s,2,512,fs,'half');
+//n=length(S);
+//
+//for i=1:n
+// S(i)=round((S(i)*10^7)/10^7);
+// end
+//
+//
+//M=fscanfMat("macros/text4_peig.txt");
+//M=roundn(M,7);
+//if(M==S )
+// test_pass=[test_pass 1];
+// else
+// test_pass=[test_pass 0];
+// disp("peig test failed");
+// end
+//
+
+/////////////////test for periodogram ///////////////////////////
+
+n = 0:319;
+x = cos(%pi/4*n);
+[pxx,w]=periodogram(x,ones(1,320),256,2000,"onesided");
+
+pxx=roundn(pxx,4);
+qxx=fscanfMat("macros/txt4_periodogram.txt");
+
+pxx=roundn(pxx,7);
+qxx=roundn(qxx,4);
+
+if(pxx==qxx)
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for periodogram");
+end
+
+
+
+
+
+
+//////// test case for pmusic.............//////////
+//n = 0:199;
+//x = cos(0.257*%pi*n) + sin(0.2*%pi*n);
+//[S,w]=pmusic(x,2,16,1);
+//S=roundn(S,6);
+//w=roundn(w,4);
+//
+//si=[2.6425624,5.7475005, 77.1482210,1.5296243,0.4725347,0.2848481,0.2508128,0.2731036,0.2950648]';
+//si=roundn(si,6);
+//
+//Wi=[0,0.0625,0.125,0.1875,0.25,0.3125,0.375,0.4375,0.5]';
+//Wi=roundn(Wi,4);
+//
+// if(si==S & w==Wi)
+// test_pass=[test_pass 1];
+// else
+// test_pass=[test_pass 0];
+// disp("pmusic test failed");
+// end
+//
+
+
+
+
+//////////// test for poly2lsf //////////////
+//
+X=[1 0.6149 0.9899 0 0.0031 -0.0082] ;
+lsf = poly2lsf(X);
+
+for i=1:length(lsf)
+ lsf(i)=round((lsf(i)*10^7))/10^7;
+end
+
+p=[0.7841731,1.5605415,1.8776459,1.8984313,2.3592523];
+p=round((p.*10^7))./10^7;
+if(lsf'==p) then
+ test_pass=[test_pass,1];
+
+else
+ test_pass=[test_pass,0];
+ disp("test for poly2lsf failed");
+end
+//
+//
+
+
+
+
+/////////// test for polyscale ////////////////
+//
+x=[1 0 0 0 0 0 0 -1];
+p=polyscale(x,1);
+
+y=[1. 0. 0. 0. 0. 0. 0. -1];
+
+if(p==y) then
+ test_pass=[test_pass,1];
+
+else
+ test_pass=[test_pass,0];
+ disp("test failed for polyscale ");
+ end
+
+
+
+
+////////test for polyval ///////////////////////
+
+p=[3 2 1];
+y=polyval(p,[ 5 7 9]);
+
+q=[86 162 262];
+
+
+if(y==q) then
+ test_pass=[test_pass,1]
+
+else
+ test_pass=[test_pass,0];
+ disp("test failed for polyval");
+
+end
+
+
+
+////////////////test for prony /////////////
+V=filter([1,1],[1,1,2],[1 zeros(1,31)]);
+[b,a]=prony(V,1,2);
+
+b=round((b.*10)./10);
+a=round((a.*10)./10);
+
+
+if (b==[1,1] ) then
+ if (a==[1,1,2]) then
+
+ test_pass=[test_pass,1];
+ end
+else
+ test_pass=[test_pass,0];
+ disp("test failed for prony");
+end
+
+
+
+/////////////test for rc2poly///////////////
+k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
+a = rc2poly(k);
+a=round((a.*10^7))./10^7;
+b= [1,0.6148162,0.9898814,0.0000243,0.0031580,-0.0082];
+b=round((b.*10^7))./10^7;
+
+if(a==b) then
+ test_pass=[test_pass,1]
+
+else
+ test_pass=[test_pass,0];
+ disp("test failed for rc2poly");
+end
+
+
+//////////test for rcosdesign //////////////
+rolloff = 0.25;
+span = 3;
+sps=2;
+b=rcosdesign(rolloff,span,sps);
+
+m=[-0.1210006 -0.0456421 0.4418023 0.7590604 0.4418023 -0.0456421 -0.1210006 ];
+
+m=round((m.*10^7))./10^7;
+b=round((b.*10^7))./10^7;
+
+if(m==b)
+ test_pass=[test_pass,1]
+
+else
+ test_pass=[test_pass,0];
+ disp("test failed for rcosdesign");
+end
+
+
+
+////////////test for rlevinson ////////////
+X=[1 6/7 5/7 8/7 3/7 6/7];
+[R U kr e] = rlevinson(X, 0.3);
+
+:
+ei =[ 0.3757546,0.0221076,-3.4125,1.1307692,0.3];
+ kri =[
+ -0.2251908
+ 0.9701364
+ -12.464286
+ -1.1538462
+ 0.8571429 ];
+ Ui =[1,-0.2251908,0.9701364,-12.464286,-1.1538462,0.8571429;0,1,-0.4436567,6.5,2,0.4285714;0,0, 1,-12.535714,-1,1.1428571;0,0,0,1,1.8461538,0.7142857;0,0,0,0,1,0.8571429;0,0,0,0,0,1];
+
+
+
+ Ri =[
+
+ 0.3958273
+ 0.0891367
+ -0.3444604
+ 0.0362590
+ -0.1329496
+ 0.1042446
+];
+
+Ri=round((Ri.*10^7)./10^7);
+R=round((R.*10^7)./10^7);
+Ui=round((Ui.*10^7)./10^7);
+U=round((U.*10^7)./10^7);
+kri=round((kri.*10^7)./10^7);
+kr=round((kr.*10^7)./10^7);
+ei=round((ei.*10^7)./10^7);
+e=round((e.*10^7)./10^7);
+
+if(Ui==U)
+ if(Ri==R)
+ if(kri==kr)
+ if(ei==e)
+ test_pass=[test_pass,1];
+ end
+end
+end
+
+else
+ test_pass=[test_pass,0];
+ disp("test failed for rlevinson");
+end
+
+
+
+///////////// test for rooteig //////////////
+
+ n=0:99;
+
+s=exp(1*%i*%pi/2*n)+2*exp(1*%i*%pi/4*n)+exp(1*%i*%pi/3*n);
+
+X = corrmtx(s,12,'mod');
+
+[W,P] = rooteig(X,3);
+Wi=[0.7745464,1.5717498,1.0481856]';
+Pi=[381.37294,103.13707,119.97409]';
+W=round(W*10^7)/10^7;
+P=round(P*10^5)/10^5;
+Wi=round(Wi*10^7)/10^7;
+Pi=round(Pi*10^5)/10^5;
+
+if(Wi==W)
+if(Pi==P)
+ test_pass=[test_pass,1];
+
+ end
+else
+ test_pass=[test_pass,0];
+ disp("test failed for rooteig");
+end
+
+
+
+/////////// test for rootmusic ///////////
+
+ n=0:99;
+ s=exp(1*%i*%pi/2*n)+2*exp(1*%i*%pi/4*n)+exp(1*%i*%pi/3*n);
+ [A,R]=corrmtx(s,12,'mod');
+ [W,P] = rootmusic(R,3,'corr');
+Wi =[0.7738111,1.5690374 ,1.0426234]';
+ Pi =[377.4255,103.18124,123.86659]';
+
+ W=round(W*10^7)/10^7;
+ P=round(P*10^7)/10^7;
+ Wi=round(Wi*10^7)/10^7;
+ Pi=round(Pi*10^7)/10^7;
+
+if(Wi==W)
+ if(Pi==P)
+ test_pass=[test_pass,1];
+ end
+
+else
+ test_pass=[test_pass,0];
+ disp("test failed for rootmusic");
+end
+
+
+/////////////test for sampled2continuos /////////
+y=sampled2continuous([1,2,3],5,6);
+//
+x=2.4166806;
+//
+y=roundn(y,7);
+x=roundn(x,7);
+//
+if(y==x)
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("test failed for sampled2continous");
+end
+
+
+////////////////test for schurrc //////////
+:
+m=linspace(1,100);
+r = xcorr(m(1:5),'unbiased');.......//autocorrelation vector
+[k,e] = schurrc(r(5:$));
+
+k_exp= [-0.9090909 0.2222222 0.2244898 0.2434211]';
+ e_exp=1.6212406 ;
+
+k=roundn(k,7);
+e=roundn(e,7);
+
+
+k_exp=roundn(k_exp,7);
+e_exp=roundn(e_exp,7);
+
+if(k==k_exp)
+ if(e==e_exp)
+ test_pass=[test_pass,1];
+ end
+else
+ test_pass=[test_pass,0];
+ disp("test failed for schurrc");
+end
+
+
+
+/////////////////test for slewrate/////////
+x=[ones(1,25) -ones(1,25) ones(1,25) ];
+t=1:length(x);
+s=slewrate(x,t);
+s=round(s);
+if(s==[-2,2])
+ test_pass=[test_pass,1];
+
+else
+ test_pass=[test_pass,0];
+ disp("test failed for slewrate");
+
+ end
+
+
+//////////test for sos2ss////////////
+sos = [1 1 1 1 0 -1 ;
+ -2 3 1 1 10 1];
+[A,B,C,D] = sos2ss(sos,2);
+
+Ai=[- 10. 0. 10. 1. ; 1. 0. 0. 0. ; 0. 1. 0. 0. ; 0. 0. 1. 0. ];
+Bi=[1 0 0 0];
+Ci=[42 4. -32. -2];
+Di=-4
+
+A=roundn(A,1);
+B=roundn(B,1);
+C=roundn(C,1);
+D=roundn(D,1);
+
+Ai=roundn(Ai,1);
+Bi=roundn(Bi,1);
+Ci=roundn(Ci,1);
+Di=roundn(Di,1);
+
+if(A==Ai)
+ if(B==Bi&C==Ci)
+ if(D==Di)
+ test_pass=[test_pass,1];
+ end
+ end
+ else
+ test_pass=[test_pass,0];
+ disp("test failed for sos2ss");
+ end
+
+
+//
+///////////test for sosbreak ////////////
+v=[1+4*%s+6*%s^2+4*%s^3+%s^4];
+ [zerosort,g]=sosbreak(v);
+gi=1;
+bi=coeff(zerosort(1));
+ai=coeff(zerosort(2));
+
+if(g==gi)
+ if(ai==[1 2 1] & bi==[1 2 1])
+ test_pass=[test_pass,1];
+ end
+else
+ test_pass=[test_pass,0];
+ disp("test failed for sosbreak");
+end
+
+
+
+
+//////////////test for specgram//////////
+N = 1024;
+n = 0:N-1;
+w= 2*%pi/5;
+x = sin(w*n)+10*sin(2*w*n);
+s = specgram(x);
+s=matrix(s,768,1);
+
+s_real=roundn(real(s),4);
+s_img=roundn(imag(s),4);
+
+m=fscanfMat('macros/txt4specgram_real.txt');
+n=fscanfMat('macros/txt4specgram_imag.txt');
+
+m=roundn(m,4);
+n=roundn(n,4);
+
+if(or(s_real==m) & or(s_img==n))
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("test failed for specgram");
+end
+//
+
+///////////test for upsample fill////////
+
+g=upsamplefill([1,3,5],2,%f);
+
+gi=[1. 1. 1. 3. 3. 3. 5. 5. 5. ];
+
+
+if(gi==g)
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("test failed for upsample fill");
+end
+
+///////////test for ss2sos///////////////
+a =[0.5095,0,0,0,0;
+0.3007, 0.2260, -0.3984, 0, 0;
+0.0977, 0.3984, 0.8706, 0, 0;
+0.0243, 0.0991, 0.4652, 0.5309, -0.4974;
+0.0079, 0.0322, 0.1512, 0.4974, 0.8384];
+
+
+b =[0.6936 0.1382 0.0449 0.0112 0.0036]';
+
+
+c =[0.0028 0.0114 0.0534 0.1759 0.6500];
+
+
+d =0.0013;
+
+a=roundn(a,3);
+b=roundn(b,3);
+c=roundn(c,3);
+d=roundn(d,3);
+
+[sos,g]=ss2sos(a,b,c,d);
+e=[0.509,0,0,0,0;0.301,0.226,-0.398,0,0;0.098,0.398,0.871,0,0;0.024,0.099,0.465,0.531,-0.497;0.008,0.032,0.151,0.497,0.838 ];
+
+if(g==0.001)
+ if (a==e) then
+ test_pass=[test_pass 1];
+ end
+else
+ test_pass=[test_pass,0];
+ disp("test failed for ss2sos");
+end
+
+
+///////////////test for upfirdn/////////////
+
+yout=upfirdn(1:100,1,1,1);
+eout=1:100;
+
+if (eout==yout)
+ test_pass=[test_pass 1];
+else
+ test_pass=[test_pass 0];
+ disp("test failed for upfirdn");
+end
+
+
+
+
+
+//////////////test for wreverse/////////////
+q=wrev([1 2 3]);
+qi=[3 2 1];
+
+if(q==qi)
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("test failed for wreverse");
+end
+
+
+///////////////test for zerocrossings///////
+
+x = linspace(0,1,100);
+y = 2*sin(2*%pi*x);
+x0= zerocrossing(x,y);
+
+x01=[0,0.5];
+
+if(x0==x01)
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("test failed for zerocrossings");
+end
+
+////////////////test for deconv ////////////
+[b, r] = deconv ([3, 6, 9, 9], [1, 2, 3]);
+
+bi=[3,0];
+ri=[0, 0 ,0 ,9];
+
+b=roundn(b,1);
+r=roundn(r,1);
+
+if(and(r==ri) & and(b==bi))
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for deconv");
+end
+
+
+
+//////////////test for downsample////////
+g=downsample([1,2,3,4,5],2);
+gi=[1 3 5];
+
+g=round(g);
+
+if(g==gi)
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for downsample");
+end
+
+//////////////////test for mpoles////////////
+
+[m,n]=mpoles([2 3 1 1 2]);
+
+mi=[1;1;2;1;2];
+ni=[2;5;1;4;3];
+
+m=round(m);
+n=round(n);
+
+
+if(and(m==mi) & and(n==ni))
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for mpoles");
+end
+
+
+/////////////test for polyreduce///////////////
+
+b=polyreduce ([0, 0, 1, 2, 3]);
+
+b=round(b);
+
+if(b==[1,2,3])
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for polyreduce");
+end
+
+
+
+
+////////////////test for prepad////////////////
+a=prepad ([1,2], 4,0,2);
+
+a=round(a);
+
+if(a==[0 0 1 2])
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for prepad");
+end
+
+
+//////////////////test for residue/////////////
+b = [1, 1, 1];
+a = [1, -5, 8, -4];
+
+[r, p, k, e] = residue (b, a);
+
+
+ ei =[1;2;1];
+ ki =[];
+ pi =[2;2;1];
+ ri =[-2;7;3];
+
+ r=round(r);
+ e=round(e);
+ k=round(k);
+ p=round(p);
+
+
+ if(and(ri==r) & and(ei==e) & and(pi==p) & and(ki==k))
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for residue");
+end
+
+
+
+
+///////////////////test for residued/////////////////////
+
+[r,p,f,m] = residued([1 1],[1 -2 1]);
+
+mi=[1;2];
+fi=[];
+pi=[1;1];
+ri=[-1;2];
+
+r=round(r);
+p=round(p);
+f=round(f);
+m=round(m);
+
+ if(and(ri==r) & and(fi==f) & and(pi==p) & and(mi==m))
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for residue");
+end
+
+
+ ///////////////////test for residuez/////////////////////
+
+[r,p,f,m] = residuez([1 1],[1 -2 1]);
+
+mi=[1;2];
+fi=[];
+pi=[1;1];
+ri=[-1;2];
+
+r=round(r);
+p=round(p);
+f=round(f);
+m=round(m);
+
+ if(and(ri==r) & and(fi==f) & and(pi==p) & and(mi==m))
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for residue");
+end
+
+
+///////////////test for gmonopuls////////////////////////
+u=gmonopuls([1 2 3],[]);
+
+u=round(u);
+
+if(u==[0 0 0])
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for gmonopuls");
+end
+
+
+
+///////////////test for convmtx//////////////////////
+o=convmtx([3;4;5],3);
+
+o=round(o);
+
+if(o==[3,0,0;4,3,0;5,4,3;0,5,4;0,0,5])
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for convmtx");
+end
+
+
+/////////////////test for yulewalker/////////////
+A=yulewalker([1 2 3]);
+A=roundn(A,2);
+
+if (A==[1.33;0.33]) then
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for yulewalker");
+end
+
+
+
+
+//////////////////////test for wkeep////////////////
+
+y=wkeep([1 2 3;4 5 6],[2 2]);
+yi=[1,2];
+
+if(yi==round(y))
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for wkeep");
+end
+
+
+
+
+//////////////////test for rc2ac////////////////
+k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
+r0 = 0.1;
+
+R = rc2ac(k,r0);
+
+R=roundn(R,4);
+
+ Ri =[0.1 ;-0.0309;-0.0790948 ;0.0786627 ;0.0293629 ;-0.0950000];
+ Ri=roundn(Ri,4);
+
+ if(R==Ri)
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for rc2ac");
+end
+
+
+
+//////////////////////test for mexihat//////////////////
+[a,b]= mexihat(1,2,3);
+ai=[0.00000 -0.35197 -0.35214];
+bi=[1.0000 1.5000 2.0000];
+
+a=roundn(a,4);
+b=roundn(b,4);
+
+ai=roundn(ai,4);
+bi=roundn(bi,4);
+
+if(and(ai==a) & and(bi==b))
+ test_pass=[test_pass,1];
+else
+ test_pass=[test_pass,0];
+ disp("tst failed for mexihat");
+end
+
+
+
+
+
+disp("all worked!!")
+
+////////////////////////////////////////////////////
+
+res=find(test_pass==0)
+
+
+
+
+if(res~=[])
+ disp("One or more tests failed")
+ exit(1)
+else
+ disp("pass")
+ exit
+end