Convert autocorrelation sequence to polynomial of prediction filter
+
+
+
Calling Sequence
+
a = ac2poly(r)
+[a,e] = ac2poly(r)
+
+
Parameters
+
r:
+
Autocorrelation sequence to be represented with an FIR linear prediction filter
+
a:
+
Output polynomial representing the linear prediction filter e/(a(1) + a(2)z + a(3)z^2 .. a(N)z^N-1)
+
e:
+
Output scaling for the lienar prediction filter
+
+
Description
+
Function ac2poly() finds the best fit polynomial for FIR linear prediction filter a, corresponding to the autocorrelation sequence r. a is the same length as r, and is normalized with the first element. So a(1) = 1.
+Author:
+Parthe Pandit
+
+
+
Bibliography
+
Kay, Steven M. Modern Spectral Estimation. Englewood Cliffs, NJ: Prentice-Hall, 1988.
string value, takes in "AKICc", "KIC", "AICc", "AIC" and "FPE", default it not using a model-selection criterion
+
a, v, k:
+
Output variables
+
+
Description
+
This is an Octave function.
+This function calculates coefficients of an autoregressive (AR) model of complex data x using the whitening lattice-filter method of Burg.
+The first argument is the data sampled. The second argument is the number of poles in the model (or limit in case a criterion is supplied).
+The third parameter takes in the criterion to limit the number of poles. The acceptable values are "AIC", "AKICc", "KIC", "AICc" which are based on information theory.
+Output variable a is a list of P+1 autoregression coefficients.
+Output variable v is the mean square of residual noise from the whitening operation of the Burg lattice filter.
+Output variable k corresponds to the reflection coefficients defining the lattice-filter embodiment of the model.
This is an Octave function.
+This function fits an AR (p)-model with Yule-Walker estimates.
+The first argument is the data vector which is to be estimated.
+Output variable a gives the AR coefficients, v gives the variance of the white noise and k gives the reflection coefficients to be used in the lattice filter.
This function returns the filter coefficients of a modified Bartlett-Hann window.
+
+
+
Calling Sequence
+
y = barthannwin(m)
+
+
Parameters
+
m:
+
positive integer value
+
y:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a modified Bartlett Hann window of length m supplied as input, to the output vector y.
w=bartlett(L) returns an L-point Bartlett window in a column vector w
+Example
+w=bartlett(4)
+w =
+
0.
+0.6666667
+0.6666667
+0.
+Author
+Ankur Mallick
+References
+[1] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1999.
This is an Octave function.
+This function generates a Bessel filter. The default is a Laplace space (s) filter.
+The third parameter takes in high or low, the default value being low. The cutoff is pi*Wc radians.
+[z,p,g] = besself(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+[...] = besself(...,’z’) returns a discrete space (Z) filter. w must be less than 1.
+[a,b,c,d] = besself(...) returns state-space matrices.
This is an Octave function.
+This function returns the input data after reversing the bits of the indices and reordering the elements of the input array.
w=blackman(N) returns an N-point symmetric Blackman window in a column vector w
+w=blackman(N,sflag)
+Returns an N point Blackman window using the type of sampling specified by sflag
+sflag can be either 'symmetric' (default) or 'periodic' (used in spectral analysis)
+Example
+w=blackman(4)
+w =
+
- 1.388D-17
+0.63
+0.63
+- 1.388D-17
+Author
+Ankur Mallick
+References
+[1] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1999.
This function returns the filter coefficients of a Blackman-Harris window.
+
+
+
Calling Sequence
+
w = blackmanharris (m)
+w = blackmanharris (m, opt)
+
+
Parameters
+
m:
+
positive integer value
+
opt:
+
string value, takes "periodic" or "symmetric"
+
w:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a Blackman-Harris window of length m supplied as input, to the output vector w.
+The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
This function returns the filter coefficients of a rectangular window.
+
+
+
Calling Sequence
+
y = boxcar (m)
+
+
Parameters
+
m:
+
positive integer value
+
y:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a rectangular window of length m supplied as input, to the output vector y.
This is an Octave function.
+This function generates a Butterworth filter. Default is a discrete space (Z) filter.
+The third parameter takes in low or high, default value is low. The cutoff is pi*Wc radians.
+[b,a] = butter(n, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.
+[b,a] = butter(n, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.
+[z,p,g] = butter(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+[...] = butter(...,’s’) returns a Laplace space filter, w can be larger than 1.
+[a,b,c,d] = butter(...) returns state-space matrices.
scalar or vector of length 2, elements must be in the range [0,1]
+
Rp:
+
real or complex value
+
Rs:
+
real or complex value
+
+
Description
+
This is an Octave function.
+This function computes the minimum filter order of a Butterworth filter with the desired response characteristics.
+The filter frequency band edges are specified by the passband frequency wp and stopband frequency ws.
+Frequencies are normalized to the Nyquist frequency in the range [0,1].
+Rp is measured in decibels and is the allowable passband ripple, and Rs is also in decibels and is the minimum attenuation in the stop band.
+If ws>wp, the filter is a low pass filter. If wp>ws, the filter is a high pass filter.
+If wp and ws are vectors of length 2, then the passband interval is defined by wp the stopband interval is defined by ws.
+If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp the filter is a band-stop or band-reject filter.
Converts a cell array to a second order section matrix
+
+
+
Parameters
+
+
+
Description
+
s=cell2sos(c) converts a a cell array c = { {B1},{A1}, {B2},{A2}, ... {BL},{AL}}
+to an L-by-6 second-order-section matrix s given by:
+s = [B1 A1
+B2 A2
+...
+BL AL]
+numerator vector Bi and denominator vector Ai contains the coefficients of a
+linear or quadratic polynomial. If the polynomial is linear, the coefficients
+zero-padded on the right.
+[s,g]=cell2sos(c) estimates the gain from the leading term of the cell array
+c={ {[g1,g2]},{B1},{A1}, {B2},{A2}, ... {BL},{AL}} to give g=g1/g2 as the gain
+Example
+c=cell(1,5);
scalar or vector of length 2, all elements must be in the range [0,1]
+
Ws:
+
scalar or vector of length 2, all elements must be in the range [0,1]
+
Rp:
+
real value
+
Rs:
+
real value
+
+
Description
+
This is an Octave function.
+This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics.
+Stopband frequency ws and passband frequency wp specify the the filter frequency band edges.
+Frequencies are normalized to the Nyquist frequency in the range [0,1].
+Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.
+If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.
+If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws.
+If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter.
scalar or vector of length 2, all elements must be in the range [0,1]
+
Ws:
+
scalar or vector of length 2, all elements must be in the range [0,1]
+
Rp:
+
real value
+
Rs:
+
real value
+
+
Description
+
This is an Octave function.
+This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics.
+Stopband frequency ws and passband frequency wp specify the the filter frequency band edges.
+Frequencies are normalized to the Nyquist frequency in the range [0,1].
+Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.
+If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.
+If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws.
+If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter.
This function returns the filter coefficients of a Dolph-Chebyshev window.
+
+
+
Calling Sequence
+
w = chebwin (m)
+w = chebwin (m, at)
+
+
Parameters
+
m:
+
positive integer value
+
at:
+
real scalar value
+
w:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a Dolph-Chebyshev window of length m supplied as input, to the output vector w.
+The second parameter is the stop band attenuation of the Fourier transform in dB. The default value is 100 dB.
This is an Octave function.
+This function generates a Chebyshev type I filter with rp dB of passband ripple.
+The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians.
+[b, a] = cheby1(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.
+[b, a] = cheby1(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.
+[z, p, g] = cheby1(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+[...] = cheby1(...,’s’) returns a Laplace space filter, w can be larger than 1.
+[a,b,c,d] = cheby1(...) returns state-space matrices.
This is an Octave function.
+This function generates a Chebyshev type II filter with rs dB of stopband attenuation.
+The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians.
+[b, a] = cheby2(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.
+[b, a] = cheby2(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.
+[z, p, g] = cheby2(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+[...] = cheby2(...,’s’) returns a Laplace space filter, w can be larger than 1.
+[a,b,c,d] = cheby2(...) returns state-space matrices.
string value, takes in "linear", "quadratic", "logarithmic"
+
phse:
+
+
+
Description
+
This is an Octave function.
+This function evaluates a chirp signal at time t. A chirp signal is a frequency swept cosine wave.
+The first argument is a vector of times to evaluate the chirp signal, second argument is the frequency at t=0, third argument is time t1 and fourth argument is frequency at t1.
+The fifth argument is the form which takes in values "linear", "quadratic" and "logarithmic", the sixth argument gives the phase shift at t=0.
This function calculates boundary indexes of clusters of 1’s.
+
+
+
Calling Sequence
+
c = clustersegment(s)
+
+
Parameters
+
s:
+
scalar, vector or matrix of real numbers (clusters of 1s)
+
c:
+
output variable, cell array of size 1 by N, where N is the number of rows in s
+
+
Description
+
This is an Octave function.
+This function calculates boundary indexes of clusters of 1’s.
+This function calculates the initial and end indices of the sequences of 1's present in the input argument.
+The output variable c is a cell array of size 1 by N, where N is the number of rows in s and each element has two rows indicating the initial index and end index of the cluster of 1's respectively. The indexing starts from 1.
input vector of size N for which correlation matrix of size m is to be calculated
+
m:
+
size of correlation matrix to be computed. Positive integer strictly smaller than the length of the input x
+
X:
+
data matrix as specified according to the input 'method'
+
s:
+
method for type of output matrix X
+
'autocorrelation':
+
(default) X is the (n + m)-by-(m + 1) rectangular Toeplitz matrix that generates an autocorrelation estimate for the leng th-n data vector x, derived using prewindowed and postwindowed data, based on an mth-order prediction error model.
+
'prewindowed':
+
X is the n-by-(m + 1) rectangular Toeplitz matrix that generates an autocorrelation estimate for the length-n data vector x, derived using prewindowed data, based on an mth-order prediction error model.
+
'postwindowed':
+
X is the n-by-(m + 1) rectangular Toeplitz matrix that generates an autocorrelation estimate for the length-n data vector x , derived using postwindowed data, based on an mth-order prediction error model.
+
'covariance':
+
X is the (n – m)-by-(m + 1) rectangular Toeplitz matrix that generates an autocorrelation estimate for the length-n data vect or x, derived using nonwindowed data, based on an mth-order prediction error model.
+
'modified':
+
X is the 2(n – m)-by-(m + 1) modified rectangular Toeplitz matrix that generates an autocorrelation estimate for the length-n d ata vector x, derived using forward and backward prediction error estimates, based on an mth-order prediction error model.
This is an Octave function
+dctmtx(n) returns a Discrete cosine transform matrix of order n-by-n. It is useful for jpeg image compression. D*A is the DCT of the columns of A and D'*A is the inverse DCT of the columns of A (when A is n-by-n).
This is an Octave function
+This fuction gives a complex matrix of values whose product with a vector produces the discrete Fourier transform. This can also be achieved by directly using the fft function i.e. y=fft(x) is same as y=A*x where A=dftmtx(n).
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.
scalar or vector, all elements should be in the range [0,1]
+
+
Description
+
This is an Octave function.
+This function generates an elliptic or Cauer filter with rp dB of passband ripple and rs dB of stopband attenuation.
+[b, a] = ellip(n, Rp, Rs, Wp) indicates low pass filter with order n, Rp decibels of ripple in the passband and a stopband Rs decibels down and cutoff of pi*Wp radians. If the fifth argument is high, then the filter is a high pass filter.
+[b, a] = ellip(n, Rp, Rs, [Wl, Wh]) indictaes band pass filter with band pass edges pi*Wl and pi*Wh. If the fifth argument is stop, the filter is a band reject filter.
+[z, p, g] = ellip(...) returns filter as zero-pole-gain.
+[...] = ellip(...,’s’) returns a Laplace space filter, w can be larger than 1.
+[a, b, c, d] = ellip(...) returns state-space matrices.
scalar or vector of length 2, all elements must be in the range [0,1]
+
Ws:
+
scalar or vector of length 2, all elements must be in the range [0,1]
+
Rp:
+
real or complex value
+
Rs:
+
real or complex value
+
+
Description
+
This is an Octave function.
+This function computes the minimum filter order of an elliptic filter with the desired response characteristics.
+Stopband frequency ws and passband frequency wp specify the the filter frequency band edges.
+Frequencies are normalized to the Nyquist frequency in the range [0,1].
+Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.
+If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.
+If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws.
+If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter.
Performs FFT-based FIR filtering using overlap-add method
+
+
+
Calling Sequence
+
+
+
Parameters
+
x:
+
real|complex numbers - vector|matrix
+
b:
+
real|complex numbers - vector|matrix
+
n:
+
positive integer
+
+
Description
+
y = fftfilt(b,x) filters the data in vector x with the filter described
+by coefficient vector b.
+y = fftfilt(b,x,n) uses n to determine the length of the FFT.
This is an Octave function
+In theory, it forwards and reverse filters the signal and corrects phase distortion upto an extent by a one-pass filter but squares the magnitude response in the process. Practically though, the correction isn't perfect and magnitude response, particularly the stop band is distorted.
This function finds the initial conditions for the delays in the transposed direct-form II filter implementation.
+The vectors b and a represent the numerator and denominator coefficients of the filter's transfer function.
Parks-McClennan optimal FIR filter order estimation
+
+
+
Calling Sequence
+
+
+
Parameters
+
f:
+
double - positive - vector
+
a:
+
double - positive - vector
+
dev:
+
double - positive - vector
+
n:
+
int - scalar
+
fo:
+
double - positive - vector
+
ao:
+
double - positive - vector
+
w:
+
double - vector
+
+
Examples
+
[1]Alow-passfilter
+f=[15002000];// frequency edges for bands
+a=[10];// desired amplitude for each band
+dev=[0.010.1];// Acceptable deviation for each band
+fs=8000;// Sampling frequency
+[n,fo,ao,w]=firpmord(f,a,dev,fs);
+
+[2]Abandstopfilter
+f=[1000180024003000];
+a=[100.5];
+dev=[0.010.10.03];
+fs=8000;
+[n,fo,ao,w]=firpmord(f,a,dev,fs);
+
+References
+[1]Rabiner,LawrenceR.,andBernardGold."Theoryandapplicationof
+digitalsignalprocessing." Englewood Cliffs, NJ, Prentice-Hall, Inc.,
+1975.777p.156-7(1975).
+[2]Rabiner,LawrenceR.,andOttoHerrmann."Thepredictabilityofcertain
+optimumfinite-impulse-responsedigitalfilters." Circuit Theory,
+IEEETransactionson20.4(1973):401-408.
This function returns the filter coefficients of a Flat Top window.
+
+
+
Calling Sequence
+
w = flattopwin (m)
+w = flattopwin (m, opt)
+
+
Parameters
+
m:
+
positive integer value
+
opt:
+
string value, takes in "periodic" or "symmetric"
+
w:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a Flat Top window of length m supplied as input, to the output vector w.
+The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+This window has low pass-band ripple but a high bandwidth.
This is an Octave function.
+This function shifts the series x supplied as input argument by a number of samples d.
+The third parameter is the interpolator, which is designed with a Kaiser-windowed sinecard by default, if not supplied.
This function returns a Gaussian convolution window.
+
+
+
Calling Sequence
+
w = gaussian (m)
+w = gaussian (m, a)
+
+
Parameters
+
m:
+
positive integer value
+
a:
+
+
w:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns a Gaussian convolution 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.
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.
Computes DFT using the second order Goertzel Algorithm
+
+
+
Calling Sequence
+
Y = goertzel(X,INDVEC,DIM)
+
+
Parameters
+
+
+
Description
+
goertzel(X,INDVEC)
+Computes the DFT of X at indices INDVEC using the second order algorithm along
+the first non-singleton dimension. Elements of INDVEC must be positive integers
+less than the length of the first non-singleton dimension. If INDVEC is empty
+the DFT is computed at all indices along the first non-singleton dimension
+goertzel(X,INDVEC,DIM)
+Implements the algorithm along dimension DIM
+In general goertzel is slower than fft when computing the DFT for all indices
+along a particular dimension. However it is computationally more efficient when
+the DFT at only a subset of indices is desired
+Example
+x=rand(1,5)
+x =
This is an Octave function.
+This function returns the filter coefficients of a Hanning window of length m supplied as input, to the output vector w.
+The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
This function does IIR Low Pass Filter to Multiband Filter Transformation.
+
+
+
Calling Sequence
+
[Num, Den, AllpassNum, AllpassDen] = iirlp2mb(B, A, Wo, Wt)
+[Num, Den, AllpassNum, AllpassDen] = iirlp2mb(B, A, Wo, Wt, Pass)
+
+
Parameters
+
B:
+
real or complex value
+
A:
+
real or complex value
+
Wo:
+
scalar or vector
+
Wt:
+
scalar or vector, elements must be monotonically increasing and >= 0 and <= 1.
+
+
Description
+
This is an Octave function.
+This function does IIR Low Pass Filter to Multiband Filter Transformation.
+The first two parameters give the numerator and denominator of the prototype low pass filter.
+The third parameter is the normalized angular frequency/pi to be transformed.
+The fourth parameter is the normalized angular frequency/pi target vector.
+The first two output variables are the numerator and denominator of the transformed filter.
+The third and fourth output variables are the numerator and denominator of the allpass transform.
+The fifth parameter can have values pass or stop, default value is pass.
This function converts analog filter with coefficients b and a to digital, conserving impulse response.
+
+
+
Calling Sequence
+
[b, a] = impinvar (b, a)
+[b, a] = impinvar (b, a, fs)
+[b, a] = impinvar (b, a, fs, tol)
+
+
Parameters
+
b:
+
real or complex valued scalar or vector
+
a:
+
real or complex valued scalar or vector, order should be greater than b
+
fs:
+
real or complex value, default value 1Hz
+
tol:
+
real or complex value, default value 0.0001
+
+
Description
+
This is an Octave function.
+This function converts analog filter with coefficients b and a to digital, conserving impulse response.
+This function does the inverse of impinvar.
y = interp(x, q)
+y = interp(x, q, n)
+y = interp(x, q, n, Wc)
+
+
Parameters
+
x:
+
scalar or vector of complex or real numbers
+
q:
+
positive integer value, or logical
+
n:
+
positive integer, default value 4
+
Wc:
+
non decreasing vector or scalar, starting from 0 uptill 1, default value 0.5
+
+
Description
+
This is an Octave function.
+This function upsamples the signal x by a factor of q, using an order 2*q*n+1 FIR filter.
+The second argument q must be an integer. The default values of the third and fourth arguments (n, Wc) are 4 and 0.5 respectively.
This function converts digital filter with coefficients b and a to analog, conserving impulse response.
+
+
+
Calling Sequence
+
[b, a] = impinvar (b, a)
+[b, a] = impinvar (b, a, fs)
+[b, a] = impinvar (b, a, fs, tol)
+
+
Parameters
+
b:
+
real or complex valued scalar or vector
+
a:
+
real or complex valued scalar or vector, order should be greater than b
+
fs:
+
real or complex value, default value 1Hz
+
tol:
+
real or complex value, default value 0.0001
+
+
Description
+
This is an Octave function.
+This function converts digital filter with coefficients b and a to analog, conserving impulse response.
+This function does the inverse of impinvar.
This function returns the filter coefficients of a Kaiser window.
+
+
+
Calling Sequence
+
w = kaiser (m)
+w = kaiser (m, beta)
+
+
Parameters
+
m:
+
positive integer value
+
beta:
+
real scalar value
+
w:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a Kaiser window of length m supplied as input, to the output vector w.
+The second parameter gives the stop band attenuation of the Fourier transform of the window on derivation.
Convert lattice filter parameters to transfer function coefficients
+
+
+
Calling Sequence
+
+
+
Description
+
[num,den] = latc2tf(k,v)
+Finds the transfer function of the IIR filter from the lattice
+coefficients k and ladder coefficients v.
+[num,den] = latc2tf(k,'iiroption')
+Finds the transfer function of the allpass or allpole (specified by
+the iiroption flag) IIR filter.
+num = latc2tf(k,'firoption')
+Finds the transfer function of the FIR filter from the lattice
+coefficients k. The firoption flag specifies the type of the FIR
+filter (can be 'min, 'max', or 'FIR')
+
Parameters:
+k - double - vector
+Lattice coefficients
+Lattice coefficients for FIR/IIR filter. Can be real or complex.
+v - double - vector
+Ladder coefficients
+Ladder coefficients for IIR filters. Can be real or complex.
+iiroption - string flag - 'allpole', or 'allpass'
+Specification of the type if IIR filter
+firoption - string flag - 'min', 'max', or 'FIR' (default)
+Speficication of the type of FIR filter
[a,g] = lpc(x,p)
+Determines the coefficients of a pth order forward linear predictor
+filter by minimizing the squared error. If p is unspecified, a
+default value of length(x)-1 is used.
This function computes the generalized Marcum Q function of order m with noncentrality parameter a and argument b.
+
+
+
Calling Sequence
+
q = marcumq (a, b)
+q = marcumq (a, b, m)
+q = marcumq (a, b, m, tol)
+
+
Parameters
+
a:
+
+
b:
+
+
m:
+
default value 1
+
tol:
+
default value eps
+
+
Description
+
This is an Octave function.
+This function computes the generalized Marcum Q function of order m with noncentrality parameter a and argument b.
+The third argument m is the order, which by default is 1.
+The fourth argument tol is the tolerance, which by default is eps.
+If input arguments are vectors which correspond in size and degree, the output is a table of values.
+This function calculates Marcum’s Q function using the infinite Bessel series, which is truncated when the relative error is less than the specified tolerance.
y = medfilt1(x)
+Applies a 3rd order 1-dimensional median filter to input x along the
+first non-zero dimension. The function appropriately pads the signal
+with zeros at the endings. For a segment, a median is calculated as
+the middle value (average of two middle values) for odd number
+number (even number) of data points.
+y = medfilt1(x,n)
+Applies a nth order 1-dimensional median filter.
+y = medfilt1(x,n,dim)
+Applies the median filter along the n-th dimension
+y = medfilt1(__, nanflag, padding)
+nanflag specifies how NaN values are treated. padding specifies the
+type of filtering to be performed at the signal edges.
+
+
+
Parameters
+
x:
+
int | double
+
n:
+
positive integer scalar
+
dim:
+
positive integer scalar
+
nanflag:
+
'includenan' (default) | 'omitnan'
+
* includenan:
+
Filtering such that the median of any segment
+
* omitnan:
+
Filtering with NaNs omitted in each segment. If a segment
[y,t]=modulate(x,fc,fs,method,opt)
+Returns the modulated vector y and the time vector 't'
+Modulation is performed according to the following table
+METHOD MODULATION SCHEME
+'am', Amplitude modulation, double side-band, suppressed carrier
+'amdsb-sc' opt not used. This is the default method.
+'amdsb-tc' Amplitude modulation, double side-band, transmitted carrier
+opt is a scalar subtracted from x before multiplying x
+with the carrier wave. It defaults to min(min(x)) so that
+the input signal after offset is always non-negative
+'amssb' Amplitude modulation, single side-band
+OPT not used.
+'fm' Frequency modulation
+opt is the constant of frequency modulation.
+opt = (fc/fs)*2*pi/max(max(abs(x))) by default
+'pm' Phase modulation
+OPT is the constant of phase modulation.
+opt = pi/max(max(abs(x))) by default
+Phase lies between -pi and +pi
+'pwm' Pulse width modulation
+opt='left' corresponds to left justified pulses.
+opt='centered' correspondes to centered pulses.
+The default value of opt is 'left'.
+'ppm' Pulse position modulation
+opt is a scalar between 0 and 1 which specifies the pulse
+width in fractions of the carrier period with default value 0.1.
+'qam' Quadrature amplitude modulation
+opt is a matrix of the same size as X which is modulated in
+quadrature with x.
+
If x is a matrix, its columns are modulated.
+Example
+y =
This is an Octave function.
+The signal is convoluted against a sigmoid window of width w and risetime rc with the units of these parameters relative to the value of the sampling frequency given in Fs (Default value=1).
This function returns the filter coefficients of a Blackman-Harris window.
+
+
+
Calling Sequence
+
w = nuttallwin (m)
+w = nuttallwin (m, opt)
+
+
Parameters
+
m:
+
positive integer value
+
opt:
+
string value, takes in "periodic" or "symmetric"
+
w:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a Blackman-Harris window defined by Nuttall of length m supplied as input, to the output vector w.
+The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
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.
Convert prediction polynomial to autocorrelation sequence.
+
+
+
Calling Sequence
+
R = poly2ac(a,efinal)
+
+
Parameters
+
a:
+
input prediction polynomial with 1st element 1 (if not, poly2ac normalizes it to 1 before proceeding).
+
efinal:
+
input prediction error
+
r:
+
output autocorrelation sequence
+
+
Description
+
This function obtains the underlying autocorrelation sequence that would best fit a linear prediction filter described by the
+denominator polynomial and the numerator scaling. The filter is H(z) = efinal/(a(1) + a(2) x z a(3) x z^2 ... a(n) x z^n-1)
This function stabilizes the polynomial transfer function.
+
+
+
Calling Sequence
+
b = polystab(a)
+
+
Parameters
+
a:
+
+
+
Description
+
This is an Octave function.
+This function stabilizes the polynomial transfer function by replacing all roots outside the unit circle with their reflection inside the unit circle.
This function calculates the primitive of a given function supplied as input.
+
+
+
Calling Sequence
+
y = primitive(f, t)
+y = primitive(f, t, x)
+
+
Parameters
+
f:
+
+
t:
+
+
+
Description
+
This is an Octave function.
+This function calculates the primitive of a given function supplied as input.
+The second parameter t is a vector at which the output is evaluated (at the points t). This vector should be ascending and ordered.
+The function approximates the primitive (indefinite integral) of the univariate function handle f with constant of integration x.
This is an Octave function.
+This function generates the signal y = sum(func(t+d,...)) for each d. If d is a matrix of two columns, the first column is the delay d and the second column is the amplitude a, and y = sum(a*func(t+d)) for each d, a. Here, func is a function which accepts a vector of times.
+If a pulse shape sampled at frequency Fs (default 1 Hz) is supplied instead of a function name, an interpolated version of the pulse is added at each delay d.
This is an Octave function
+y = rectpuls(t) returns a continuous, aperiodic, unity-height rectangular pulse depending upon input t, centered about t=0 and having default width of 1.
+y = rectpuls(t,w) generates a rectangle of width w.
This function returns the filter coefficients of a rectangular window.
+
+
+
Calling Sequence
+
y = rectwin (m)
+
+
Parameters
+
m:
+
positive integer value
+
y:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a rectangular window of length m supplied as input, to the output vector y.
This function resamples in the input sequence x supplied by a factor of p/q.
+
+
+
Calling Sequence
+
y = resample(x, p, q)
+y = resample(x, p, q, h)
+[y, h] = resample(...)
+
+
Parameters
+
x:
+
scalar, vector or matrix of real or complex numbers
+
p:
+
positive integer value
+
q:
+
positive integer value
+
h:
+
scalar, vector or matrix of real or complex numbers
+
+
Description
+
This is an Octave function.
+This function resamples in the input sequence x supplied by a factor of p/q. If x is a matrix, then every column is resampled.hange the sample rate of x by a factor of p/q.
+This is performed using a polyphase algorithm. The impulse response h, given as parameter 4, of the antialiasing filter is either specified or designed with a Kaiser-windowed sinecard.
This 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.
This function calculates the square root of the sum of values of input vector IN.
+
+
+
Calling Sequence
+
OUT=rssq(IN)
+OUT=rssq(IN,orientation)
+
+
Parameters
+
in:
+
Vector or Matrix of real or complex elements.
+
orientation:
+
A string with possible values "r", "c" or "m" or numericals such as '1' or '2',giving the dimension along which the rssq value is to be calculated.
+
out:
+
A scalar with real value when input is a vector.When input is a matrix, out is the root sum squared value along the orientation specified or the default one when not specified.
+
+
Description
+
For vector as input, the output is real valued scalar containing the rssq value. The rssq value can be calculated by taking the square root of the squared sum of the elements.
+If the input IN is a matrix, the output of function is rssq value of each column stored in a row vector OUT.
+
When the elements of IN are COMPLEX, the absolute value of the element is used to calculate the output.
+When the orientation is not specified for N dimensional array, it is taken as the index of the first dimension of IN that is greater than 1 and calculation is done along that orientation.
+
When the orientation is specified the output is calculated along that dimension.
+The orientation can be specified as 1 for rssq value of columns of matrix IN or as r.
+For rssq value of rows of matrix orientation should be 2 or c.
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:
+
+
+
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.
+The third parameter t is all the instants where output x is needed from intput n and this time is relative to x(0).
This is an Octave function
+This function returns a sawtooth wave with period 2*pi with +1/-1 as the maximum and minimum values for elements of t. If width is specified, it determines where the maximum is in the interval [0,2*pi].
This function implements a multisignal Schmitt triggers with lev levels supplied as input.
+
+
+
Calling Sequence
+
v = schtrig (x, lev)
+v = schtrig (x, lev, rs)
+
+
Parameters
+
x:
+
vector or matrix of real numbers
+
lev:
+
real number
+
rs:
+
default value 1
+
+
Description
+
This is an Octave function.
+This function implements a multisignal Schmitt triggers with lev levels supplied as input.
+The argument 1 is a matrix (or a vector) and this trigger works along its first dimension.
[p,num]=seqperiod(x)
+Returns an integer p such that x(1:p) is the smallest subsequence that repeats in x
+The number of times the subsequence repeats is returned in num (may not be an integer)
+Repetitions may be incomplete at the end of the sequence but no breaks are permitted between repetitions
+If there is no subsequence that repeats in x then p=length(x)
+If x is a matrix or n-dimesnional array, the function operates along the first non-singleton dimension of x
This function computes the filter coefficients for all Savitzsky-Golay smoothing filters.
+
+
+
Calling Sequence
+
F = sgolay (p, n)
+F = sgolay (p, n, m)
+F = sgolay (p, n, m, ts)
+
+
Parameters
+
p:
+
polynomial
+
n:
+
odd integer value, larger than polynomial p
+
m:
+
positive integer less than 2^31 or logical
+
ts:
+
real or complex value
+
+
Description
+
This is an Octave function.
+This function computes the filter coefficients for all Savitzsky-Golay smoothing filters of order p for length n (odd).
+m can be used in order to get directly the mth derivative; ts is a scaling factor.
y = sgolayfilt (x)
+y = sgolayfilt (x, p)
+y = sgolayfilt (x, p, n)
+y = sgolayfilt (x, p, n, m)
+y = sgolayfilt (x, p, n, m, ts)
+
+
Parameters
+
x:
+
vector or matrix of real or complex numbers
+
p:
+
polynomial order, real number less than n, default value 3
+
n:
+
integer, odd number greater than p
+
m:
+
vector of real positive valued numbers, length n
+
ts:
+
real number, default value 1
+
+
Description
+
This function applies a Savitzky-Golay FIR smoothing filter to the data given in the vector x; if x is a matrix, this function operates
+on each column.
+The polynomial order p should be real, less than the size of the frame given by n.
+m is a weighting vector with default value identity matrix.
+ts is the dimenstion along which the filter operates. If not specified, the function operates along the first non singleton dimension.
Real or complex valued vector or matrix, strictly positive value for scalar input
+
fc:
+
Real or complex valued vector or matrix, strictly positive value for scalar input
+
+
Description
+
This is an Octave function
+This function implements the complex Shannon wavelet function and returns the value obtained. The complex Shannon wavelet is defined by a bandwidth parameter FB, a wavelet center frequency FC on an N point regular grid in the interval [LB,UB].
[y,perm,nshifts]=shiftdata(x,dim)
+Shifts the entries along dimension dim in x to the first column and returns the permutation vector in perm
+[y,perm,nshifts]=shiftdata(x)
+Shifts the entries along dimension dim in x to the first column and returns the number of shifts in nshifts
+
+
Examples
+
//When dim is specified:
+x=testmatrix('magi',3)
+x=
+
+8.1.6.
+3.5.7.
+4.9.2.
+[y,perm,nshifts]=shiftdata(x,2)
+nshifts=
+
+[]
+perm=
+
+2.1.
+y=
+
+8.3.4.
+1.5.9.
+6.7.2.
+//When dim is not specified:
+x=1:5
+x=
+
+1.2.3.4.5.
+[y,perm,nshifts]=shiftdata(x)
+nshifts=
+
+1.
+perm=
+
+[]
+y=
+
+1.
+2.
+3.
+4.
+5.
Converts a second order section matrix to a cell array
+
+
+
Parameters
+
+
+
Description
+
c=sos2cell(s) converts an L-by-6 second-order-section matrix s given by:
+s = [B1 A1
+B2 A2
+...
+BL AL]
+to a cell array c = { {B1},{A1}, {B2},{A2}, ... {BL},{AL}} where each
+numerator vector Bi and denominator vector Ai contains the coefficients of a
+linear or quadratic polynomial. If the polynomial is linear, the coefficients
+zero-padded on the right
+c=sos2cell(s,g) adds a leading gain term to the start of the cell array as:
+c={ {[g,1]},{B1},{A1}, {B2},{A2}, ... {BL},{AL}}
+Example
+s=rand(2,6)
+s =
This is an Octave function.
+This function converts series second-order sections to direct H(z) = B(z)/A(z) form.
+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.
This is an Octave function.
+This function converts series second-order sections to zeros, poles, and gains (pole residues).
+The input is the sos matrix and the second parameter is the overall gain, default value of which is 1.
+The outputs are z, p, k. z and p are column vectors containing zeros and poles respectively, and k is the overall gain.
This is an Octave function
+Second order section digital filter sos is applied to the input vector and the output vector obtained is of the same length.
strips(x)
+Plots a vector x in horizontal strips of length 250
+If x is a matrix, it plots each column of x on a separate strip with the leftmost
+column as the topmost strip
+strips(x,sd)
+Plots x in strips of length sd samples each
+strips(x,sd,fs)
+Plots x in strips of duration sd seconds with sampling frequency fs (in Hz)
+strips(x,sd,fs,scale)
+Plots x in strips as above, and scales the vertical axis by scale
+If x is a matrix, strips uses a column vector of all the elements of x for the strip plot
+If x has complex entries, only the real part of those entries are considered
+Author
+Ankur Mallick
This function converts direct-form filter coefficients to series second-order sections.
+
+
+
Calling Sequence
+
[sos] = tf2sos (b, a)
+[sos, g] = tf2sos (b, a)
+
+
Parameters
+
b:
+
matrix of real numbers
+
a:
+
matrix of real numbers
+
+
Description
+
This is an Octave function.
+This function converts direct-form filter coefficients to series second-order sections.
+The input parameters b and a are vectors specifying the digital filter H(z) = B(z)/A(z).
+The output is the sos matrix and the overall gain.
+If there is only one output argument, the overall filter gain is applied to the first second-order section in the sos matrix.
This function returns the filter coefficients of a triangular window.
+
+
+
Calling Sequence
+
y = triang (m)
+
+
Parameters
+
m:
+
positive integer value
+
y:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a triangular window of length m supplied as input, to the output vector y.
This function generates a triangular pulse which is sampled at times t over the interval [-w/2,w/2]. The value of skew lies between -1
+and 1.
+The value of skew represents the relative placement of the peak in the given width.
This function returns the filter coefficients of a Tukey window.
+
+
+
Calling Sequence
+
w = tukeywin (m)
+w = tukeywin (m, r)
+
+
Parameters
+
m:
+
positive integer
+
r:
+
positive real number, between 0 and 1
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a Tukey window of length m supplied as input, to the output vector w.
+The second parameter r defines the ratio between the constant and cosine section and its value has to be between 0 and 1, with default value 0.5.
Uniformly decodes the input vector or n-dimensional array of integers u with peak values +/- v
+If u has only positive values, the range of integers is assumed to be [0,2^n-1]
+If u has positive and negative values the range of integers is assumed to be [-2^(n-1),2^(n-1)-1]
+If v is not specified, its default value is 1
+If saturatemode='wrap' the output is wrapped using modulo arithmetic if overflow occurs
+If saturatemode='saturate' the output is saturated if overflow accors
+Example
+u = int8([-1 1 2 -5]);
+ysat = udecode(u,3)
+ysat =
+
- 0.25 0.25 0.5 - 1.
+Author
+Ankur Mallick
+[1] International Telecommunication Union. General Aspects of Digital Transmission Systems: Vocabulary of Digital Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms. ITU-T Recommendation G.701. March, 1993.
Performs uniform quantization of the input into 2^n levels
+
+
+
Calling Sequence
+
y=uencode(u,n,v,'signflag')
+
+
Parameters
+
+
+
Description
+
Uniformly quantizes the input vector or n-dimensional array u into 2^n levels in the interval [-v,v]
+If v is not specified, its default value is 1
+'signflag' is a string that determines the nature of the quantization
+If signflag='unsigned' then y contains unsigned integers in the range [0,2^n-1] corresponding to the 2^n levels
+If signflag='unsigned' then y contains signed integers in the range [-2^(n-1),2^(n-1)-1] corresponding to the 2^n levels
+The size of the integers in y in bits(8,16, or 32) depends on the value of n
+If the input lies beyond +/- v it is saturated
+Example
+y=uencode(-1:0.5:1,3)
+y =
+
0 2 4 6 7
+Author
+Ankur Mallick
+References
+[1] International Telecommunication Union. General Aspects of Digital Transmission Systems: Vocabulary of Digital Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms. ITU-T Recommendation G.701. March, 1993.
This is an Octave function.
+This function returns the coefficients of an Ultraspherical window of length m supplied as input, to the output vector w.
+The second parameter controls the ratio between side lobe to side lobe of the window's Fourier transform.
+The third parameter controls the ratio between main lobe width to side lobe. The default value is beta.
+The value of xmu is also returned for given beta, att or latt.
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.
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.
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
+
This is an Octave function.
+This function upsamples a vector interleaving given values or copies of the vector elements.
+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.
y=vco(x,fc,fs)
+Creates a frequency modulated cosine wave y whose frequency varies as the magnitude of x
+x lies in [-1,1]. x=-1 corresponds to a frequency of 0, x=0 corresponds to a frequency of fc
+and x=1 corresponds to a frequency of 2fc.
+y=vco(x,[fmin fmax],fs)
+Scales the frequency range so that x=-1 corresponds to a frequency of fmin and
+x=1 corresponds to a frequency of fmax
+If x is a matrix the same operation is performed on the columns on x
+Size of y is the same as the size of x
+Example
+x=rand()
+x =
This function returns the filter coefficients of a Welch window.
+
+
+
Calling Sequence
+
w = welchwin (m)
+w = welchwin (m, opt)
+
+
Parameters
+
m:
+
positive integer value
+
opt:
+
string value, takes "periodic" or "symmetric"
+
w:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function returns the filter coefficients of a Welch window of length m supplied as input, to the output vector w.
+The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+For symmetric, the length should be an integer>2. For periodic, the length should be an integer>1.
This function creates an m-point window from the function f given as input.
+
+
+
Calling Sequence
+
w = window(f, m)
+w = window(f, m, opts)
+
+
Parameters
+
f:
+
string value
+
m:
+
positive integer value
+
opts:
+
string value, takes in "periodic" or "symmetric"
+
w:
+
output variable, vector of real numbers
+
+
Description
+
This is an Octave function.
+This function creates an m-point window from the function f given as input, in the output vector w.
+f can take any valid function as a string, for example "blackmanharris".
Real, complex or string type input vector or matrix
+
l:
+
Length of matrix required
+
opt:
+
Character input to determine which side to extract from
+
+
Description
+
This is an Octave function
+[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).
This is an Octave function.
+This function converts filter poles and zeros to second-order sections.
+The first and second parameters are column vectors containing zeros and poles. The third parameter is the overall filter gain, the default value of which is 1.
+The output is the sos matrix and the overall gain.
+If there is only one output argument, the overall filter gain is applied to the first second-order section in the sos matrix.
+
+
diff --git a/help/en_US/seqperiod.xml b/help/en_US/seqperiod.xml
new file mode 100644
index 0000000..f2f7e33
--- /dev/null
+++ b/help/en_US/seqperiod.xml
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
+ seqperiod
+ Calculates the period of a sequence
+
+
+
+
+ Calling Sequence
+
+ [p,num]=seqperiod(x)
+
+
+
+
+ Parameters
+
+ x:
+ A vector matrix or n-dimensional array
+
+
+
+
+ Description
+
+[p,num]=seqperiod(x)
+Returns an integer p such that x(1:p) is the smallest subsequence that repeats in x
+The number of times the subsequence repeats is returned in num (may not be an integer)
+Repetitions may be incomplete at the end of the sequence but no breaks are permitted between repetitions
+If there is no subsequence that repeats in x then p=length(x)
+If x is a matrix or n-dimesnional array, the function operates along the first non-singleton dimension of x
+
+
+
+
+ Examples
+
+
+
+
+ Authors
+
+ Ankur Mallick
+
+
+
diff --git a/help/en_US/sgolay.xml b/help/en_US/sgolay.xml
new file mode 100644
index 0000000..676b931
--- /dev/null
+++ b/help/en_US/sgolay.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+ sgolay
+ This function computes the filter coefficients for all Savitzsky-Golay smoothing filters.
+
+
+
+
+ Calling Sequence
+
+ F = sgolay (p, n)
+ F = sgolay (p, n, m)
+ F = sgolay (p, n, m, ts)
+
+
+
+
+ Parameters
+
+ p:
+ polynomial
+ n:
+ odd integer value, larger than polynomial p
+ m:
+ positive integer less than 2^31 or logical
+ ts:
+ real or complex value
+
+
+
+
+ Description
+
+This is an Octave function.
+This function computes the filter coefficients for all Savitzsky-Golay smoothing filters of order p for length n (odd).
+m can be used in order to get directly the mth derivative; ts is a scaling factor.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/sgolayfilt.xml b/help/en_US/sgolayfilt.xml
new file mode 100644
index 0000000..23ca7d5
--- /dev/null
+++ b/help/en_US/sgolayfilt.xml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+ sgolayfilt
+
+
+
+
+
+ Calling Sequence
+
+ y = sgolayfilt (x)
+ y = sgolayfilt (x, p)
+ y = sgolayfilt (x, p, n)
+ y = sgolayfilt (x, p, n, m)
+ y = sgolayfilt (x, p, n, m, ts)
+
+
+
+
+ Parameters
+
+ x:
+ vector or matrix of real or complex numbers
+ p:
+ polynomial order, real number less than n, default value 3
+ n:
+ integer, odd number greater than p
+ m:
+ vector of real positive valued numbers, length n
+ ts:
+ real number, default value 1
+
+
+
+
+ Description
+
+This function applies a Savitzky-Golay FIR smoothing filter to the data given in the vector x; if x is a matrix, this function operates
+on each column.
+The polynomial order p should be real, less than the size of the frame given by n.
+m is a weighting vector with default value identity matrix.
+ts is the dimenstion along which the filter operates. If not specified, the function operates along the first non singleton dimension.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/shanwavf.xml b/help/en_US/shanwavf.xml
new file mode 100644
index 0000000..3a633c3
--- /dev/null
+++ b/help/en_US/shanwavf.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+ shanwavf
+
+
+
+
+
+ Calling Sequence
+
+ [psi,x]=shanwavf(lb,ub,n,fb,fc)
+
+
+
+
+ Parameters
+
+ lb:
+ Real or complex valued vector or matrix
+ ub:
+ Real or complex valued vector or matrix
+ n:
+ Real valued integer strictly positive
+ fb:
+ Real or complex valued vector or matrix, strictly positive value for scalar input
+ fc:
+ Real or complex valued vector or matrix, strictly positive value for scalar input
+
+
+
+
+ Description
+
+This is an Octave function
+This function implements the complex Shannon wavelet function and returns the value obtained. The complex Shannon wavelet is defined by a bandwidth parameter FB, a wavelet center frequency FC on an N point regular grid in the interval [LB,UB].
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/shiftdata.xml b/help/en_US/shiftdata.xml
new file mode 100644
index 0000000..84bdb79
--- /dev/null
+++ b/help/en_US/shiftdata.xml
@@ -0,0 +1,99 @@
+
+
+
+
+
+
+
+ shiftdata
+ Shifts data by rearranging dimensions
+
+
+
+
+ Calling Sequence
+
+
+
+
+
+ Parameters
+
+
+
+
+
+ Description
+
+[y,perm,nshifts]=shiftdata(x,dim)
+Shifts the entries along dimension dim in x to the first column and returns the permutation vector in perm
+[y,perm,nshifts]=shiftdata(x)
+Shifts the entries along dimension dim in x to the first column and returns the number of shifts in nshifts
+
+
+
+
+ Examples
+
+
+
+
+ See also
+
+ permute
+ unshiftdata
+ Author
+ Mallick
+
+
+
diff --git a/help/en_US/slewrate.xml b/help/en_US/slewrate.xml
new file mode 100644
index 0000000..97afbfb
--- /dev/null
+++ b/help/en_US/slewrate.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ slewrate
+
+
+
+
diff --git a/help/en_US/sos2cell.xml b/help/en_US/sos2cell.xml
new file mode 100644
index 0000000..6e5da15
--- /dev/null
+++ b/help/en_US/sos2cell.xml
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+ sos2cell
+ Converts a second order section matrix to a cell array
+
+
+
+
+ Parameters
+
+
+
+
+
+ Description
+
+c=sos2cell(s) converts an L-by-6 second-order-section matrix s given by:
+s = [B1 A1
+B2 A2
+...
+BL AL]
+to a cell array c = { {B1},{A1}, {B2},{A2}, ... {BL},{AL}} where each
+numerator vector Bi and denominator vector Ai contains the coefficients of a
+linear or quadratic polynomial. If the polynomial is linear, the coefficients
+zero-padded on the right
+c=sos2cell(s,g) adds a leading gain term to the start of the cell array as:
+c={ {[g,1]},{B1},{A1}, {B2},{A2}, ... {BL},{AL}}
+Example
+s=rand(2,6)
+s =
+
+
+
+
+column 1 to 5
+
+
+0.0437334 0.2639556 0.2806498 0.7783129 0.1121355
+0.4818509 0.4148104 0.1280058 0.2119030 0.6856896
+
+
+column 6
+
+
+0.1531217
+0.6970851
+
+
+sos2cell(s,2)
+ans =
+
+
+
+
+
+
+column 1 to 3
+
+
+![2,1] [0.0437334,0.2639556,0.2806498] [0.7783129,0.1121355,0.1531217] !
+
+
+column 4 to 5
+
+
+![0.4818509,0.4148104,0.1280058] [0.2119030,0.6856896,0.6970851] !
+Author
+Ankur Mallick
+
+
+
diff --git a/help/en_US/sos2ss.xml b/help/en_US/sos2ss.xml
new file mode 100644
index 0000000..99a5812
--- /dev/null
+++ b/help/en_US/sos2ss.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ sos2ss
+ [nargout,nargin]=argn();
+
+
+
diff --git a/help/en_US/sos2tf.xml b/help/en_US/sos2tf.xml
new file mode 100644
index 0000000..4d4e48e
--- /dev/null
+++ b/help/en_US/sos2tf.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+ sos2tf
+ This function converts series second-order sections to direct H(z) = B(z)/A(z) form.
+
+
+
+
+ Calling Sequence
+
+ [B] = sos2tf(sos)
+ [B] = sos2tf(sos, g)
+ [B,A] = sos2tf(...)
+
+
+
+
+ Parameters
+
+ sos:
+ matrix of real or complex numbers
+ g:
+ real or complex value, default value is 1
+
+
+
+
+ Description
+
+This is an Octave function.
+This function converts series second-order sections to direct H(z) = B(z)/A(z) form.
+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
+
+
+
diff --git a/help/en_US/sos2zp.xml b/help/en_US/sos2zp.xml
new file mode 100644
index 0000000..efabf07
--- /dev/null
+++ b/help/en_US/sos2zp.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+ sos2zp
+ This function converts series second-order sections to zeros, poles, and gains (pole residues).
+
+
+
+
+ Calling Sequence
+
+ z = sos2zp (sos)
+ z = sos2zp (sos, g)
+ [z, p] = sos2zp (...)
+ [z, p, k] = sos2zp (...)
+
+
+
+
+ Parameters
+
+ sos:
+ matrix of real or complex numbers
+ g:
+ real or complex value, default value is 1
+ z:
+ column vector
+ p:
+ column vector
+
+
+
+
+ Description
+
+This is an Octave function.
+This function converts series second-order sections to zeros, poles, and gains (pole residues).
+The input is the sos matrix and the second parameter is the overall gain, default value of which is 1.
+The outputs are z, p, k. z and p are column vectors containing zeros and poles respectively, and k is the overall gain.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/sosbreak.xml b/help/en_US/sosbreak.xml
new file mode 100644
index 0000000..3957d94
--- /dev/null
+++ b/help/en_US/sosbreak.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ sosbreak
+ function for breaking a polynomial in second order polynomials (and an extra linear)
+
+
+
diff --git a/help/en_US/sosfilt.xml b/help/en_US/sosfilt.xml
new file mode 100644
index 0000000..25ce8aa
--- /dev/null
+++ b/help/en_US/sosfilt.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+ sosfilt
+
+
+
+
+
+ Calling Sequence
+
+ [y]=sosfilt(sos,x)
+
+
+
+
+ Parameters
+
+ sos:
+ Real or complex valued Lx6 vector or matrix
+ x:
+ Real or complex valued vector or matrix
+
+
+
+
+ Description
+
+This is an Octave function
+Second order section digital filter sos is applied to the input vector and the output vector obtained is of the same length.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/specgram.xml b/help/en_US/specgram.xml
new file mode 100644
index 0000000..a0215bb
--- /dev/null
+++ b/help/en_US/specgram.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ specgram
+
+
+
+
diff --git a/help/en_US/ss2sos.xml b/help/en_US/ss2sos.xml
new file mode 100644
index 0000000..b0cda76
--- /dev/null
+++ b/help/en_US/ss2sos.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ ss2sos
+ not taking if, order and scale as input since they do not seem useful
+
+
+
diff --git a/help/en_US/statelevels.xml b/help/en_US/statelevels.xml
new file mode 100644
index 0000000..70d7cfb
--- /dev/null
+++ b/help/en_US/statelevels.xml
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+ statelevels
+
+
+
+
+
+ Calling Sequence
+
+ levels=statelevels(x, nbins, method, bounds)
+ [levels histogram]=statelevels(x, nbins, method, bounds)
+ [levels histogram bins]=statelevels(x, nbins, method, bounds)
+ [levels histogram bins]=statelevels(x, nbins, method, bounds, 'fig', On or Off)
+
+
+
+
+ Parameters
+
+ x:
+ real vector
+ nbins:
+ number of histogram bins to use in the histogram as a positive scalar, where the default value is 100
+ method:
+ method to estimate the statelevels using specified METHOD as one of 'mean' or 'mode', where the default value is 'mode'
+ bounds:
+ specify the lower and upper bound for the histogram as a two-element row vector
+ fig:
+ specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.
+ levels:
+ return lower and upper level values
+ histogram:
+ return histogram values
+ bins:
+ return binlevels values
+
+
+
+
+ Examples
+
+
+
+
+ See also
+
+
+
+
+
+ Authors
+
+ Jitendra Singh
+
+
+
diff --git a/help/en_US/stmcb.xml b/help/en_US/stmcb.xml
new file mode 100644
index 0000000..2490a4b
--- /dev/null
+++ b/help/en_US/stmcb.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ stmcb
+ function [b,a] = stmcb( x, u_in, q, p, niter, a_in )
+
+
+
diff --git a/help/en_US/strips.xml b/help/en_US/strips.xml
new file mode 100644
index 0000000..f31e366
--- /dev/null
+++ b/help/en_US/strips.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+ strips
+ Plots vector or matrix in strips
+
+
+
+
+ Calling Sequence
+
+ strips(x);
+ strips(x,sd);
+ strips(x,sd,fs);
+ strips(x,sd,fs,scale);
+
+
+
+
+ Parameters
+
+
+
+
+
+ Description
+
+strips(x)
+Plots a vector x in horizontal strips of length 250
+If x is a matrix, it plots each column of x on a separate strip with the leftmost
+column as the topmost strip
+strips(x,sd)
+Plots x in strips of length sd samples each
+strips(x,sd,fs)
+Plots x in strips of duration sd seconds with sampling frequency fs (in Hz)
+strips(x,sd,fs,scale)
+Plots x in strips as above, and scales the vertical axis by scale
+If x is a matrix, strips uses a column vector of all the elements of x for the strip plot
+If x has complex entries, only the real part of those entries are considered
+Author
+Ankur Mallick
+
+
+
diff --git a/help/en_US/subspaceMethodsInputParser.xml b/help/en_US/subspaceMethodsInputParser.xml
new file mode 100644
index 0000000..908ead3
--- /dev/null
+++ b/help/en_US/subspaceMethodsInputParser.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ subspaceMethodsInputParser
+ Input parser to be used by pmusic and peig
+
+
+
diff --git a/help/en_US/tf2sos.xml b/help/en_US/tf2sos.xml
new file mode 100644
index 0000000..0c63687
--- /dev/null
+++ b/help/en_US/tf2sos.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+ tf2sos
+ This function converts direct-form filter coefficients to series second-order sections.
+
+
+
+
+ Calling Sequence
+
+ [sos] = tf2sos (b, a)
+ [sos, g] = tf2sos (b, a)
+
+
+
+
+ Parameters
+
+ b:
+ matrix of real numbers
+ a:
+ matrix of real numbers
+
+
+
+
+ Description
+
+This is an Octave function.
+This function converts direct-form filter coefficients to series second-order sections.
+The input parameters b and a are vectors specifying the digital filter H(z) = B(z)/A(z).
+The output is the sos matrix and the overall gain.
+If there is only one output argument, the overall filter gain is applied to the first second-order section in the sos matrix.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/tf2zp.xml b/help/en_US/tf2zp.xml
new file mode 100644
index 0000000..176e203
--- /dev/null
+++ b/help/en_US/tf2zp.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ tf2zp
+ [z,p,k]= tf2zp(b,a);
+
+
+
diff --git a/help/en_US/tf2zpk.xml b/help/en_US/tf2zpk.xml
new file mode 100644
index 0000000..3abb26c
--- /dev/null
+++ b/help/en_US/tf2zpk.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ tf2zpk
+ form
+
+
+
diff --git a/help/en_US/transpose.xml b/help/en_US/transpose.xml
new file mode 100644
index 0000000..a8d7108
--- /dev/null
+++ b/help/en_US/transpose.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ transpose
+ funcprot(0);
+
+
+
diff --git a/help/en_US/trial_iirlp2mb.xml b/help/en_US/trial_iirlp2mb.xml
new file mode 100644
index 0000000..b7364ca
--- /dev/null
+++ b/help/en_US/trial_iirlp2mb.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ trial_iirlp2mb
+ B = varargin(1)
+
+
+
diff --git a/help/en_US/triang.xml b/help/en_US/triang.xml
new file mode 100644
index 0000000..f351107
--- /dev/null
+++ b/help/en_US/triang.xml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+ triang
+ This function returns the filter coefficients of a triangular window.
+
+
+
+
+ Calling Sequence
+
+ y = triang (m)
+
+
+
+
+ Parameters
+
+ m:
+ positive integer value
+ y:
+ output variable, vector of real numbers
+
+
+
+
+ Description
+
+This is an Octave function.
+This function returns the filter coefficients of a triangular window of length m supplied as input, to the output vector y.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/tripuls.xml b/help/en_US/tripuls.xml
new file mode 100644
index 0000000..99282a0
--- /dev/null
+++ b/help/en_US/tripuls.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+ tripuls
+
+
+
+
+
+ Calling Sequence
+
+ [y] = tripuls(t)
+ [y] = tripuls(t,w)
+ [y] = tripuls(t,w,skew)
+
+
+
+
+ Parameters
+
+ t:
+ vector of real or complex numbers
+ w:
+ real or complex number
+ skew:
+ real number, -1 <= s <= 1
+
+
+
+
+ Description
+
+This function generates a triangular pulse which is sampled at times t over the interval [-w/2,w/2]. The value of skew lies between -1
+and 1.
+The value of skew represents the relative placement of the peak in the given width.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/truth.xml b/help/en_US/truth.xml
new file mode 100644
index 0000000..d6ede61
--- /dev/null
+++ b/help/en_US/truth.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ truth
+ y = %t
+
+
+
diff --git a/help/en_US/tukeywin.xml b/help/en_US/tukeywin.xml
new file mode 100644
index 0000000..c4983d3
--- /dev/null
+++ b/help/en_US/tukeywin.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+ tukeywin
+ This function returns the filter coefficients of a Tukey window.
+
+
+
+
+ Calling Sequence
+
+ w = tukeywin (m)
+ w = tukeywin (m, r)
+
+
+
+
+ Parameters
+
+ m:
+ positive integer
+ r:
+ positive real number, between 0 and 1
+
+
+
+
+ Description
+
+This is an Octave function.
+This function returns the filter coefficients of a Tukey window of length m supplied as input, to the output vector w.
+The second parameter r defines the ratio between the constant and cosine section and its value has to be between 0 and 1, with default value 0.5.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/udecode.xml b/help/en_US/udecode.xml
new file mode 100644
index 0000000..2a0e567
--- /dev/null
+++ b/help/en_US/udecode.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+ udecode
+ Decodes the input uniformly quantized values
+
+
+
+
+ Calling Sequence
+
+ y=uencode(u,n,v,'saturatemode')
+
+
+
+
+ Parameters
+
+
+
+
+
+ Description
+
+Uniformly decodes the input vector or n-dimensional array of integers u with peak values +/- v
+If u has only positive values, the range of integers is assumed to be [0,2^n-1]
+If u has positive and negative values the range of integers is assumed to be [-2^(n-1),2^(n-1)-1]
+If v is not specified, its default value is 1
+If saturatemode='wrap' the output is wrapped using modulo arithmetic if overflow occurs
+If saturatemode='saturate' the output is saturated if overflow accors
+Example
+u = int8([-1 1 2 -5]);
+ysat = udecode(u,3)
+ysat =
+
+
+- 0.25 0.25 0.5 - 1.
+Author
+Ankur Mallick
+[1] International Telecommunication Union. General Aspects of Digital Transmission Systems: Vocabulary of Digital Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms. ITU-T Recommendation G.701. March, 1993.
+
+
+
+
+ See also
+
+ uencode
+ floor
+
+
+
diff --git a/help/en_US/uencode.xml b/help/en_US/uencode.xml
new file mode 100644
index 0000000..b5cede1
--- /dev/null
+++ b/help/en_US/uencode.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+ uencode
+ Performs uniform quantization of the input into 2^n levels
+
+
+
+
+ Calling Sequence
+
+ y=uencode(u,n,v,'signflag')
+
+
+
+
+ Parameters
+
+
+
+
+
+ Description
+
+Uniformly quantizes the input vector or n-dimensional array u into 2^n levels in the interval [-v,v]
+If v is not specified, its default value is 1
+'signflag' is a string that determines the nature of the quantization
+If signflag='unsigned' then y contains unsigned integers in the range [0,2^n-1] corresponding to the 2^n levels
+If signflag='unsigned' then y contains signed integers in the range [-2^(n-1),2^(n-1)-1] corresponding to the 2^n levels
+The size of the integers in y in bits(8,16, or 32) depends on the value of n
+If the input lies beyond +/- v it is saturated
+Example
+y=uencode(-1:0.5:1,3)
+y =
+
+
+0 2 4 6 7
+Author
+Ankur Mallick
+References
+[1] International Telecommunication Union. General Aspects of Digital Transmission Systems: Vocabulary of Digital Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms. ITU-T Recommendation G.701. March, 1993.
+
+
+
+
+ See also
+
+ udecode
+ floor
+
+
+
diff --git a/help/en_US/ultrwin.xml b/help/en_US/ultrwin.xml
new file mode 100644
index 0000000..16c6400
--- /dev/null
+++ b/help/en_US/ultrwin.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+ ultrwin
+ This function returns the coefficients of an Ultraspherical window.
+
+
+
+
+ Calling Sequence
+
+ w = ultrwin (m, mu, par)
+ w = ultrwin (m, mu, par, key)
+ w = ultrwin (m, mu, par, key, norm)
+ [w, xmu] = ultrwin (...)
+
+
+
+
+ Parameters
+
+ m:
+ positive integer value
+ mu:
+
+ par:
+
+ key:
+
+ norm:
+
+
+
+
+
+ Description
+
+This is an Octave function.
+This function returns the coefficients of an Ultraspherical window of length m supplied as input, to the output vector w.
+The second parameter controls the ratio between side lobe to side lobe of the window's Fourier transform.
+The third parameter controls the ratio between main lobe width to side lobe. The default value is beta.
+The value of xmu is also returned for given beta, att or latt.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/unshiftdata.xml b/help/en_US/unshiftdata.xml
new file mode 100644
index 0000000..57e0408
--- /dev/null
+++ b/help/en_US/unshiftdata.xml
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+ unshiftdata
+ Inverts the effect of shiftdata
+
+
+
+
+ Calling Sequence
+
+
+
+
+
+ Parameters
+
+
+
+
+
+ Description
+
+y=unshiftdata(x,perm,nshifts)
+Applies the permutation perm or number of shifts nshifts on x to invert shiftdata
+
+
+
+
+ Examples
+
+
+
+
+ See also
+
+
+
+
diff --git a/help/en_US/upfirdn.xml b/help/en_US/upfirdn.xml
new file mode 100644
index 0000000..6688531
--- /dev/null
+++ b/help/en_US/upfirdn.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+ upfirdn
+ 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
+
+
+
diff --git a/help/en_US/upsample.xml b/help/en_US/upsample.xml
new file mode 100644
index 0000000..3d73473
--- /dev/null
+++ b/help/en_US/upsample.xml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+ upsample
+ 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
+
+
+
diff --git a/help/en_US/upsamplefill.xml b/help/en_US/upsamplefill.xml
new file mode 100644
index 0000000..8a6e352
--- /dev/null
+++ b/help/en_US/upsamplefill.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+ upsamplefill
+ 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
+ w:
+ scalar or vector of real or complex values
+ cpy:
+ can take in "true" or "false", default is false
+
+
+
+
+ Description
+
+This is an Octave function.
+This function upsamples a vector interleaving given values or copies of the vector elements.
+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
+
+
+
diff --git a/help/en_US/var.xml b/help/en_US/var.xml
new file mode 100644
index 0000000..53bc9bc
--- /dev/null
+++ b/help/en_US/var.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+ var
+
+
+
+
+
+ Calling Sequence
+
+ y=var(x)
+ y=var(x,w)
+ y=var(x,w,dim)
+
+
+
+
+ Parameters
+
+ x:
+ a vector or matrix.
+ w:
+ weight vector W of length X, or may take the value of 0 and 1. The default value is 0. Consider only non-negative values.
+ dim:
+ consider the variance along the dimension of X. 1 for clumun wise variamce and 2 for row wise variance.
+ y:
+ returns the variance of the values in X.
+
+
+
diff --git a/help/en_US/vco.xml b/help/en_US/vco.xml
new file mode 100644
index 0000000..44310c1
--- /dev/null
+++ b/help/en_US/vco.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+ vco
+ Voltage Controlled Oscillator
+
+
+
+
+ Calling Sequence
+
+ y=vco(x,fc,fs)
+ y=vco(x,[fmin fmax],fs)
+
+
+
+
+ Parameters
+
+
+
+
+
+ Description
+
+y=vco(x,fc,fs)
+Creates a frequency modulated cosine wave y whose frequency varies as the magnitude of x
+x lies in [-1,1]. x=-1 corresponds to a frequency of 0, x=0 corresponds to a frequency of fc
+and x=1 corresponds to a frequency of 2fc.
+y=vco(x,[fmin fmax],fs)
+Scales the frequency range so that x=-1 corresponds to a frequency of fmin and
+x=1 corresponds to a frequency of fmax
+If x is a matrix the same operation is performed on the columns on x
+Size of y is the same as the size of x
+Example
+x=rand()
+x =
+
+
+0.2113249
+y=vco(x,2000,8000)
+y =
+
+
+0.9454092
+Author
+Ankur Mallick
+
+
+
diff --git a/help/en_US/welchwin.xml b/help/en_US/welchwin.xml
new file mode 100644
index 0000000..aad08db
--- /dev/null
+++ b/help/en_US/welchwin.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+ welchwin
+ This function returns the filter coefficients of a Welch window.
+
+
+
+
+ Calling Sequence
+
+ w = welchwin (m)
+ w = welchwin (m, opt)
+
+
+
+
+ Parameters
+
+ m:
+ positive integer value
+ opt:
+ string value, takes "periodic" or "symmetric"
+ w:
+ output variable, vector of real numbers
+
+
+
+
+ Description
+
+This is an Octave function.
+This function returns the filter coefficients of a Welch window of length m supplied as input, to the output vector w.
+The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+For symmetric, the length should be an integer>2. For periodic, the length should be an integer>1.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/window.xml b/help/en_US/window.xml
new file mode 100644
index 0000000..19d4312
--- /dev/null
+++ b/help/en_US/window.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+ window
+ This function creates an m-point window from the function f given as input.
+
+
+
+
+ Calling Sequence
+
+ w = window(f, m)
+ w = window(f, m, opts)
+
+
+
+
+ Parameters
+
+ f:
+ string value
+ m:
+ positive integer value
+ opts:
+ string value, takes in "periodic" or "symmetric"
+ w:
+ output variable, vector of real numbers
+
+
+
+
+ Description
+
+This is an Octave function.
+This function creates an m-point window from the function f given as input, in the output vector w.
+f can take any valid function as a string, for example "blackmanharris".
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/wkeep.xml b/help/en_US/wkeep.xml
new file mode 100644
index 0000000..3bac5e2
--- /dev/null
+++ b/help/en_US/wkeep.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+ wkeep
+
+
+
+
+
+ Calling Sequence
+
+ [y]=wkeep(x,l)
+ [y]=wkeep(x,l,opt)
+
+
+
+
+ Parameters
+
+ x:
+ Real, complex or string type input vector or matrix
+ l:
+ Length of matrix required
+ opt:
+ Character input to determine which side to extract from
+
+
+
+
+ Description
+
+This is an Octave function
+[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).
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/wrev.xml b/help/en_US/wrev.xml
new file mode 100644
index 0000000..2068027
--- /dev/null
+++ b/help/en_US/wrev.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+ wrev
+
+
+
+
+
+ Calling Sequence
+
+ [y]=wrev(x)
+
+
+
+
+ Parameters
+
+ x:
+ Input vector of string, real or complex values
+
+
+
+
+ Description
+
+This is an Octave function.
+This function reverses the order of elements of the input vector x.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/xcorr2.xml b/help/en_US/xcorr2.xml
new file mode 100644
index 0000000..3768635
--- /dev/null
+++ b/help/en_US/xcorr2.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+ xcorr2
+
+
+
+
+
+ Calling Sequence
+
+ c = xcorr2 (a)
+ c = xcorr2 (a, b)
+ c = xcorr2 (a, b, biasflag)
+
+
+
diff --git a/help/en_US/zerocrossing.xml b/help/en_US/zerocrossing.xml
new file mode 100644
index 0000000..5109f99
--- /dev/null
+++ b/help/en_US/zerocrossing.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+ zerocrossing
+ This function estimates the points at which a given waveform crosses the x-axis.
+
+
+
+
+ Calling Sequence
+
+ x = zerocrossing (w, y)
+
+
+
+
+ Parameters
+
+ w:
+
+ y:
+
+ x:
+
+
+
+
+
+ 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
+
+
+
diff --git a/help/en_US/zp2sos.xml b/help/en_US/zp2sos.xml
new file mode 100644
index 0000000..1f57c0b
--- /dev/null
+++ b/help/en_US/zp2sos.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+ zp2sos
+ This function converts filter poles and zeros to second-order sections.
+
+
+
+
+ Calling Sequence
+
+ [sos] = zp2sos(z)
+ [sos] = zp2sos(z, p)
+ [sos] = zp2sos(z, p, k)
+ [sos, g] = zp2sos(...)
+
+
+
+
+ Parameters
+
+ z:
+ column vector
+ p:
+ column vector
+ k:
+ real or complex value, default value is 1
+
+
+
+
+ Description
+
+This is an Octave function.
+This function converts filter poles and zeros to second-order sections.
+The first and second parameters are column vectors containing zeros and poles. The third parameter is the overall filter gain, the default value of which is 1.
+The output is the sos matrix and the overall gain.
+If there is only one output argument, the overall filter gain is applied to the first second-order section in the sos matrix.
+
+
+
+
+ Examples
+
+
+
diff --git a/help/en_US/zplane.xml b/help/en_US/zplane.xml
new file mode 100644
index 0000000..64a7172
--- /dev/null
+++ b/help/en_US/zplane.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ zplane
+ funcprot(0);
+
+
+
diff --git a/jar/scilab_en_US_help.jar b/jar/scilab_en_US_help.jar
new file mode 100644
index 0000000..4b15c19
Binary files /dev/null and b/jar/scilab_en_US_help.jar differ
diff --git a/loader.sce b/loader.sce
new file mode 100644
index 0000000..2d835fa
--- /dev/null
+++ b/loader.sce
@@ -0,0 +1,10 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce: Please, do not edit this file
+
+try
+ getversion("scilab");
+catch
+ error("Scilab 5.0 or more is required.");
+end;
+
+exec(get_absolute_file_path("loader.sce")+"etc/"+"FOSSEE_Signal_Processing_Toolbox.start");
diff --git a/macros/README.md b/macros/README.md
new file mode 100644
index 0000000..35c430c
--- /dev/null
+++ b/macros/README.md
@@ -0,0 +1,2 @@
+# callOctave
+Wrapper classes for calling Octave functions
diff --git a/macros/ac2poly.bin b/macros/ac2poly.bin
new file mode 100644
index 0000000..5df28ee
Binary files /dev/null and b/macros/ac2poly.bin differ
diff --git a/macros/ac2poly.sci b/macros/ac2poly.sci
new file mode 100644
index 0000000..ef7b233
--- /dev/null
+++ b/macros/ac2poly.sci
@@ -0,0 +1,30 @@
+function [a,varargout] = ac2poly(r)
+// Convert autocorrelation sequence to polynomial of prediction filter
+//
+// Calling Sequence
+// a = ac2poly(r)
+// [a,e] = ac2poly(r)
+//
+// Parameters
+// r: Autocorrelation sequence to be represented with an FIR linear prediction filter
+// a: Output polynomial representing the linear prediction filter e/(a(1) + a(2)z + a(3)z^2 .. a(N)z^N-1)
+// e: Output scaling for the lienar prediction filter
+//
+// Description
+// Function ac2poly() finds the best fit polynomial for FIR linear prediction filter a, corresponding to the autocorrelation sequence r. a is the same length as r, and is normalized with the first element. So a(1) = 1.
+//
+// Author
+// Parthe Pandit
+//
+// Bibliography
+// Kay, Steven M. Modern Spectral Estimation. Englewood Cliffs, NJ: Prentice-Hall, 1988.
+
+//errcheck
+if (type(r) > 1) then
+ error('Input autocorrelation sequence needs to be of type double');
+end
+
+[a,e] = levinson(r);
+varargout = list(e);
+
+endfunction
diff --git a/macros/ac2poly.sci~ b/macros/ac2poly.sci~
new file mode 100644
index 0000000..653ccce
--- /dev/null
+++ b/macros/ac2poly.sci~
@@ -0,0 +1,29 @@
+function [a,varargout] = ac2poly(r)
+// Convert autocorrelation sequence to polynomial of prediction filter
+//
+// Calling Sequence
+// a = ac2poly(r)
+// [a,e] = ac2poly(r)
+//
+// Parameters
+// r: Autocorrelation sequence to be represented with an FIR linear prediction filter
+// a: Output polynomial representing the linear prediction filter e/(a(1) + a(2)z + a(3)z^2 .. a(N)z^N-1)
+// e: Output scaling for the lienar prediction filter
+//
+// Description
+// Function ac2poly() finds the best fit polynomial for FIR linear prediction filter a, corresponding to the autocorrelation sequence r. a is the same length as r, and is normalized with the first element. So a(1) = 1.
+// Author:
+// Parthe Pandit
+//
+// Bibliography
+// Kay, Steven M. Modern Spectral Estimation. Englewood Cliffs, NJ: Prentice-Hall, 1988.
+
+//errcheck
+if (type(r) > 1) then
+ error('Input autocorrelation sequence needs to be of type double');
+end
+
+[a,e] = levinson(r);
+varargout = list(e);
+
+endfunction
diff --git a/macros/ac2rc.bin b/macros/ac2rc.bin
new file mode 100644
index 0000000..fbfb4f1
Binary files /dev/null and b/macros/ac2rc.bin differ
diff --git a/macros/ac2rc.sci b/macros/ac2rc.sci
new file mode 100644
index 0000000..46de215
--- /dev/null
+++ b/macros/ac2rc.sci
@@ -0,0 +1,51 @@
+function [k,R0] = ac2rc(R)
+// Convert autocorrelation sequence to reflection coefficients.
+//
+// Calling Sequence
+// k = ac2rc(R)
+// [k,R0] = ac2rc(R)
+//
+// Parameters
+// R: The input autocorrelation sequence. If r is a matrix, each column of r is treated as a separate signal.
+// k: Returns the reflection coefficients
+// R0: the zero lag autocorrelation, R0, based on the autocorrelation sequence, R.
+//
+// Examples
+// X = [7 6 5 8 3 6 8 7 5 2 4 7 4 3 2 5 4 9 5 3 5 7 3 9 4 1 2 0 5 4 8 6 4 6 5 3];
+// [k,R0] = ac2rc(X)
+// or t=[2 5 6; 8 6 5; 8 9 4]
+// [k,R0] = ac2rc(t)
+//
+// Author
+// Jitendra Singh
+//
+
+ // call function "levin" before running this function
+
+if or(type(R)==10) then
+ error ('Input arguments must be double.')
+end
+
+if isvector(R) then
+ R=R(:);
+
+ [x,y,z] = levin(R)
+k=z;
+R0=R;
+
+else
+ n=size(R);
+
+ for i=1:n(2)
+ r=R(:,i);
+
+ [x,y, z] = levin(r)
+
+ kk(:,i)= z;
+
+k=kk;
+R0=R(1,:);
+ end
+
+ end
+endfunction
diff --git a/macros/ac2rc.sci~ b/macros/ac2rc.sci~
new file mode 100644
index 0000000..bace840
--- /dev/null
+++ b/macros/ac2rc.sci~
@@ -0,0 +1,47 @@
+function [k,R0] = ac2rc(R)
+// Convert autocorrelation sequence to reflection coefficients.
+// Calling Sequence
+// k = ac2rc(R)
+// [k,R0] = ac2rc(R)
+// Parameters
+// R: The input autocorrelation sequence. If r is a matrix, each column of r is treated as a separate signal.
+// k: Returns the reflection coefficients
+// R0: the zero lag autocorrelation, R0, based on the autocorrelation sequence, R.
+// Examples
+// X = [7 6 5 8 3 6 8 7 5 2 4 7 4 3 2 5 4 9 5 3 5 7 3 9 4 1 2 0 5 4 8 6 4 6 5 3];
+// [k,R0] = ac2rc(X)
+// or t=[2 5 6; 8 6 5; 8 9 4]
+// [k,R0] = ac2rc(t)
+// Author
+// Jitendra Singh
+//
+
+ // call function "levin" before running this function
+
+if or(type(R)==10) then
+ error ('Input arguments must be double.')
+end
+
+if isvector(R) then
+ R=R(:);
+
+ [x,y,z] = levin(R)
+k=z;
+R0=R;
+
+else
+ n=size(R);
+
+ for i=1:n(2)
+ r=R(:,i);
+
+ [x,y, z] = levin(r)
+
+ kk(:,i)= z;
+
+k=kk;
+R0=R(1,:);
+ end
+
+ end
+endfunction
diff --git a/macros/arParEst.bin b/macros/arParEst.bin
new file mode 100644
index 0000000..354bcea
Binary files /dev/null and b/macros/arParEst.bin differ
diff --git a/macros/arParEst.sci b/macros/arParEst.sci
new file mode 100644
index 0000000..971bc45
--- /dev/null
+++ b/macros/arParEst.sci
@@ -0,0 +1,83 @@
+function [model_est, var_est, msg_strg] = arParEst(data_in, order, method)
+
+ checkNArgin(3, 3, argn(2))
+
+ model_est = [];
+ var_est = [];
+
+ if isvector(data_in) then
+ data_in = data_in(:);
+ end
+
+ select method
+ case 'covariance' then
+ x_min_len = 2*order;
+ case 'modified' then
+ x_min_len = (3*order)/2;
+ else
+ msg_strg = 'Error in function arParEst: Unknown estimation method'
+ return;
+ end
+
+ if size(data_in, 1)< x_min_len then
+ if (strcmp(method, 'covariance') == 0) then
+ if isvector(data_in) then
+ msg_strg = 'length of input vector should be greater than 2 times of the input order of the model'
+ return
+ else
+ msg_strg = 'number of rows in input matrix should be greater than 2 times of the input order of the model'
+ return
+ end
+
+ elseif (strcmp(method, 'modified') == 0) then
+ if isvector(data_in) then
+ msg_strg = 'length of input vector should be greater than 3/2 times of the input order of the model'
+ return
+ else
+ msg_strg = 'number of rows in input matrix should be greater than 3/2 times of the input order of the model'
+ return
+ end
+ end
+ end
+
+ if issparse(data_in) then
+ msg_strg = 'Input data should not be sparse';
+ return
+ end
+
+ if isempty(order) | order ~= round(order) then
+ msg_strg = 'Model order should be an integer';
+ return
+ end
+
+ msg_strg = [];
+ model_est = zeros((order + 1), size(data_in, 2));
+ var_est = zeros(1, size(data_in, 2));
+
+ for i = 1: size(data_in, 2)
+ data_corrmtx = corrmtx(data_in(:, i), order, method);
+ data_allcols = data_corrmtx(:, 2:size(data_corrmtx,2));
+ data_sincol = data_corrmtx(:, 1);
+
+ model_est(:, i) = [1; -data_allcols\data_sincol];
+
+ var_tmp = data_sincol'*data_allcols;
+ var_est(:, i) = data_sincol'*data_sincol + var_tmp*model_est(2:size(model_est, 1), i);
+
+ var_est(:, i) = abs(real(var_est(:, i)));
+ end
+
+ model_est = model_est.';
+
+
+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
+
+endfunction
diff --git a/macros/arburg.bin b/macros/arburg.bin
new file mode 100644
index 0000000..3d5ebe9
Binary files /dev/null and b/macros/arburg.bin differ
diff --git a/macros/arburg.sci b/macros/arburg.sci
new file mode 100644
index 0000000..de4dcbb
--- /dev/null
+++ b/macros/arburg.sci
@@ -0,0 +1,57 @@
+function varargout = arburg( x, poles, criterion )
+//This function calculates coefficients of an autoregressive (AR) model of complex data.
+//Calling Sequence
+//a = arburg(x, poles)
+//a = arburg(x, poles, criterion)
+//[a, v] = arburg(...)
+//[a, v, k] = arburg(...)
+//Parameters
+//x: vector of real or complex numbers, of length > 2
+//poles: positive integer value < length(x) - 2
+//criterion: string value, takes in "AKICc", "KIC", "AICc", "AIC" and "FPE", default it not using a model-selection criterion
+//a, v, k: Output variables
+//Description
+//This is an Octave function.
+//
+//This function calculates coefficients of an autoregressive (AR) model of complex data x using the whitening lattice-filter method of Burg.
+//
+//The first argument is the data sampled. The second argument is the number of poles in the model (or limit in case a criterion is supplied).
+//The third parameter takes in the criterion to limit the number of poles. The acceptable values are "AIC", "AKICc", "KIC", "AICc" which are based on information theory.
+//Output variable a is a list of P+1 autoregression coefficients.
+//Output variable v is the mean square of residual noise from the whitening operation of the Burg lattice filter.
+//Output variable k corresponds to the reflection coefficients defining the lattice-filter embodiment of the model.
+//Examples
+//arburg([1,2,3,4,5],2)
+//ans =
+// 1.00000 -1.86391 0.95710
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+if(lhs>3)
+error("Wrong number of output arguments.")
+elseif(rhs<2)
+error("Wrong number of input arguments.")
+end
+
+ select(lhs)
+ case 1 then
+ if(rhs==2)
+ a = callOctave("arburg",x,poles)
+ elseif(rhs==3)
+ a = callOctave("arburg",x,poles,criterion)
+ end
+ case 2 then
+ if(rhs==2)
+ [a,v] = callOctave("arburg",x,poles)
+ elseif(rhs==3)
+ [a,v] = callOctave("arburg",x,poles,criterion)
+ end
+ case 3 then
+ if(rhs==2)
+ [a,v,k] = callOctave("arburg",x,poles)
+ elseif(rhs==3)
+ [a,v,k] = callOctave("arburg",x,poles,criterion)
+ end
+ end
+endfunction
diff --git a/macros/arburg.sci~ b/macros/arburg.sci~
new file mode 100644
index 0000000..1ca6e01
--- /dev/null
+++ b/macros/arburg.sci~
@@ -0,0 +1,55 @@
+function varargout = arburg( x, poles, criterion )
+//This function calculates coefficients of an autoregressive (AR) model of complex data.
+//Calling Sequence
+//a = arburg(x, poles)
+//a = arburg(x, poles, criterion)
+//[a, v] = arburg(...)
+//[a, v, k] = arburg(...)
+//Parameters
+//x: vector of real or complex numbers, of length > 2
+//poles: positive integer value < length(x) - 2
+//criterion: string value, takes in "AKICc", "KIC", "AICc", "AIC" and "FPE", default it not using a model-selection criterion
+//a, v, k: Output variables
+//Description
+//This is an Octave function.
+//This function calculates coefficients of an autoregressive (AR) model of complex data x using the whitening lattice-filter method of Burg.
+//The first argument is the data sampled. The second argument is the number of poles in the model (or limit in case a criterion is supplied).
+//The third parameter takes in the criterion to limit the number of poles. The acceptable values are "AIC", "AKICc", "KIC", "AICc" which are based on information theory.
+//Output variable a is a list of P+1 autoregression coefficients.
+//Output variable v is the mean square of residual noise from the whitening operation of the Burg lattice filter.
+//Output variable k corresponds to the reflection coefficients defining the lattice-filter embodiment of the model.
+//Examples
+//arburg([1,2,3,4,5],2)
+//ans =
+// 1.00000 -1.86391 0.95710
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+if(lhs>3)
+error("Wrong number of output arguments.")
+elseif(rhs<2)
+error("Wrong number of input arguments.")
+end
+
+ select(lhs)
+ case 1 then
+ if(rhs==2)
+ a = callOctave("arburg",x,poles)
+ elseif(rhs==3)
+ a = callOctave("arburg",x,poles,criterion)
+ end
+ case 2 then
+ if(rhs==2)
+ [a,v] = callOctave("arburg",x,poles)
+ elseif(rhs==3)
+ [a,v] = callOctave("arburg",x,poles,criterion)
+ end
+ case 3 then
+ if(rhs==2)
+ [a,v,k] = callOctave("arburg",x,poles)
+ elseif(rhs==3)
+ [a,v,k] = callOctave("arburg",x,poles,criterion)
+ end
+ end
+endfunction
diff --git a/macros/arcov.bin b/macros/arcov.bin
new file mode 100644
index 0000000..f0ef408
Binary files /dev/null and b/macros/arcov.bin differ
diff --git a/macros/arcov.sci b/macros/arcov.sci
new file mode 100644
index 0000000..b6d11cc
--- /dev/null
+++ b/macros/arcov.sci
@@ -0,0 +1,34 @@
+function [ar_coeff, var_est] = arcov(data_in, order)
+//Autoregressive all-pole model parameters — covariance method
+//Calling Sequence
+//a = arcov(x,p)
+//[a,e] = arcov(x,p)
+//Parameters
+// a: contains normalized estimates of the AR system parameters, A(z), in descending powers of z.
+// e: variance estimate of the white noise input to the AR model
+// x: is the input signal
+// p: is the order of the auto regressive model
+
+ checkNArgin(2,2, argn(2));
+ if type(data_in)==10 then
+ error("Input should not be of type char");
+ end
+ method = 'covariance';
+ [ar_coeff, var_est, msg] = arParEst(data_in, order, method);
+ if ~isempty(msg) then
+ error(msg);
+ end
+
+
+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
+
+endfunction
diff --git a/macros/arcov.sci~ b/macros/arcov.sci~
new file mode 100644
index 0000000..179e34a
--- /dev/null
+++ b/macros/arcov.sci~
@@ -0,0 +1,33 @@
+function [ar_coeff, var_est] = arcov(data_in, order)
+//arcov Autoregressive all-pole model parameters — covariance method
+//Calling Syntax
+//a = arcov(x,p)
+//[a,e] = arcov(x,p)
+//a, contains normalized estimates of the AR system parameters, A(z), in descending powers of z.
+//e variance estimate of the white noise input to the AR model
+// x is the input signal
+// p is the order of the auto regressive model
+
+ checkNArgin(2,2, argn(2));
+ if type(data_in)==10 then
+ error("Input should not be of type char");
+ end
+ method = 'covariance';
+ [ar_coeff, var_est, msg] = arParEst(data_in, order, method);
+ if ~isempty(msg) then
+ error(msg);
+ end
+
+
+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
+
+endfunction
diff --git a/macros/armcov.bin b/macros/armcov.bin
new file mode 100644
index 0000000..6465aab
Binary files /dev/null and b/macros/armcov.bin differ
diff --git a/macros/armcov.sci b/macros/armcov.sci
new file mode 100644
index 0000000..0c5158c
--- /dev/null
+++ b/macros/armcov.sci
@@ -0,0 +1,22 @@
+function [ar_coeff, var_est] = armcov(data_in, order)
+
+ checkNArgin(2,2, argn(2));
+ method = 'modified';
+ [ar_coeff, var_est, msg] = arParEst(data_in, order, method);
+ if ~isempty(msg) then
+ error(msg);
+ end
+
+
+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
+
+endfunction
diff --git a/macros/aryule.bin b/macros/aryule.bin
new file mode 100644
index 0000000..c902718
Binary files /dev/null and b/macros/aryule.bin differ
diff --git a/macros/aryule.sci b/macros/aryule.sci
new file mode 100644
index 0000000..e752ced
--- /dev/null
+++ b/macros/aryule.sci
@@ -0,0 +1,39 @@
+function [a, v, k] = aryule (x, p)
+//This function fits an AR (p)-model with Yule-Walker estimates.
+//Calling Sequence
+//a = aryule (x, p)
+//[a, v] = aryule (x, p)
+//[a, v, k] = aryule (x, p)
+//Parameters
+//x: vector of real or complex numbers, length > 2
+//p: positive integer value < length(x) - 1
+//a, v, k: Output variables
+//Description
+//This is an Octave function.
+//
+//This function fits an AR (p)-model with Yule-Walker estimates.
+//The first argument is the data vector which is to be estimated.
+//Output variable a gives the AR coefficients, v gives the variance of the white noise and k gives the reflection coefficients to be used in the lattice filter.
+//Examples
+//aryule([1,2,3,4,5],2)
+//ans =
+// 1. - 0.8140351 0.1192982
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+
+if(rhs~=2)
+error("Wrong number of input arguments.")
+end
+
+ select(lhs)
+ case 1 then
+ a = callOctave("aryule",x,p)
+ case 2 then
+ [a,v] = callOctave("aryule",x,p)
+ case 3 then
+ [a,v,k] = callOctave("aryule",x,p)
+ end
+
+endfunction
diff --git a/macros/aryule.sci~ b/macros/aryule.sci~
new file mode 100644
index 0000000..c933340
--- /dev/null
+++ b/macros/aryule.sci~
@@ -0,0 +1,38 @@
+function [a, v, k] = aryule (x, p)
+//This function fits an AR (p)-model with Yule-Walker estimates.
+//Calling Sequence
+//a = aryule (x, p)
+//[a, v] = aryule (x, p)
+//[a, v, k] = aryule (x, p)
+//Parameters
+//x: vector of real or complex numbers, length > 2
+//p: positive integer value < length(x) - 1
+//a, v, k: Output variables
+//Description
+//This is an Octave function.
+//This function fits an AR (p)-model with Yule-Walker estimates.
+//The first argument is the data vector which is to be estimated.
+//Output variable a gives the AR coefficients, v gives the variance of the white noise and k gives the reflection coefficients to be used in the lattice filter.
+//Examples
+//aryule([1,2,3,4,5],2)
+//ans =
+// 1. - 0.8140351 0.1192982
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+
+if(rhs~=2)
+error("Wrong number of input arguments.")
+end
+
+ select(lhs)
+ case 1 then
+ a = callOctave("aryule",x,p)
+ case 2 then
+ [a,v] = callOctave("aryule",x,p)
+ case 3 then
+ [a,v,k] = callOctave("aryule",x,p)
+ end
+
+endfunction
diff --git a/macros/barthannwin.bin b/macros/barthannwin.bin
new file mode 100644
index 0000000..1b9ed25
Binary files /dev/null and b/macros/barthannwin.bin differ
diff --git a/macros/barthannwin.sci b/macros/barthannwin.sci
new file mode 100644
index 0000000..7ba7017
--- /dev/null
+++ b/macros/barthannwin.sci
@@ -0,0 +1,28 @@
+function y = barthannwin(m)
+//This function returns the filter coefficients of a modified Bartlett-Hann window.
+//Calling Sequence
+//y = barthannwin(m)
+//Parameters
+//m: positive integer value
+//y: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a modified Bartlett Hann window of length m supplied as input, to the output vector y.
+//Examples
+//barthannwin(4)
+//ans =
+// 0.
+// 0.73
+// 0.73
+// 0.
+
+funcprot(0);
+rhs = argn(2)
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+
+y = callOctave("barthannwin",m)
+
+endfunction
+
diff --git a/macros/bartlett.bin b/macros/bartlett.bin
new file mode 100644
index 0000000..373d8c0
Binary files /dev/null and b/macros/bartlett.bin differ
diff --git a/macros/bartlett.sci b/macros/bartlett.sci
new file mode 100644
index 0000000..b450e7c
--- /dev/null
+++ b/macros/bartlett.sci
@@ -0,0 +1,35 @@
+function w=bartlett(L)
+//Generates a Bartlett window
+//Calling Sequence
+//w=bartlett(L)
+//Parameters
+//L
+//A positive integer describing the length of the bartlett window
+//Description
+//w=bartlett(L) returns an L-point Bartlett window in a column vector w
+//Example
+//w=bartlett(4)
+// w =
+//
+// 0.
+// 0.6666667
+// 0.6666667
+// 0.
+//Author
+//Ankur Mallick
+//References
+//[1] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1999.
+ funcprot(0);
+ if(argn(2)~=1)
+ error('Incorrect number of input arguments.');
+ elseif(~isscalar(L)|L<=0|round(L)~=L)
+ error('L must be a positive integer')
+ elseif(L==1)
+ w=1; //Trivial case
+ else
+ N=L-1;
+ w1=2*(0:1:N/2)/N;
+ w2=2-2*(floor(N/2)+1:1:N)/N; //floor used to adjust for odd/even
+ w=[w1, w2]';
+ end
+endfunction
diff --git a/macros/besself.bin b/macros/besself.bin
new file mode 100644
index 0000000..69dbfd2
Binary files /dev/null and b/macros/besself.bin differ
diff --git a/macros/besself.sci b/macros/besself.sci
new file mode 100644
index 0000000..f65b12a
--- /dev/null
+++ b/macros/besself.sci
@@ -0,0 +1,53 @@
+function [a, b, c, d] = besself (n, w, varargin)
+//This function generates a Bessel filter.
+//Calling Sequence
+//[a, b] = besself(n, w)
+//[a, b] = besself (n, w, "high")
+//[a, b, c] = besself (…)
+//[a, b, c, d] = besself (…)
+//[…] = besself (…, "z")
+//Parameters
+//n: positive integer value
+//w: positive real value
+//Description
+//This is an Octave function.
+//This function generates a Bessel filter. The default is a Laplace space (s) filter.
+//The third parameter takes in high or low, the default value being low. The cutoff is pi*Wc radians.
+//[z,p,g] = besself(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+//[...] = besself(...,’z’) returns a discrete space (Z) filter. w must be less than 1.
+//[a,b,c,d] = besself(...) returns state-space matrices.
+//Examples
+//[a,b]=besself(2,3,"low")
+//a = 9.0000
+//b =
+// 1.0000 5.1962 9.0000
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+if(rhs<2 | rhs>4)
+error("Wrong number of input arguments.")
+end
+if(lhs<2 | lhs>4)
+error("Wrong number of output arguments.")
+end
+
+
+ select (rhs)
+ case 2 then
+ if (lhs==2) [a,b] = callOctave("besself",n, w)
+ elseif (lhs==3) [a,b,c] = callOctave("besself",n, w)
+ elseif (lhs==4) [a,b,c,d] = callOctave("besself",n, w)
+ end
+ case 3 then
+ if (lhs==2) [a,b] = callOctave("besself",n, w,varargin(1))
+ elseif (lhs==3) [a,b,c] = callOctave("besself",n, w,varargin(1))
+ elseif (lhs==4) [a,b,c,d] = callOctave("besself",n, w,varargin(1))
+ end
+ case 4 then
+ if (lhs==2) [a,b] = callOctave("besself",n, w,varargin(1),varargin(2))
+ elseif (lhs==3) [a,b,c] = callOctave("besself",n, w,varargin(1),varargin(2))
+ elseif (lhs==4) [a,b,c,d] = callOctave("besself",n, w,varargin(1),varargin(2))
+ end
+ end
+endfunction
diff --git a/macros/bitrevorder.bin b/macros/bitrevorder.bin
new file mode 100644
index 0000000..f167fa0
Binary files /dev/null and b/macros/bitrevorder.bin differ
diff --git a/macros/bitrevorder.sci b/macros/bitrevorder.sci
new file mode 100644
index 0000000..a4b6da8
--- /dev/null
+++ b/macros/bitrevorder.sci
@@ -0,0 +1,25 @@
+function [y,i]=bitrevorder(x)
+
+// Returns input data in bit-reversed order
+// Calling Sequence
+// [y,i]=bitrevorder(x)
+// Parameters
+// x: Vector of real or complex values
+// Description
+// This is an Octave function.
+// This function returns the input data after reversing the bits of the indices and reordering the elements of the input array.
+// Examples
+// 1. [y]=bitrevorder ([i,1,3,6i])
+// y = [0 + 1i 3 + 0i 1 + 0i 0 + 6i]
+// 2. [y,i]=bitrevorder (['a','b','c','d'])
+// y = acbd
+// i = [1 3 2 4]
+
+funcprot(0);
+[lhs,rhs]=argn(0);
+if (rhs<1) then
+ error ("Wrong number of input arguments.")
+end
+[y,i]=callOctave("bitrevorder",x)
+
+endfunction
diff --git a/macros/bitrevorder.sci~ b/macros/bitrevorder.sci~
new file mode 100644
index 0000000..86f6a35
--- /dev/null
+++ b/macros/bitrevorder.sci~
@@ -0,0 +1,25 @@
+function [y,i]=bitrevorder(x)
+
+// Returns input data in bit-reversed order
+// Calling Sequence
+// [y,i]=bitrevorder(x)
+// Parameters
+// x: Vector of real or complex values
+// Description
+// This is an Octave function.
+// This function returns the input data after reversing the bits of the indices and reordering the elements of the input array.
+// Examples
+// 1. [y]=bitrevorder ([i,1,3,6i])
+// y = [0 + 1i 3 + 0i 1 + 0i 0 + 6i]
+// 2. [y,i]=bitrevorder (['a','b','c','d'])
+// y = acbd
+// i = [1 3 2 4]
+
+funcprot(0);
+[lhs,rhs]=argn(0);
+if (rhs<1) then
+ error ("Wrong number of input arguments.")
+end
+[y,i]=callOctave("bitrevorder",x)
+end
+endfunction
diff --git a/macros/blackman.bin b/macros/blackman.bin
new file mode 100644
index 0000000..020909f
Binary files /dev/null and b/macros/blackman.bin differ
diff --git a/macros/blackman.sci b/macros/blackman.sci
new file mode 100644
index 0000000..1847f99
--- /dev/null
+++ b/macros/blackman.sci
@@ -0,0 +1,60 @@
+function w=blackman(N,sflag)
+//Generates a Blackman window
+//Calling Sequence
+//w=blackman(N)
+//w=blackman(N,sflag)
+//Parameters
+//N
+//A positive integer describing the length of the blackman window
+//sflag
+//Specifies the type of blackman window desired. Can be 'symmetric' or 'periodic'
+//Description
+//w=blackman(N) returns an N-point symmetric Blackman window in a column vector w
+//w=blackman(N,sflag)
+//Returns an N point Blackman window using the type of sampling specified by sflag
+//sflag can be either 'symmetric' (default) or 'periodic' (used in spectral analysis)
+//Example
+//w=blackman(4)
+//w =
+//
+// - 1.388D-17
+// 0.63
+// 0.63
+// - 1.388D-17
+//Author
+//Ankur Mallick
+//References
+//[1] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1999.
+ funcprot(0);
+ if(argn(2)<2)
+ sflag='symmetric'; //Default
+ end
+ if(argn(2)<1|argn(2)>2)
+ error('Incorrect number of input arguments.');
+ elseif(~isscalar(N)|N<=0|round(N)~=N)
+ error('N must be a positive integer')
+ elseif(sflag~='symmetric'&sflag~='periodic')
+ error('Sampling flag must be either symmetric or periodic');
+ elseif(N==1)
+ w=1; //Trivial case
+ else
+ flag=0;
+ if(sflag=='periodic')
+ N=N+1;
+ flag=1;
+ end
+ if(pmodulo(N,2)==1)
+ M=(N+1)/2; //odd
+ else
+ M=N/2; //even
+ end
+ n=0:1:M-1;
+ w1=0.42-0.5*cos(2*%pi*n/(N-1))+0.08*cos(4*%pi*n/(N-1));
+ p=2*M-N; //0 for N even, 1 for N odd
+ w=[w1, w1(M-p:-1:1)]';
+ if(flag==1)
+ //Periodic case
+ w(N)=[];
+ end
+ end
+endfunction
diff --git a/macros/blackmanharris.bin b/macros/blackmanharris.bin
new file mode 100644
index 0000000..c9760f6
Binary files /dev/null and b/macros/blackmanharris.bin differ
diff --git a/macros/blackmanharris.sci b/macros/blackmanharris.sci
new file mode 100644
index 0000000..f2affdf
--- /dev/null
+++ b/macros/blackmanharris.sci
@@ -0,0 +1,35 @@
+function w = blackmanharris (m, opt)
+//This function returns the filter coefficients of a Blackman-Harris window.
+//Calling Sequence
+//w = blackmanharris (m)
+//w = blackmanharris (m, opt)
+//Parameters
+//m: positive integer value
+//opt: string value, takes "periodic" or "symmetric"
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Blackman-Harris window of length m supplied as input, to the output vector w.
+//The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+//Examples
+//blackmanharris(5,"periodic")
+//ans =
+// 0.00006
+// 0.1030115
+// 0.7938335
+// 0.7938335
+// 0.1030115
+
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 1 then
+ w = callOctave("blackmanharris",m)
+ case 2 then
+ w = callOctave("blackmanharris",m,opt)
+ end
+endfunction
+
diff --git a/macros/blackmannuttall.bin b/macros/blackmannuttall.bin
new file mode 100644
index 0000000..f242bc0
Binary files /dev/null and b/macros/blackmannuttall.bin differ
diff --git a/macros/blackmannuttall.sci b/macros/blackmannuttall.sci
new file mode 100644
index 0000000..29dd1b0
--- /dev/null
+++ b/macros/blackmannuttall.sci
@@ -0,0 +1,34 @@
+function [w] = blackmannuttall (m, opt)
+//This function returns the filter coefficients of a Blackman-Nuttall window.
+//Calling Sequence
+//w = blackmannuttall (m)
+//w = blackmannuttall (m, opt)
+//Parameters
+//m: positive integer value
+//opt: string value, takes "periodic" or "symmetric"
+//w: output variable, vector of real numbers
+//Description.
+//This is an Octave function.
+//This function returns the filter coefficients of a Blackman-Nuttall window of length m supplied as input, to the output vector w.
+//The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+//Examples
+//blackmannuttall(5,"symmetric")
+//ans =
+// 0.0003628
+// 0.2269824
+// 1.
+// 0.2269824
+// 0.0003628
+rhs = argn(2)
+
+if (rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+ select (rhs)
+ case 1 then
+ w = callOctave("blackmannuttall",m)
+ case 2 then
+ w = callOctave("blackmannuttall",m,opt)
+ end
+endfunction
+
diff --git a/macros/bohmanwin.bin b/macros/bohmanwin.bin
new file mode 100644
index 0000000..53ea3a9
Binary files /dev/null and b/macros/bohmanwin.bin differ
diff --git a/macros/bohmanwin.sci b/macros/bohmanwin.sci
new file mode 100644
index 0000000..183637c
--- /dev/null
+++ b/macros/bohmanwin.sci
@@ -0,0 +1,27 @@
+function y = bohmanwin (m)
+//This function returns the filter coefficients of a Bohman window.
+//Calling Sequence
+//y = bohmanwin (m)
+//Parameters
+//m: positive integer value
+//y: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Bohman window of length m supplied as input, to the output vector y.
+//Examples
+//bohmanwin(4)
+//ans =
+// 0.
+// 0.6089978
+// 0.6089978
+// 0.
+
+rhs = argn(2)
+
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+
+y = callOctave("bohmanwin",m)
+
+endfunction
diff --git a/macros/boxcar.bin b/macros/boxcar.bin
new file mode 100644
index 0000000..9f129da
Binary files /dev/null and b/macros/boxcar.bin differ
diff --git a/macros/boxcar.sci b/macros/boxcar.sci
new file mode 100644
index 0000000..120c6e9
--- /dev/null
+++ b/macros/boxcar.sci
@@ -0,0 +1,28 @@
+function [y] = boxcar (m)
+//This function returns the filter coefficients of a rectangular window.
+//Calling Sequence
+//y = boxcar (m)
+//Parameters
+//m: positive integer value
+//y: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a rectangular window of length m supplied as input, to the output vector y.
+//Examples
+//boxcar(6)
+//ans =
+// 1.
+// 1.
+// 1.
+// 1.
+// 1.
+// 1.
+
+rhs = argn(2)
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+
+y = callOctave("boxcar",m)
+
+endfunction
diff --git a/macros/buffer.bin b/macros/buffer.bin
new file mode 100644
index 0000000..7cb0a77
Binary files /dev/null and b/macros/buffer.bin differ
diff --git a/macros/buffer.sci b/macros/buffer.sci
new file mode 100644
index 0000000..5cc480a
--- /dev/null
+++ b/macros/buffer.sci
@@ -0,0 +1,59 @@
+function [y, z, opt] = buffer (x, n, p, opt)
+//This function buffers the given data into a matrix of signal frames
+//Calling Sequence
+//[y] = buffer (x, n)
+//[y] = buffer (x, n, p)
+//[y] = buffer (x, n, p)
+//[y, z, opt] = buffer (...)
+//Parameters
+//x: Data to be buffered
+//n: Positive integer equal to number of rows in the produced data buffer
+//p: Integer less than n, default value 0
+//opt: In case of overlap, it can be a vector of length p or the string "nodelay", In case of underlap, it is an integer between 0 and p
+//Description
+//This function buffers the given data into a matrix of signal frames
+//Examples
+//buffer(1,3,2)
+//ans =
+// 0 0
+// 0 1
+// 1 0
+//This function is being called from Octave
+
+funcprot(0);
+lhs = argn(1)
+rhs = argn(2)
+if (rhs < 2 | rhs > 4)
+error("Wrong number of input arguments.")
+end
+
+select(rhs)
+
+ case 2 then
+ if(lhs==1)
+ y = callOctave("buffer",x,n)
+ elseif(lhs==3)
+ [y,z,opt] = callOctave("buffer",x,n)
+ else
+ error("Wrong number of output argments.")
+ end
+
+ case 3 then
+ if(lhs==1)
+ y = callOctave("buffer",x,n,p)
+ elseif(lhs==3)
+ [y,z,op] = callOctave("buffer",x,n,p)
+ else
+ error("Wrong number of output argments.")
+ end
+ case 4 then
+ if(lhs==1)
+ y = callOctave("buffer",x,n,p,opt)
+ elseif(lhs==3)
+ [y,z,opt] = callOctave("buffer",x,n,p,opt)
+ else
+ error("Wrong number of output argments.")
+ end
+ end
+endfunction
+
diff --git a/macros/buildmacros.sce b/macros/buildmacros.sce
new file mode 100644
index 0000000..7f3e1bc
--- /dev/null
+++ b/macros/buildmacros.sce
@@ -0,0 +1,15 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the BSD.
+// This source file is licensed as described in the file LICENSE, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// https://opensource.org/licenses/BSD-3-Clause
+// Author: Shamika Mohanan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+tbx_build_macros("FOSSEE_Signal_Processing_Toolbox", get_absolute_file_path("buildmacros.sce"));
+
+clear tbx_build_macros;
+
diff --git a/macros/buildmacros.sce~ b/macros/buildmacros.sce~
new file mode 100644
index 0000000..3580198
--- /dev/null
+++ b/macros/buildmacros.sce~
@@ -0,0 +1,15 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the BSD.
+// This source file is licensed as described in the file LICENSE, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// https://opensource.org/licenses/BSD-3-Clause
+// Author: Shamika Mohanan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+tbx_build_macros("FOSSEE_Scilab_Octave_Interface_Toolbox", get_absolute_file_path("buildmacros.sce"));
+
+clear tbx_build_macros;
+
diff --git a/macros/butter.bin b/macros/butter.bin
new file mode 100644
index 0000000..1ed2eaf
Binary files /dev/null and b/macros/butter.bin differ
diff --git a/macros/butter.sci b/macros/butter.sci
new file mode 100644
index 0000000..a11da7e
--- /dev/null
+++ b/macros/butter.sci
@@ -0,0 +1,58 @@
+function [a, b, c, d] = butter (n, w, varargin)
+//This function generates a Butterworth filter.
+//Calling Sequence
+//[a, b] = butter (n, w)
+//[a, b] = butter (n, w, "high")
+//[a, b] = butter (n, [wl, wh])
+//[b, a] = butter (n, [wl, wh], "stop")
+//[a, b, c] = butter (…)
+//[a, b, c, d] = butter (…)
+//[…] = butter (…, "s")
+//Parameters
+//n: positive integer value
+//w: positive real value, w in the range [0,1]
+//Description
+//This is an Octave function.
+//This function generates a Butterworth filter. Default is a discrete space (Z) filter.
+//The third parameter takes in low or high, default value is low. The cutoff is pi*Wc radians.
+//[b,a] = butter(n, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.
+//[b,a] = butter(n, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.
+//[z,p,g] = butter(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+//[...] = butter(...,’s’) returns a Laplace space filter, w can be larger than 1.
+//[a,b,c,d] = butter(...) returns state-space matrices.
+//Examples
+//[a,b]=butter(3, 0.7)
+//a =
+// 0.37445 1.12336 1.12336 0.37445
+//b =
+// 1.00000 1.16192 0.69594 0.13776
+
+rhs = argn(2)
+lhs = argn(1)
+if(rhs>4 | rhs<2)
+error("Wrong number of input arguments.")
+end
+if(lhs>4 | lhs<2)
+error("Wrong number of output arguments.")
+end
+
+ select (rhs)
+ case 2 then
+ if (lhs==2) [a,b] = callOctave("butter",n, w)
+ elseif (lhs==3) [a,b,c] = callOctave("butter",n, w)
+ elseif (lhs==4) [a,b,c,d] = callOctave("butter",n, w)
+ end
+ case 3 then
+ if (lhs==2) [a,b] = callOctave("butter",n, w,varargin(1))
+ elseif (lhs==3) [a,b,c] = callOctave("butter",n, w,varargin(1))
+ elseif (lhs==4) [a,b,c,d] = callOctave("butter",n, w,varargin(1))
+ end
+ case 4 then
+ if (lhs==2) [a,b] = callOctave("butter",n, w,varargin(1),varargin(2))
+ elseif (lhs==3) [a,b,c] = callOctave("butter",n, w,varargin(1),varargin(2))
+ elseif (lhs==4) [a,b,c,d] = callOctave("butter",n, w,varargin(1),varargin(2))
+ end
+ end
+endfunction
+
+
diff --git a/macros/buttord.bin b/macros/buttord.bin
new file mode 100644
index 0000000..a6cdc9c
Binary files /dev/null and b/macros/buttord.bin differ
diff --git a/macros/buttord.sci b/macros/buttord.sci
new file mode 100644
index 0000000..2a17521
--- /dev/null
+++ b/macros/buttord.sci
@@ -0,0 +1,39 @@
+function [n, Wc] = buttord(Wp, Ws, Rp, Rs)
+///This function computes the minimum filter order of a Butterworth filter with the desired response characteristics.
+//Calling Sequence
+//n = buttord(Wp, Ws, Rp, Rs)
+//[n, Wc] = buttord(Wp, Ws, Rp, Rs)
+//Parameters
+//Wp: scalar or vector of length 2
+//Ws: scalar or vector of length 2, elements must be in the range [0,1]
+//Rp: real or complex value
+//Rs: real or complex value
+//Description
+//This is an Octave function.
+//This function computes the minimum filter order of a Butterworth filter with the desired response characteristics.
+//The filter frequency band edges are specified by the passband frequency wp and stopband frequency ws.
+//Frequencies are normalized to the Nyquist frequency in the range [0,1].
+//Rp is measured in decibels and is the allowable passband ripple, and Rs is also in decibels and is the minimum attenuation in the stop band.
+//If ws>wp, the filter is a low pass filter. If wp>ws, the filter is a high pass filter.
+//If wp and ws are vectors of length 2, then the passband interval is defined by wp the stopband interval is defined by ws.
+//If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp the filter is a band-stop or band-reject filter.
+//Examples
+//Wp = 40/500
+//Ws = 150/500
+//[n, Wn] = buttord(Wp, Ws, 3, 60)
+//n = 5
+//Wn = 0.080038
+
+rhs = argn(2)
+lhs = argn(1)
+if(rhs~=4)
+error("Wrong number of input arguments.")
+end
+
+ select(lhs)
+ case 1 then
+ n = callOctave(Wp,Ws,Rp,Rs)
+ case 2 then
+ [n,Wc] = callOctave(Wp,Ws,Rp,Rs)
+ end
+endfunction
diff --git a/macros/callOct.sci~ b/macros/callOct.sci~
new file mode 100644
index 0000000..a9061e1
--- /dev/null
+++ b/macros/callOct.sci~
@@ -0,0 +1,18 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the BSD.
+// This source file is licensed as described in the file LICENSE, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// https://opensource.org/licenses/BSD-3-Clause
+// Author: Shamika Mohanan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+
+
+function a=callOct(fname,varargin)
+
+ a=callOctave(fname,varargin);
+
+endfunction
diff --git a/macros/cconv.bin b/macros/cconv.bin
new file mode 100644
index 0000000..977d0b2
Binary files /dev/null and b/macros/cconv.bin differ
diff --git a/macros/cconv.sci b/macros/cconv.sci
new file mode 100644
index 0000000..c7560ef
--- /dev/null
+++ b/macros/cconv.sci
@@ -0,0 +1,50 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function o=cconv(a,b,n)
+ [nargout,nargin]=argn();
+ if nargin==2 then
+ n=length(a)+length(b)-1;
+ end
+ if type(a)~=1 | type(b)~=1 | type(n)~=1 then
+ error('check the data type of input'); //to check if the inputs are real/complex arrays
+ end
+ if size(n)~=[1,1] then
+ error('check the data type of input'); //to check that n is single dimensional
+ end
+ if floor(n)~=n | imag(n)~=0 then
+ error('check that n is an integer');//to check if n is an integer
+ end
+ //checking if a is a 1d vector(row or column) and turning it into row vector
+ [i,j]=size(a);
+ if j~=1 & i~=1 then
+ error('a should be a vector');
+ elseif j==1
+ a=a';
+ end
+ //checking if b is a 1d vector(row or column) and turning it into row vector
+ [i,j]=size(b);
+ if j~=1 & i~=1 then
+ error('b should be a vector');
+ elseif j==1
+ b=b';
+ end
+
+ //adjusting length of a
+ if n<=length(a) then
+ a=a(1:n);
+ else
+ a=[a,zeros(1,n-length(a))]
+ end
+ //adjusting length of b
+ if n<=length(b) then
+ b=b(1:n);
+ else
+ b=[b,zeros(1,n-length(b))]
+ end
+ //computing ffts (for speed)
+ aft=fft(a);
+ bft=fft(b);
+ //circular convolution dft is the product of dft of the 2
+ oft=aft.*bft;
+ o=ifft(oft);
+endfunction
diff --git a/macros/cell2sos.bin b/macros/cell2sos.bin
new file mode 100644
index 0000000..becc9e0
Binary files /dev/null and b/macros/cell2sos.bin differ
diff --git a/macros/cell2sos.sci b/macros/cell2sos.sci
new file mode 100644
index 0000000..39402b3
--- /dev/null
+++ b/macros/cell2sos.sci
@@ -0,0 +1,95 @@
+function [s,g] = cell2sos(c)
+//Converts a cell array to a second order section matrix
+//Calling Sequences
+//s=cell2sos(c)
+//[s,g]=cell2sos(c)
+//Parameters
+//c
+//A cell array
+//g
+//The scalar gain
+//Description
+//s=cell2sos(c) converts a a cell array c = { {B1},{A1}, {B2},{A2}, ... {BL},{AL}}
+//to an L-by-6 second-order-section matrix s given by:
+// s = [B1 A1
+// B2 A2
+// ...
+// BL AL]
+//numerator vector Bi and denominator vector Ai contains the coefficients of a
+//linear or quadratic polynomial. If the polynomial is linear, the coefficients
+//zero-padded on the right.
+//[s,g]=cell2sos(c) estimates the gain from the leading term of the cell array
+//c={ {[g1,g2]},{B1},{A1}, {B2},{A2}, ... {BL},{AL}} to give g=g1/g2 as the gain
+//Example
+//c=cell(1,5);
+//
+//c(1,1).entries=[2, 1];
+//
+//c(1,2).entries=rand(1,3);
+//
+//c(1,3).entries=rand(1,3);
+//
+//c(1,4).entries=rand(1,3);
+//
+//c(1,5).entries=rand(1,3);
+//
+// c =
+// column 1 to 3
+//
+//![2,1] [0.2113249,0.7560439,0.0002211] [0.3303271,0.6653811,0.6283918] !
+//
+// column 4 to 5
+//
+//![0.8497452,0.6857310,0.8782165] [0.0683740,0.5608486,0.6623569] !
+//[s,g]=cell2sos(c);
+//s =
+//
+// column 1 to 5
+//
+// 0.2113249 0.7560439 0.0002211 0.3303271 0.6653811
+// 0.8497452 0.6857310 0.8782165 0.0683740 0.5608486
+//
+// column 6
+//
+// 0.6283918
+// 0.6623569
+//
+//g =
+//
+// 2.
+//Author
+//Ankur Mallick
+ if(argn(2)~=1) then
+ error("Wrong number of input arguments");
+ end
+
+ L=prod(size(c));
+ for i=1:L
+ if(type(c(i))~=17)
+ error('Cell contents must themselves be cell objects');
+ end
+ end
+ if (argn(1)==2)
+ d=c(1).entries;
+ if(length(d)==2)
+ g1=d(1);
+ g2=d(2);
+ g=g1/g2;
+ c=c(2:L);
+ else
+ g=1;
+ end
+ end
+ L=prod(size(c));
+ s=zeros(L/2,6);
+ for i=1:2:L-1
+ j=ceil(i/2)
+ b=c(i).entries;
+ a=c(i+1).entries;
+ b=b(:).';
+ a=a(:).';
+ b=[b,zeros(1,3-length(b))];
+ a=[a,zeros(1,3-length(b))];
+ s(j,:)=[b,a];
+ end
+endfunction
diff --git a/macros/cheb1ord.bin b/macros/cheb1ord.bin
new file mode 100644
index 0000000..7cf442d
Binary files /dev/null and b/macros/cheb1ord.bin differ
diff --git a/macros/cheb1ord.sci b/macros/cheb1ord.sci
new file mode 100644
index 0000000..b2789bf
--- /dev/null
+++ b/macros/cheb1ord.sci
@@ -0,0 +1,36 @@
+function [n, Wc] = cheb1ord(Wp, Ws, Rp, Rs)
+//This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics.
+//Calling Sequence
+//n = cheb1ord(Wp, Ws, Rp, Rs)
+//[n, Wc] = cheb1ord(Wp, Ws, Rp, Rs)
+//Parameters
+//Wp: scalar or vector of length 2, all elements must be in the range [0,1]
+//Ws: scalar or vector of length 2, all elements must be in the range [0,1]
+//Rp: real value
+//Rs: real value
+//Description
+//This is an Octave function.
+//This function computes the minimum filter order of a Chebyshev type I filter with the desired response characteristics.
+//Stopband frequency ws and passband frequency wp specify the the filter frequency band edges.
+//Frequencies are normalized to the Nyquist frequency in the range [0,1].
+//Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.
+//If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.
+//If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws.
+//If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter.
+//Examples
+//cheb1ord(0.1,0.2,-0.3,4)
+//ans = 2
+
+rhs = argn(2)
+lhs = argn(1)
+if(rhs~=4)
+error("Wrong number of input arguments.")
+end
+
+ select(lhs)
+ case 1 then
+ n = callOctave("cheb1ord",Wp,Ws,Rp,Rs)
+ case 2 then
+ [n,Wc] = callOctave("cheb1ord",Wp,Ws,Rp,Rs)
+ end
+endfunction
diff --git a/macros/cheb2ord.bin b/macros/cheb2ord.bin
new file mode 100644
index 0000000..b1602ec
Binary files /dev/null and b/macros/cheb2ord.bin differ
diff --git a/macros/cheb2ord.sci b/macros/cheb2ord.sci
new file mode 100644
index 0000000..815ba0d
--- /dev/null
+++ b/macros/cheb2ord.sci
@@ -0,0 +1,36 @@
+function [n, Wc] = cheb2ord(Wp, Ws, Rp, Rs)
+//This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics.
+//Calling Sequence
+//n = cheb2ord(Wp, Ws, Rp, Rs)
+//[n, Wc] = cheb2ord(Wp, Ws, Rp, Rs)
+//Parameters
+//Wp: scalar or vector of length 2, all elements must be in the range [0,1]
+//Ws: scalar or vector of length 2, all elements must be in the range [0,1]
+//Rp: real value
+//Rs: real value
+//Description
+//This is an Octave function.
+//This function computes the minimum filter order of a Chebyshev type II filter with the desired response characteristics.
+//Stopband frequency ws and passband frequency wp specify the the filter frequency band edges.
+//Frequencies are normalized to the Nyquist frequency in the range [0,1].
+//Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.
+//If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.
+//If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws.
+//If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter.
+//Examples
+//cheb2ord([0.25,0.3],[0.2,0.8],0.3,0.4)
+//ans = 1
+
+rhs = argn(2)
+lhs = argn(1)
+if(rhs~=4)
+error("Wrong number of input arguments.")
+end
+
+ select(lhs)
+ case 1 then
+ n = callOctave("cheb2ord",Wp,Ws,Rp,Rs)
+ case 2 then
+ [n,Wc] = callOctave("cheb2ord",Wp,Ws,Rp,Rs)
+ end
+endfunction
diff --git a/macros/chebwin.bin b/macros/chebwin.bin
new file mode 100644
index 0000000..cd27563
Binary files /dev/null and b/macros/chebwin.bin differ
diff --git a/macros/chebwin.sci b/macros/chebwin.sci
new file mode 100644
index 0000000..781bb6e
--- /dev/null
+++ b/macros/chebwin.sci
@@ -0,0 +1,37 @@
+function w = chebwin (m, at)
+//This function returns the filter coefficients of a Dolph-Chebyshev window.
+//Calling Sequence
+//w = chebwin (m)
+//w = chebwin (m, at)
+//Parameters
+//m: positive integer value
+//at: real scalar value
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Dolph-Chebyshev window of length m supplied as input, to the output vector w.
+//The second parameter is the stop band attenuation of the Fourier transform in dB. The default value is 100 dB.
+//Examples
+//chebwin(7)
+//ans =
+// 0.0565041
+// 0.3166085
+// 0.7601208
+// 1.
+// 0.7601208
+// 0.3166085
+// 0.0565041
+
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+select(rhs)
+case 1 then
+w = callOctave("chebwin",m)
+case 2 then
+w = callOctave("chebwin",m,at)
+end
+endfunction
+
+
diff --git a/macros/cheby1.bin b/macros/cheby1.bin
new file mode 100644
index 0000000..5fff1f3
Binary files /dev/null and b/macros/cheby1.bin differ
diff --git a/macros/cheby1.sci b/macros/cheby1.sci
new file mode 100644
index 0000000..52ff1ad
--- /dev/null
+++ b/macros/cheby1.sci
@@ -0,0 +1,59 @@
+function [a, b, c, d] = cheby1 (n, rp, w, varargin)
+//This function generates a Chebyshev type I filter with rp dB of passband ripple.
+//Calling Sequence
+//[a, b] = cheby1 (n, rp, w)
+//[a, b] = cheby1 (n, rp, w, "high")
+//[a, b] = cheby1 (n, rp, [wl, wh])
+//[a, b] = cheby1 (n, rp, [wl, wh], "stop")
+//[a, b, c] = cheby1 (…)
+//[a, b, c, d] = cheby1 (…)
+//[…] = cheby1 (…, "s")
+//Parameters
+//n: positive integer value
+//rp: non negative scalar value
+//w: vector, all elements must be in the range [0,1]
+//Description
+//This is an Octave function.
+//This function generates a Chebyshev type I filter with rp dB of passband ripple.
+//The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians.
+//[b, a] = cheby1(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.
+//[b, a] = cheby1(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.
+//[z, p, g] = cheby1(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+//[...] = cheby1(...,’s’) returns a Laplace space filter, w can be larger than 1.
+//[a,b,c,d] = cheby1(...) returns state-space matrices.
+//Examples
+//[a,b,c]=cheby1(2,6,0.7,"high")
+//a =
+// 1 1
+//b =
+// -0.62915 + 0.55372i -0.62915 - 0.55372i
+//c = 0.055649
+
+rhs = argn(2)
+lhs = argn(1)
+[rows,columns] = size(w)
+if(rhs>5 | rhs<3)
+error("Wrong number of input arguments.")
+end
+if(lhs>4 | lhs<2)
+error("Wrong number of output arguments.")
+end
+
+ select (rhs)
+ case 3 then
+ if (lhs==2) [a,b] = callOctave("cheby1",n, rp, w)
+ elseif (lhs==3) [a,b,c] = callOctave("cheby1",n, rp, w)
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby1",n, rp, w)
+ end
+ case 4 then
+ if (lhs==2) [a,b] = callOctave("cheby1",n, rp, w, varargin(1))
+ elseif (lhs==3) [a,b,c] = callOctave("cheby1",n, rp, w, varargin(1))
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby1",n, rp, w, varargin(1))
+ end
+ case 5 then
+ if (lhs==2) [a,b] = callOctave("cheby1",n, rp, rs, w, varargin(1), varargin(2))
+ elseif (lhs==3) [a,b,c] = callOctave("cheby1",n, rp, rs, w, varargin(1), varargin(2))
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby1",n, rp, rs, w, varargin(1), varargin(2))
+ end
+ end
+endfunction
diff --git a/macros/cheby2.bin b/macros/cheby2.bin
new file mode 100644
index 0000000..f68fe52
Binary files /dev/null and b/macros/cheby2.bin differ
diff --git a/macros/cheby2.sci b/macros/cheby2.sci
new file mode 100644
index 0000000..6504837
--- /dev/null
+++ b/macros/cheby2.sci
@@ -0,0 +1,59 @@
+function [a, b, c, d] = cheby2 (n, rs, w, varargin)
+//This function generates a Chebyshev type II filter with rs dB of stopband attenuation.
+//Calling Sequence
+//[a, b] = cheby2 (n, rs, wc)
+//[a, b] = cheby2 (n, rs, wc, "high")
+//[a, b] = cheby2 (n, rs, [wl, wh])
+//[a, b] = cheby2 (n, rs, [wl, wh], "stop")
+//[a, b, c] = cheby2 (…)
+//[a, b, c, d] = cheby2 (…)
+//[…] = cheby2 (…, "s")
+//Parameters
+//n: positive integer value
+//rp: non negative scalar value
+//w: vector, all elements must be in the range [0,1]
+//Description
+//This is an Octave function.
+//This function generates a Chebyshev type II filter with rs dB of stopband attenuation.
+//The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians.
+//[b, a] = cheby2(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.
+//[b, a] = cheby2(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.
+//[z, p, g] = cheby2(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+//[...] = cheby2(...,’s’) returns a Laplace space filter, w can be larger than 1.
+//[a,b,c,d] = cheby2(...) returns state-space matrices.
+//Examples
+//[a,b,c]=cheby2(2,5,0.7,"high")
+//a =
+// -0.31645 - 0.94861i -0.31645 + 0.94861i
+//b =
+// -0.39388 + 0.53138i -0.39388 - 0.53138i
+//c = 0.47528
+
+rhs = argn(2)
+lhs = argn(1)
+
+if(rhs>5 | rhs<3)
+error("wrong number of input arguments.")
+end
+if(lhs<4 | lhs<2)
+error("Wrong number of output arguments.")
+end
+
+select (rhs)
+ case 3 then
+ if (lhs==2) [a,b] = callOctave("cheby2",n, rp, w)
+ elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, w)
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, w)
+ end
+ case 4 then
+ if (lhs==2) [a,b] = callOctave("cheby2",n, rp, w, varargin(1))
+ elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, w, varargin(1))
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, w, varargin(1))
+ end
+ case 5 then
+ if (lhs==2) [a,b] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2))
+ elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2))
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2))
+ end
+ end
+endfunction
diff --git a/macros/cheby2.sci~ b/macros/cheby2.sci~
new file mode 100644
index 0000000..9efd721
--- /dev/null
+++ b/macros/cheby2.sci~
@@ -0,0 +1,58 @@
+function [a, b, c, d] = cheby2 (n, rs, w, varargin)
+//This function generates a Chebyshev type II filter with rs dB of stopband attenuation.
+//Calling Sequence
+//[a, b] = cheby2 (n, rs, wc)
+//[a, b] = cheby2 (n, rs, wc, "high")
+//[a, b] = cheby2 (n, rs, [wl, wh])
+//[a, b] = cheby2 (n, rs, [wl, wh], "stop")
+//[a, b, c] = cheby2 (…)
+//[a, b, c, d] = cheby2 (…)
+//[…] = cheby2 (…, "s")
+//Parameters
+//n: positive integer value
+//rp: non negative scalar value
+//w: vector, all elements must be in the range [0,1]
+//Description
+//This is an Octave function.
+//This function generates a Chebyshev type II filter with rs dB of stopband attenuation.
+//The fourth parameter takes in high or low, default value is low. The cutoff is pi*Wc radians.
+//[b, a] = cheby2(n, Rp, [Wl, Wh]) indicates a band pass filter with edges pi*Wl and pi*Wh radians.
+//[b, a] = cheby2(n, Rp, [Wl, Wh], ’stop’) indicates a band reject filter with edges pi*Wl and pi*Wh radians.
+//[z, p, g] = cheby2(...) returns filter as zero-pole-gain rather than coefficients of the numerator and denominator polynomials.
+//[...] = cheby2(...,’s’) returns a Laplace space filter, w can be larger than 1.
+//[a,b,c,d] = cheby2(...) returns state-space matrices.
+//Examples
+//[a,b,c]=cheby2(2,5,0.7,"high")
+//a =
+// -0.31645 - 0.94861i -0.31645 + 0.94861i
+//b =
+// -0.39388 + 0.53138i -0.39388 - 0.53138i
+//c = 0.47528
+
+rhs = argn(2)
+lhs = argn(1)
+
+if(rhs>5 | rhs<3)
+error("wrong number of input arguments.")
+end
+if(lhs<4 | lhs<2)
+error("Wrong number of output arguments.")
+end
+
+select (rhs)
+ case 3 then
+ if (lhs==2) [a,b] = callOctave("cheby2",n, rp, w)
+ elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, w)
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, w)
+ end
+ case 4 then
+ if (lhs==2) [a,b] = callOctave("cheby2",n, rp, w, varargin(1))
+ elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, w, varargin(1))
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, w, varargin(1))
+ end
+ case 5 then
+ if (lhs==2) [a,b] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2))
+ elseif (lhs==3) [a,b,c] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2))
+ elseif (lhs==4) [a,b,c,d] = callOctave("cheby2",n, rp, rs, w, varargin(1), varargin(2))
+ end
+ end
diff --git a/macros/check.bin b/macros/check.bin
new file mode 100644
index 0000000..678d4a0
Binary files /dev/null and b/macros/check.bin differ
diff --git a/macros/check.sci b/macros/check.sci
new file mode 100644
index 0000000..c7a1678
--- /dev/null
+++ b/macros/check.sci
@@ -0,0 +1,5 @@
+function [s] = check(str)
+funcprot(0);
+is_AKICc = (str == "AKICc")
+disp(is_AKICc)
+endfunction
diff --git a/macros/chirp.bin b/macros/chirp.bin
new file mode 100644
index 0000000..4251c53
Binary files /dev/null and b/macros/chirp.bin differ
diff --git a/macros/chirp.sci b/macros/chirp.sci
new file mode 100644
index 0000000..41a94e6
--- /dev/null
+++ b/macros/chirp.sci
@@ -0,0 +1,55 @@
+function [y] = chirp(t,f0,t1,f1,frm,phse)
+//This function evaluates a chirp signal at time t.
+//Calling Sequence
+//y = chirp(t)
+//y = chirp(t, f0)
+//y = chirp(t, f0, t1)
+//y = chirp(t, f0, t1, f1)
+//y = chirp(t, f0, t1, f1, frm)
+//y = chirp(t, f0, t1, f1, frm, phse)
+//Parameters
+//t: vector
+//f0:
+//t1:
+//f1:
+//frm: string value, takes in "linear", "quadratic", "logarithmic"
+//phse:
+//Description
+//This is an Octave function.
+//This function evaluates a chirp signal at time t. A chirp signal is a frequency swept cosine wave.
+//The first argument is a vector of times to evaluate the chirp signal, second argument is the frequency at t=0, third argument is time t1 and fourth argument is frequency at t1.
+//The fifth argument is the form which takes in values "linear", "quadratic" and "logarithmic", the sixth argument gives the phase shift at t=0.
+//Examples
+//chirp([4,3,2,1],4,5,0.9)
+//ans =
+// column 1 to 3
+// 0.9685832 0.2486899 0.0627905
+// column 4
+// - 0.3681246
+
+funcprot(0);
+
+rhs = argn(2)
+if(rhs<1 | rhs>6)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 1 then
+ y = callOctave("chirp",t)
+ case 2 then
+ y = callOctave("chirp",t,f0)
+ case 3 then
+ y = callOctave("chirp",t,f0,t1)
+ case 4 then
+ y = callOctave("chirp",t,f0,t1,f1)
+ case 5 then
+ //if(~(form == "linear" | form == "quadratic" | form == "logarithmic"))
+ //error("Chirp does not understand that form. Enter linear, quadratic or logarithmic.")
+ //else
+ y = callOctave("chirp",t,f0,t1,f1,frm)
+ //end
+ case 6 then
+ y = callOctave("chirp",t,f0,t1,f1,frm,phse)
+ end
+endfunction
+
diff --git a/macros/clustersegment.bin b/macros/clustersegment.bin
new file mode 100644
index 0000000..fc1d371
Binary files /dev/null and b/macros/clustersegment.bin differ
diff --git a/macros/clustersegment.sci b/macros/clustersegment.sci
new file mode 100644
index 0000000..07957ee
--- /dev/null
+++ b/macros/clustersegment.sci
@@ -0,0 +1,27 @@
+function c = clustersegment(s)
+//This function calculates boundary indexes of clusters of 1’s.
+//Calling Sequence
+//c = clustersegment(s)
+//Parameters
+//s: scalar, vector or matrix of real numbers (clusters of 1s)
+//c: output variable, cell array of size 1 by N, where N is the number of rows in s
+//Description
+//This is an Octave function.
+//This function calculates boundary indexes of clusters of 1’s.
+//This function calculates the initial and end indices of the sequences of 1's present in the input argument.
+//The output variable c is a cell array of size 1 by N, where N is the number of rows in s and each element has two rows indicating the initial index and end index of the cluster of 1's respectively. The indexing starts from 1.
+//Examples
+//y = clustersegment ([0,1,0,0,1,1])
+//y =
+// 2. 5.
+// 2. 6.
+
+funcprot(0);
+rhs = argn(2)
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+
+c = callOctave("clustersegment", s)
+
+endfunction
diff --git a/macros/cmorwavf.bin b/macros/cmorwavf.bin
new file mode 100644
index 0000000..ecaa435
Binary files /dev/null and b/macros/cmorwavf.bin differ
diff --git a/macros/cmorwavf.sci b/macros/cmorwavf.sci
new file mode 100644
index 0000000..6c20fc5
--- /dev/null
+++ b/macros/cmorwavf.sci
@@ -0,0 +1,26 @@
+function [psi,x]=cmorwavf(lb,ub,n,fb,fc)
+funcprot(0);
+
+// Finds the Complex Morlet Wavelet
+// Calling Sequence
+// [psi,x]=cmorwavf(lb,ub,n,fb,fc)
+// Parameters
+// lb: Real or complex valued vector or matrix
+// ub: Real or complex valued vector or matrix
+// n: Real scalar strictly positive integer
+// fb: Real or complex scalar value
+// fc: Real or complex scalar value
+// Description
+// This is an Octave function.
+// This function returns the value of the Complex Morlet Waveform defined by a positive bandwidth parameter FB, a wavelet center frequency FC on an N point regular grid for the interval [LB,UB].
+// Examples
+// [a,b]=cmorwavf(1,2,1,3,4)
+// b=2
+// a=[0.0858628 -1.682D-16i]
+
+rhs=argn(2);
+if(rhs~=5) then
+ error ("Wrong number of input arguments.")
+end
+[psi,x]=callOctave("cmorwavf",lb,ub,n,fb,fc)
+endfunction
diff --git a/macros/convmtx.bin b/macros/convmtx.bin
new file mode 100644
index 0000000..1925e20
Binary files /dev/null and b/macros/convmtx.bin differ
diff --git a/macros/convmtx.sci b/macros/convmtx.sci
new file mode 100644
index 0000000..c0aa891
--- /dev/null
+++ b/macros/convmtx.sci
@@ -0,0 +1,36 @@
+//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
+
+endfunction
diff --git a/macros/convmtx1.sce b/macros/convmtx1.sce
new file mode 100644
index 0000000..75fa242
--- /dev/null
+++ b/macros/convmtx1.sce
@@ -0,0 +1,4 @@
+h=[1 2 3 4 56];
+n=6;
+A=convmtx(h,n);
+disp(A);
diff --git a/macros/corrmtx.bin b/macros/corrmtx.bin
new file mode 100644
index 0000000..1a11222
Binary files /dev/null and b/macros/corrmtx.bin differ
diff --git a/macros/corrmtx.sci b/macros/corrmtx.sci
new file mode 100644
index 0000000..2a7a000
--- /dev/null
+++ b/macros/corrmtx.sci
@@ -0,0 +1,126 @@
+function [X,varargout]= corrmtx(x,m,varargin)
+// Generate data matrix for autocorrelation matrix estimation
+//
+// Calling Sequence
+// X = corrmtx(x,m)
+// [X,R] = corrmtx(x,m)
+// X = corrmtx(x,m,s)
+// [X,R] = corrmtx(x,m,s)
+//
+// Parameters
+// x: input vector of size N for which correlation matrix of size m is to be calculated
+// m: size of correlation matrix to be computed. Positive integer strictly smaller than the length of the input x
+// X: data matrix as specified according to the input 'method'
+// s: method for type of output matrix X
+// 'autocorrelation': (default) X is the (n + m)-by-(m + 1) rectangular Toeplitz matrix that generates an autocorrelation estimate for the leng th-n data vector x, derived using prewindowed and postwindowed data, based on an mth-order prediction error model.
+// 'prewindowed': X is the n-by-(m + 1) rectangular Toeplitz matrix that generates an autocorrelation estimate for the length-n data vector x, derived using prewindowed data, based on an mth-order prediction error model.
+// 'postwindowed': X is the n-by-(m + 1) rectangular Toeplitz matrix that generates an autocorrelation estimate for the length-n data vector x , derived using postwindowed data, based on an mth-order prediction error model.
+// 'covariance': X is the (n – m)-by-(m + 1) rectangular Toeplitz matrix that generates an autocorrelation estimate for the length-n data vect or x, derived using nonwindowed data, based on an mth-order prediction error model.
+// 'modified': X is the 2(n – m)-by-(m + 1) modified rectangular Toeplitz matrix that generates an autocorrelation estimate for the length-n d ata vector x, derived using forward and backward prediction error estimates, based on an mth-order prediction error model.
+// R: (m + 1)-by-(m + 1) autocorrelation matrix estimate calculated as X'*X
+//
+// Description
+// Consider the generic matrix X below
+// _ _
+// | x(1) ..........0 |
+// | : . : |
+// | : . : |
+// | x(m+1).......x(1)|
+// | : . : |
+// | : . : |
+//X = | x(n-m).....x(m+1)|
+// | : . : |
+// | : . : |
+// | x(n).......x(n-m)|
+// | : . : |
+// | : . : |
+// |_0 ..........x(n)_|
+// --
+// For different inputs of string s the output would vary ass described below
+// 'autocorrelation' — (default) X = X, above.
+// 'prewindowed' — X is the n-by-(m + 1) submatrix of X whose first row is [x(1) … 0] and whose last row is [x(n) … x(n – m)]
+// 'postwindowed' — X is the n-by-(m + 1) submatrix of X whose first row is [x(m + 1) … x(1)] and whose last row is [0 … x(n)]
+// 'covariance' — X is the (n – m)-by-(m + 1) submatrix of X whose first row is [x(m + 1) … x(1)] and whose last row is [x(n) … x(n – m)]
+// 'modified' — X is the 2(n – m)-by-(m + 1) matrix X_mod shown below
+// _ _
+// | x(m+1) ......x(1)|
+// | : . : |
+// | : . : |
+// | x(n-m).....x(m+1)|
+// | : . : |
+// | : . : |
+// | x(n).......x(n-m)|
+// X_mod= | x*(1).....x*(m+1)|
+// | : . : |
+// | : . : |
+// | x*(m+1)...x*(n-m)|
+// | : . : |
+// | : . : |
+// |_x*(n-m) ...x*(n)_|
+//
+// Examples
+//
+//
+//
+// See also
+// peig
+// pmusic
+// rooteig
+// rootmusic
+// xcorr
+//
+// Author:
+// Parthe Pandit
+//
+// Bilbligraphy
+// Marple, S. Lawrence. Digital Spectral Analysis. Englewood Cliffs, NJ: Prentice-Hall, 1987.
+
+
+
+ if(~isvector(x)) then
+ error("Input x must be a length n vector")
+ return
+ elseif (~isscalar(m)) then
+ error("Input m must be scalar")
+ return
+ end
+
+ if (length(varargin) > 1) then
+ error('Too many input arguments. Third argument must be method for correlation matrix computation')
+ return
+ elseif (length(varargin) < 1)
+ method = 'autocorrelation';
+ elseif (length(varargin) == 1 & type(varargin(1))~=10)
+ disp(type(varargin));
+ error("Input method needs to be string")
+ return
+ else
+ method = varargin(1);
+ end
+ n = length(x);
+ x = matrix(x,1,n);
+ x_padded = [zeros(1,m),x,zeros(1,m)];
+ X = zeros( (n + m),(m + 1) );
+ for i = 1:size(X,1)
+ X(i,:) = x_padded(m+i:-1:i);
+ end
+
+ select method
+ case "autocorrelation" then
+ X = X;
+ case 'prewindowed' then
+ X = X(1:n,:);
+ case 'postwindowed' then
+ X = X(m+1:$,:);
+ case 'covariance' then
+ X = X(m+1:n,:);
+ case 'modified' then
+ X = [X(m+1:n,:) ; conj(mtlb_fliplr(X(m+1:n,:)))];
+ else X = X;
+end
+
+
+ varargout = list(X'*X);
+
+
+endfunction
diff --git a/macros/cummax.bin b/macros/cummax.bin
new file mode 100644
index 0000000..0dc047b
Binary files /dev/null and b/macros/cummax.bin differ
diff --git a/macros/cummax.sci b/macros/cummax.sci
new file mode 100644
index 0000000..672dc5c
--- /dev/null
+++ b/macros/cummax.sci
@@ -0,0 +1,196 @@
+function M = cummax(varargin)
+ // Cumulative maximum
+ //
+ // Calling Sequence
+ // M = cummax(A)
+ // returns the cumulative maximum of the arguments of A. The dimension
+ // of M is same as the dimension of A. If A is a 2D matrix, the operation
+ // is performed along the columns. For a hypermatrix, the operation is
+ // performed along the first non-zero dimension
+ // M = cummax(A,dim)
+ // The operation is performed along the dimension specified by dim
+ // M = cummax(_,direction)
+ // direction specifies as the direction of operation
+ //
+ // Parameters
+ // A - real|complex numbers - vector|matrix
+ // Input Array
+ // For complex elements, cummax compares the magnitude of elements. If
+ // the magnitude are same, phase angles are compared.
+ // dim - positive integer - scalar
+ // Dimension to operate along
+ // If no dimension is specified, then the default value is the first
+ // array dimension whose value is greater than 1
+ // direction - string flag - 'forward' (default) or 'reverse'
+ // Direction of cumulation
+ // If the direction is forward, cummax works from 1 to end of the active
+ // dimension. Otherwise, it works in the opposite sense
+ //
+ // Examples
+ // 1) Cumulative maximum values in a vector
+ // v = [8 9 1 10 6 1 3 6 10 10]
+ // M = cummax(v)
+ //
+ // Expected output: [8 8 1 1 1 1 1 1 1 1]
+ //
+ // Authors
+ // Ayush Baid
+ //
+ // See Also
+ // cummax | cumprod | cumsum | max | max
+
+
+
+ [numOutArgs,numInArgs] = argn(0);
+
+ // ** Checking number of arguments
+
+ if numInArgs<1 | numInArgs>3 then
+ msg = "cummax: Wrong number of input argument; 1-6 expected";
+ error(77,msg);
+ end
+
+ if numOutArgs~=1 then
+ msg = "cummax: Wrong number of output argument; 1 expected";
+ error(78,msg);
+ end
+
+
+ // ** Parsing input args **
+
+ // defining default arguments
+ isForward = %t;
+ dim = [];
+ directionArg = "";
+ A = varargin(1);
+
+ // A should contain numeric entries
+ if ~(type(A)==1 | type(A)==8 | type(A)==17) then
+ msg = "cummax: Wrong type for argument #1 (A); Real or complex entries expected ";
+ error(53,msg);
+ end
+
+ if numInArgs>1 then
+ temp = varargin(2);
+ if type(temp)==10 then
+ // it is the direction argument
+ directionArg = temp;
+ elseif type(temp)==1 | type(temp)==8 then
+ dim = int(temp);
+ else
+ msg = "cummax: Wrong type for argument #2; Either dim (integer) or direction (string) expected";
+ error(53,msg);
+ end
+ end
+
+ if numInArgs>2 then
+ directionArg = varargin(3);
+ if type(directionArg)~=10 then
+ msg = "cummax: Wrong type for argument #3 (direction); String expected";
+ error(53,msg);
+ end
+ end
+
+ if isempty(dim) then
+ dimArray = 1:ndims(A);
+ dim = find(size(A)~=1,1);
+ end
+
+ // additional checks on dim
+ if size(A,dim)==1 then
+ M = A;
+ return
+ end
+
+ // extracting direction
+ if strcmpi(directionArg,"reverse")==0 then
+ isForward = %f;
+ elseif strcmpi(directionArg,"forward")==0 then
+ isForward = %t;
+ elseif strcmpi(directionArg,"")~=0 then
+ msg = "cummax: Wrong value for argument #3 (direction)";
+ error(53,msg);
+ end
+
+ sizeA = size(A);
+ sizeDim = size(A,dim);
+
+ // restructuring A into a 3D matrix with the specified dimension as the middle elements
+
+ leftSize = prod(sizeA(1:dim-1));
+ rightSize = prod(sizeA(dim+1:$));
+ middleSize = sizeDim;
+
+
+ A_ = matrix(A,[leftSize,middleSize,rightSize]);
+ M_ = zeros(leftSize,middleSize,rightSize);
+
+ for i=1:leftSize
+ for j=1:rightSize
+ M_(i,:,j) = cummaxVec(A_(i,:,j),isForward);
+ end
+ end
+
+ M = matrix(M_,sizeA);
+
+endfunction
+
+
+function out = cummaxVec(inp,isForward)
+ // performs cummax on vector inputs
+
+ if isForward then
+ startIndex=1;
+ endIndex = length(inp);
+ step = 1;
+ else
+ startIndex=length(inp);
+ endIndex = 1;
+ step = -1;
+ end
+
+ out(startIndex) = inp(startIndex);
+ if isreal(inp) then
+ for i=startIndex+step:step:endIndex
+ if isnan(out(i-step)) then
+ out(i) = inp(i);
+ elseif inp(i)>=out(i-step) then
+ out(i) = inp(i);
+ else
+ out(i) = out(i-step);
+ end
+ end
+ else
+ magVec = abs(inp);
+ phaseVec = atan(imag(inp),real(inp));
+
+ // phase - first compare absolute value; then give priority to positive phases
+
+ prevMag = magVec(startIndex);
+ prevPhase = phaseVec(startIndex);
+
+ for i=(startIndex+step):step:endIndex
+ if isnan(out(i-step)) then
+ out(i) = inp(i);
+ prevMag = magVec(i);
+ prevPhase = phaseVec(i);
+ elseif magVec(i)>prevMag then
+ out(i) = inp(i);
+ prevMag = magVec(i);
+ prevPhase = phaseVec(i);
+ elseif magVec(i)prevPhase then
+ out(i) = inp(i);
+ prevMag = magVec(i);
+ prevPhase = phaseVec(i);
+ else
+ out(i) = out(i-step);
+ end
+ end
+ end
+ end
+
+
+endfunction
diff --git a/macros/cummin.bin b/macros/cummin.bin
new file mode 100644
index 0000000..860597d
Binary files /dev/null and b/macros/cummin.bin differ
diff --git a/macros/cummin.sci b/macros/cummin.sci
new file mode 100644
index 0000000..fccbd52
--- /dev/null
+++ b/macros/cummin.sci
@@ -0,0 +1,204 @@
+function M = cummin(varargin)
+ // Cumulative minimum
+ //
+ // Calling Sequence
+ // M = cummin(A)
+ // returns the cumulative minimum of the arguments of A. The dimension
+ // of M is same as the dimension of A. If A is a 2D matrix, the operation
+ // is performed along the columns. For a hypermatrix, the operation is
+ // performed along the first non-zero dimension
+ // M = cummin(A,dim)
+ // The operation is performed along the dimension specified by dim
+ // M = cummin(_,direction)
+ // direction specifies as the direction of operation
+ //
+ // Parameters
+ // A - real|complex numbers - vector|matrix
+ // Input Array
+ // For complex elements, cummin compares the magnitude of elements. If
+ // the magnitude are same, phase angles are compared.
+ // dim - positive integer - scalar
+ // Dimension to operate along
+ // If no dimension is specified, then the default value is the first
+ // array dimension whose value is greater than 1
+ // direction - string flag - 'forward' (default) or 'reverse'
+ // Direction of cumulation
+ // If the direction is forward, cummin works from 1 to end of the active
+ // dimension. Otherwise, it works in the opposite sense
+ //
+ // Examples
+ // 1) Cumulative minimum values in a vector
+ // v = [8 9 1 10 6 1 3 6 10 10]
+ // M = cummin(v)
+ //
+ // Expected output: [8 8 1 1 1 1 1 1 1 1]
+ //
+ // Authors
+ // Ayush Baid
+ //
+ // See Also
+ // cummax | cumprod | cumsum | max | min
+
+
+
+ [numOutArgs,numInArgs] = argn(0);
+
+ // ** Checking number of arguments
+
+ if numInArgs<1 | numInArgs>3 then
+ msg = "cummin: Wrong number of input argument; 1-6 expected";
+ error(77,msg);
+ end
+
+ if numOutArgs~=1 then
+ msg = "cummin: Wrong number of output argument; 1 expected";
+ error(78,msg);
+ end
+
+
+ // ** Parsing input args **
+
+ // defining default arguments
+ isForward = %t;
+ dim = [];
+ directionArg = "";
+ A = varargin(1);
+
+ // A should contain numeric entries
+ if ~(type(A)==1 | type(A)==8 | type(A)==17) then
+ msg = "cummin: Wrong type for argument #1 (A); Real or complex entries expected ";
+ error(53,msg);
+ end
+
+ if numInArgs>1 then
+ temp = varargin(2);
+ if type(temp)==10 then
+ // it is the direction argument
+ directionArg = temp;
+ elseif type(temp)==1 | type(temp)==8 then
+ dim = int(temp);
+ else
+ msg = "cummin: Wrong type for argument #2; Either dim (integer) or direction (string) expected";
+ error(53,msg);
+ end
+ end
+
+ if numInArgs>2 then
+ directionArg = varargin(3);
+ if type(directionArg)~=10 then
+ msg = "cummin: Wrong type for argument #3 (direction); String expected";
+ error(53,msg);
+ end
+ end
+
+ if isempty(dim) then
+ dimArray = 1:ndims(A);
+ dim = find(size(A)~=1,1);
+ end
+
+ // additional checks on dim
+ if size(A,dim)==1 then
+ M = A;
+ return
+ end
+
+ // extracting direction
+ if strcmpi(directionArg,"reverse")==0 then
+ isForward = %f;
+ elseif strcmpi(directionArg,"forward")==0 then
+ isForward = %t;
+ elseif strcmpi(directionArg,"")~=0 then
+ msg = "cummin: Wrong value for argument #3 (direction)";
+ error(53,msg);
+ end
+
+ sizeA = size(A);
+ sizeDim = size(A,dim);
+
+ // restructuring A into a 3D matrix with the specified dimension as the middle elements
+
+ leftSize = prod(sizeA(1:dim-1));
+ rightSize = prod(sizeA(dim+1:$));
+ middleSize = sizeDim;
+
+
+ A_ = matrix(A,[leftSize,middleSize,rightSize]);
+ M_ = zeros(leftSize,middleSize,rightSize);
+
+ for i=1:leftSize
+ for j=1:rightSize
+ M_(i,:,j) = cumminVec(A_(i,:,j),isForward);
+ end
+ end
+
+ M = matrix(M_,sizeA);
+
+endfunction
+
+
+function out = cumminVec(inp,isForward)
+ // performs cummin on vector inputs
+
+ if isForward then
+ startIndex=1;
+ endIndex = length(inp);
+ step = 1;
+ else
+ startIndex=length(inp);
+ endIndex = 1;
+ step = -1;
+ end
+
+ if isreal(inp,1e-7) then
+ inp = real(inp);
+ end
+
+ out = zeros(size(inp,1),size(inp,2));
+ out(startIndex) = inp(startIndex);
+
+ if isreal(inp) then
+ for i=(startIndex+step):step:endIndex
+
+ if isnan(out(i-step)) then
+ out(i) = inp(i);
+ elseif inp(i)<=out(i-step) then
+ out(i) = inp(i);
+ else
+ out(i) = out(i-step);
+ end
+ end
+ else
+ magVec = abs(inp);
+ phaseVec = atan(imag(inp),real(inp));
+
+ // phase - first compare absolute value; then compare phase in [-pi,pi]
+
+ prevMag = magVec(startIndex);
+ prevPhase = phaseVec(startIndex);
+
+
+ for i=(startIndex+step):step:endIndex
+ if isnan(out(i-step)) then
+ out(i) = inp(i);
+ prevMag = magVec(i);
+ prevPhase = phaseVec(i);
+ elseif magVec(i)prevMag then
+ out(i) = out(i-step);
+ else
+ if phaseVec(i)0 then
+ dboutput(i, j) = 10 * log10((abs(X(i, j)) * abs(X(i, j))) / R);
+
+ else
+ dboutput(i, j) = -%inf;
+ end
+ end
+ end
+
+elseif rhs == 2 then
+
+ if (SignalType == 'voltage' | SignalType == 'Voltage' | SignalType == 'VOLTAGE') then
+ R = 1;
+ for i = 1: nr
+ for j = 1: nc
+ if (type(X(i, j)))==10 then
+ dboutput(i, j) = 10 * log10((ascii(X(i, j)) * ascii(X(i, j))) / R);
+ elseif abs(X(i,j))>0 then
+ dboutput(i, j) = 10 * log10((abs(X(i, j)) * abs(X(i, j))) / R);
+ else
+ dboutput(i, j) = -%inf;
+ end
+ end
+ end
+
+ elseif(SignalType == 'power' | SignalType == 'Power' | SignalType == 'POWER') then[i, j] = size(X);
+
+ R = 1;
+ for i = 1: nr
+ for j = 1: nc
+ if (type(X(i, j)))==10 then
+ dboutput(i, j) = 10 * log10((ascii(X(i, j)) * ascii(X(i, j))) / R);
+ elseif (X(i, j)) > 0 then
+ dboutput(i, j) = 10 * log10(X(i, j));
+ elseif(X(i,j)==0) then
+ dboutput(i,j)=-%inf;
+ else //function should not accept negative values for power
+
+ error("Power cannot be negative")
+ end
+ end
+
+ end
+
+ elseif(type(SignalType == 1))
+ R = SignalType;
+ for i = 1: nr
+ for j = 1: nc
+ if (type(X(i, j)))==10 then
+ dboutput(i, j) = 10 * log10((ascii(X(i, j)) * ascii(X(i, j))) / R);
+ elseif abs(X(i,j))>0 then
+ dboutput(i, j) = 10 * log10((abs(X(i, j)) * abs(X(i, j))) / R);
+ else
+ dboutput(i,j)=-%inf;
+ end
+ end
+ end
+ end
+
+elseif rhs == 3 then
+
+ if (type(SignalType) == 1) then
+ error('Incorrect argument. Argument 2 specifies the signal type represented by elements of X');
+
+ elseif(SignalType == 'voltage' | SignalType == 'Voltage' | SignalType == 'VOLTAGE') then
+ for i = 1: nr
+ for j = 1: nc
+ if (type(X(i, j)))==10 then
+ dboutput(i, j) = 10 * log10((ascii(X(i, j)) * ascii(X(i, j))) / R);
+ elseif abs(X(i,j))>0 then
+ dboutput(i, j) = 10 * log10((abs(X(i, j)) * abs(X(i, j))) / R);
+ else
+ dboutput(i,j)=-%inf;
+ end
+ end
+ end
+
+ elseif(SignalType == 'power' | SignalType == 'Power' | SignalType == 'POWER') then
+
+
+ for i = 1: nr
+ for j = 1: nc
+ if (type(X(i, j)))==10 then
+ dboutput(i, j) = 10 * log10((ascii(X(i, j)) * ascii(X(i, j))) / R);
+ elseif (X(i, j)) > 0 then
+ dboutput(i, j) = 10 * log10(X(i, j));
+ elseif(X(i,j)==0) then
+ dboutput(i,j)=-%inf;
+ else
+ error("Power cannot be negative");
+ end
+ end
+
+
+
+ end
+ end
+
+ end
+
+ endfunction
diff --git a/macros/db2pow.bin b/macros/db2pow.bin
new file mode 100644
index 0000000..d369ded
Binary files /dev/null and b/macros/db2pow.bin differ
diff --git a/macros/db2pow.sci b/macros/db2pow.sci
new file mode 100644
index 0000000..acc83d6
--- /dev/null
+++ b/macros/db2pow.sci
@@ -0,0 +1,29 @@
+function [y] = db2pow(ydb)
+
+//This function calculates the power value in Watt of the decibel value ydb passed as the parameter
+//Calling sequence
+//function [y] = mag2pow(ydb)
+//Parameters
+//ydb : scalar or vector or matrix or N-D array
+//Examples
+//ydb = 20
+//y=mag2pow(ydb)
+//Authors
+//Ishita Bedi
+//Modified to handle char i/p by Debdeep Dey
+
+funcprot(0);
+rhs = argn(2)
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+//This statement calculates the power in Watt of ydb which was in decibel using ydb = 10log (y) -- log base 10
+if(type(ydb)~=10) then
+ y = 10.^(ydb/10);
+else
+ y1=ascii(y);
+ y = 10.^(y1/10);
+end
+
+endfunction
+
diff --git a/macros/dctmtx.bin b/macros/dctmtx.bin
new file mode 100644
index 0000000..68472e5
Binary files /dev/null and b/macros/dctmtx.bin differ
diff --git a/macros/dctmtx.sci b/macros/dctmtx.sci
new file mode 100644
index 0000000..e0c2354
--- /dev/null
+++ b/macros/dctmtx.sci
@@ -0,0 +1,25 @@
+function [y]= dctmtx(n)
+
+// Performs Direct Cosine Transformation
+// Calling Sequence
+// [y]=dctmtx(n)
+// Parameters
+// n: Real scalar integer greater than or equal to 1
+// Description
+// This is an Octave function
+// dctmtx(n) returns a Discrete cosine transform matrix of order n-by-n. It is useful for jpeg image compression. D*A is the DCT of the columns of A and D'*A is the inverse DCT of the columns of A (when A is n-by-n).
+// Examples
+// 1. dctmtx(2)
+// ans = [0.70711 0.70711; 0.70711 -0.70711]
+// 2. dctmtx(3)
+// ans = [5.7735e-01 5.7735e-01 5.7735e-01;
+// 7.0711e-01 4.9996e-17 -7.0711e-01;
+// 4.0825e-01 -8.1650e-01 4.0825e-01]
+
+funcprot(0);
+rhs=argn(2);
+if (rhs<1) then
+ error ("Wrong number of input arguments.")
+else [y]=callOctave("dctmtx",n)
+end
+endfunction
diff --git a/macros/decimate.bin b/macros/decimate.bin
new file mode 100644
index 0000000..ea34ac2
Binary files /dev/null and b/macros/decimate.bin differ
diff --git a/macros/decimate.sci b/macros/decimate.sci
new file mode 100644
index 0000000..5a2e428
--- /dev/null
+++ b/macros/decimate.sci
@@ -0,0 +1,47 @@
+function y = decimate(x, q, n, ftype)
+rhs = argn(2)
+if(rhs<2 | rhs>4)
+error("Wrong number of input arguments.")
+elseif(~(sum(length(q)==1) & q == fix (q) & q > 0))
+error("Parameter 2 must be a positive integer.")
+end
+if (nargin < 3)
+ftype = "iir"
+n = []
+elseif (nargin < 4)
+if (ischar (n))
+ftype = n
+n = []
+else
+ftype = "iir"
+end
+end
+
+if (~ and(strcmp (ftype, {"fir", "iir"})))
+error("Filter type must be either fir or iir.")
+end
+
+fir = strcmp (ftype, "fir")
+if (isempty (n))
+if (fir)
+n = 30
+else
+n = 8
+end
+end
+
+if(~(sum(length(n)==1) & n == fix (n) & n > 0))
+error("N must be a positive integer.")
+end
+select(rhs)
+case 2 then
+y = callOctave("decimate", x, q)
+case 3 then
+y = callOctave("decimate", x, q, n)
+case 4 then
+y = callOctave("decimate", x, q, n, ftype)
+end
+endfunction
+
+
+
diff --git a/macros/decimate.sci~ b/macros/decimate.sci~
new file mode 100644
index 0000000..376241a
--- /dev/null
+++ b/macros/decimate.sci~
@@ -0,0 +1,48 @@
+function y = decimate(x, q, n, ftype)
+rhs = argn(2)
+if(rhs<2 | rhs>4)
+error("Wrong number of input arguments.")
+end
+elseif(~(sum(length(q)==1) & q == fix (q) & q > 0))
+error("Parameter 2 must be a positive integer.")
+end
+if (nargin < 3)
+ftype = "iir"
+n = []
+elseif (nargin < 4)
+if (ischar (n))
+ftype = n
+n = []
+else
+ftype = "iir"
+end
+end
+
+if (~ and(strcmp (ftype, {"fir", "iir"})))
+error("Filter type must be either fir or iir.")
+end
+
+fir = strcmp (ftype, "fir")
+if (isempty (n))
+if (fir)
+n = 30
+else
+n = 8
+end
+end
+
+if(~(sum(length(n)==1) & n == fix (n) & n > 0))
+error("N must be a positive integer.")
+end
+select(rhs)
+case 2 then
+y = callOctave("decimate", x, q)
+case 3 then
+y = callOctave("decimate", x, q, n)
+case 4 then
+y = callOctave("decimate", x, q, n, ftype)
+end
+endfunction
+
+
+
diff --git a/macros/dftmtx.bin b/macros/dftmtx.bin
new file mode 100644
index 0000000..df1c875
Binary files /dev/null and b/macros/dftmtx.bin differ
diff --git a/macros/dftmtx.sci b/macros/dftmtx.sci
new file mode 100644
index 0000000..39ef91f
--- /dev/null
+++ b/macros/dftmtx.sci
@@ -0,0 +1,23 @@
+function [d]=dftmtx(n)
+
+// Computes Discrete n-by-n Fourier transformation matrix
+// Calling Sequence
+// [d]=dftmtx(n)
+// Parameters
+// n: Real positive scalar number
+// Description
+// This is an Octave function
+// This fuction gives a complex matrix of values whose product with a vector produces the discrete Fourier transform. This can also be achieved by directly using the fft function i.e. y=fft(x) is same as y=A*x where A=dftmtx(n).
+// Examples
+// 1. dftmtx(3)
+// ans = 1.00000 + 0.00000i 1.00000 + 0.00000i 1.00000 + 0.00000i
+// 1.00000 + 0.00000i -0.50000 - 0.86603i -0.50000 + 0.86603i
+// 1.00000 - 0.00000i -0.50000 + 0.86603i -0.50000 - 0.86603i
+
+funcprot(0);
+rhs=argn(2);
+if (rhs<1) then
+ error("Wrong number of input arguments.")
+else d= callOctave("dftmtx",n)
+end
+endfunction
diff --git a/macros/diric.bin b/macros/diric.bin
new file mode 100644
index 0000000..47eaa34
Binary files /dev/null and b/macros/diric.bin differ
diff --git a/macros/diric.sci b/macros/diric.sci
new file mode 100644
index 0000000..077bb13
--- /dev/null
+++ b/macros/diric.sci
@@ -0,0 +1,24 @@
+function [y]= diric(x,n)
+
+// Calculates the dirichlet function
+// Calling Sequence
+// [y]=diric(x,n)
+// Parameters
+// x: Real valued vector or matrix
+// n: Real positive integer or complex integer
+// Description
+// This is an Octave function
+// y=diric(x,n) returns the dirichlet function values of parameter x.
+// Examples
+// 1. diric([1 2 3],3)
+// ans= 0.6935349 0.0559021 -0.3266617
+// 2. diric(1,2)
+// ans= 0.8775826
+
+funcprot(0);
+rhs=argn(2);
+if (rhs~=2) then
+ error ("Wrong number of input arguments.")
+else y= callOctave("diric",x,n)
+end
+endfunction
diff --git a/macros/downsample.bin b/macros/downsample.bin
new file mode 100644
index 0000000..149a5cb
Binary files /dev/null and b/macros/downsample.bin differ
diff --git a/macros/downsample.sci b/macros/downsample.sci
new file mode 100644
index 0000000..9bd1591
--- /dev/null
+++ b/macros/downsample.sci
@@ -0,0 +1,31 @@
+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.")
+end
+
+ select(rhs)
+ case 2 then
+ y = callOctave("downsample",x,n)
+ case 3 then
+ y = callOctave("downsample",x,n,phase)
+ end
+endfunction
diff --git a/macros/dutycycle.bin b/macros/dutycycle.bin
new file mode 100644
index 0000000..710c058
Binary files /dev/null and b/macros/dutycycle.bin differ
diff --git a/macros/dutycycle.sci b/macros/dutycycle.sci
new file mode 100755
index 0000000..1938453
--- /dev/null
+++ b/macros/dutycycle.sci
@@ -0,0 +1,455 @@
+function [d, initialcross, finalcross, nextcross, midreference]= dutycycle(x, varargin)
+
+
+ // This function estimate duty cycle of bilevel waveform pulses.
+ // Calling Sequence
+ // d=dutycycle(x)
+ // d= dutycycle(X,Fs)
+ // d=dutycycle(x, t)
+ // d= dutycycle(tau, prf)
+ // d=dutycycle (x, t, 'Polarity', pol)
+ // d=dutycycle(x, t, 'MidPercentReferenceLevel', N )
+ // d=dutycycle(x, t, 'Tolerance', M)
+ // d=dutycycle(x, t,'StateLevels', O)
+
+ // [d initialcross finalcross nextcross midreference]=dutycycle(x)
+ // [d initialcross finalcross nextcross midreference]=dutycycle(x, t)
+ // [d initialcross finalcross nextcross midreference]=dutycycle(x, Fs)
+ // [d initialcross finalcross nextcross midreference]=dutycycle(x, t, 'Polarity', pol)
+ // [d initialcross finalcross nextcross midreference]=dutycycle(x, t, 'MidPercentReferenceLevel', N )
+ // [d initialcross finalcross nextcross midreference]= dutycycle(x, t, 'Tolerance', M)
+ // [d initialcross finalcross nextcross midreference]= dutycycle(x, t,'StateLevels', O)
+ // [d initialcross finalcross nextcross midreference]= dutycycle(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.
+ // t: defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.
+ // tau: define real scalar input pulse width TAU (in seconds).
+ // prf: pulse repetition frequency PRF (in Hz). The product of TAU and PRF must be less than or equal to 1.
+ // Polarity: specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive'.
+ // MidPercentReferenceLevel: specify the mid percent reference leves as a percentage, default value of N is 50.
+ // Tolerance: define the tolerance value as real scaler value, where default value of M is 2.0.
+ // StateLevels: define the lower and upper state levels as two element real vector.
+ // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.
+ // d: returns the ratio of the pulse width to the pulse period for each positive-polarity pulse
+ // initialcross: returns a vector of initial cross values of bilevel waveform transitions X
+ // finalcross: returns a vector of final cross values of bilevel waveform transitions X
+ // nextcross: returns a vector of next cross values of bilevel waveform transitions X
+ // midreference: return mid reference value corrosponding to mid percenr reference value.
+
+ // Examples
+ // x=[1.2, 5, 10, -20, 12]
+ //t=1:length(x)
+ //d=dutycycle(x, t)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+ // run statelevels and midcross function before running risetime function.
+
+
+
+
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+end
+
+
+
+ if sum(length(x))==1 & length(varargin)==0 then
+ error('You need exactly two inputs specified when TAU is a scalar.')
+ elseif sum(length(x))==1 & type(varargin(1))==1 then
+
+
+ if length(argn(1))>1 then
+ error('Too many outputs specified when TAU is a scalar.');
+ end
+
+ dd=x*varargin(1);
+
+ if or(dd>1) then
+
+ error('The product of TAU and PRF should be less than or equal to 1.')
+ else
+ d=x*varargin(1);
+ end
+
+ else
+
+
+ if length(varargin)==0 then
+ varargin=varargin;
+ end
+
+ sindex=[];
+if length(varargin)>=1 then
+a=1;
+for i=1:length(varargin)
+ if type(varargin(i))==10 then
+ sindex(a)=i;
+ a=a+1;
+ end
+end
+end
+
+
+pol='POSITIVE';
+polidx=[];
+fig='OFF'
+index_on=[];
+if (~isempty(sindex)) then
+ for j=1:length(sindex)
+ select convstr(varargin(sindex(j)), 'u') // validating input variable names
+ 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);
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+
+ error('parameter StateLevels required a value.')
+
+
+ elseif type(varargin(sindex(j)+1))==10 then
+
+ error('Expected STATELEVELS to be one of these types: double, Instead its type was char.')
+ end
+
+ case {'MIDPERCENTREFERENCELEVEL'}
+ if length(varargin) <=sindex(j) then
+ error(strcat(['parameter MidPercentRefernceLevel required a value.']));
+ end
+
+ if type(varargin(sindex(j)+1))==1 then
+ midpercentval= varargin(sindex(j)+1);
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+ error('parameter MidPercentRefernceLevel required a value.')
+
+ elseif type(varargin(sindex(j)+1))==10 then
+ error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.')
+ end
+
+
+
+
+ case {'TOLERANCE'}
+
+ 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);
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+
+ error('parameter Tolerance required a value.');
+
+ elseif type(varargin(sindex(j)+1))==10 then
+
+ error('Expected Tolerance to be one of these types: double, Instead its type was char.');
+ end
+
+
+
+ case {'FIG'}
+
+ if length(varargin) <=sindex(j) then
+ error(strcat(['parameter fig required a value.']));
+ end
+
+ if type(varargin(sindex(j)+1))==1 then
+ error ('Expected fig to match one of these strings: on or off');
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+ error('parameter fig required a value.')
+ else
+ fig= convstr(varargin(sindex(j)+1), 'u');
+
+ end
+
+
+ if fig == 'OFF' | fig == 'ON' then
+ else
+ error('Expected fig to match one of these strings: on or off');
+ end
+
+
+
+ case{'ON'}
+ index_on=sindex(j)
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(sindex(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+ case{'OFF'}
+
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(sindex(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+
+
+
+ case{'POLARITY'}
+
+ if length(varargin)<=sindex(j) then
+ error ('Parameter polarity requires a value.')
+ end
+
+ if type( varargin(sindex(j)+1))==1 then
+ error ('POLARITY must be either ''Positive'' or ''Negative''.')
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' then
+
+ error ('Parameter polarity requires a value.')
+
+
+ elseif convstr(varargin(sindex(j)+1), 'u') ~= 'POSITIVE' & convstr(varargin(sindex(j)+1), 'u')~= 'NEGATIVE' then
+
+ error ('POLARITY must be either ''Positive'' or ''Negative''.');
+
+ else
+ polidx=sindex(j);
+ end
+
+
+ case {'POSITIVE'}
+
+ if j==1 then
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY'
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ else
+ polinputidx= sindex(j);
+
+ pol= convstr(varargin (sindex(j)), 'u') ;
+ end
+
+ case {'NEGATIVE'}
+
+ if j==1 then
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY'
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ else
+ polinputidx= sindex(j);
+
+ pol= convstr(varargin (sindex(j)), 'u') ;
+ end
+
+ else
+ error(strcat(['Invalid optional argument'," ", varargin(sindex(j))]));
+ end // switch
+ end // for
+ end // if
+//
+
+if length(index_on)>0 then
+ varargin(index_on)='OFF';
+end
+
+
+if length(polidx)>0 then
+ varargin(polidx)=null();
+ varargin(polinputidx-1)=null();
+end
+
+
+ [crossval midref levels t tolerance]= midcross(x, varargin(:));
+
+ upperbound= levels(2)- (tolerance/100)*(levels(2)-levels(1));
+ mostupperbound=levels(2)+ (tolerance/100)*(levels(2)-levels(1));
+ lowerbound= levels(1)+ (tolerance/100)*(levels(2)-levels(1));
+ mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1));
+
+ int_pos=[];
+ final_pos=[];
+ int_neg=[];
+ final_neg=[];
+ nextcross_pos=[];
+nextcross_neg=[];
+
+if length(crossval)>=2 then
+
+if x(1)>midref then
+
+ int_pos=crossval(2:2:$);
+ final_pos=crossval(3:2:$);
+ int_neg=crossval(1:2:$);
+ final_neg=crossval(2:2:$);
+
+else
+
+ int_pos=crossval(1:2:$);
+ final_pos=crossval(2:2:$);
+ int_neg=crossval(2:2:$);
+ final_neg=crossval(3:2:$);
+
+end
+
+
+
+
+if length(int_pos)>=2 then
+ nextcross_pos=int_pos(2:$);
+end
+
+if length(int_neg)>=2 then
+ nextcross_neg=int_neg(2:$);
+ end
+
+
+
+
+if length(int_pos)>length(final_pos) then
+ int_pos=int_pos(1:($-1))
+elseif length(int_neg)>length(final_neg) then
+ int_neg=int_neg(1:($-1))
+ end
+
+
+
+
+
+
+ if length(int_pos)>length(nextcross_pos) then
+ int_pos=int_pos(1:($-1))
+
+ end
+ if length(final_pos)>length(nextcross_pos)
+ final_pos=final_pos(1:($-1))
+
+ end
+
+ if length(int_neg)>length(nextcross_neg) then
+ int_neg=int_neg(1:($-1));
+ end
+
+ if length(final_neg)>length(nextcross_neg) then
+ final_neg=final_neg(1:($-1));
+ end
+
+
+end
+
+
+
+d=[];
+
+
+ if pol=='POSITIVE' then
+
+ initialcross=int_pos;
+ finalcross=final_pos;
+ nextcross=nextcross_pos;
+
+ d=(finalcross-initialcross)./(nextcross-initialcross);
+
+ else
+
+ initialcross=int_neg;
+ finalcross=final_neg
+ nextcross=nextcross_neg;
+ d=(finalcross-initialcross)./(nextcross-initialcross);
+
+ end
+
+
+
+
+ midreference=midref;
+
+
+//midreference=midref;
+
+ if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels
+
+ if length(d)==0 then
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+ // xtitle('', 'Time (second)','Level (Volts)' );
+ plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,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)
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?')
+
+
+ else
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+
+ plot(t,midreference * ones(1, length(t)),'-g', 'LineWidth',0.5)
+
+
+ //n=length(finalcross);
+
+
+// rects=[initialcross(1:2:$); levels(2)*ones(d(1:2:$)); p(1:2:$); (levels(2)-levels(1))*ones(p(1:2:$))]
+//
+//
+// col=-10*ones(p(1:2:$));
+
+ midc=[nextcross, initialcross, finalcross];
+ midcross=gsort(midc, 'c','i' )
+
+ plot(midcross, midreference*ones(midcross), "r*", 'MarkerSize',15);
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5)
+
+ plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5)
+
+ // xrects(rects, col);
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends([ "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [ [1;1], [-10;5], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?')
+
+ end
+end
+end
+//
+//
+endfunction
diff --git a/macros/ellip.bin b/macros/ellip.bin
new file mode 100644
index 0000000..2fda3a0
Binary files /dev/null and b/macros/ellip.bin differ
diff --git a/macros/ellip.sci b/macros/ellip.sci
new file mode 100644
index 0000000..264d9fe
--- /dev/null
+++ b/macros/ellip.sci
@@ -0,0 +1,60 @@
+function [a, b, c, d] = ellip (n, rp, rs, w, varargin)
+//This function generates an elliptic or Cauer filter with rp dB of passband ripple and rs dB of stopband attenuation.
+//Calling Sequence
+//[a, b] = ellip (n, rp, rs, wp)
+//[a, b] = ellip (n, rp, rs, wp, "high")
+//[a, b] = ellip (n, rp, rs, [wl, wh])
+//[a, b] = ellip (n, rp, rs, [wl, wh], "stop")
+//[a, b, c] = ellip (…)
+//[a, b, c, d] = ellip (…)
+//[…] = ellip (…, "s")
+//Parameters
+//n: positive integer value
+//rp: non negative scalar value
+//rs: non negative scalar value
+//w: scalar or vector, all elements should be in the range [0,1]
+//Description
+//This is an Octave function.
+//This function generates an elliptic or Cauer filter with rp dB of passband ripple and rs dB of stopband attenuation.
+//[b, a] = ellip(n, Rp, Rs, Wp) indicates low pass filter with order n, Rp decibels of ripple in the passband and a stopband Rs decibels down and cutoff of pi*Wp radians. If the fifth argument is high, then the filter is a high pass filter.
+//[b, a] = ellip(n, Rp, Rs, [Wl, Wh]) indictaes band pass filter with band pass edges pi*Wl and pi*Wh. If the fifth argument is stop, the filter is a band reject filter.
+//[z, p, g] = ellip(...) returns filter as zero-pole-gain.
+//[...] = ellip(...,’s’) returns a Laplace space filter, w can be larger than 1.
+//[a, b, c, d] = ellip(...) returns state-space matrices.
+//Examples
+//[a,b]=ellip(2, 0.5, 0.7, [0.3,0.4])
+//a =
+// 0.88532 -1.58410 2.40380 -1.58410 0.88532
+//b =
+// 1.00000 -1.78065 2.68703 -1.75725 0.97454
+
+rhs = argn(2)
+lhs = argn(1)
+if(rhs>3)
+[rows,columns] = size(w)
+end
+if(rhs>6 | rhs<4)
+error("Wrong number of input arguments.")
+end
+if(lhs>4 | lhs<2)
+error("Wrong number of output arguments.")
+end
+
+select (rhs)
+ case 4 then
+ if (lhs==2) [a,b] = callOctave("ellip",n, rp, rs, w)
+ elseif (lhs==3) [a,b,c] = callOctave("ellip",n, rp, rs, w)
+ elseif (lhs==4) [a,b,c,d] = callOctave("ellip",n, rp, rs, w)
+ end
+ case 5 then
+ if (lhs==2) [a,b] = callOctave("ellip",n, rp, rs, w, varargin(1))
+ elseif (lhs==3) [a,b,c] = callOctave("ellip",n, rp, rs, w, varargin(1))
+ elseif (lhs==4) [a,b,c,d] = callOctave("ellip",n, rp, rs, w, varargin(1))
+ end
+ case 6 then
+ if (lhs==2) [a,b] = callOctave("ellip",n, rp, rs, w, varargin(1), varargin(2))
+ elseif (lhs==3) [a,b,c] = callOctave("ellip",n, rp, rs, w,varargin(1), varargin(2))
+ elseif (lhs==4) [a,b,c,d] = callOctave("ellip",n, rp, rs, w, varargin(1), varargin(2))
+ end
+ end
+endfunction
diff --git a/macros/ellipord.bin b/macros/ellipord.bin
new file mode 100644
index 0000000..60fca21
Binary files /dev/null and b/macros/ellipord.bin differ
diff --git a/macros/ellipord.sci b/macros/ellipord.sci
new file mode 100644
index 0000000..cc81ab7
--- /dev/null
+++ b/macros/ellipord.sci
@@ -0,0 +1,36 @@
+function [n, Wp] = ellipord(Wp, Ws, Rp, Rs)
+//This function computes the minimum filter order of an elliptic filter with the desired response characteristics.
+//Calling Sequence
+//[n] = ellipord(Wp, Ws, Rp, Rs)
+//[n, Wp] = ellipord(Wp, Ws, Rp, Rs)
+//Parameters
+//Wp: scalar or vector of length 2, all elements must be in the range [0,1]
+//Ws: scalar or vector of length 2, all elements must be in the range [0,1]
+//Rp: real or complex value
+//Rs: real or complex value
+//Description
+//This is an Octave function.
+//This function computes the minimum filter order of an elliptic filter with the desired response characteristics.
+//Stopband frequency ws and passband frequency wp specify the the filter frequency band edges.
+//Frequencies are normalized to the Nyquist frequency in the range [0,1].
+//Rp is measured in decibels and is the allowable passband ripple and Rs is also measured in decibels and is the minimum attenuation in the stop band.
+//If ws>wp then the filter is a low pass filter. If wp>ws, then the filter is a high pass filter.
+//If wp and ws are vectors of length 2, then the passband interval is defined by wp and the stopband interval is defined by ws.
+//If wp is contained within the lower and upper limits of ws, the filter is a band-pass filter. If ws is contained within the lower and upper limits of wp, the filter is a band-stop or band-reject filter.
+//Examples
+//[a,b]=ellipord(0.2, 0.5, 0.7, 0.4)
+//a = 1
+//b = 0.20000
+
+rhs = argn(2)
+lhs = argn(1)
+if(rhs~=4)
+error("Wrong number of input arguments.")
+end
+select(lhs)
+case 1 then
+n = callOctave("ellipord",Wp,Ws,Rp,Rs)
+case 2 then
+[n,Wp] = callOctave("ellipord",Wp,Ws,Rp,Rs)
+end
+endfunction
diff --git a/macros/enbw.bin b/macros/enbw.bin
new file mode 100644
index 0000000..6dabe0e
Binary files /dev/null and b/macros/enbw.bin differ
diff --git a/macros/enbw.sci b/macros/enbw.sci
new file mode 100644
index 0000000..f7cc457
--- /dev/null
+++ b/macros/enbw.sci
@@ -0,0 +1,56 @@
+function bw= enbw (window, fs)
+
+
+
+ // This function estimate Equivalent noise bandwidth.
+ // Calling Sequence
+ // bw=enbw(window)
+ // bw=enbw(window, fs)
+ //
+ // Parameters
+ // window: specify the sample window.
+ // fs: specify the sampling rate of window.
+ // bw: returns the two-sided equivalent noise bandwidth for a uniformly sampled window
+
+ // Examples
+ // window=1:10
+ //fs=2.5
+ //bw=enbw(window, fs)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+ if isreal(window) then
+ else
+ error ('Input arguments window should be real.')
+end
+
+ if isvector(window) then
+ else
+ error ('Input arguments window should be a vector.')
+end
+
+
+ if or(type(window)==10) then
+ error ('Input arguments must be double.')
+end
+
+ if type (window)~=1 then
+ error ('Expected input number 1, WINDOW, to be one of these types: double, single..Isntead its type was char.' )
+ end
+
+ rms_win= sqrt(mean(window.*window));
+
+ bw = (rms_win/mean(window))^2;
+
+
+if argn(2) > 1
+
+ if fs<=0 then
+ error ('Expected input number 2, Fs, to be positive.')
+ end
+
+ bw = bw * (fs) / length(window);
+end
+
+endfunction
diff --git a/macros/eqtflength.bin b/macros/eqtflength.bin
new file mode 100644
index 0000000..4aa5c4b
Binary files /dev/null and b/macros/eqtflength.bin differ
diff --git a/macros/eqtflength.sci b/macros/eqtflength.sci
new file mode 100644
index 0000000..505322f
--- /dev/null
+++ b/macros/eqtflength.sci
@@ -0,0 +1,34 @@
+function [b,a,N,M] = eqtflength(b,a)
+//Modifies the input vector to give output vectors of the same length
+//Calling Sequence
+//[b,a] = eqtflength(b,a)
+//[b,a,N,M] = eqtflength(b,a)
+
+//Author
+//Debdeep Dey
+ if(argn(2)~=2)
+ error('Incorrect number of input arguments');
+ elseif(length(a)==0|max(abs(a))==0)
+ error('Division by zero not allowed');
+ elseif(type(b)==10 | type(a)==10)
+ b=b;
+ a=a;
+ else
+ a=a(:).';
+ b=b(:).';
+ a=[a,zeros(1,max(0,length(b)-length(a)))];
+ b=[b,zeros(1,max(0,length(a)-length(b)))];
+ ai=find(a~=0);
+ bi=find(b~=0);
+ M=ai($)-1;
+ if isempty(bi) then
+ N=0;
+ else
+ N=bi($)-1;
+ end
+ n=max(M+1,N+1);
+ a=a(1:n);
+ b=b(1:n);
+ end
+endfunction
+
diff --git a/macros/falltime.bin b/macros/falltime.bin
new file mode 100644
index 0000000..318d449
Binary files /dev/null and b/macros/falltime.bin differ
diff --git a/macros/falltime.sci b/macros/falltime.sci
new file mode 100644
index 0000000..b2e436a
--- /dev/null
+++ b/macros/falltime.sci
@@ -0,0 +1,380 @@
+function [f, lowercrossvalue, uppercrossvalue, lowerreference, upperreference]=falltime(x, varargin)
+
+ // This function estimate falltime values of real vector X.
+ // Calling Sequence
+ // r=falltime(x)
+ // r=falltime(x, t)
+ // r=falltime(x, Fs)
+ // r=falltime(x, t, 'PercentReferenceLevels', N )
+ // r=falltime(x, t, 'Tolerance', M)
+ // r=falltime(x, t,'StateLevels', O)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]=falltime(x)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]=falltime(x, Fs)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]=falltime(x, t)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]=falltime(x, t, 'PercentReferenceLevels', N )
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]= falltime(x, t, 'Tolerance', M)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]= falltime(x, t,'StateLevels', O)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]= falltime(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.
+ // t: defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.
+ // PercentReferenceLevels: specify the percentreferenceleves 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'.
+ // f: return fall time of negative-going bilevel waveform transitions X.
+ // lowercrossvalue: return the lowerc cross value.
+ // uppercrossvalue: return the upper cross value.
+ // lowerreference: return lower reference value corrosponding to lower percent reference value.
+ // upperreference: return upper reference value corrosponding to upper percent reference value.
+
+ // Examples
+ // x=[1.2, 5, 10, -20, 12]
+ //t=1:length(x)
+ //f=falltime(x, t)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+
+ // run statelevels and midcross function before running risetime function.
+
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+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
+else
+ t=1:length(x);
+end
+
+
+if length(varargin)>=2 & type(varargin(1))==1 & type(varargin(2))==1 then
+ error ("Too many leading numeric arguments (at most 2 expected).");
+end
+
+
+
+
+sindex=[];
+if length(varargin)>=1 then
+a=1;
+
+for i=1:length(varargin)
+ if type(varargin(i))==10 then
+ sindex(a)=i;
+ a=a+1;
+ end
+end
+end
+
+
+if length(sindex)>5 then
+ error('Unexpected argument.')
+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')
+
+end
+
+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);
+
+ 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.')
+
+
+ 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'}
+ if length(varargin) <=sindex(j) then
+ 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.')
+ end
+
+ if length( midpercentval)~=2 then
+ 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
+ fig= convstr(varargin(sindex(j)+1), 'u');
+
+ end
+
+
+ if fig == 'OFF' | fig == 'ON' then
+ else
+ error('Expected fig to match one of these strings: on or off');
+ 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);
+
+ 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
+ error(strcat(['Invalid optional argument'," ", varargin(sindex(j))]));
+ end // switch
+ end // for
+ end // if
+
+/////////////////////////////////////////////
+
+
+
+ indexx=[];
+if length(sindex)>=1 then
+a=1;
+for i=1:length(sindex)
+
+ indexx(a)=find(convstr(varargin(sindex(i)), 'u')=='MIDPERCENTREFERENCELEVEL')
+ a=a+1;
+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;
+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')
+
+ a=a+1;
+
+end
+end
+
+if sum(index_on)>0 then
+ Lvarargin(sindex(find(index_on>0)))='OFF';
+ Uvarargin(sindex(find(index_on>0)))='OFF';
+end
+
+
+
+
+
+ [lcrossval lref levels t tolerance]= midcross(x, Lvarargin(:)); // calling midcross function to get lower cross values
+
+ [ucrossval uref]=midcross(x, Uvarargin(:)); // calling midcross function to get upper cross values
+
+
+ if length(lcrossval)==length(ucrossval) then
+ dff=lcrossval-ucrossval
+ f=dff(dff>0)
+ elseif length(lcrossval)>length(ucrossval)
+ n=length(ucrossval);
+ dff=lcrossval-ucrossval(1:n);
+ f=dff(dff>0)
+ else
+ n=length(lcrossval);
+ dff=lcrossval(1:n)-ucrossval;
+ f=dff(dff>0)
+
+ end
+
+ difference=ucrossval-lcrossval;
+ Nindex=find(difference<0);
+
+
+
+ uppercrossvalue=ucrossval(Nindex);
+ lowercrossvalue=lcrossval(Nindex);
+
+ lowerreference=lref;
+ 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));
+
+
+
+
+
+ if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels
+ if length(f)==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,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)
+
+ xlabel("Time (second)", "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='?')
+
+
+ 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=[uppercrossvalue; upperreference*ones(uppercrossvalue); f; (upperreference-lowerreference)*ones(f)]
+
+ col=-10*ones(f);
+
+ 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,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)
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["risetime"; "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
+
+
+endfunction
diff --git a/macros/fftfilt.bin b/macros/fftfilt.bin
new file mode 100644
index 0000000..4ddcc74
Binary files /dev/null and b/macros/fftfilt.bin differ
diff --git a/macros/fftfilt.sci b/macros/fftfilt.sci
new file mode 100644
index 0000000..1fcd211
--- /dev/null
+++ b/macros/fftfilt.sci
@@ -0,0 +1,207 @@
+function y = fftfilt(b, x, varargin)
+ // Performs FFT-based FIR filtering using overlap-add method
+ //
+ // Calling sequence
+ // y = fftfilt(b,x)
+ // y = fftfilt(b,x,n)
+ //
+ // Parameters
+ // x: real|complex numbers - vector|matrix
+ // Input data to be filtered
+ // If x is a matrix, each column is treated as an independent observation.
+ // b: real|complex numbers - vector|matrix
+ // Filter coefficients
+ // If b is a matrix and x is a vector, each column is treated as an
+ // independent filter. If both x and b are matrices, each column of x
+ // if filtered using corresponding column of b.
+ // n: positive integer
+ // Parameter used to determine the length of the fft
+ //
+ // Description
+ // y = fftfilt(b,x) filters the data in vector x with the filter described
+ // by coefficient vector b.
+ // y = fftfilt(b,x,n) uses n to determine the length of the FFT.
+ //
+ // Examples
+ // 1) Filtering a sine wave
+ // 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];
+ // y = fftfilt(b,x);
+ //
+ // Authors
+ // Ayush Baid
+
+
+
+
+ [numOutArgs,numInArgs] = argn(0);
+
+// ** Checking number of arguments
+
+ if numInArgs<1 | numInArgs>3 then
+ msg = "fftfilt: Wrong number of input argument; 1-3 expected";
+ error(77,msg);
+ end
+
+ if numOutArgs~=1 then
+ msg = "fftfilt: Wrong number of output argument; 1 expected";
+ error(78,msg);
+ end
+
+ // variables to keep track if the input vectors are column vectors
+ transform_x = %f;
+
+// ** checking the type of input arguments **
+ if isempty(b) then
+ y = zeros(size(x,1),size(x,2));
+ return;
+ end
+
+ // b should contain numeric entries
+ if ~(type(b)==1 | type(b)==8 | type(b)==17) then
+ msg = "fftfilt: Wrong type for argument #1 (b); Real or complex entries expected ";
+ error(53,msg);
+ end
+
+ // x should contain numeric entries
+ if ~(type(x)==1 | type(x)==8 | type(x)==17) then
+ msg = "fftfilt: Wrong type for argument #2 (x); Real or complex entries expected ";
+ error(53,msg);
+ end
+ temp = size(x,1);
+
+ // b and x must have compatible dimensions
+ inpType = 0;
+ if size(b,1)==1 | size(b,2)==1 then
+ // b is a vector; hence x can be a matrix
+ inpType = 1;
+ // if x is a vector; it should be a column vector
+ if size(x,1)==1 then
+ x = x(:);
+ transform_x = %t;
+ end
+
+ // covert b to column vector
+ b = b(:);
+ else
+ // b is a matrix, hence x should either be a vector or a matrix with
+ // same number of columns
+
+ if size(x,1)==1 | size(x,2)==1 then
+ inpType = 2;
+ if size(x,1)==1 then
+ x = x(:);
+ transform_x = %t;
+ end
+ else
+ // check compatibility
+ if size(b,2)~=size(x,2) then
+ msg = "fftfilt: Wrong size for arguments #1 (b) and #2 (x); Must have same number of columns";
+ error(60,msg);
+ end
+ inpType = 3;
+ end
+ end
+
+
+ // getting the length of data vector x
+ nx = size(x,1);
+ nb = size(b,1);
+
+ if numInArgs==2 then // the param n was not passed
+ // figure out the nfft (length of the fft) and L (length of fft inp block)to be used
+ if (nb>=nx | nb>2^20) then
+ // take a single fft
+ nfft = 2^nextpow2(nb+nx-1);
+ L = nx;
+ else
+ // estimated flops for the fft operation (2.5nlog n for n in powers of 2 till 20)
+ fftflops = [5, 20, 60, 160, 400, 960, 2240, 5120, 11520, 25600, 56320, 122880, 266240, 573440, 1228800, 2621440, 5570560, 11796480, 24903680, 52428800];
+ n = 2.^(1:20);
+ candidateSet = find(n>(nb-1)); // all candidates for nfft must be > (nb-1)
+ n = n(candidateSet);
+ fftflops = fftflops(candidateSet);
+
+ // minimize (number of blocks)*(number of flops per fft)
+ L = n - (nb - 1);
+ numOfBlocks = ceil(nx./L);
+ [dum,ind] = min( numOfBlocks .* fftflops ); //
+ nfft = n(ind);
+ L = L(ind);
+
+ end
+ else // nfft is given
+ if nfft < nb then
+ nfft = nb;
+ end
+ nfft = 2.^(ceil(log(nfft)/log(2))); // forcing nfft to a power of 2 for speed
+ L = nfft - nb + 1;
+ end
+
+ // performing fft on b
+
+ if nb0 then
+ pad = zeros(temp,size(block,2));
+ block = [block; pad];
+ end
+
+ X = fft(block,-1,1);
+ end
+ Y = fft(X.*B,1,1);
+
+ yEndIndex = min(nx, blockStartIndex+nfft-1);
+
+ y(blockStartIndex:yEndIndex,:) = y(blockStartIndex:yEndIndex,:) + Y(1:(yEndIndex-blockStartIndex+1),:);
+
+ blockStartIndex = blockStartIndex+L;
+ end
+
+
+ // if both data and filter coeffs were real, the output should be real
+ if ~(or(imag(b(:))) | or(imag(x(:)))) then
+ y = real(y);
+ end
+
+
+ if inpType==1 & transform_x then
+ y = y';
+ end
+
+
+endfunction
+
+
+
diff --git a/macros/filternorm.bin b/macros/filternorm.bin
new file mode 100644
index 0000000..8e15a18
Binary files /dev/null and b/macros/filternorm.bin differ
diff --git a/macros/filternorm.sci b/macros/filternorm.sci
new file mode 100644
index 0000000..fec6755
--- /dev/null
+++ b/macros/filternorm.sci
@@ -0,0 +1,147 @@
+function L = filternorm(b,a,varargin)
+// Calculates the L-2 norm or L-infinity norm of a digital filter
+//
+// Calling Sequence
+// L = filternorm(b,a)
+// L = filternorm(b,a,pnorm)
+// L = filternorm(b,a,2,tol)
+//
+//
+// Parameters
+// b: The filter numerator coefficients.
+// a: The filter denominator coefficients.
+// pnorm: The L-norm to be calculated. The values accepted are 2 (L2 norm) or %inf (L-infinity norm). Default value is 2.
+// tol: The tolerance of the L-2 norm to be calculated. If tol not specified, it defaults to 10^(-8). tol must be a positive scalar
+//
+//
+// Examples
+// // 1) L-2 norm of an IIR filter with tol = 10^(-10)
+// b = [-3 2];
+// a = [1 -0.5];
+// L = filternorm(b, a, 2, 10d-10);
+//
+//
+// See also
+// norm
+// zp2sos
+//
+// Authors
+// Ayush Baid
+
+exec('impz.sci', -1);
+
+// ** Check on number of input, output arguments
+[numOutArgs, numInArgs] = argn(0);
+
+if numInArgs<2 | numInArgs>4 then
+ msg = "filternorm: Wrong number of input argument; 2-4 expected";
+ error(77,msg);
+end
+
+if numOutArgs~=1 then
+ msg = "filternorm: Wrong number of output argument; 1 expected";
+ error(78,msg);
+end
+
+// ** Check on b and a **
+if isempty(a) then
+ a = 1;
+end
+if isempty(b) then
+ b = 1;
+end
+
+b = b(:);
+a = a(:);
+
+// check on datatype
+if type(b)~=1 & type(b)~=8 then
+ msg = "filternorm: Wrong type for argument #1 (b): Real or complex matrix expected";
+ error(53,msg);
+end
+if type(a)~=1 & type(a)~=8 then
+ msg = "filternorm: Wrong type for argument #2 (a): Real or complex matrix expected";
+ error(53,msg);
+end
+
+// check on dimensions
+if size(b,1)==1 then
+ b = b(:);
+end
+if size(a,1)==1 then
+ a = a(:);
+end
+
+if size(b,2)~=size(a,2) then
+ msg = "filternorm: Wrong size for arguments #1 (b) and #2(a): Same number of columns expected";
+ error(60,msg);
+end
+
+// ** Parsing the remaining arguments **
+if length(varargin)==1 & ~isempty(varargin) then
+ pnorm = varargin(1);
+ tol = 1e-8;
+elseif length(varargin)==2 then
+ pnorm = varargin(1);
+ tol = varargin(2);
+ if tol<=0 | length(tol)~=1 then
+ msg = "filternorm: Wrong value for argument #4 (tol): Must be a positive real scalar";
+ error(116,msg);
+ end
+else
+ pnorm = 2;
+ tol = 1e-8;
+end
+
+if pnorm~=2 & length(varargin)==2 then
+ msg = "filternorm: Warning - Wrong value for argument #3 (pnorm): Must be 2 when tolerance is used";
+end
+
+// ** Calculations **
+
+if isinf(pnorm) then
+ // We need to compute the frequency response and then get the one
+ // with the highest magnitude
+ h = frmag(b, a, 1024);
+ L = max(h);
+else
+ if size(a,1) == 1 then
+ // the filter is FIR; impluse response is the filter coeffs
+ L = norm(b,pnorm)/a;
+ else
+ // the filter is IIR
+ // Checking for stability, as we wont be able to calc impulse response
+ // within a given tolerance.
+
+ pole_mag = abs(roots(a));
+
+ // stability check
+ max_dist = max(pole_mag);
+ if max_dist>=1 then
+ // poles lie on the unit circle or outside it. We do not have a
+ // decaying impulse response and hence truncation is not advisable
+ msg = "filternorm: Non convergent impulse response. All poles should lie inside the unit circle";
+ error(msg);
+ end
+
+ // ****
+ // Theory: (assuming stable filter)
+ // Each pole will contribute a decaying exponential. The pole with
+ // the highest magnitude will decay the slowest (i.e. will be the most
+ // dominant). Therefore, we will work with pole(s) having the largest
+ // magnitude to obtain a bound on the L2 norm of the tail.
+ // ****
+
+ // get the multiplicity of the largest pole
+ mult = sum(pole_mag>(max_dist-1e-5) & pole_mag<(max_dist+1e-5));
+
+ // Using integration of a^(-x) to get a bound
+ N = mult*log(tol)/log(max_dist);
+
+ // TODO: get filter coeffs using impzlength from octave
+ [h, temp1] = impz(b,a);
+ L = norm(h,2);
+ end
+end
+
+endfunction
diff --git a/macros/filtfilt.bin b/macros/filtfilt.bin
new file mode 100644
index 0000000..ada5742
Binary files /dev/null and b/macros/filtfilt.bin differ
diff --git a/macros/filtfilt.sci b/macros/filtfilt.sci
new file mode 100644
index 0000000..f263da6
--- /dev/null
+++ b/macros/filtfilt.sci
@@ -0,0 +1,23 @@
+function [y]=filtfilt(b,a,x)
+
+// Zero phase digital filtering
+// Calling Sequence
+// [y]=filtfilt(b,a,x)
+// Parameters
+// b: Real or complex valued vector or matrix
+// a: Real or complex valued vector or matrix
+// x: Real or complex valued vector or matrix
+// Description
+// This is an Octave function
+// In theory, it forwards and reverse filters the signal and corrects phase distortion upto an extent by a one-pass filter but squares the magnitude response in the process. Practically though, the correction isn't perfect and magnitude response, particularly the stop band is distorted.
+// Examples
+// 1. [a,b]=filtfilt (1,2i,[i -4 0])
+// a = [0.00000 - 0.25000i 1.00000 + 0.00000i 0.00000 + 0.00000i]
+
+funcprot(0);
+rhs=argn(2);
+if (rhs~=3) then
+ error ("Wrong number of input arguments.")
+else y=callOctave("filtfilt",b,a,x)
+end
+endfunction
diff --git a/macros/filtic.bin b/macros/filtic.bin
new file mode 100644
index 0000000..cd79ea4
Binary files /dev/null and b/macros/filtic.bin differ
diff --git a/macros/filtic.sci b/macros/filtic.sci
new file mode 100644
index 0000000..3fd919a
--- /dev/null
+++ b/macros/filtic.sci
@@ -0,0 +1,37 @@
+function zf = filtic (b, a, y, x)
+
+//This function finds the initial conditions for the delays in the transposed direct-form II filter implementation
+//Calling Sequence
+//zf = filtic (b, a, y)
+//zf = filtic (b, a, y, x)
+//Parameters
+//b: vector of real or complex numbers
+//a: vector of real or complex numbers
+//y: vector of real or complex numbers
+//x: vector of real or complex numbers
+//Description
+//This function finds the initial conditions for the delays in the transposed direct-form II filter implementation.
+//The vectors b and a represent the numerator and denominator coefficients of the filter's transfer function.
+//Examples
+//filtic([i,1,-i,5], [1,2,3i], [0.8i,7,9])
+//ans =
+// 0.00000 - 22.60000i
+// 2.40000 + 0.00000i
+// 0.00000 + 0.00000i
+//This function is being called from Octave
+
+funcprot(0);
+rhs = argn(2)
+
+if(rhs>4 | rhs<3)
+ error("Wrong number of input agruments.")
+end
+
+select(rhs)
+case 3 then
+zf = callOctave("filtic",b,a,y)
+case 4 then
+zf = callOctave("filtic",b,a,y,x)
+end
+endfunction
+
diff --git a/macros/filtord.bin b/macros/filtord.bin
new file mode 100644
index 0000000..dd4f7ed
Binary files /dev/null and b/macros/filtord.bin differ
diff --git a/macros/filtord.sci b/macros/filtord.sci
new file mode 100644
index 0000000..56f30bf
--- /dev/null
+++ b/macros/filtord.sci
@@ -0,0 +1,104 @@
+//filtord Filter order
+//Calling Syntax
+//n = filtord(b,a)
+//n = filtord(sos)
+//n = filtord(d)
+//n = filtord(b,a) returns
+//the filter order, n, for the causal rational
+//system function specified by the numerator coefficients, b,
+//and denominator coefficients, a.
+//n = filtord(sos) returns
+//the filter order for the filter specified by the second-order sections
+//matrix, sos. sos is a K-by-6
+//matrix. The number of sections, K, must be greater
+//than or equal to 2. Each row of sos corresponds
+//to the coefficients of a second-order filter. The ith
+//row of the second-order section matrix corresponds to [bi(1)
+//bi(2) bi(3) ai(1) ai(2) ai(3)].
+//n = filtord(d) returns
+//the filter order, n, for the digital filter, d.
+//Use the function designfilt to
+//generate d.
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function m=filtord(varargin)
+ [nargout,nargin]=argn();
+ narginchk(1,2,argn(2));
+ if (nargin==2) then
+ a=varargin(1);
+ b=varargin(2);
+ if(length(b)==0) then
+ b=[0];
+ end
+ if length(a)==0 then
+ a=[0];
+ end
+
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ elseif (nargin==1) then
+ sos=varargin(1);
+ if type(sos)~=1 then
+ error('check input dimension');
+ end
+ v=size(sos);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('no. of columns must be 6');
+ end
+ a=1;b=1;
+ for i=[1:v(1)]
+ a=convol(a,sos(1:3));
+ b=convol(b,sos(4:6));
+ end
+ end
+ k=length(a);
+ order_a=0;
+ for i=k:-1:1
+ if (a(1,i)~=0) then
+ order_a=i;
+ break;
+ end
+ end
+ k=length(b);
+ order_b=0;
+ for i=[k:-1:1]
+ if (b(1,i)~=0) then
+ order_b=i;
+ break;
+ end
+ end
+ m=max(order_a,order_b)-1;
+endfunction
+function narginchk(l,h,eip)
+ if (eiph) then
+ error("too many input arguments");
+ end
+endfunction
diff --git a/macros/firpmord.bin b/macros/firpmord.bin
new file mode 100644
index 0000000..8f8dddd
Binary files /dev/null and b/macros/firpmord.bin differ
diff --git a/macros/firpmord.sci b/macros/firpmord.sci
new file mode 100755
index 0000000..c72f76e
--- /dev/null
+++ b/macros/firpmord.sci
@@ -0,0 +1,246 @@
+function [n, fo, ao, w] = firpmord(f, a, dev, varargin)
+// Parks-McClennan optimal FIR filter order estimation
+//
+//
+// Calling sequence
+// [n,fo,ao,w] = firpmord(f,a,dev)
+// [n,fo,ao,w] = firpmord(f,a,dev,fs)
+//
+//
+// Parameters
+// f: double - positive - vector
+// Frequency band edges (between 0 and Fs/2).
+// Length of f is two less than the length of a.
+// a: double - positive - vector
+// Desired amplitudes at the frequency bands specified by f.
+// dev: double - positive - vector
+// Maximum allowable deviations.
+// Maximum acceptable deviations or ripples between the frequency response
+// and the desired amplitudes in the frequency bands specified by f. Must have
+// the same length as a.
+// n: int - scalar
+// Filter order
+// fo: double - positive - vector
+// Frequency vector
+// ao: double - positive - vector
+// Amplitude vector
+// w: double - vector
+// Weights
+//
+//
+// Examples
+// [1] A low-pass filter
+// f = [1500 2000]; // frequency edges for bands
+// a = [1 0]; // desired amplitude for each band
+// dev = [0.01 0.1]; // Acceptable deviation for each band
+// fs = 8000; // Sampling frequency
+// [n,fo,ao,w] = firpmord(f,a,dev,fs);
+//
+// [2] A bandstop filter
+// f = [1000 1800 2400 3000];
+// a = [1 0 0.5];
+// dev = [0.01 0.1 0.03];
+// fs = 8000;
+// [n,fo,ao,w] = firpmord(f,a,dev,fs);
+//
+//
+// References
+// [1] Rabiner, Lawrence R., and Bernard Gold. "Theory and application of
+// digital signal processing." Englewood Cliffs, NJ, Prentice-Hall, Inc.,
+// 1975. 777 p. 156-7 (1975).
+// [2] Rabiner, Lawrence R., and Otto Herrmann. "The predictability of certain
+// optimum finite-impulse-response digital filters." Circuit Theory,
+// IEEE Transactions on 20.4 (1973): 401-408.
+//
+// Authors
+// Ayush Baid
+//
+//
+// See Also
+// buttord | cheb1ord | cheb2ord | ellipord | firpm | kaiserord
+
+ [numOutArgs,numInArgs] = argn(0);
+
+
+ // ********************
+ // Checking number of arguments
+ // ********************
+
+ if numInArgs~=3 & numInArgs~=4 then
+ msg = "firpmord: Wrong number of input argument; 3-4 expected";
+ error(77,msg);
+ end
+
+ if numOutArgs~=4 then
+ msg = "firpmord: Wrong number of output argument; 4 expected";
+ error(78,msg);
+ end
+
+ // ********************
+ // Parsing input args
+ // ********************
+
+ // Parsing fs
+ fs = 2; // default
+ if length(varargin)==1 then
+ fs = varargin(1);
+ if length(fs)~=1 then
+ msg = "firpmord: Wrong type for argument #4 (fs): Positive real scalar expected";
+ error(53,msg);
+ end
+ if fs<=0 then
+ msg = "firpmord: Wrong type for argument #4 (fs): Positive real scalar expected";
+ error(53,msg);
+ end
+ if type(fs)~=1 & type(fs)~=8 then
+ msg = "firpmord: Wrong type for argument #4 (fs): Positive real scalar expected";
+ error(53,msg);
+ end
+ end
+
+ // Checks on f
+ if ~isvector(f) | (type(f)~=1 & type(f)~=8) then
+ msg = "firpmord: Wrong type for argument #1 (f): Vector of positive reals expected";
+ error(53,msg);
+ end
+
+ if ~(and(f>=0) & and(f<=fs/2)) then
+ msg = "firpmord: Wrong value for argument #1 (f): Values must be between 0 and fs/2";
+ error(116,msg);
+ end
+
+
+ // Check on a
+ if ~isvector(a) | (type(a)~=1 & type(a)~=8) then
+ msg = "firpmord: Wrong type for argument #2 (a): Vector of positive reals expected";
+ error(53,msg);
+ end
+ if ~and(a>=0) then
+ msg = "firpmord: Wrong value for argument #2 (a): Values must be positive";
+ error(116,msg);
+ end
+
+ if length(f)~=2*length(a)-2 then
+ msg = "firpmord: Wrong type for arguments #1(f) and #2 (a): Length of f must be two less than twice the length of a ";
+ error(53,msg);
+ end
+
+
+ // Check on dev
+ if ~isvector(dev) | (type(dev)~=1 & type(dev)~=8) then
+ msg = "firpmord: Wrong type for argument #3 (dev): Vector of positive reals expected";
+ error(53,msg);
+ end
+ if ~and(dev>0) then
+ msg = "firpmord: Wrong value for argument #3 (dev): Values must be positive";
+ error(116,msg);
+ end
+ if length(dev)~=length(a) then
+ msg = "firpmord: Wrong type for arguments #2(a) and #3 (dev): Length of a and dev must be equal";
+ error(53,msg);
+ end
+
+ // ********************
+ // Some preprocessing
+ // ********************
+
+ // Turn every vector into a column vector
+ f = f(:);
+ a = a(:);
+ dev = dev(:);
+
+ // Normalizing frequencies
+ f = f./fs;
+
+ // Get deviation relative to the amplutudes
+ is_zero = a==0;
+ dev = dev./(is_zero+a); // no scaling req. when desired amplitude is 0
+
+
+ num_bands = size(a,1);
+
+ // Dividing frequency band edges into 2 vectors, f1 and f2, denoting
+ // passband and stopband edges respectively.
+ f1 = f(1:2:$-1);
+ f2 = f(2:2:$);
+
+
+ // ********************'
+ // Calculations for filter order
+ // ********************
+
+ // Note: Amplitudes don't matter for order as they can be adjusted by
+ // scaling and linear shifting
+
+ if num_bands==2 then
+ // Simple low-pass or high-pass filter, use single_transition_order_estimation
+
+ L = single_trans_order_est(f1(1), f2(1), dev(1), dev(2));
+ else
+ // We have a bandpass filter, which will be considered to be composed
+ // of a cascade of simple high-pass/low-pass filters
+
+ // The first filter is considered high-pass (if it is low pass in reality,
+ // the filter just has to be negated; filter order does not change)
+
+ // Loop over different simple filters and select the highest required length
+ L = 0
+ for i=2:num_bands-1
+ L1 = single_trans_order_est(f1(i-1), f2(i-1), dev(i), dev(i-1));
+ L2 = single_trans_order_est(f1(i), f2(i), dev(i), dev(i+1));
+ L = max([L; L1; L2]);
+ end
+ end
+
+ // filt. order = L-1
+ n = ceil(L) - 1;
+
+ // frequency and respective amplitudes
+ fo = [0;2*f;1];
+ ao = zeros(size(fo,1),1);
+ ao(1:2:$) = a;
+ ao(2:2:$) = a;
+
+ // weights
+ w = ones(size(dev,1),1)*max(dev)./dev;
+
+endfunction
+
+function L = single_trans_order_est(freq1, freq2, delta1, delta2)
+// Calculates the filter order for a single transition band filter ( simple
+// low-pass or simple high-pass filter)
+//
+//
+// Parameters (assuming a low-pass filter; notations change for high pass filter)
+// freq1: passband cutoff frequency (normalized)
+// freq2: stopband cutoff frequency (normalized)
+// delta1: passband ripple (max. allowed)
+// delta2: stopband attenuation (not in dB)
+// L: filter length; filter order = L-1
+//
+// Note: will not work well when transition near f = 0 or 0.5
+//
+// References
+// [1] Rabiner, Lawrence R., and Bernard Gold. "Theory and application of
+// digital signal processing." Englewood Cliffs, NJ, Prentice-Hall, Inc.,
+// 1975. 777 p. 156-7 (1975).
+
+ // Creating a matrix for consice representation of coeffs a_i used in Eq. 3.142
+ // and b_i in Eq. 3.143 in [1]
+ A = [-4.278e-1, -4.761e-1; -5.941e-1, 7.114e-2; -2.66e-3, 5.309e-3];
+ B = [11.01217, 0.51244];
+
+ log_delta1 = log10(delta1);
+ log_delta2 = log10(delta2);
+
+ // Evaluating Eq. 3.142 (Ref. [1])
+ D = [1, log_delta1, log_delta1.^2] * A * [1; log_delta2];
+
+ // Evaluating Eq. 3.143 (Ref. [1])
+ f = B * [1; log_delta1 - log_delta2];
+
+ // Evaluating Eq. 3.145 (Ref. [1])
+ del_freq = abs(freq1 - freq2);
+ L = D./del_freq - f.*del_freq + 1;
+
+endfunction
diff --git a/macros/firtype.bin b/macros/firtype.bin
new file mode 100644
index 0000000..411b2de
Binary files /dev/null and b/macros/firtype.bin differ
diff --git a/macros/firtype.sci b/macros/firtype.sci
new file mode 100644
index 0000000..4fa1122
--- /dev/null
+++ b/macros/firtype.sci
@@ -0,0 +1,34 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function typ=firtype(b)
+ if (type(b)~=1) then
+ error('check input type');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(1)~=1 & v(2)~=1 then
+ error('check input dimension');
+ elseif v(2)==1
+ b=b';
+ end
+ m=length(b);
+ sym=(b-b($:-1:1))*(b-b($:-1:1))';//zero if symmetrical
+ antisym=(b+b($:-1:1))*(b+b($:-1:1))';//zero if antisymmetrical
+ if (sym==0) then
+ if (pmodulo(m,2)==1) then
+ typ=1;
+ else
+ typ=2;
+ end
+ elseif (antisym==0)
+ if (pmodulo(m,2)==1) then
+ typ=3;
+ else
+ typ=4;
+ end
+ else
+ typ=-1;//not linear phas
+ end
+endfunction
diff --git a/macros/flattopwin.bin b/macros/flattopwin.bin
new file mode 100644
index 0000000..f9795b4
Binary files /dev/null and b/macros/flattopwin.bin differ
diff --git a/macros/flattopwin.sci b/macros/flattopwin.sci
new file mode 100644
index 0000000..41250c1
--- /dev/null
+++ b/macros/flattopwin.sci
@@ -0,0 +1,47 @@
+function w = flattopwin (m, opt)
+//This function returns the filter coefficients of a Flat Top window.
+//Calling Sequence
+//w = flattopwin (m)
+//w = flattopwin (m, opt)
+//Parameters
+//m: positive integer value
+//opt: string value, takes in "periodic" or "symmetric"
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Flat Top window of length m supplied as input, to the output vector w.
+//The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+//This window has low pass-band ripple but a high bandwidth.
+//Examples
+//flattopwin(8,"periodic")
+//ans =
+// 0.0009051
+// - 0.0264124
+// - 0.0555580
+// 0.4435496
+// 1.
+// 0.4435496
+// - 0.0555580
+// - 0.0264124
+funcprot(0);
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+
+if(rhs==2)
+ if(opt~="periodic" & opt~="symmetric")
+ error("Window type should be periodic or symmetric.")
+ end
+end
+
+ select(rhs)
+ case 1 then
+ w = callOctave("flattopwin",m)
+ case 2 then
+ w = callOctave("flattopwin",m,opt)
+ end
+endfunction
+
+
+
diff --git a/macros/fracshift.bin b/macros/fracshift.bin
new file mode 100644
index 0000000..989ab10
Binary files /dev/null and b/macros/fracshift.bin differ
diff --git a/macros/fracshift.sci b/macros/fracshift.sci
new file mode 100644
index 0000000..fc02579
--- /dev/null
+++ b/macros/fracshift.sci
@@ -0,0 +1,42 @@
+function [y, h] = fracshift( x, d, h )
+//This function shifts the series x supplied as input argument by a number of samples d.
+//Calling Sequence
+//y = fracshift(x, d)
+//y = fracshift(x, d, h)
+//[y, h] = fracshift(...)
+//Parameters
+//x:
+//d:
+//h:
+//Description
+//This is an Octave function.
+//This function shifts the series x supplied as input argument by a number of samples d.
+//The third parameter is the interpolator, which is designed with a Kaiser-windowed sinecard by default, if not supplied.
+//Examples
+//fracshift([1,2,3],5)
+//ans =
+// 1. 2. 3.
+
+funcprot(0);
+lhs = argn(1)
+rhs = argn(2)
+if(rhs<2 | rhs>3)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 2 then
+ if(lhs==1)
+ y = callOctave("fracshift",x,d)
+ elseif(lhs==2)
+ [y,h] = callOctave("fracshift",x,d)
+ end
+ case 3 then
+ if(lhs==1)
+ [y] = callOctave("fracshift",x,d,h)
+ elseif(lhs==2)
+ [y,h] = callOctave("fracshift",x,d,h)
+ end
+ end
+endfunction
+
diff --git a/macros/fwhm.bin b/macros/fwhm.bin
new file mode 100644
index 0000000..38e0180
Binary files /dev/null and b/macros/fwhm.bin differ
diff --git a/macros/fwhm.sci b/macros/fwhm.sci
new file mode 100644
index 0000000..732f623
--- /dev/null
+++ b/macros/fwhm.sci
@@ -0,0 +1,43 @@
+function [f] = fwhm(y, varargin)
+//This function computes peak full width at half minimum or at another level of peak minimum for vector or matrix data y supplied as input.
+//Calling Sequence
+//f = fwhm (y)
+//f = fwhm (x, y)
+//f = fwhm (…, "zero")
+//f = fwhm (…, "min")
+//f = fwhm (…, "alevel", level)
+//f = fwhm (…, "rlevel", level)
+//Parameters
+//y: vector or matrix
+
+//Description
+//This is an Octave function.
+//This function computes peak full width at half minimum or at another level of peak minimum for vector or matrix data y supplied as input.
+//If y is a matrix, fwhm is calculated for each column as a row vector.
+//The second argument is by default "zero" which computes the fwhm at half maximum. If it is "min", fwhm is computed at middle curve.
+//The option "rlevel" computes full-width at the given relative level of peak profile.
+//The option "alevel" computes full-width at the given absolute level of y.
+//This function returns 0 if FWHM does not exist.
+//Examples
+//fwhm([1,2,3;9,-7,0.6],[4,5,6])
+//ans = 0.
+funcprot(0);
+
+rhs = argn(2)
+if(rhs<1 | rhs>5)
+error("Wrong number of input arguments.")
+end
+
+select(rhs)
+ case 1 then
+ f = callOctave("fwhm",y)
+ case 2 then
+ f = callOctave("fwhm",y,varargin(1))
+ case 3 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2))
+ case 4 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2),varargin(3))
+ case 5 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2),varargin(3),varargin(4))
+ end
+endfunction
diff --git a/macros/fwhmjlt.bin b/macros/fwhmjlt.bin
new file mode 100644
index 0000000..98edf6c
Binary files /dev/null and b/macros/fwhmjlt.bin differ
diff --git a/macros/fwhmjlt.sci b/macros/fwhmjlt.sci
new file mode 100644
index 0000000..4e9eb9c
--- /dev/null
+++ b/macros/fwhmjlt.sci
@@ -0,0 +1,18 @@
+function [f]=bitrevorder(y,varargin)
+rhs = argn(2)
+if(rhs<1 | rhs>5)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 1 then
+ f = callOctave("fwhm",y)
+ case 2 then
+ f = callOctave("fwhm",y,varargin(1))
+ case 3 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2))
+ case 4 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2),varargin(3))
+ case 5 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2),varargin(3),varargin(4))
+ end
+endfunction
diff --git a/macros/fwhmjlt.sci~ b/macros/fwhmjlt.sci~
new file mode 100644
index 0000000..93fc505
--- /dev/null
+++ b/macros/fwhmjlt.sci~
@@ -0,0 +1,18 @@
+
+rhs = argn(2)
+if(rhs<1 | rhs>5)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 1 then
+ f = callOctave("fwhm",y)
+ case 2 then
+ f = callOctave("fwhm",y,varargin(1))
+ case 3 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2))
+ case 4 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2),varargin(3))
+ case 5 then
+ f = callOctave("fwhm",y,varargin(1),varargin(2),varargin(3),varargin(4))
+ end
+endfunction
diff --git a/macros/gauspuls.bin b/macros/gauspuls.bin
new file mode 100644
index 0000000..7ed8b82
Binary files /dev/null and b/macros/gauspuls.bin differ
diff --git a/macros/gauspuls.sci b/macros/gauspuls.sci
new file mode 100644
index 0000000..ad853ee
--- /dev/null
+++ b/macros/gauspuls.sci
@@ -0,0 +1,31 @@
+function [y]=gauspuls(t,fc,bw)
+
+// Generates Gaussian-modulated sinusoidal pulses
+// Calling Sequence
+// [y]=gauspuls(t,fc,bw)
+// [y]=gauspuls(t,fc)
+// [y]=gauspuls(t)
+// Parameters
+// t: Real or complex valued vector or matrix
+// fc: Real non negative number or complex number
+// bw: Real positive number or complex number
+// Description
+// This is an Octave function
+// This function returns a Gaussian RF pulse of unity amplitude at the times indicated in array t.
+// Examples
+// 1. gauspuls(1,2,3)
+// ans= 1.427D-56
+// 2. gauspuls([1 2 3],1,1)
+// ans= 0.0281016 0.0000006 1.093D-14
+
+funcprot(0);
+rhs=argn(2);
+if ( rhs<1 ) then
+ error ("Wrong number of input arguments.")
+elseif (rhs==1)
+ y= callOctave("gauspuls",t)
+elseif (rhs==2)
+ y= callOctave("gauspuls",t,fc)
+else y= callOctave("gauspuls",t,fc,bw)
+end
+endfunction
diff --git a/macros/gaussdesign.bin b/macros/gaussdesign.bin
new file mode 100644
index 0000000..8b05521
Binary files /dev/null and b/macros/gaussdesign.bin differ
diff --git a/macros/gaussdesign.sci b/macros/gaussdesign.sci
new file mode 100644
index 0000000..fa4a82c
--- /dev/null
+++ b/macros/gaussdesign.sci
@@ -0,0 +1,132 @@
+function filter_coeffs = gaussdesign(BwSt_prod, num_of_symb, samp_per_symb)
+// GAUSSDESIGN designs a Gaussian pulse-shaping filter which is a low pass FIR
+// filter
+// Inputs:
+// BwSt_prod: it stands for 3 dB bandwidth symbol-time product.
+// Bandwidth is the one-sided and in hertz. Symbol-time is
+// in seconds.
+// num_of_symb: filter truncated to these many number of symbols
+// samp_per_symb: each symbol represented by these many samples
+// Output:
+// filter_coeffs: returned filter coefficients
+
+
+
+ // Check validity of number of inout arguments
+ checkNArgin(1, 3, argn(2));
+
+ // Check validity of number of output arguments
+ checkNArgout(0, 1, argn(1));
+
+ // Check validity of input arguments
+ valid_class_BwSt = ['single', 'double'];
+ properties_BwSt = ['scalar', 'nonempty', 'nonNan', 'real', 'positive'];
+ checkIpValidity(BwSt_prod, valid_class_BwSt, properties_BwSt);
+
+ if (argn(2) >= 2) then
+ valid_class_nos = ['single', 'double'];
+ properties_nos = ['scalar', 'nonempty', 'nonNan', 'real', 'positive', 'integer'];
+ checkIpValidity(num_of_symb, valid_class_nos, properties_nos);
+ else
+ num_of_symb = 3;
+ end
+
+ if argn(2) == 3 then
+ valid_class_sps = ['single', 'double'];
+ properties_sps = ['scalar', 'nonempty', 'nonNan', 'real', 'positive', 'integer'];
+ checkIpValidity(samp_per_symb, valid_class_sps, properties_sps);
+ else
+ samp_per_symb = 2;
+ end
+
+ // check if inputs fit the symmetry condition
+ 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
+
+ // Finding the filter coefficients
+ length_of_filt = (num_of_symb*samp_per_symb) + 1;
+ ax = linspace((-num_of_symb/2), (num_of_symb/2), length_of_filt);
+ den = sqrt(log(2)/2)/(BwSt_prod);
+ filter_coeffs_tmp = (sqrt(%pi)/den)*exp(-(ax*%pi/den).^2);
+
+ // Normalizing
+ filter_coeffs = filter_coeffs_tmp./sum(filter_coeffs_tmp);
+
+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
+endfunction
+
+
+function checkNArgout(min_argout, max_argout, num_of_argout)
+ if num_of_argout < min_argout then
+ error('Not enough output arguments')
+ end
+
+ if num_of_argout > max_argout then
+ error('Too many output arguments')
+ end
+endfunction
+
+function checkIpValidity(variable, valid_class, properties)
+// Function to check the validity of the input variable
+// Inputs:
+// valid_class: vector of valid classes for the input variable
+// properties: vector of necessary properties of the input variable
+
+ for idx = 1:length(length(valid_class))
+ if ~strcmpi(valid_class(idx), 'double') | ~strcmpi(valid_class(idx), 'single') then
+ if type(variable) ~= 1 then
+ 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
+ error('Input variable should be of type scalar');
+ end
+ end
+
+ if ~strcmpi(properties(jdx), 'nonempty') then
+ if isempty(variable) then
+ 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
+ end
+
+endfunction
diff --git a/macros/gaussian.bin b/macros/gaussian.bin
new file mode 100644
index 0000000..472d182
Binary files /dev/null and b/macros/gaussian.bin differ
diff --git a/macros/gaussian.sci b/macros/gaussian.sci
new file mode 100644
index 0000000..59ddb3c
--- /dev/null
+++ b/macros/gaussian.sci
@@ -0,0 +1,34 @@
+function w = gaussian (m, a)
+//This function returns a Gaussian convolution window.
+//Calling Sequence
+//w = gaussian (m)
+//w = gaussian (m, a)
+//Parameters
+//m: positive integer value
+//a:
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns a Gaussian convolution 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
+//gaussian(5,6)
+//ans =
+// 5.380D-32
+// 1.523D-08
+// 1.
+// 1.523D-08
+// 5.380D-32
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+if(rhs==1)
+w = callOctave("gaussian",m)
+elseif(rhs==2)
+w = callOctave("gaussian",m, a)
+end
+endfunction
+
diff --git a/macros/gausswin.bin b/macros/gausswin.bin
new file mode 100644
index 0000000..8133cd0
Binary files /dev/null and b/macros/gausswin.bin differ
diff --git a/macros/gausswin.sci b/macros/gausswin.sci
new file mode 100644
index 0000000..eb3b3d8
--- /dev/null
+++ b/macros/gausswin.sci
@@ -0,0 +1,32 @@
+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
+
diff --git a/macros/gmonopuls.bin b/macros/gmonopuls.bin
new file mode 100644
index 0000000..bc0bcfb
Binary files /dev/null and b/macros/gmonopuls.bin differ
diff --git a/macros/gmonopuls.sci b/macros/gmonopuls.sci
new file mode 100644
index 0000000..6fa9db0
--- /dev/null
+++ b/macros/gmonopuls.sci
@@ -0,0 +1,27 @@
+function [y]=gmonopuls(t,fc)
+
+// Gaussian monopulse
+// Caling Sequence
+// [y]=gmonopuls(t)
+// [y]=gmonopuls(t,fc)
+// Parameters
+// t: Real or complex valued vector or matrix
+// fc: Real non-negative value or complex value or a vector or matrix with not all real values negative.
+// Description
+// This is an Octave function
+// This function returns samples of the Gaussian monopulse of amplitude unity.
+// Examples
+// 1. gmonopuls([1 2 3],0.1)
+// ans= 0.85036 0.94070 0.52591
+// 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
+endfunction
diff --git a/macros/goertzel.bin b/macros/goertzel.bin
new file mode 100644
index 0000000..b1af7e2
Binary files /dev/null and b/macros/goertzel.bin differ
diff --git a/macros/goertzel.sci b/macros/goertzel.sci
new file mode 100644
index 0000000..bc0061c
--- /dev/null
+++ b/macros/goertzel.sci
@@ -0,0 +1,79 @@
+function Y = goertzel(X,INDVEC,DIM)
+//Computes DFT using the second order Goertzel Algorithm
+//Calling Sequence
+//Y = goertzel(X,INDVEC,DIM)
+//Parameters
+//X
+//A vector matrix or n-dimensional array
+//INDVEC
+//The indices at which the DFT is to be computed
+//DIM
+//The dimension along which the algorithm is to be implemented
+//Description
+//goertzel(X,INDVEC)
+//Computes the DFT of X at indices INDVEC using the second order algorithm along
+//the first non-singleton dimension. Elements of INDVEC must be positive integers
+//less than the length of the first non-singleton dimension. If INDVEC is empty
+//the DFT is computed at all indices along the first non-singleton dimension
+//goertzel(X,INDVEC,DIM)
+//Implements the algorithm along dimension DIM
+//In general goertzel is slower than fft when computing the DFT for all indices
+//along a particular dimension. However it is computationally more efficient when
+//the DFT at only a subset of indices is desired
+//Example
+//x=rand(1,5)
+//x =
+//
+// 0.6283918 0.8497452 0.6857310 0.8782165 0.0683740
+//y=goertzel(x,2);
+//y =
+//
+// - 0.3531539 - 0.6299881i
+//Author
+//Ankur Mallick
+//References
+//Goertzel, G. (January 1958), "An Algorithm for the Evaluation of Finite Trigonometric Series", American Mathematical Monthly 65 (1): 34–35, doi:10.2307/2310304
+ funcprot(0);
+ if(argn(2)<3|isempty(DIM))
+ DIM=find(size(X)>1,1); //First non-singleton dimension
+ end
+ if(DIM>ndims(X))
+ error('Invalid Dimensions');
+ end
+ perm=[DIM, 1:DIM-1, DIM+1:ndims(X)];
+ X=permute(X,perm); //Makes DIM the leading dimension
+ S=size(X);
+ if(argn(2)<2|isempty(INDVEC))
+ INDVEC=1:S(1);
+ end
+ if(max(INDVEC)>S(1)|min(INDVEC)<1)
+ error('Index out of bounds');
+ elseif(or(INDVEC~=round(INDVEC)))
+ error('Indices must be integers');
+ end
+ X1=matrix(X,1,prod(S));
+ T=[type(X1), type(INDVEC), type(DIM)]; //all inputs should be of type double
+ if(~and(T==1))
+ error('Invalid data type');
+ end
+ //Implementing Goertzel algorithm
+ len=[length(INDVEC), S(2:length(S))];
+ Y=matrix(zeros(1,prod(len)),len);
+ v=ones(length(INDVEC),1);
+ w=(2*%pi*(INDVEC-1)/S(1))';
+ re=2*cos(w);
+ im=sin(w);
+ for i=1:prod(S(2:length(S)))
+ x=X(:,i)
+ sp1=0;
+ sp2=0;
+ for j=1:S(1)
+ s=x(j)*v+re.*sp1-sp2;
+ sp2=sp1;
+ sp1=s;
+ end
+ Y(:,i)=((re/2)+im*%i).*sp1-sp2;
+ end
+ iperm(perm)=1:length(perm);
+ Y=permute(Y,iperm); //Converting Y to the original shape of X
+endfunction
diff --git a/macros/grpdelay.bin b/macros/grpdelay.bin
new file mode 100644
index 0000000..be071e0
Binary files /dev/null and b/macros/grpdelay.bin differ
diff --git a/macros/grpdelay.sci b/macros/grpdelay.sci
new file mode 100644
index 0000000..a7ffdad
--- /dev/null
+++ b/macros/grpdelay.sci
@@ -0,0 +1,51 @@
+function [gd,w] = grpdelay(b,a,nfft,whole,Fs)
+//This function computes the group delay of a filter.
+//Calling Sequence
+//gd = grpdelay(b)
+//gd = grpdelay(b, a)
+//gd = grpdelay(b, a, nfft)
+//gd = grpdelay(b, a, nfft, whole)
+//gd = grpdelay(b, a, nfft, whole, Fs)
+//[gd, w] = grpdelay(...)
+
+//Parameters
+//b:
+//a:
+//nfft:
+
+//Description
+//This is an Octave function.
+//This function computes the group delay of a filter.
+//[g, w] = grpdelay(b) returns the group delay g of the FIR filter with coefficients b. The response is evaluated at 512 angular frequencies between 0 and pi. w is a vector containing the 512 frequencies.
+//[g, w] = grpdelay(b, a) returns the group delay of the rational IIR filter whose numerator has coefficients b and denominator coefficients a.
+//[g, w] = grpdelay(b, a, n) returns the group delay evaluated at n angular frequencies.
+//[g, w] = grpdelay(b, a, n, ’whole’) evaluates the group delay at n frequencies between 0 and 2*pi.
+//[g, f] = grpdelay(b, a, n, Fs) evaluates the group delay at n frequencies between 0 and Fs/2.
+//[g, f] = grpdelay(b, a, n, ’whole’, Fs) evaluates the group delay at n frequencies between 0 and Fs.
+//[g, w] = grpdelay(b, a, w) evaluates the group delay at frequencies w (radians per sample).
+//[g, f] = grpdelay(b, a, f, Fs) evaluates the group delay at frequencies f (in Hz).
+//Examples
+//grpdelay(1,2,3)
+//ans =
+// 0.
+// 0.
+// 0.
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<1 | rhs>5)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 1 then
+ [gd,w] = callOctave("grpdelay",b)
+ case 2 then
+ [gd,w] = callOctave("grpdelay",b,a)
+ case 3 then
+ [gd,w] = callOctave("grpdelay",b,a,nfft)
+ case 4 then
+ [gd,w] = callOctave("grpdelay",b,a,nfft,whole)
+ case 5 then
+ [gd,w] = callOctave("grpdelay",b,a,nfft,whole,Fs)
+ end
+endfunction
diff --git a/macros/hann.bin b/macros/hann.bin
new file mode 100644
index 0000000..6d9679a
Binary files /dev/null and b/macros/hann.bin differ
diff --git a/macros/hann.sci b/macros/hann.sci
new file mode 100644
index 0000000..b95ed4f
--- /dev/null
+++ b/macros/hann.sci
@@ -0,0 +1,37 @@
+function w = hann (varargin)
+//This function returns the filter coefficients of a Hanning window.
+//Calling Sequence
+//w = hann(m)
+//w = hann(m, "symmteric")
+//w = hann(m, "periodic")
+//Parameters
+//m: positive integer value
+//opt: string value, takes in "periodic" or "symmetric"
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Hanning window of length m supplied as input, to the output vector w.
+//The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+//Examples
+//hann(6,"symmetric")
+//ans =
+// 0.
+// 0.3454915
+// 0.9045085
+// 0.9045085
+// 0.3454915
+// 0.
+funcprot(0);
+rhs = argn(2)
+m = varargin(1)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 1 then
+ w = callOctave("hann",varargin(1))
+ case 2 then
+ w = callOctave("hann",varargin(1),varargin(2))
+ end
+endfunction
diff --git a/macros/helperHarmonicDistortionAmplifier.bin b/macros/helperHarmonicDistortionAmplifier.bin
new file mode 100644
index 0000000..e577060
Binary files /dev/null and b/macros/helperHarmonicDistortionAmplifier.bin differ
diff --git a/macros/helperHarmonicDistortionAmplifier.sci b/macros/helperHarmonicDistortionAmplifier.sci
new file mode 100755
index 0000000..511b3a9
--- /dev/null
+++ b/macros/helperHarmonicDistortionAmplifier.sci
@@ -0,0 +1,31 @@
+function outputVoltage = helperHarmonicDistortionAmplifier(inputVoltage)
+//helperHarmonicDistortionADC Helper function for HarmonicDistortionExample.m
+
+// model parameters
+noiseVrms = 0.4e-6; // RMS voltage of input noisefloor
+
+// polynomial coefficients
+a0 = 25e-3; // dc bias (25mV)
+a1 = 1; // voltage gain
+a2 = 6e-5; // second order term
+a3 = -1e-3; // third order term
+a4 = 5e-6; // fourth order term
+a5 = 1e-5; // fifth order term
+
+// polyval function has constant term at the end.
+polyCoeff = [a5 a4 a3 a2 a1 a0];
+
+// get number of input samples
+n = size(inputVoltage,2);
+
+// add noise at input
+inputNoise = noiseVrms*rand(1,n,"normal");
+distortedInput = inputVoltage + inputNoise;
+
+// adjust input by DC bias, voltage gain and higher order terms
+outputVoltage = polyval(polyCoeff, distortedInput);
+endfunction
+
+
+
+
diff --git a/macros/icceps.bin b/macros/icceps.bin
new file mode 100644
index 0000000..937de63
Binary files /dev/null and b/macros/icceps.bin differ
diff --git a/macros/icceps.sci b/macros/icceps.sci
new file mode 100644
index 0000000..07debde
--- /dev/null
+++ b/macros/icceps.sci
@@ -0,0 +1,50 @@
+function inv_ceps = icceps(input, remv_samp)
+// ICCEPS computes the inverse cepstrum of a real-valued input. This spectrum
+// will be complex in nature
+// Inputs:
+// input: Real-valued input
+// remv_samps: Number of samples of delay to be removed
+// Outputs:
+// inv_ceps: Inverse cepstrum output
+
+// Check validity of number of inout arguments
+checkNArgin(1,3, argn(2));
+
+// Check validity of input signal
+checkInputSig(input);
+
+// Seeting default input
+if argn(2) < 2 then
+ remv_samp = 0;
+end
+
+input_in_freq = fft(input);
+tmp = exp(real(input_in_freq)+ %i*phaseFactor(imag(input_in_freq), remv_samp));
+inv_ceps = real(ifft(tmp));
+
+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
+endfunction
+
+function checkInputSig(incoming_sig)
+ if isempty(incoming_sig)| issparse(incoming_sig)| (~isreal(incoming_sig)) then
+ error('Input is not valid')
+ end
+endfunction
+
+function y = phaseFactor(incoming_sig, delay_elmnts)
+ len = length(incoming_sig);
+ input_rnd = floor((len+1)/2);
+ y = (incoming_sig(:).') + (%pi*delay_elmnts*(0:(len-1))/input_rnd);
+ if size(incoming_sig, 2)==1 then
+ y = y';
+ end
+endfunction
diff --git a/macros/iirlp2mb.bin b/macros/iirlp2mb.bin
new file mode 100644
index 0000000..4459654
Binary files /dev/null and b/macros/iirlp2mb.bin differ
diff --git a/macros/iirlp2mb.sci b/macros/iirlp2mb.sci
new file mode 100644
index 0000000..54f1a6b
--- /dev/null
+++ b/macros/iirlp2mb.sci
@@ -0,0 +1,41 @@
+function [Num,Den,AllpassNum,AllpassDen] = iirlp2mb(varargin)
+//This function does IIR Low Pass Filter to Multiband Filter Transformation.
+//Calling Sequence
+//[Num, Den, AllpassNum, AllpassDen] = iirlp2mb(B, A, Wo, Wt)
+//[Num, Den, AllpassNum, AllpassDen] = iirlp2mb(B, A, Wo, Wt, Pass)
+//Parameters
+//B: real or complex value
+//A: real or complex value
+//Wo: scalar or vector
+//Wt: scalar or vector, elements must be monotonically increasing and >= 0 and <= 1.
+//Description
+//This is an Octave function.
+//This function does IIR Low Pass Filter to Multiband Filter Transformation.
+//The first two parameters give the numerator and denominator of the prototype low pass filter.
+//The third parameter is the normalized angular frequency/pi to be transformed.
+//The fourth parameter is the normalized angular frequency/pi target vector.
+//The first two output variables are the numerator and denominator of the transformed filter.
+//The third and fourth output variables are the numerator and denominator of the allpass transform.
+//The fifth parameter can have values pass or stop, default value is pass.
+//Examples
+//iirlp2mb(5,9,0.3,0.4)
+//ans = 0.55556
+
+B = varargin(1)
+A = varargin(2)
+Wo = varargin(3)
+Wt = varargin(4)
+rhs = argn(2)
+lhs = argn(1)
+if(rhs < 4 | rhs > 5)
+error("Wrong number of input arguments.")
+end
+select(rhs)
+case 4 then
+[Num,Den,AllpassNum,AllpassDen] = callOctave("iirlp2mb",varargin(1),varargin(2),varargin(3),varargin(4))
+case 5 then
+[Num,Den,AllpassNum,AllpassDen] = callOctave("iirlp2mb",varargin(1),varargin(2),varargin(3),varargin(4),varargin(5))
+end
+endfunction
+
+
diff --git a/macros/impinvar.bin b/macros/impinvar.bin
new file mode 100644
index 0000000..bc5bea1
Binary files /dev/null and b/macros/impinvar.bin differ
diff --git a/macros/impinvar.sci b/macros/impinvar.sci
new file mode 100644
index 0000000..ff90f6a
--- /dev/null
+++ b/macros/impinvar.sci
@@ -0,0 +1,40 @@
+function [b_out, a_out] = impinvar (b, a, fs, tol)
+//This function converts analog filter with coefficients b and a to digital, conserving impulse response.
+//Calling Sequence
+//[b, a] = impinvar (b, a)
+//[b, a] = impinvar (b, a, fs)
+//[b, a] = impinvar (b, a, fs, tol)
+//Parameters
+//b: real or complex valued scalar or vector
+//a: real or complex valued scalar or vector, order should be greater than b
+//fs: real or complex value, default value 1Hz
+//tol: real or complex value, default value 0.0001
+//Description
+//This is an Octave function.
+//This function converts analog filter with coefficients b and a to digital, conserving impulse response.
+//This function does the inverse of impinvar.
+//Examples
+//b = 0.0081000
+//a = [2.0000000, 0.56435378, 0.4572792, 0.00705544, 0.091000]
+//[ay,by] = impinvar(b,a,10)
+//ay =
+// 0.0000e+00 7.5293e-08 2.9902e-07 7.4238e-08
+//by =
+// 1.00000 -3.96992 5.91203 -3.91428 0.97218
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<2)
+error("Wrong number of input arguments.")
+end
+
+
+ select(rhs)
+ case 2 then
+ [b, a] = callOctave("impinvar",b,a)
+ case 3 then
+ [b, a] = callOctave("impinvar",b,a,fs)
+ case 4 then
+ [b, a] = callOctave("impinvar",b,a,fs,tol)
+ end
+endfunction
diff --git a/macros/impz.bin b/macros/impz.bin
new file mode 100644
index 0000000..eb1ef54
Binary files /dev/null and b/macros/impz.bin differ
diff --git a/macros/impz.sci b/macros/impz.sci
new file mode 100644
index 0000000..cfa9b32
--- /dev/null
+++ b/macros/impz.sci
@@ -0,0 +1,55 @@
+function [x_r, t_r] = impz(b, a, n, fs)
+
+//
+//Calling Sequence
+//x_r = impz(b)
+//x_r = impz(b, a)
+//x_r = impz(b, a, n)
+//x_r = impz(b, a, n, fs)
+//[x_r, t_r] = impz(b, a, n, fs)
+
+//Parameters
+//
+
+//Description
+
+//Examples
+
+
+//This function is being called from Octave
+
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+if(rhs<1 | rhs>4)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 1 then
+ if(lhs==1)
+ [x_r] = callOctave("impz",b)
+ elseif(lhs==2)
+ [x_r,t_r] = callOctave("impz",b)
+ end
+ case 2 then
+ if(lhs==1)
+ [x_r] = callOctave("impz",b,a)
+ elseif(lhs==2)
+ [x_r,t_r] = callOctave("impz",b,a)
+ end
+ case 3 then
+ if(lhs==1)
+ [x_r] = callOctave("impz",b,a,n)
+ elseif(lhs==2)
+ [x_r,t_r] = callOctave("impz",b,a,n)
+ end
+ case 4 then
+ if(lhs==1)
+ [x_r] = callOctave("impz",b,a,n,fs)
+ elseif(lhs==2)
+ [x_r,t_r] = callOctave("impz",b,a,n,fs)
+ end
+ end
+endfunction
diff --git a/macros/impzlength.bin b/macros/impzlength.bin
new file mode 100644
index 0000000..147b140
Binary files /dev/null and b/macros/impzlength.bin differ
diff --git a/macros/impzlength.sci b/macros/impzlength.sci
new file mode 100644
index 0000000..6e75968
--- /dev/null
+++ b/macros/impzlength.sci
@@ -0,0 +1,252 @@
+
+function len = impzlength (b, varargin)
+// Impulse response length
+//
+// Calling Sequence
+// len = impzlength(b, a, tol)
+// returns the impulse response length for the causal discrete-time filter
+// with the transfer function coefficients for numerator and denominator in
+// a and b respectively. For stable IIR filters, len is the effective length
+// impulse response length, i.e. the length after which the response is
+// essentially zero
+// len = impzlength(sos)
+// returns the impulse response length of the filter specified by second
+// order sections matrix. sos is a Kx6 matrix, where K is the number of
+// sections. Each row of the sos matrix corresponds to a second order
+// biquad filter
+// len = impzlength(__, tol)
+// specifies a tolerance for estimating the effective impulse response
+// length in case of an IIR filter. By default, tol is 5e-5. Increasing tol
+// leads to shorter len and vice-versa
+//
+// Parameters
+// b - real|complex - vector|scalar
+// Numerator coefficients
+// a - real|complex - vector|scalar
+// Denominator coefficients
+// sos - real|complex - matrix (K-by-6)
+// Second order estimates
+// tol - positive real - scalar
+// Tolerance for estimating the effective length of an IIR filter impulse
+// response
+//
+// Examples
+// 1) Low pass IIR filter with pole at 0.9
+// b = 1;
+// a = [1 -0.9];
+// len = impzlength(b,a);
+//
+// See also
+// designfilt | digitalFilter | impz | zp2sos
+//
+// Authors
+// Ayush Baid
+
+[numOutArgs, numInArgs] = argn(0);
+
+// *****
+// Checking the number of arguments
+// *****
+if numInArgs<1 | numInArgs>3 then
+ msg = "impzlength: Wrong number of input argument; 1-3 expected";
+ error(77,msg);
+end
+
+if numOutArgs~=1 then
+ msg = "cummin: Wrong number of output argument; 1 expected";
+ error(78,msg);
+end
+
+// *****
+// Parsing input arguments
+// *****
+isSos = %f;
+tol = 5e-5;
+a = 1;
+
+if size(b,2)==6 & size(b,1)>=2 then
+ // input is sos
+ isSos = %t;
+ if length(varargin)==1 then
+ tol = varargin(1);
+ elseif length(varargin)>1 then
+ msg = "impzlength: Wrong number of input arguments; only one extra argument if 1st argument is sos";
+ error(77,msg);
+ end
+else
+ if length(varargin)==0 then
+ msg = "impzlength: Wrong number of input arguments; atleast 2 required when input is transfer function coefficients";
+ error(77,msg);
+ elseif length(varargin)==1 then
+ a = varargin(1);
+ else
+ a = varargin(1);
+ tol = varargin(2);
+ end
+end
+
+// *****
+// Check on argument types
+// *****
+
+// checking arguments
+
+// ** b or sos
+if ~isSos then
+ if isempty(b) then
+ b = 1;
+ end
+ if size(b,1)==1 & size(b,2)~=1 then
+ b = b(:);
+ elseif size(b,2)~=1 then
+ // only scalar/vector accepted
+ msg = "impzlength: Wrong size of input argument #1 (b); must be a vector"
+ error(60,msg);
+ end
+end
+
+if type(b)~=8 & type(b)~=1 then
+ msg = "impzlength: Wrong type for argument #1 (b); Real or complex entries expected ";
+ error(53,msg);
+end
+
+// ** a
+
+if isempty(a) then
+ a = 1;
+end
+if size(a,1)==1 & size(a,2)~=1 then
+ a = a(:);
+elseif size(a,2)~=1 then
+ // only scalar/vector accepted
+ msg = "impzlength: Wrong size of input argument #2 (a); must be a vector"
+ error(60,msg);
+end
+
+if type(a)~=8 & type(a)~=1 then
+ msg = "impzlength: Wrong type for argument #2 (a); Real or complex entries expected ";
+ error(53,msg);
+end
+
+// ** tol
+if (type(tol)~=8 & type(tol)~=1) | length(tol)~=1 | tol<=0 then
+ if isSos then
+ msg = "impzlength: Wrong type for argument #2 (tol); Positive scalar expected"
+ else
+ msg = "impzlength: Wrong type for argument #3 (tol); Positive scalar expected"
+ end
+ error(53,msg);
+end
+
+
+// *****
+// Calculation
+// *****
+
+if isSos
+ // calculating the length of all fir components and the max length of all
+ // iir components
+ fir_len = 1;
+ iir_len = 1;
+ for i=1:size(b,1)
+ num = b(i,1:3);
+ den = b(i,4:6);
+
+ if den(2)==0 & den(3)==0 then
+ // fir section
+ fir_len = fir_len + length(num) - 1;
+ else
+ iir_len = max(iir_len, impzlength_singlefilter(num,den,tol));
+ end
+ end
+ len = max(fir_len, iir_len);
+else
+ len = impzlength_singlefilter(b,a,tol);
+end
+
+endfunction
+
+function len = impzlength_singlefilter (b, a, tol)
+ // Adapted to scilab from octave's signal package (GNU GPL)
+
+ if length(a) > 1 & sum(a(2:$))~=0 then
+ // IIR filter
+ precision = 1e-6;
+
+ r = roots(a);
+ pole_mag = abs(r);
+ maxpole = max(pole_mag);
+
+ // get the multiplicity of maxpole
+ mult = get_multiplicity(r,maxpole);
+
+ if (maxpole > 1+precision) then // unstable -- cutoff at 120 dB
+ n = floor(6/log10(maxpole));
+ elseif (maxpole < 1-precision) then //stable
+ n = floor(mult*log10(tol)/log10(maxpole));
+ else // periodic -- cutoff after 5 cycles
+ n = 30;
+
+ unit_poles_idx = find(pole_mag>=1-precision);
+
+ r(unit_poles_idx) = -r(unit_poles_idx);
+
+ pole_phase = atan(imag(r),real(r));
+
+
+ // find longest period less than infinity
+ // cutoff after 5 cycles (w=10*pi)
+ periodic_idx = find(unit_poles_idx & abs(pole_phase)>0);
+ if ~isempty(periodic_idx) then
+ disp('periodic');
+ n = ceil(10*%pi./min(abs(pole_phase(periodic_idx))));
+ //if (n_periodic > n) then
+ // n = n_periodic;
+ //end
+ end
+
+ // find most damped pole
+ // cutoff at -60 dB
+ damped_idx = find(pole_mag<1-precision);
+ if ~isempty(damped_idx) then
+ n_damped = floor(log10(tol)/log10(max(pole_mag(damped_idx))));
+ if (n_damped > n) then
+ n = n_damped;
+ end
+ end
+ end
+
+ // n = n + length(b) - 1;
+ len = max(length(a)+length(b)-1,floor(n));
+
+ else
+ len = length(b);
+ end
+
+
+
+endfunction
+
+function mult = get_multiplicity(poles,query_mag)
+ // returns the number of the poles with the given magnitude
+ // Complex conjugate pairs are counted as 1
+
+ mags = abs(poles);
+ conj_poles = conj(poles);
+
+ // get indices of poles with matching magnitude
+ idx = mags>query_mag-1e-3 & mags4) //source code says rhs<1 -- but crashes for just one arg
+error("Wrong number of input arguments.")
+end
+
+
+
+
+ select(rhs)
+ case 2 then
+ y = callOctave("interp",x,q)
+ case 3 then
+ y = callOctave("interp",x,q,n)
+ case 4 then
+ y = callOctave("interp",x,q,n,Wc)
+ end
+endfunction
diff --git a/macros/intfilt.bin b/macros/intfilt.bin
new file mode 100644
index 0000000..3a02288
Binary files /dev/null and b/macros/intfilt.bin differ
diff --git a/macros/intfilt.sci b/macros/intfilt.sci
new file mode 100644
index 0000000..15da95c
--- /dev/null
+++ b/macros/intfilt.sci
@@ -0,0 +1,291 @@
+function [h, a]= intfilt(R, L, freqmult)
+
+
+ // This function estimate Interpolated FIR Filter Design.
+ // Calling Sequence
+ // h=intfilt(R,L,freqmult)
+ // [h a]=intfilt(R,L,freqmult)
+
+ // Parameters
+ // R: Samples. It should be numeric
+ // L: bandlimited interpolation samples. It must be nonzero.
+ // freqmult: bandlimitedness of ALPHA times the Nyquist frequency, IT can be numeric or character ('B' or 'L', B is length
+ // (N+1)*L-1 for N odd and (N+1)*L for N even)
+
+ // h: linear phase FIR filter.
+
+ // Examples
+ // h=intfilt(20,10,'l')
+ // h=intfilt(20,10,1)
+ //
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+ if or(type(R)==10) | or(type(L)==10) then
+ error ('Argument R and L must be numeric.')
+
+ else
+
+
+
+
+ if argn(2)==3 then
+ if type(freqmult)==10 then
+ typ=freqmult;
+ n=L;
+ else
+ freqmult=double(freqmult);
+ typ='b';
+ end
+
+ end
+
+ if freqmult==0 then
+ h=repmat(%nan,[1,(2*R*L-1)])
+ a=1;
+ else
+
+
+ //typ(1)=='b' | typ(1)=='B'
+
+ if convstr(typ(1), 'u') =='B' then
+ n=2*R*L-1;
+
+
+ if freqmult==1 then
+ M=[R R 0 0];
+ F= [0 1/(2*R) 1/(2*R) 0.5];
+ else
+ M=R*[1 1];
+
+ if type(freqmult)==10 then
+ F=[0 98/2/R];
+ else
+ F=[0 freqmult/2/R]
+ end
+
+ for f=(1/R):(1/R):.5,
+
+ if type(freqmult)==10 then
+ F=[F f-(98/2/R) f+(98/2/R)];
+ else
+ F=[F f-(freqmult/2/R) f+(freqmult/2/R)];
+ end
+
+ M=[M 0 0];
+ end;
+
+ if (F(length(F))>.5),
+ F(length(F))=.5;
+ end;
+ end
+ N=n-1; F=F*2; M=M
+
+
+if (max(F)>1) | (min(F)<0)
+ error('Frequencies in F must be in range [0,1]')
+end
+
+
+
+
+if ((length(F)-fix(length(F)./2).*2)~=0)
+ error('Argument F should of even length');
+end
+
+if (length(F) ~= length(M))
+ error('The input arguments F & A must have same length');
+end
+
+
+ W = ones(length(F)/2,1);
+ ftype = '';
+
+
+ ftype = 0; differ = 0;
+
+
+N = N+1;
+
+F=F(:)/2; M=M(:); W=sqrt(W(:));
+dF = diff(F);
+
+if (length(F) ~= length(W)*2)
+ error('There should be one weight per band.');
+end
+
+
+if or(dF<0),
+
+ error('F frequency must be increasing')
+
+end
+
+
+
+if and(dF(2:2:length(dF)-1)==0) & length(dF) > 1,
+ band = 1;
+else
+ band = 0;
+end
+if and((W-W(1))==0)
+ weights = 1;
+else
+ weights = 0;
+end
+
+L=(N-1)/2;
+
+Nodd = N-fix(N./2).*2;
+
+
+ if ~Nodd
+ m=(0:L)+.5;
+ else
+ m=(0:L);
+ end
+
+
+ k=m';
+ need_matrix = (~band) | (~weights);
+
+
+
+
+ if need_matrix
+
+ I1=k(:,ones(size(m,1),size(m,2)))+m(ones(size(k,1),size(k,2)),:);
+ I2=k(:,ones(size(m,1),size(m,2)))-m(ones(size(k,1),size(k,2)),:);
+ G=zeros(size(I1,1),size(I1,2));
+ end
+
+ if Nodd
+ k=k(2:length(k));
+ b0=0;
+ end;
+ b=zeros(size(k,1),size(k,2));
+
+ dd=diff(F);
+
+ if or(dd==0) & R==1 then
+
+ h=repmat(%nan,[1,n])
+ a=1
+
+ else
+ for s=1:2:length(F),
+
+
+ m=(M(s+1)-M(s))/(F(s+1)-F(s));
+ b1=M(s)-m*F(s);
+ if Nodd
+ b0 = b0 + (b1*(F(s+1)-F(s)) + m/2*(F(s+1)*F(s+1)-F(s)*F(s)))* abs(W((s+1)/2)^2) ;
+ end
+
+ b=b(:)
+ b = b+(m/(4*%pi*%pi)*(cos(2*%pi*k*F(s+1))-cos(2*%pi*k*F(s)))./(k.*k))* abs(W((s+1)/2)^2);
+
+
+
+ b = b' + (F(s+1)*(m*F(s+1)+b1)*sinf(2*k*F(s+1))- F(s)*(m*F(s)+b1)*sinf(2*k*F(s)))* abs(W((s+1)/2)^2);
+ if need_matrix
+
+
+
+ mat=matrix((.5*F(s+1)*(sinf(2*I1*F(s+1))+sinf(2*I2*F(s+1)))- .5*F(s)*(sinf(2*I1*F(s))+sinf(2*I2*F(s))) ) * abs(W((s+1)/2)^2),size(G,1),size(G,2)) ;
+ mat=mat';
+ G=G+mat;
+
+
+ end
+ end;
+
+
+ if Nodd
+ b=[b0; b'];
+ end;
+
+ if need_matrix
+ a=G\b;
+ else
+ a=(W(1)^2)*4*b;
+ if Nodd
+ a(1) = a(1)/2;
+ end
+ end
+ if Nodd
+ h=[a(L+1:-1:2)/2; a(1); a(2:L+1)/2].';
+ else
+ h=.5*[flipud(a); a].';
+ end;
+ end;
+
+ //typ(1)=='l' | typ(1)=='L'
+
+
+
+ elseif convstr(typ(1), 'u') =='L' then
+
+ if n==0 then
+ h=ones(1,R)
+ return
+ end
+
+ t=0:n*R+1;
+ l=ones(n+1,length(t));
+
+ for i=1:n+1
+ for j=1:n+1
+ if (j~=i) then
+ l(i,:)=l(i,:).*(t/R-j+1)/(i-j);
+ end
+ end
+ end
+
+ h=zeros(1,(n+1)*R);
+
+ for i=0:R-1
+ for j=0:n
+ h(j*R+i+1)=l((n-j)+1,round((n-1)/2*R+i+1));
+ end
+end
+
+
+
+if h(1) == 0,
+ h(1) = [];
+ end
+
+else
+ error ('This type of filter is not recognized.')
+
+
+ end
+ a=1;
+
+
+ end
+ end
+
+endfunction
+
+
+
+////// Supplementary function
+
+function y=sinf(x)
+
+ for i=1:length(x)
+ if x(i)==0 then
+ y(i)=1;
+ else
+
+ y(i)=sin(%pi*x(i))/(%pi*x(i));
+ end
+
+ end
+
+ y=y';
+endfunction
diff --git a/macros/invimpinvar.bin b/macros/invimpinvar.bin
new file mode 100644
index 0000000..a5f115f
Binary files /dev/null and b/macros/invimpinvar.bin differ
diff --git a/macros/invimpinvar.sci b/macros/invimpinvar.sci
new file mode 100644
index 0000000..4e8bd7b
--- /dev/null
+++ b/macros/invimpinvar.sci
@@ -0,0 +1,42 @@
+function [b_out, a_out] = invimpinvar (b, a, fs, tol)
+//This function converts digital filter with coefficients b and a to analog, conserving impulse response.
+//Calling Sequence
+//[b, a] = impinvar (b, a)
+//[b, a] = impinvar (b, a, fs)
+//[b, a] = impinvar (b, a, fs, tol)
+//Parameters
+//b: real or complex valued scalar or vector
+//a: real or complex valued scalar or vector, order should be greater than b
+//fs: real or complex value, default value 1Hz
+//tol: real or complex value, default value 0.0001
+//Description
+//This is an Octave function.
+//This function converts digital filter with coefficients b and a to analog, conserving impulse response.
+//This function does the inverse of impinvar.
+//Examples
+//b = 0.0081000
+//a = [2.0000000, 0.56435378, 0.4572792, 0.00705544, 0.091000]
+//[ay, by] = invimpinvar(b,a,10)
+//ay =
+// -1.6940e-16 4.6223e+00 -4.5210e+00 7.2880e+02
+//by =
+// Columns 1 through 4:
+// 1.0000e+00 3.0900e+01 9.6532e+02 1.2232e+04
+// Column 5:
+// 1.1038e+05
+funcprot(0);
+rhs = argn(2)
+if(rhs<2)
+error("Wrong number of input arguments.")
+end
+
+
+ select(rhs)
+ case 2 then
+ [b_out,a_out] = callOctave("invimpinvar",b,a)
+ case 3 then
+ [b_out,a_out] = callOctave("invimpinvar",b,a,fs)
+ case 4 then
+ [b_out,a_out] = callOctave("invimpinvar",b,a,fs,tol)
+ end
+endfunction
diff --git a/macros/is2rc.bin b/macros/is2rc.bin
new file mode 100644
index 0000000..325d4b5
Binary files /dev/null and b/macros/is2rc.bin differ
diff --git a/macros/is2rc.sci b/macros/is2rc.sci
new file mode 100644
index 0000000..ad68f5f
--- /dev/null
+++ b/macros/is2rc.sci
@@ -0,0 +1,38 @@
+function [k] = is2rc(isin)
+// Convert inverse sine parameters to reflection coefficients
+//
+// Calling Sequence
+// K = is2rc(isin)
+//
+// Parameters
+// isin: input inverse sine parameters. Needs to be an array real numbers
+// k: output reflection coefficients corresponding to the reflection coefficients in input
+//
+// Description
+// This function returns a vector of reflection coefficients from a vector of inverse sine parameters
+// output array has k(i) = sin(pi/2*isin(i))
+//
+// Example
+// k = [0.3090 0.9801 0.0031 0.0082 -0.0082];
+// isin = rc2is(k) //Gives inverse sine parameters
+// k_dash = is2rc(isin)
+//
+// See also
+// rc2is
+// rc2poly
+// rc2ac
+// rc2lar
+//
+// Author
+// Parthe Pandit
+//
+// Bibliography
+// J.R. Deller, J.G. Proakis, J.H.L. Hansen, "Discrete-Time Processing of Speech Signals", Prentice Hall, Section 7.4.5
+
+//errcheck1
+if (~isreal(isin)),
+ error('Input inverse sine coefficients are not real');
+end
+
+k = sin(isin*%pi/2);
+endfunction
diff --git a/macros/isallpass.bin b/macros/isallpass.bin
new file mode 100644
index 0000000..6f27769
Binary files /dev/null and b/macros/isallpass.bin differ
diff --git a/macros/isallpass.sci b/macros/isallpass.sci
new file mode 100644
index 0000000..d76c295
--- /dev/null
+++ b/macros/isallpass.sci
@@ -0,0 +1,149 @@
+//isallpass Determine whether filter is allpass
+
+//Calling Syntax
+//flag = isallpass(b,a)
+//flag = isallpass(sos)
+//flag = isallpass(...,tol)
+// b and a are the vectors containing zero and pole coefficients respectively
+//tol, tolerance is used to determine when two numbers are close enough to be considered equal.
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function isall=isallpass(varargin)
+ [nargout,nargin]=argn();
+ if (nargin==2) then
+ v=size(varargin(1));
+ if (v(2)~=6) | (v(2)==6 & v(1)==1) then
+ a=varargin(1);
+ b=varargin(2);
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ tol=0;
+ else
+ sos=varargin(1);
+ if type(sos)~=1 then
+ error('check input dimension');
+ end
+ v=size(sos);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('no. of columns must be 6');
+ end
+ a=1;b=1;
+ for i=[1:v(1)]
+ a=convol(a,sos(1:3));
+ b=convol(b,sos(4:6));
+ end
+ tol=varargin(3);
+ if (type(tol)~=1) then
+ error('check input type');
+ end
+ if (size(tol)~=[1,1]) then
+ error('check input dimension');
+ end
+ end
+ elseif (nargin==1) then
+ tol=0;
+ sos=varargin(1);
+ if type(sos)~=1 then
+ error('check input dimension');
+ end
+ v=size(sos);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('no. of columns must be 6');
+ end
+ a=1;b=1;
+ for i=[1:v(1)]
+ a=convol(a,sos(1:3));
+ b=convol(b,sos(4:6));
+ end
+ elseif (nargin==3) then
+ a=varargin(1);
+ b=varargin(2);
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ tol=varargin(3);
+ if (type(tol)~=1) then
+ error('check input type');
+ end
+ if (size(tol)~=[1,1]) then
+ error('check input dimension');
+ end
+ else
+ error('no. of inputs not matching');
+ end
+
+ poly_a=inv_coeff(a($:-1:1));
+ poly_b=inv_coeff(b);
+ gc=gcd([poly_a,poly_b]);
+ [r,den]=pdiv(poly_b,gc);
+ [r,num]=pdiv(poly_a,gc);
+ poles=roots(den);
+ zerosinv=roots(num);
+ //sorting the zeros and poles to facilitate comparision
+ [l,k]=gsort(imag(poles));
+ poles=poles(k);
+ [l,k]=gsort(real(poles));
+ poles=poles(k);
+ [l,k]=gsort(imag(poles));
+ zerosinv=zerosinv(k);
+ [l,k]=gsort(real(poles));
+ zerosinv=zerosinv(k);
+ maxerr=max((poles-conj(zerosinv)).*conj(poles-conj(zerosinv)));
+ if zerosinv==[] & poles==[] then
+ isall=1;
+ elseif maxerr<=tol then
+ isall=1;
+ else
+ isall=0;
+ end
+
+endfunction
diff --git a/macros/isfir.bin b/macros/isfir.bin
new file mode 100644
index 0000000..c9670a9
Binary files /dev/null and b/macros/isfir.bin differ
diff --git a/macros/isfir.sci b/macros/isfir.sci
new file mode 100644
index 0000000..d9e4a05
--- /dev/null
+++ b/macros/isfir.sci
@@ -0,0 +1,57 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function fir=isfir(varargin)
+ [nargout,nargin]=argn();
+ if (nargin==2) then
+ a=varargin(1);
+ b=varargin(2);
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ elseif (nargin==1) then
+ sos=varargin(1);
+ if type(sos)~=1 then
+ error('check input dimension');
+ end
+ v=size(sos);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('no. of columns must be 6');
+ end
+ a=1;b=1;
+ for i=[1:v(1)]
+ a=convol(a,sos(1:3));
+ b=convol(b,sos(4:6));
+ end
+ else
+ error('no. of inputs not matching');
+ end
+ if length(b)==1 then
+ fir=1;
+ else
+ fir=0;
+ end
+endfunction
diff --git a/macros/islinphase.bin b/macros/islinphase.bin
new file mode 100644
index 0000000..2f00f5e
Binary files /dev/null and b/macros/islinphase.bin differ
diff --git a/macros/islinphase.sci b/macros/islinphase.sci
new file mode 100644
index 0000000..f004419
--- /dev/null
+++ b/macros/islinphase.sci
@@ -0,0 +1,134 @@
+//islinphase Determine whether filter has linear phase
+
+// Calling Syntax
+//flag = islinphase(b,a)
+//flag = islinphase(sos)
+//flag = islinphase(...,tol)
+
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function islin=islinphase(varargin)
+ [nargout,nargin]=argn();
+ if (nargin==2) then
+ v=size(varargin(1));
+ if (v(2)~=6) | (v(2)==6 & v(1)==1) then
+ a=varargin(1);
+ b=varargin(2);
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ tol=0;
+ else
+ sos=varargin(1);
+ if type(sos)~=1 then
+ error('check input dimension');
+ end
+ v=size(sos);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('no. of columns must be 6');
+ end
+ a=1;b=1;
+ for i=[1:v(1)]
+ a=convol(a,sos(1:3));
+ b=convol(b,sos(4:6));
+ end
+ tol=varargin(3);
+ if (type(tol)~=1) then
+ error('check input type');
+ end
+ if (size(tol)~=[1,1]) then
+ error('check input dimension');
+ end
+ end
+ elseif (nargin==1) then
+ tol=0;
+ sos=varargin(1);
+ if type(sos)~=1 then
+ error('check input dimension');
+ end
+ v=size(sos);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('no. of columns must be 6');
+ end
+ a=1;b=1;
+ for i=[1:v(1)]
+ a=convol(a,sos(1:3));
+ b=convol(b,sos(4:6));
+ end
+ elseif (nargin==3) then
+ a=varargin(1);
+ b=varargin(2);
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ tol=varargin(3);
+ if (type(tol)~=1) then
+ error('check input type');
+ end
+ if (size(tol)~=[1,1]) then
+ error('check input dimension');
+ end
+ else
+ error('no. of inputs not matching');
+ end
+ if length(b)==1 then
+ err=a-a($:-1:1);
+ maxerr=max(err.*conj(err));
+ if err<=tol then
+ islin=1;
+ else
+ islin=0;
+ end
+ else
+ islin=0;
+ end
+
+endfunction
diff --git a/macros/ismaxphase.bin b/macros/ismaxphase.bin
new file mode 100644
index 0000000..3684e9a
Binary files /dev/null and b/macros/ismaxphase.bin differ
diff --git a/macros/ismaxphase.sci b/macros/ismaxphase.sci
new file mode 100644
index 0000000..e40adbe
--- /dev/null
+++ b/macros/ismaxphase.sci
@@ -0,0 +1,86 @@
+//ismaxphase Determine whether filter is maximum phase
+//Syntax
+//flag = ismaxphase(b,a)
+//flag = ismaxphase(sos)
+//flag = ismaxphase(...,tol)
+// b and a are the vectors containing zero and pole coefficients respectively
+//tol, tolerance is used to determine when two numbers are close enough to be considered equal.
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function ismax=ismaxphase(varargin)
+ [nargout,nargin]=argn();
+ if (nargin==2) then
+ a=varargin(1);
+ b=varargin(2);
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ elseif (nargin==1) then
+ sos=varargin(1);
+ if type(sos)~=1 then
+ error('check input dimension');
+ end
+ v=size(sos);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('no. of columns must be 6');
+ end
+ a=1;b=1;
+ for i=[1:v(1)]
+ a=convol(a,sos(1:3));
+ b=convol(b,sos(4:6));
+ end
+ else
+ error('no. of inputs not matching');
+ end
+ poly_a=inv_coeff(a);
+ poly_b=inv_coeff(b);
+ z=inv_coeff([1,0]);
+ gc=gcd([poly_a,poly_b]);
+ [r,den]=pdiv(poly_b,gc);
+ [r,num]=pdiv(poly_a,gc);
+ maxpole=min(abs(roots(den)));
+ minzero=max(abs(roots(num)));
+ if length(a)==1 then
+ if length(b)==1 then
+ ismax=0;
+ elseif minzero>1 then
+ ismax=0;
+ else
+ ismax=1;
+ end
+ elseif maxpole>1 then
+ if length(b)==1 then
+ ismax=0;
+ elseif minzero>1 then
+ ismax=0;
+ else
+ ismax=1;
+ end
+ else
+ ismax=0;
+ end
+endfunction
diff --git a/macros/isminphase.bin b/macros/isminphase.bin
new file mode 100644
index 0000000..fc1991d
Binary files /dev/null and b/macros/isminphase.bin differ
diff --git a/macros/isminphase.sci b/macros/isminphase.sci
new file mode 100644
index 0000000..ccd2754
--- /dev/null
+++ b/macros/isminphase.sci
@@ -0,0 +1,79 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function ismin=isminphase(varargin)
+ [nargout,nargin]=argn();
+ if (nargin==2) then
+ a=varargin(1);
+ b=varargin(2);
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ elseif (nargin==1) then
+ sos=varargin(1);
+ if type(sos)~=1 then
+ error('check input dimension');
+ end
+ v=size(sos);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('no. of columns must be 6');
+ end
+ a=1;b=1;
+ for i=[1:v(1)]
+ a=convol(a,sos(i,1:3));
+ b=convol(b,sos(i,4:6));
+ end
+ else
+ error('no. of inputs not matching');
+ end
+ poly_a=inv_coeff(a);
+ poly_b=inv_coeff(b);
+ z=inv_coeff([1,0]);
+ gc=gcd([poly_a,poly_b]);
+ [r,den]=pdiv(poly_b,gc);
+ [r,num]=pdiv(poly_a,gc);
+ maxpole=min(abs(roots(den)));
+ maxzero=min(abs(roots(num)));
+ if length(a)==1 then
+ if length(b)==1 then
+ ismin=1;
+ elseif maxzero>1 then
+ ismin=1;
+ else
+ ismin=0;
+ end
+ elseif maxpole>1 then
+ if length(b)==1 then
+ ismin=1;
+ elseif maxzero>1 then
+ ismin=1;
+ else
+ ismin=0;
+ end
+ else
+ ismin=0;
+ end
+endfunction
diff --git a/macros/isstable.bin b/macros/isstable.bin
new file mode 100644
index 0000000..304c4be
Binary files /dev/null and b/macros/isstable.bin differ
diff --git a/macros/isstable.sci b/macros/isstable.sci
new file mode 100644
index 0000000..db7d5b5
--- /dev/null
+++ b/macros/isstable.sci
@@ -0,0 +1,96 @@
+//isstable True for stable filter
+// FLAG = ISSTABLE(B,A) returns a logical output, FLAG, equal to TRUE if
+// the filter specified by numerator coefficients B, and denominator
+// coefficients A, is stable. Input vectors B, and A define a filter with
+// transfer function:
+//
+// jw -jw -jmw
+// jw B(e) b(1) + b(2)e + .... + b(m+1)e
+// H(e) = ---- = ------------------------------------
+// jw -jw -jnw
+// A(e) a(1) + a(2)e + .... + a(n+1)e
+//
+// FLAG = ISSTABLE(SOS) returns TRUE if the filter specified using the
+// second order sections matrix, SOS, is stable. SOS is a Kx6 matrix,
+// where the number of sections, K, must be greater than or equal to 2.
+// Each row of SOS corresponds to the coefficients of a second order
+// filter. From the transfer function displayed above, the ith row of the
+// SOS matrix corresponds to [bi(1) bi(2) bi(3) ai(1) ai(2) ai(3)].
+// Calling Syntax
+// flag=isstable(b,a);
+// flag=isstable(sos);
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function isstab=isstable(varargin)
+[nargout,nargin]=argn();
+if (nargin==2) then//(a,b) is the input
+ a=varargin(1);
+ b=varargin(2);
+ //verifying type and length of input
+ if type(a)~=1 | type(b)~=1 then
+ error('check input type');
+ end
+ v=size(a);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ v=size(b);
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ elseif n~=1 then
+ error('check input dimension');
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ k=n;
+ elseif n~=1 then
+ error('check input dimension');
+ end
+elseif (nargin==1) then//sos form is given as input
+ sos=varargin(1);
+ v=size(sos);
+ if(v(1)>1) then
+ //verifying type and length of input
+ if type(sos)~=1 then
+ error('check input type');
+ end
+
+ if length(v)>2 then
+ error('check input dimension');
+ end
+ if v(2)~=6 then
+ error('When first input is a matrix, it must have exactly 6 columns to be a valid SOS matrix.');
+ end
+ a=1;b=1;
+ //converting it to rational form
+ for i=[1:v(1)]
+ a=convol(a,sos(i,1:3));
+ b=convol(b,sos(i,4:6));
+ end
+ else
+ b=1;
+ end
+else
+ error('no. of inputs not matching');
+end
+if length(b)==1 then
+ isstab=1;
+else
+ poly_a=inv_coeff(a);//constructing numerator polynomial
+ poly_b=inv_coeff(b);//constructing denominator polynomial
+ gc=gcd([poly_a,poly_b]);//computing gcd to remove common roots
+ [r,den]=pdiv(poly_b,gc);//dividing off gcd
+ time_constant=min(abs(roots(den)));//finding the minumum magnitude pole
+ if time_constant<=1 then//pole magnitude should be greater than 1
+ disp('unstable system');
+ isstab=0;
+ else
+ isstab=1;
+ end
+end
+endfunction
diff --git a/macros/kaiser.bin b/macros/kaiser.bin
new file mode 100644
index 0000000..4e00979
Binary files /dev/null and b/macros/kaiser.bin differ
diff --git a/macros/kaiser.sci b/macros/kaiser.sci
new file mode 100644
index 0000000..2c33b3f
--- /dev/null
+++ b/macros/kaiser.sci
@@ -0,0 +1,33 @@
+function w = kaiser (m, beta)
+//This function returns the filter coefficients of a Kaiser window.
+//Calling Sequence
+//w = kaiser (m)
+//w = kaiser (m, beta)
+//Parameters
+//m: positive integer value
+//beta: real scalar value
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Kaiser window of length m supplied as input, to the output vector w.
+//The second parameter gives the stop band attenuation of the Fourier transform of the window on derivation.
+//Examples
+//kaiser(6,0.2)
+//ans =
+// 0.9900745
+// 0.9964211
+// 0.9996020
+// 0.9996020
+// 0.9964211
+// 0.9900745
+funcprot(0);
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+if(rhs==1)
+w = callOctave("kaiser", m)
+elseif(rhs==2)
+w = callOctave("kaiser", m, beta)
+end
+endfunction
diff --git a/macros/lar2rc.bin b/macros/lar2rc.bin
new file mode 100644
index 0000000..16ad37f
Binary files /dev/null and b/macros/lar2rc.bin differ
diff --git a/macros/lar2rc.sci b/macros/lar2rc.sci
new file mode 100644
index 0000000..15fa4ee
--- /dev/null
+++ b/macros/lar2rc.sci
@@ -0,0 +1,35 @@
+function k=lar2rc(g)
+
+//lar2rc convert log area ratios to reflection coefficients.
+// Calling Sequence
+// k = lar2rc(g)
+// Parameters
+// g: define log area ratios.
+// k: returns the reflection coefficients.
+// Examples
+//X = [7 6 5 8 3 6 8 7 5 2 4 7 4 3 2 5 4 9 5 3 5 7 3 9 4 1 2 0 5 4 8 6 4 6 5 3];
+// k = lar2rc(X)
+// or t=[2 5 6; 8 6 5; 8 9 4]
+// k = lar2rc(t)
+//
+// See also
+//
+// Author
+// Jitendra Singh
+//
+//Modified to match MATLAB o/p when i/p is of type char and is a string by Debdeep Dey
+ if or(type(g)==10) then
+ [r,c]=size(g);
+ if r==1 & c==1 then
+ k=ones(1,length(g));
+ else
+ k=ones(size(g,1), size(g,2))
+ end
+
+else
+ if ~isreal(g) then
+ error('Log area ratios must be real.')
+ end
+ k=-(tanh(-g/2));
+ end
+endfunction
diff --git a/macros/latc2tf.bin b/macros/latc2tf.bin
new file mode 100644
index 0000000..96fbc64
Binary files /dev/null and b/macros/latc2tf.bin differ
diff --git a/macros/latc2tf.sci b/macros/latc2tf.sci
new file mode 100644
index 0000000..fb19e6d
--- /dev/null
+++ b/macros/latc2tf.sci
@@ -0,0 +1,225 @@
+function [num,den] = latc2tf(k,varargin)
+ // Convert lattice filter parameters to transfer function coefficients
+ //
+ //
+ // Calling sequence
+ // [num,den] = latc2tf(k,v)
+ // [num,den] = latc2tf(k,'iiroption')
+ // num = latc2tf(k,'firoption')
+ //
+ //
+ // Description
+ // [num,den] = latc2tf(k,v)
+ // Finds the transfer function of the IIR filter from the lattice
+ // coefficients k and ladder coefficients v.
+ // [num,den] = latc2tf(k,'iiroption')
+ // Finds the transfer function of the allpass or allpole (specified by
+ // the iiroption flag) IIR filter.
+ // num = latc2tf(k,'firoption')
+ // Finds the transfer function of the FIR filter from the lattice
+ // coefficients k. The firoption flag specifies the type of the FIR
+ // filter (can be 'min, 'max', or 'FIR')
+ //
+ // Parameters:
+ // k - double - vector
+ // Lattice coefficients
+ // Lattice coefficients for FIR/IIR filter. Can be real or complex.
+ // v - double - vector
+ // Ladder coefficients
+ // Ladder coefficients for IIR filters. Can be real or complex.
+ // iiroption - string flag - 'allpole', or 'allpass'
+ // Specification of the type if IIR filter
+ // firoption - string flag - 'min', 'max', or 'FIR' (default)
+ // Speficication of the type of FIR filter
+ //
+ // Examples
+ // 1) FIR filter
+ // k1 = [1/2 1/2 1/4];
+ // [num1,den1] = latc2tf(k1);
+ //
+ // See also
+ // latcfilt | tf2latc
+ //
+ // References
+ // [1] J.G. Proakis, D.G. Manolakis, Digital Signal Processing,
+ // 3rd ed., Prentice Hall, N.J., 1996, Chapter 7.
+ // [2] S. K. Mitra, Digital Signal Processing, A Computer
+ // Based Approach, McGraw-Hill, N.Y., 1998, Chapter 6.
+ //
+ // Authors
+ // Ayush Baid
+
+
+ [numOutArgs,numInArgs] = argn(0);
+
+// ** Check on number of input arguments **
+ if numOutArgs<1 | numOutArgs>2 then
+ msg = "cummin: Wrong number of output argument; 1-2 expected";
+ error(78,msg);
+ end
+
+ if numInArgs<1 | numInArgs>2 then
+ msg = "cummin: Wrong number of input argument; 1-2 expected";
+ error(77,msg);
+ end
+
+
+// ** Parsing the input arguments **
+
+// 1) k:
+// must be a vector
+// can be real or complex valued, (negative values allowed)
+
+ // checking data type
+ if ~(type(k)==1 | type(k)==8) then
+ msg = "latc2tf: Wrong type for argument #1 (k); Real or complex vector expected";
+ error(53,msg);
+ end
+
+ // checking the dimensions (must be a vector)
+ if ~(size(k,1)==1 | size(k,2)==1) then
+ msg = "latc2tf: Wrong type for argument #1 (k); Real or complex vector expected";
+ error(53,msg);
+ end
+ // convert to column vector
+ if size(k,1)==1 then
+ k = k(:);
+ end
+
+ L = length(varargin);
+// Parsing the 2nd argument
+ if L>=1 then
+ arg2 = varargin(1);
+ // string check
+ if type(arg2)==10 then
+ if strcmpi(arg2,'FIR')==0 then
+ [num,den] = latc2tf_fir(k,2);
+ elseif strcmpi(arg2,'min')==0 then
+ [num,den] = latc2tf_fir(k,0);
+ elseif strcmpi(arg2,'max')==0 then
+ [num,den] = latc2tf_fir(k,1);
+ elseif strcmpi(arg2,'allpole')==0 then
+ [num,den] = latc2tf_iir2(k,1);
+ elseif strcmpi(arg2,'allpass')==0 then
+ [num,den] = latc2tf_iir1(k);
+ else
+ msg = "latc2tf: Wrong value for argument #2 (string flag) ";
+ error(53,msg);
+ end
+ elseif (type(arg2)==1 | type(arg2)==8) then
+ // arg2 is ladder coefficients
+
+ // check for vector input
+ if ~(size(arg2,1)==1 | size(arg2,2)==1) then
+ msg = "latc2tf: Wrong type for argument #2 (v); Real or complex vector expected";
+ error(53,msg);
+ end
+
+ // convert to column vector
+ if size(arg2,1)==1 then
+ arg2 = arg2(:);
+ end
+
+ [num,den] = latc2tf_iir2(k,arg2);
+
+ else
+ msg = "latc2tf: Wrong type for argument #2; Real or complex vector" + ...
+ "(ladder coeffs k) or string flag expected";
+ error(53,msg);
+ end
+ else
+ [num,den] = latc2tf_fir(k,2);
+ end
+
+ num = num';
+ den = den';
+
+endfunction
+
+function [num,den] = latc2tf_fir(k,option)
+ // latc2tf for FIR filters
+ // Input Arguments
+ // k: lattice coefficients
+ // option: 0 for min-phase (default), 1 for max-phase; 2 for fir
+
+ if isempty(k) then
+ num = 1;
+ den = 1;
+ return
+ end
+
+ den = 1;
+
+ p = length(k);
+ num = 1;
+
+ for j=2:p+1
+ num = [num; 0] + k(j-1)*[0; conj(num($:-1:1,:))];
+ end
+
+ if option==1 then
+ num = conj(num($:-1:1));
+ end
+
+
+endfunction
+
+function [num,den] = latc2tf_iir1(k)
+ // for all pass IIR filters
+
+ if isempty(k) then
+ num = 1;
+ den = 1;
+ return
+ end
+
+ p = length(k);
+ den = 1;
+
+ for j=2:p+1
+ den = [den; 0] + k(j-1)*[0; conj(den($:-1:1,:))];
+ end
+
+ num = conj(den($:-1:1));
+
+
+endfunction
+
+
+function [num,den] = latc2tf_iir2(k,v)
+ // for allpole and general IIR fitlers
+ if isempty(k) & isempty(v) then
+ num = [];
+ den = [];
+ elseif isempty(k) & length(v)==1 then
+ num = v;
+ den = 1;
+ else
+ // k is a column vector
+ M = size(k,1)+1;
+
+ // pad v with appropriate number of zeros
+ l_v = size(v,1);
+ diff = M - l_v;
+ if diff>0 then
+ v = [v; zeros(diff,1)];
+ elseif diff<0 then
+ k = [k; zeros(-diff,1)];
+ end
+
+
+ p = length(k);
+ den = 1;
+
+ for j=2:p+1
+ den = [den; 0] + k(j-1)*[0; conj(den($:-1:1,:))];
+ end
+
+ exec('rlevinson.sci',-1);
+
+ [r,temp] = rlevinson(den,1);
+
+ num = (temp*v);
+ end
+
+endfunction
diff --git a/macros/latcfilt.bin b/macros/latcfilt.bin
new file mode 100644
index 0000000..3887ce0
Binary files /dev/null and b/macros/latcfilt.bin differ
diff --git a/macros/latcfilt.sci b/macros/latcfilt.sci
new file mode 100644
index 0000000..941aa7e
--- /dev/null
+++ b/macros/latcfilt.sci
@@ -0,0 +1,106 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+//the function is for application on vectors only
+function [f,g,zo]=latcfilt(k,x,v,zi,dim)
+ [nargout,nargin]=argn();
+ //(k,x)
+ if nargin==2 then
+ v=[zeros(length(k)-1,1);1];
+ zi=zeros(length(k),1);
+ //(k,x,v)
+ elseif nargin==3 then
+ zi=zeros(length(k),1);
+ //making sure k is not a matrix
+ [m,n]=size(k);
+ if m~=1 & n~=1 then
+ error('k cannot be a matrix');
+ end
+ //(k,x,v,zi)
+ elseif nargin==4
+ [m,n]=size(k);
+ if m~=1 & n~=1 then
+ error('k cannot be a matrix');
+ end
+ //(k,x,v,zi,dim)
+ elseif nargin==5
+ if dim==2 then
+ x=x';
+ end
+ [m,n]=size(k);
+ if m~=1 & n~=1 then
+ error('k cannot be a matrix');
+ end
+ else
+ error('check input format');
+ end
+
+ //making sure they are all real or complex matrices
+ if type(k)~=1 | type(x)~=1 | type(v)~=1 | type(zi)~=1 then
+ error('wrong input data type');
+ end
+ //sanitising v
+ [m,n]=size(v);
+ if m==1 then
+ v=v';
+ elseif m~=1 & n~=1
+ error('v cannot be a matrix');
+ end
+ if length(v)~=(length(k)+1) then
+ error('dimension mis-match between k and v');
+ end
+ //sanitising zi
+ [m,n]=size(zi);
+ if m==1 then
+ zi=zi';
+ elseif m~=1 & n~=1
+ error('zi cannot be a matrix');
+ end
+ if length(zi)~=(length(k)) then
+ error('dimension mis-match between zi and k');
+ end
+ //if k is row vector make it a column vector
+ [m,n]=size(k);
+ if m==1 then
+ k=k';
+ end
+ //if x is row vector make it a column vector
+ [m,n]=size(x);
+ if m==1 then
+ x=x';
+ end
+ [m,n]=size(x);
+ [mk,nk]=size(k);
+ //when x and k are both matrices
+ if nk>1 & n>1 then
+ if nk==n then
+ f=[];g=[];zo=[];
+ for i=[1:n]
+ [f1,g1,zo1]=latcfilt1(k(:,i),x(:,i),v,zi);
+ f=[f,f1];
+ g=[g,g1];
+ zo=[zo,zo1];
+ end
+ else
+ error('the number of columns of k and x must match');
+ end
+ //k is a vector
+ elseif nk==1
+ f=[];g=[];zo=[];
+ for i=[1:n]
+ [f1,g1,zo1]=latcfilt1(k,x(:,i),v,zi);
+ f=[f,f1];
+ g=[g,g1];
+ zo=[zo,zo1];
+ end
+ //k is a column
+ elseif n==1
+ f=[];g=[];zo=[];
+ for i=[1:nk]
+ [f1,g1,zo1]=latcfilt1(k(:,i),x,v,zi);
+ f=[f,f1];
+ g=[g,g1];
+ zo=[zo,zo1];
+ end
+ end
+
+endfunction
diff --git a/macros/latcfilt1.bin b/macros/latcfilt1.bin
new file mode 100644
index 0000000..72f06d8
Binary files /dev/null and b/macros/latcfilt1.bin differ
diff --git a/macros/latcfilt1.sci b/macros/latcfilt1.sci
new file mode 100644
index 0000000..194ec76
--- /dev/null
+++ b/macros/latcfilt1.sci
@@ -0,0 +1,28 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+//the function is for application on vectors only
+function [f,g,zo]=latcfilt1(k,v,x,zi)
+ N=length(k);
+ gv=zi;
+ //gv[n+1]=Agv[n]+Bfv[n]
+ //fv[n]=-Cgv[n]+Dx[n]
+ //computing A,B,C and D as required by the system
+ C=[];
+ for i=[1:N]
+ C=[C;[zeros(1,N-i),(k(i:N))']]
+ end
+ A=[zeros(1,N);[eye(N-1,N-1),zeros(N-1,1)]];
+ B=[1,zeros(1,N-1);diag(k(1:(N-1))),zeros(N-1,1)];
+ D=ones(N,1);
+ l=length(x);
+ g=[];
+ f=[];
+ //iterating through the input entry
+ for i=[1:l]
+ fv=D*x(i)-C*gv;
+ gv=A*gv+B*fv;
+ g=[g;gv(N)+k(N)*fv(N)];
+ f=[f;v(N+1)*g(i)+(v(1:N))'*gv];
+ end
+ zo=gv;
+endfunction
diff --git a/macros/levdown.bin b/macros/levdown.bin
new file mode 100644
index 0000000..06045ae
Binary files /dev/null and b/macros/levdown.bin differ
diff --git a/macros/levdown.sci b/macros/levdown.sci
new file mode 100644
index 0000000..f09612b
--- /dev/null
+++ b/macros/levdown.sci
@@ -0,0 +1,15 @@
+function [a,e]=levdown(a, efinal)
+
+
+ ee=a($);
+
+ a = (a-a($)*flipdim(a,2,1))/(1-a($)^2);
+
+ a=a(1:$-1)
+
+
+ econj=conj(ee);
+ econj=econj';
+ e = efinal/(1.-(econj.*ee));
+
+endfunction
diff --git a/macros/levin.bin b/macros/levin.bin
new file mode 100644
index 0000000..87a4029
Binary files /dev/null and b/macros/levin.bin differ
diff --git a/macros/levin.sci b/macros/levin.sci
new file mode 100644
index 0000000..9f4d002
--- /dev/null
+++ b/macros/levin.sci
@@ -0,0 +1,58 @@
+function [ar, sigma2,rc] = levin(r);
+// //[ar,sigma2,rc]=lev(r)
+// //Resolve the Yule-Walker equations:
+// //
+// // |r(0) r(1) ... r(N-1)|| a(1) | |sigma2|
+// // |r(1) r(0) ... r(n-1)|| a(2) | | 0 |
+// // | : : ... : || : |=| 0 |
+// // | : : ... : || : | | 0 |
+// // |r(N-1) r(N-2) ... r(0) ||a(N-1)| | 0 |
+// //
+// //using Levinson's algorithm.
+// // r :Correlation coefficients
+// // ar :Auto-Regressive model parameters
+// // sigma2 :Scale constant
+// // rc :Reflection coefficients
+if length(r)==1 then
+ ar=1;
+ sigma2=r;
+ rc=[];
+ else
+
+
+
+ ar = 0;
+ aj(1) = 1;
+ ej = r(1);
+ rc = [];
+ p=length(r)-1
+
+
+ for j=1:p,
+ aj1 = zeros(j+1, 1);
+ aj1(1) = 1;
+ gammaj = r(j+1);
+ for i=2:j,
+ gammaj = gammaj + aj(i)*r(j-i+2);
+ end
+ if ej==0 then
+ lambdaj1=%nan
+ else
+ lambdaj1 = -gammaj/ej;
+ end
+
+ rc=[rc; lambdaj1];
+
+ for i=2:j,
+ aj1(i) = aj(i)+lambdaj1*(aj(j-i+2)');
+ end
+ aj1(j+1) = lambdaj1;
+ ej1 = ej*(1-abs(lambdaj1)^2);
+
+ aj = aj1;
+ ar = aj1;
+ ej = ej1;
+ end
+ sigma2 = sqrt(ej1);
+ end
+ endfunction
diff --git a/macros/levinson.bin b/macros/levinson.bin
new file mode 100644
index 0000000..55ad79d
Binary files /dev/null and b/macros/levinson.bin differ
diff --git a/macros/levinson.sci b/macros/levinson.sci
new file mode 100644
index 0000000..ccb0ab9
--- /dev/null
+++ b/macros/levinson.sci
@@ -0,0 +1,83 @@
+//levinson levinson- durbin algorithm
+//calling syntax
+//a = levinson(r)
+//a = levinson(r,n)
+//[a,e] = levinson(r,n)
+//[a,e,k] = levinson(r,n)
+
+// where
+// a is the coefficients of a length(r)-1 order autoregressive
+//linear process
+//e is the prediction error when order is n
+// k is a column vector containing the reflection coefficients of length n
+
+// Author Debdeep Dey
+function [a, v_f, ref_f] = levinson (acf, p)
+
+if ( argn(2)<1 )
+ error("Too few input arguments");
+ // elseif( length(acf)<2 )
+ // error( "levinson: arg 1 (acf) must be vector of length >1\n");
+elseif ( argn(2)>1 & ( ~isscalar(p) | fix(p)~=p ) )
+ error( "levinson: arg 2 (p) must be integer >0\n");
+elseif (isempty(acf))
+ error("R cannot be empty");
+else
+ if ((argn(2) == 1)|(p>=length(acf)))
+ p = length(acf) - 1;
+ end
+ if( size(acf,1)==1 & size(acf,2)>1 ) then
+ acf=acf(:);
+
+ end // force a column vector
+ if size(acf,1)>=1 then // handles matrix i/p
+
+ acf=acf';
+ a=acf;
+ rows=size(acf,1);
+ for i=1:rows
+ acf_temp=acf(i,:);
+ acf_temp=acf_temp(:);
+ p=length(acf_temp)-1;
+ //disp(acf_temp);
+ if argn(1) < 3 & p < 100
+
+ //// Kay & Marple Eqn (2.39)
+
+ R = toeplitz(acf_temp(1:p), conj(acf_temp(1:p)));
+ an = R \ -acf_temp(2:p+1);
+ an= [ 1, an.' ];
+ v_f(i,:)= real( an*conj(acf_temp(1:p+1)) );
+ a(i,:)=an;
+ an=[];
+
+ else
+
+ //// Kay & Marple Eqns (2.42-2.46)
+
+ ref = zeros(p,1);
+ g = -acf_temp(2)/acf_temp(1);
+
+ an = [ g ];
+ v= real( ( 1 - g*conj(g)) * acf_temp(1) );
+ ref(1) = g;
+ for t = 2 : p
+ g = -(acf_temp(t+1) + an * acf_temp(t:-1:2)) / v;
+ an = [ an+g*conj(an(t-1:-1:1)), g ];
+ v = v * ( 1 - real(g*conj(g)) ) ;
+ ref(t) = g;
+ end
+ v_f(i,:)=v;
+ v=[];
+ ref_f(:,i)=ref;
+ an = [1, an];
+ a(i,:)=an;
+ an=[];
+ end //end if
+ end //end for
+ end
+end
+
+
+
+endfunction
diff --git a/macros/lib b/macros/lib
new file mode 100644
index 0000000..196ee56
Binary files /dev/null and b/macros/lib differ
diff --git a/macros/lpc.bin b/macros/lpc.bin
new file mode 100644
index 0000000..ccaf9d9
Binary files /dev/null and b/macros/lpc.bin differ
diff --git a/macros/lpc.sci b/macros/lpc.sci
new file mode 100644
index 0000000..02ab1a5
--- /dev/null
+++ b/macros/lpc.sci
@@ -0,0 +1,173 @@
+function [a,g] = lpc(x,varargin)
+ // Linear prediction filter coefficients
+ //
+ //
+ // Calling Sequence
+ // [a,g] = lpc(x)
+ // [a,g] = lpc(x,p)
+ //
+ //
+ // Description
+ // [a,g] = lpc(x,p)
+ // Determines the coefficients of a pth order forward linear predictor
+ // filter by minimizing the squared error. If p is unspecified, a
+ // default value of length(x)-1 is used.
+ //
+ // Parameters
+ // x: double
+ // The input signal. If x is a matrix, each column in treated as an
+ // independent computation
+ // p: int, natural number, scalar
+ // The order of the linear prediction filter to be inferred. Value must
+ // be a scalar and a positive natural number. p must be less than or
+ // equal to the length of the signal vector
+ // a: double
+ // The coefficients of the forward linear predictor. Coefficient for
+ // each signal input is returned as a row vector.
+ // g: double
+ // Column vector of averaged square prediction error
+ //
+ //
+ // Examples
+ // 1)
+ // noise = randn(20000,1);
+ // x = filter(1,[1 1/5 1/3 1/4],noise);
+ // x = x(15904:20000);
+ // [a,g] = lpc(x,3);
+ //
+ //
+ // References
+ // [1] Hayes, Monson H. Statistical digital signal processing and modeling.
+ // John Wiley & Sons, 2009, pg. 220
+ //
+ // See also
+ // aryule | levinson | prony | pyulear | stmcb
+ //
+ // Authors
+ // Ayush Baid
+ //
+
+ // ** Check on number of arguments **
+ [numOutArgs,numInArgs] = argn(0);
+
+ if numInArgs<1 | numInArgs>2 then
+ msg = "lpc: Wrong number of input argument; 1-2 expected";
+ error(77,msg);
+ end
+ if numOutArgs~=2 then
+ msg = "lpc: Wrong number of output argument; 2 expected";
+ error(78,msg);
+ end
+
+ // ** Parsing input arguments **
+ // 1) check on x
+
+ // check on dimensions
+ if size(x,1)==1 | size(x,2)==1 then
+ // x is a single signal
+ x = x(:); // converting to column vector
+ end
+ if ndims(x)>2 then
+ msg = "lpc: Wrong size for argument #1 (x): a vector or 2D matrix expected"
+ error(60,msg);
+ end
+
+ // check on data type
+ if type(x)==8 then
+ // convert int to double
+ x = double(x);
+ elseif type(x)~=1 then
+ msg = "lpc: Wrong type for argument #1 (x): Real or complex matrix expected";
+ error(53,msg);
+ end
+
+ if length(varargin)==0 then
+ p = size(x,1)-1;
+ else
+ p = varargin(1);
+ // 2) check on p
+ if length(p)~=1 then
+ msg = "lpc: Wrong size for argument #2 (p): Scalar expected";
+ error(60,msg);
+ end
+
+ if type(p)~=1 & type(p)~=8 then
+ msg = "lpc: Wrong type for argument #2 (p): Natural number expected";
+ error(53,msg);
+ end
+
+ if p~=round(p) | p<=0 then
+ msg = "lpc: Wrong type for argument #2 (p): Natural number expected";
+ error(53,msg);
+ end
+
+ if p>size(x,1) then
+ msg = "lpc: Wrong value for argument #2 (p): Must be less than or equal to the length of the signal vector";
+ error(53,msg);
+ end
+
+ if ~isreal(p) then
+ msg = "lpc: Wrong type for argument #2 (p): Real scalar expected";
+ error(53,msg);
+ end
+ end
+
+ num_signals = size(x,2);
+
+ // ** Processing **
+ N = size(x,1);
+
+ // zero pad x
+ x = [x; zeros(2^nextpow2(2*N-1)-N,size(x,2))];
+ X = fft(x,-1,1);
+ R = fft(abs(X).^2,1,1);
+ R = R./N; // Biased autocorrelation estimate
+
+ // change ieee mode to handle division by zero
+ ieee_prev = ieee();
+ ieee(2);
+ [a,g] = ld_recursion(R,p);
+ ieee(int(ieee_prev));
+
+
+ // filter coeffs should be real if input is real
+ for signal_idx=1:num_signals
+ if isreal(x(:,signal_idx)) then
+ a(signal_idx,:) = real(a(signal_idx,:));
+ end
+ end
+
+endfunction
+
+function [a,e] = ld_recursion(R,p)
+ // Solve for LP coefficients using Levinson-Derbin recursion
+ //
+ // Paramaters
+ // R: double
+ // Autocorrelation matrix where column corresponds to autocorrelation
+ // to be treated independently
+ // a: double
+ // Matrix where rows denote filter cofficients of the corresponding
+ // autocorrelation values
+ // e: double
+ // Column vector denoting error variance for each filter computation
+
+
+ num_filters = size(R,2);
+
+
+ // Initial filter (order 0)
+ a = zeros(num_filters,p+1);
+ a(:,1) = 1;
+ e = R(1,:).';
+
+
+ // Solving in a bottom-up fashion (low to high filter coeffs)
+ for m=1:p
+ k_m = -sum(a(:,m:-1:1).*R(2:m+1,:).',2)./e;
+ a(:,2:m+1) = a(:,2:m+1) + k_m(:,ones(1,m)).*conj(a(:,m:-1:1));
+
+ e = (1-abs(k_m).^2).*e;
+ end
+
+endfunction
diff --git a/macros/lsf2poly.bin b/macros/lsf2poly.bin
new file mode 100644
index 0000000..4c20636
Binary files /dev/null and b/macros/lsf2poly.bin differ
diff --git a/macros/lsf2poly.sci b/macros/lsf2poly.sci
new file mode 100644
index 0000000..b3da450
--- /dev/null
+++ b/macros/lsf2poly.sci
@@ -0,0 +1,85 @@
+function a=lsf2poly(lsf)
+//lsf2poly function convert line spectral frequencies to prediction polynomial.
+// Calling Sequence
+// a = lsf2poly(lsf)
+
+// Parameters
+// lsf: define line spectral frequencies.
+// a: Return the prediction polynomial.
+
+// Examples
+//X = [0.5 0.752 1.6 1.8 2.45 0.8]
+// a = lsf2poly(X)
+//
+// See also
+//
+// Author
+// Jitendra Singh
+//
+
+if isempty(lsf) then
+ a=[];
+ else
+
+ if or(type(lsf)==10) then
+ error ('Input arguments must be double.')
+end
+
+
+ if ~isreal(lsf) then
+ error ('Line spectral frequencies must be real.')
+ end
+
+ if max(lsf)>%pi | min(lsf)<0 then
+ error ('Line spectral frequencies must be between 0 and pi.')
+ end
+
+
+ if size(lsf,1)==1 & size(lsf,2) then
+
+ error('Input should be vector of length more than one or matrix.')
+ end
+
+
+ if isvector(lsf) then
+ lsf=lsf(:);
+ end
+ lsf1=lsf;
+ n=size(lsf1);
+ c=n(2);
+ for i=1:c
+ lsf2=lsf1(:,i);
+ lsf2=lsf2(:);
+ nn=length(lsf2);
+ ImgReal=exp(%i*lsf2);
+
+ odd=ImgReal(1:2:$);
+ even=ImgReal(2:2:$);
+
+ odd1=[odd; conj(odd)];
+ even1=[even; conj(even)];
+
+ odd2= poly(odd1, 'x');
+ odd2=real(odd2);
+ odd2=flipdim(coeff(odd2), 2,1);
+ even2= poly(even1,'x');
+ even2=real(even2);
+ even2=flipdim(coeff(even2),2, 1);
+
+
+ if (nn-fix(nn./2).*2)~=0 then
+ even3=conv(even2, [1 0 -1]);
+ odd3=odd2;
+
+ else
+ odd3=conv(odd2, [1 1]);
+ even3=conv(even2, [1 -1]);
+ end
+ aa=0.5*(odd3+even3);
+ aa($)=[];
+ aaa(i,:)=aa;
+ end
+ a=aaa;
+ end
+
+endfunction
diff --git a/macros/mag2db.bin b/macros/mag2db.bin
new file mode 100644
index 0000000..58186d6
Binary files /dev/null and b/macros/mag2db.bin differ
diff --git a/macros/mag2db.sci b/macros/mag2db.sci
new file mode 100644
index 0000000..dc1af27
--- /dev/null
+++ b/macros/mag2db.sci
@@ -0,0 +1,17 @@
+//ydb = mag2db(y) expresses in decibels (dB) the magnitude measurements specified in y.
+//The relationship between magnitude and decibels is ydb = 20 log10(y).
+//Author
+//Debdeep Dey
+
+
+function [ydb] = mag2db(y)
+funcprot(0);
+
+ ydb(find(abs(y)>0))= 20 * log10(y(find(abs(y)>0)));
+ ydb(find(real(y)<0))=%nan;
+ ydb(find(y==0))=-%inf;
+ ydb=matrix(ydb,size(y));
+
+
+endfunction
+
diff --git a/macros/marcumq.bin b/macros/marcumq.bin
new file mode 100644
index 0000000..187ddfa
Binary files /dev/null and b/macros/marcumq.bin differ
diff --git a/macros/marcumq.sci b/macros/marcumq.sci
new file mode 100644
index 0000000..630ec97
--- /dev/null
+++ b/macros/marcumq.sci
@@ -0,0 +1,38 @@
+function q = marcumq (a, b, m, tol)
+//This function computes the generalized Marcum Q function of order m with noncentrality parameter a and argument b.
+//Calling Sequence
+//q = marcumq (a, b)
+//q = marcumq (a, b, m)
+//q = marcumq (a, b, m, tol)
+//Parameters
+//a:
+//b:
+//m: default value 1
+//tol: default value eps
+//Description
+//This is an Octave function.
+//This function computes the generalized Marcum Q function of order m with noncentrality parameter a and argument b.
+//The third argument m is the order, which by default is 1.
+//The fourth argument tol is the tolerance, which by default is eps.
+//If input arguments are vectors which correspond in size and degree, the output is a table of values.
+//This function calculates Marcum’s Q function using the infinite Bessel series, which is truncated when the relative error is less than the specified tolerance.
+//Examples
+//marcumq([1,2,3],4)
+//ans =
+// 0.0028895 0.0341348 0.1965122
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<2 | rhs>4)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 2 then
+ q = callOctave("marcumq",a,b)
+ case 3 then
+ q = callOctave("marcumq",a,b,m)
+ case 4 then
+ q = callOctave("marcumq",a,b,m,tol)
+ end
+endfunction
+
diff --git a/macros/medfilt1.bin b/macros/medfilt1.bin
new file mode 100644
index 0000000..d5cc06f
Binary files /dev/null and b/macros/medfilt1.bin differ
diff --git a/macros/medfilt1.sci b/macros/medfilt1.sci
new file mode 100644
index 0000000..b81a03a
--- /dev/null
+++ b/macros/medfilt1.sci
@@ -0,0 +1,345 @@
+function y = medfilt1(x, varargin)
+ // 1D median filtering
+ //
+ // Calling sequence
+ // y = medfilt1(x)
+ // y = medfilt1(x, n)
+ // y = medfilt1(x, n, dim)
+ // y = medfitl1(__, nanflag, padding)
+ //
+ // Description
+ // y = medfilt1(x)
+ // Applies a 3rd order 1-dimensional median filter to input x along the
+ // first non-zero dimension. The function appropriately pads the signal
+ // with zeros at the endings. For a segment, a median is calculated as
+ // the middle value (average of two middle values) for odd number
+ // number (even number) of data points.
+ // y = medfilt1(x,n)
+ // Applies a nth order 1-dimensional median filter.
+ // y = medfilt1(x,n,dim)
+ // Applies the median filter along the n-th dimension
+ // y = medfilt1(__, nanflag, padding)
+ // nanflag specifies how NaN values are treated. padding specifies the
+ // type of filtering to be performed at the signal edges.
+ //
+ // Parameters
+ // x: int | double
+ // Input signal.
+ // n: positive integer scalar
+ // Filter order.
+ // Defaults to 3.The order of the median filter. Must be less than
+ // (length of the signal) where signals are 1D vectors along the
+ // dimension of x to be filtered
+ // dim: positive integer scalar
+ // Dimension to filter along.
+ // Defaults to first non-singleton dimension of x
+ // nanflag: 'includenan' (default) | 'omitnan'
+ // NaN condition.
+ // * includenan: Filtering such that the median of any segment
+ // containing a NaN is also a NaN.
+ // * omitnan: Filtering with NaNs omitted in each segment. If a segment
+ // contains all NaNs, the result is NaN
+ // y: int | double
+ // The filtered signal.
+ // y has the same size as x
+ //
+ // Examples
+ // 1) Noise supression using median filtering
+ // fs = 1e3;
+ // t = 1:1/fs:1;
+ // s = sin(2*%pi*2*t)+ cos(2*%pi*5*t);
+ // // Adding noise
+ // x = s + 0.1*randn(size(s));
+ // y = medfilt1(x);
+ //
+ // See also
+ // filter | hampel | median | sgolayfilt
+ //
+ // Authors
+ // Ayush Baid
+
+
+
+ // *************************************************************************
+ // Checking number of arguments
+ // *************************************************************************
+ [numOutArgs, numInArgs] = argn(0);
+
+ if numInArgs<1 | numInArgs>5 then
+ msg = "medfilt1: Wrong number of input argument; 1-5 expected";
+ error(77, msg);
+ end
+ if numOutArgs~=1 then
+ msg = "medfilt1: Wrong number of output argument; 1 expected";
+ error(78, msg);
+ end
+
+
+
+ // *************************************************************************
+ // Parsing input arguments
+ // *************************************************************************
+
+ // * Parsing x *
+ temp = x(:);
+ if type(temp)~=1 & type(temp)~=8 then
+ msg = "medfilt1: Wrong type for argument #1 (x): Int/double expected"
+ error(53, msg);
+ end
+
+
+ // * Parsing nanflag and padding *
+ // Getting all the string arguments
+ stringIndices = list();
+ for i=1:length(varargin);
+ e = varargin(i);
+ if type(e)==10 then
+ stringIndices($+1)=i;
+ end
+ end
+
+ nanflag = %f; // 0->includenan (default); 1->omitnan
+ padflag = %t; // 1->zeropad (default); 0->truncate
+ if ~isempty(stringIndices) then
+ // checking for 'omitnan'
+ if or(strcmpi(varargin(stringIndices), 'omitnan')) then
+ nanflag = %t;
+ end
+
+ // checking for 'truncate'
+ if or(strcmpi(varargin(stringIndices), 'truncate')) then
+ padflag = %f;
+ end
+ varargin(stringIndices) = [];
+ end
+
+
+ // setting default value for n and dim
+ n = 3;
+ dim = 1;
+ L = length(size(x));
+ for i=1:L
+ if size(x, i)>1 then
+ dim = i;
+ end
+ end
+
+ // * Parsing n and dim *
+ if length(varargin)==1 then
+ if ~isempty(varargin(1)) then
+ n = varargin(1);
+ end
+ elseif length(varargin)==2 then
+ if ~isempty(varargin(1)) then
+ n = varargin(1);
+ end
+ if ~isempty(varargin(2)) then
+ dim = varargin(2);
+ end
+ else
+ msg = "medfilt1: Wrong type of input arguments; Atmost 3 numerical input expected";
+ error(53, msg);
+ end
+
+ // check on n
+ if length(n)~=1 then
+ msg = "medfilt1: Wrong size for argument #2 (n): Scalar expected";
+ error(60,msg);
+ end
+
+ if type(n)~=1 & type(n)~=8 then
+ msg = "medfilt1: Wrong type for argument #2 (n): Natural number expected";
+ error(53,msg);
+ end
+
+ if n~=round(n) | n<=0 then
+ msg = "medfilt1: Wrong type for argument #2 (n): Natural number expected";
+ error(53,msg);
+ end
+
+ if ~isreal(n) then
+ msg = "medfilt1: Wrong type for argument #2 (n): Real scalar expected";
+ error(53,msg);
+ end
+
+ // check on dim
+ if length(dim)~=1 then
+ msg = "medfilt1: Wrong size for argument #3 (dim): Scalar expected";
+ error(60,msg);
+ end
+
+ if type(dim)~=1 & type(dim)~=8 then
+ msg = "medfilt1: Wrong type for argument #3 (dim): Natural number expected";
+ error(53,msg);
+ end
+
+ if dim~=round(dim) | dim<=0 then
+ msg = "medfilt1: Wrong type for argument #3 (dim): Natural number expected";
+ error(53,msg);
+ end
+
+ if ~isreal(dim) then
+ msg = "medfilt1: Wrong type for argument #3 (dim): Real scalar expected";
+ error(53,msg);
+ end
+
+
+ // *************************************************************************
+ // Processing for median filtering column by column
+ // *************************************************************************
+
+ inp_size = size(x);
+
+
+ // Permuting x to bring the dimension to be acted upon as the first dimesnion
+ perm_vec = [2:dim, 1, dim+1:length(inp_size)];
+ reverse_perm_vec = [dim, 1:dim-1, dim+1:length(inp_size)];
+ x = permute(x, perm_vec);
+
+ size_vec = size(x);
+
+ y = x; // just initialization
+
+ for i=1:prod(size_vec(2:$))
+ temp = medfilt_colvector(x(:,i), n, padflag, nanflag);
+ y(:,i) = temp;
+ end
+
+
+
+ y = permute(y, reverse_perm_vec);
+
+
+endfunction
+
+function med = medfilt_colvector(x, n, zeropadflag, nanflag)
+ // Performs median filtering (of order n) on a column vector (x)
+ // zeropadflag -> zero pad instead of truncation
+ // nanflag -> discard all blocks containing nan, else do not consider nan values
+
+ med = zeros(size(x,1),1);
+ disp('here1');
+
+
+ // ** zero pad the signal **
+ pad_length = floor(n/2); // padding on a size
+ x = [zeros(pad_length,1); x; zeros(pad_length,1)];
+
+ nx = length(x);
+
+ // Arrange data in blocks
+ top_row = 1:(nx-n);
+
+ idx = zeros(n,length(top_row));
+
+ for i=1:n
+ idx(i,:) = top_row + (i-1);
+ end
+
+ blocks = matrix(x(idx), size(idx));
+
+
+ if nanflag then
+ disp('here2');
+ med = median(blocks, 1)';
+
+ // set result of all the blocks containing nan to nan
+ nanpresent = or(isnan(blocks), 1);
+ med(nanpresent) = %nan;
+ else
+ disp('here3');
+ // we have to neglect nans
+ sorted_blocks = gsort(blocks, 'r', 'i');
+
+ // get the count of non-nan elements
+ num_elems = n - sum(isnan(sorted_blocks), 1);
+
+ // find the median
+ offset = (0:size(blocks,2)-1)*size(blocks,1);
+ idx1 = offset+ceil(num_elems/2);
+ idx2 = offset+ceil((num_elems/2)+0.25);
+
+
+ // temporarily setting idx1 to 1 so as to not give errors in median calc.
+ // Will later replace values at such indices with Nan
+ idx1(idx1==0)=1;
+ med = (sorted_blocks(idx1) + sorted_blocks(idx2))./2;
+
+ med(idx1==0) = %nan;
+ end
+
+ if ~zeropadflag then
+ // ** recalculate boundary blocks with truncation truncate at the boundaries **
+
+ // divide the input signal into 3 parts; 1st and last part have truncation
+ for i=ceil(n/2):n
+ // ** first part **
+ block = x(1:i);
+
+ // * median calc for a block *
+ if nanflag then
+ med(i-ceil(n/2)+1) = median(block, 1);
+
+ // set result of all the blocks containing nan to nan
+ nanpresent = or(isnan(block), 1);
+ if nanpresent then
+ med(i-ceil(n/2)+1) = %nan;
+ end
+ else
+ // we have to neglect nans
+ sorted_block = gsort(block, 'r', 'i');
+
+ // get the count of non-nan elements
+ num_elems = length(block) - sum(isnan(sorted_block), 1);
+
+ // find the median
+ idx1 = ceil(num_elems/2);
+ idx2 = ceil(num_elems/2+0.25);
+
+
+ // temporarily setting idx1 to 1 so as to not give errors in median calc.
+ // Will later replace values at such indices with Nan
+ if idx1==0 then
+ med(i-ceil(n/2)+1) = %nan;
+ else
+ med(i-ceil(n/2)+1) = (sorted_block(idx1, :)+sorted_block(idx2, :))./2;
+ end
+ end
+
+
+ // ** last part **
+ block = x($:-1:$-i);
+
+ // * median calc for a block *
+ if nanflag then
+ med($+ceil(n/2)-i) = median(block, 1);
+
+ // set result of all the blocks containing nan to nan
+ nanpresent = or(isnan(block), 1);
+ if nanpresent then
+ med($-ceil(n/2)+i) = %nan;
+ end
+ med($+ceil(n/2)-i) = %nan;
+ else
+ // we have to neglect nans
+ sorted_block = gsort(block, 'r', 'i');
+
+ // get the count of non-nan elements
+ num_elems = length(block) - sum(isnan(sorted_block), 1);
+
+ // find the median
+ idx1 = ceil(num_elems/2);
+ idx2 = ceil(num_elems/2+0.25);
+
+ // temporarily setting idx1 to 1 so as to not give errors in median calc.
+ // Will later replace values at such indices with Nan
+ if idx1==0 then
+ med($+ceil(n/2)-i) = %nan;
+ else
+ med($+ceil(n/2)-i) = (sorted_block(idx1) + sorted_block(idx2))./2;
+ end
+ end
+ end
+ end
+
+endfunction
diff --git a/macros/medfilt1.sci~ b/macros/medfilt1.sci~
new file mode 100644
index 0000000..0a41f12
--- /dev/null
+++ b/macros/medfilt1.sci~
@@ -0,0 +1,346 @@
+function y = medfilt1(x, varargin)
+ // 1D median filtering
+ //
+ // Calling sequence
+ // y = medfilt1(x)
+ // y = medfilt1(x, n)
+ // y = medfilt1(x, n, dim)
+ // y = medfitl1(__, nanflag, padding)
+ //
+ // Description
+ // y = medfilt1(x)
+ // Applies a 3rd order 1-dimensional median filter to input x along the
+ // first non-zero dimension. The function appropriately pads the signal
+ // with zeros at the endings. For a segment, a median is calculated as
+ // the middle value (average of two middle values) for odd number
+ // number (even number) of data points.
+ // y = medfilt1(x,n)
+ // Applies a nth order 1-dimensional median filter.
+ // y = medfilt1(x,n,dim)
+ // Applies the median filter along the n-th dimension
+ // y = medfilt1(__, nanflag, padding)
+ // nanflag specifies how NaN values are treated. padding specifies the
+ // type of filtering to be performed at the signal edges.
+ //
+ // Parameters
+ // x: int | double
+ // Input signal.
+ // n: positive integer scalar
+ // Filter order.
+ // Defaults to 3.The order of the median filter. Must be less than
+ // (length of the signal) where signals are 1D vectors along the
+ // dimension of x to be filtered
+ // dim: positive integer scalar
+ // Dimension to filter along.
+ // Defaults to first non-singleton dimension of x
+ // nanflag: 'includenan' (default) | 'omitnan'
+ // NaN condition.
+ // * includenan: Filtering such that the median of any segment
+ // containing a NaN is also a NaN.
+ // * omitnan: Filtering with NaNs omitted in each segment. If a segment
+ // contains all NaNs, the result is NaN
+ // y: int | double
+ // The filtered signal.
+ // y has the same size as x
+ //
+ // Examples
+ // 1) Noise supression using median filtering
+ // fs = 1e3;
+ // t = 1:1/fs:1;
+ // s = sin(2*%pi*2*t)+ cos(2*%pi*5*t);
+ // // Adding noise
+ // x = s + 0.1*randn(size(s));
+ // y = medfilt1(x);
+ //
+ // See also
+ // filter | hampel | median | sgolayfilt
+ //
+ // Authors
+ // Ayush Baid
+
+
+
+ // *************************************************************************
+ // Checking number of arguments
+ // *************************************************************************
+ [numOutArgs, numInArgs] = argn(0);
+
+ if numInArgs<1 | numInArgs>5 then
+ msg = "medfilt1: Wrong number of input argument; 1-5 expected";
+ error(77, msg);
+ end
+ if numOutArgs~=1 then
+ msg = "medfilt1: Wrong number of output argument; 1 expected";
+ error(78, msg);
+ end
+
+
+
+ // *************************************************************************
+ // Parsing input arguments
+ // *************************************************************************
+
+ // * Parsing x *
+ temp = x(:);
+ if type(temp)~=1 & type(temp)~=8 then
+ msg = "medfilt1: Wrong type for argument #1 (x): Int/double expected"
+ error(53, msg);
+ end
+
+
+ // * Parsing nanflag and padding *
+ // Getting all the string arguments
+ stringIndices = list();
+ for i=1:length(varargin);
+ e = varargin(i);
+ if type(e)==10 then
+ stringIndices($+1)=i;
+ end
+ end
+
+ nanflag = %f; // 0->includenan (default); 1->omitnan
+ padflag = %t; // 1->zeropad (default); 0->truncate
+ if ~isempty(stringIndices) then
+ // checking for 'omitnan'
+ if or(strcmpi(varargin(stringIndices), 'omitnan')) then
+ nanflag = %t;
+ end
+
+ // checking for 'truncate'
+ if or(strcmpi(varargin(stringIndices), 'truncate')) then
+ padflag = %f;
+ end
+ varargin(stringIndices) = [];
+ end
+
+
+ // setting default value for n and dim
+ n = 3;
+ dim = 1;
+ L = length(size(x));
+ for i=1:L
+ if size(x, i)>1 then
+ dim = i;
+ end
+ end
+
+ // * Parsing n and dim *
+ if length(varargin)==1 then
+ if ~isempty(varargin(1)) then
+ n = varargin(1);
+ end
+ elseif length(varargin)==2 then
+ if ~isempty(varargin(1)) then
+ n = varargin(1);
+ end
+ if ~isempty(varargin(2)) then
+ dim = varargin(2);
+ end
+ else
+ msg = "medfilt1: Wrong type of input arguments; Atmost 3 numerical input expected";
+ error(53, msg);
+ end
+
+ // check on n
+ if length(n)~=1 then
+ msg = "medfilt1: Wrong size for argument #2 (n): Scalar expected";
+ error(60,msg);
+ end
+
+ if type(n)~=1 & type(n)~=8 then
+ msg = "medfilt1: Wrong type for argument #2 (n): Natural number expected";
+ error(53,msg);
+ end
+
+ if n~=round(n) | n<=0 then
+ msg = "medfilt1: Wrong type for argument #2 (n): Natural number expected";
+ error(53,msg);
+ end
+
+ if ~isreal(n) then
+ msg = "medfilt1: Wrong type for argument #2 (n): Real scalar expected";
+ error(53,msg);
+ end
+
+ // check on dim
+ if length(dim)~=1 then
+ msg = "medfilt1: Wrong size for argument #3 (dim): Scalar expected";
+ error(60,msg);
+ end
+
+ if type(dim)~=1 & type(dim)~=8 then
+ msg = "medfilt1: Wrong type for argument #3 (dim): Natural number expected";
+ error(53,msg);
+ end
+
+ if dim~=round(dim) | dim<=0 then
+ msg = "medfilt1: Wrong type for argument #3 (dim): Natural number expected";
+ error(53,msg);
+ end
+
+ if ~isreal(dim) then
+ msg = "medfilt1: Wrong type for argument #3 (dim): Real scalar expected";
+ error(53,msg);
+ end
+
+
+ // *************************************************************************
+ // Processing for median filtering column by column
+ // *************************************************************************
+
+ inp_size = size(x);
+
+
+ // Permuting x to bring the dimension to be acted upon as the first dimesnion
+ perm_vec = [2:dim, 1, dim+1:length(inp_size)];
+ reverse_perm_vec = [dim, 1:dim-1, dim+1:length(inp_size)];
+ x = permute(x, perm_vec);
+
+ size_vec = size(x);
+
+ y = x; // just initialization
+
+ for i=1:prod(size_vec(2:$))
+ temp = medfilt_colvector(x(:,i), n, padflag, nanflag);
+ y(:,i) = temp;
+ end
+
+
+
+ y = permute(y, reverse_perm_vec);
+
+
+endfunction
+
+function med = medfilt_colvector(x, n, zeropadflag, nanflag)
+ // Performs median filtering (of order n) on a column vector (x)
+ // zeropadflag -> zero pad instead of truncation
+ // nanflag -> discard all blocks containing nan, else do not consider nan values
+
+ med = zeros(size(x,1),1);
+ disp('here1');
+
+
+ // ** zero pad the signal **
+ pad_length = floor(n/2); // padding on a size
+ x = [zeros(pad_length,1); x; zeros(pad_length,1)];
+
+ nx = length(x);
+
+ // Arrange data in blocks
+ top_row = 1:(nx-n);
+
+ idx = zeros(n,length(top_row));
+
+ for i=1:n
+ idx(i,:) = top_row + (i-1);
+ end
+
+ blocks = matrix(x(idx), size(idx));
+
+
+ if nanflag then
+ disp('here2');
+ med = median(blocks, 1)';
+
+ // set result of all the blocks containing nan to nan
+ nanpresent = or(isnan(blocks), 1);
+ med(nanpresent) = %nan;
+ else
+ disp('here3');
+ // we have to neglect nans
+ sorted_blocks = gsort(blocks, 'r', 'i');
+
+ // get the count of non-nan elements
+ num_elems = n - sum(isnan(sorted_blocks), 1);
+
+ // find the median
+ offset = (0:size(blocks,2)-1)*size(blocks,1);
+ idx1 = offset+ceil(num_elems/2);
+ idx2 = offset+ceil((num_elems/2)+0.25);
+
+
+ // temporarily setting idx1 to 1 so as to not give errors in median calc.
+ // Will later replace values at such indices with Nan
+ idx1(idx1==0)=1;
+ med = (sorted_blocks(idx1) + sorted_blocks(idx2))./2;
+
+ med(idx1==0) = %nan;
+ end
+
+ if ~zeropadflag then
+ // ** recalculate boundary blocks with truncation truncate at the boundaries **
+
+ // divide the input signal into 3 parts; 1st and last part have truncation
+ for i=ceil(n/2):n
+ // ** first part **
+ block = x(1:i);
+
+ // * median calc for a block *
+ if nanflag then
+ med(i-ceil(n/2)+1) = median(block, 1);
+
+ // set result of all the blocks containing nan to nan
+ nanpresent = or(isnan(block), 1);
+ if nanpresent then
+ med(i-ceil(n/2)+1) = %nan;
+ end
+ else
+ // we have to neglect nans
+ sorted_block = gsort(block, 'r', 'i');
+
+ // get the count of non-nan elements
+ num_elems = length(block) - sum(isnan(sorted_block), 1);
+
+ // find the median
+ idx1 = ceil(num_elems/2);
+ idx2 = ceil(num_elems/2+0.25);
+
+
+ // temporarily setting idx1 to 1 so as to not give errors in median calc.
+ // Will later replace values at such indices with Nan
+ if idx1==0 then
+ med(i-ceil(n/2)+1) = %nan;
+ else
+ med(i-ceil(n/2)+1) = (sorted_block(idx1, :)+sorted_block(idx2, :))./2;
+ end
+ end
+
+
+ // ** last part **
+ block = x($:-1:$-i);
+
+ // * median calc for a block *
+ if nanflag then
+ med($+ceil(n/2)-i) = median(block, 1);
+
+ // set result of all the blocks containing nan to nan
+ nanpresent = or(isnan(block), 1);
+ if nanpresent then
+ med($-ceil(n/2)+i) = %nan;
+ end
+ med($+ceil(n/2)-i) = %nan;
+ end
+ else
+ // we have to neglect nans
+ sorted_block = gsort(block, 'r', 'i');
+
+ // get the count of non-nan elements
+ num_elems = length(block) - sum(isnan(sorted_block), 1);
+
+ // find the median
+ idx1 = ceil(num_elems/2);
+ idx2 = ceil(num_elems/2+0.25);
+
+ // temporarily setting idx1 to 1 so as to not give errors in median calc.
+ // Will later replace values at such indices with Nan
+ if idx1==0 then
+ med($+ceil(n/2)-i) = %nan;
+ else
+ med($+ceil(n/2)-i) = (sorted_block(idx1) + sorted_block(idx2))./2;
+ end
+ end
+ end
+ end
+
+endfunction
diff --git a/macros/mexihat.bin b/macros/mexihat.bin
new file mode 100644
index 0000000..9e4879d
Binary files /dev/null and b/macros/mexihat.bin differ
diff --git a/macros/mexihat.sci b/macros/mexihat.sci
new file mode 100644
index 0000000..3f2ed48
--- /dev/null
+++ b/macros/mexihat.sci
@@ -0,0 +1,27 @@
+function [psi,x]=mexihat(lb,ub,n)
+
+// Generates Mexican Hat wavelet
+// Calling Sequence
+// [psi,x]=mexihat(lb,ub,n)
+// Parameters
+// lb: Real or complex valued vector or matrix
+// ub: Real or complex valued vector or matrix
+// n: Real strictly positive scalar number
+// Description
+// This is an Octave function
+// 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)
+// 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]
+
+funcprot(0);
+rhs=argn(2);
+if (rhs<3) then
+ error ("Wrong number of input arguments.")
+else [psi,x]=callOctave("mexihat",lb,ub,n)
+end
+endfunction
diff --git a/macros/meyeraux.bin b/macros/meyeraux.bin
new file mode 100644
index 0000000..5d3239f
Binary files /dev/null and b/macros/meyeraux.bin differ
diff --git a/macros/meyeraux.sci b/macros/meyeraux.sci
new file mode 100644
index 0000000..657e829
--- /dev/null
+++ b/macros/meyeraux.sci
@@ -0,0 +1,23 @@
+function [y]=meyeraux(x)
+
+// Returns value of Meyer Wavelet Auxiliary function
+// Calling Sequence
+// [y]=meyeraux(x)
+// Parameters
+// x: Real or complex valued vector or matrix
+// Description
+// This is an Octave function.
+// This function returns values of the auxiliary function used for Meyer wavelet generation.
+// Examples
+// 1. meyeraux([1 2 3])
+// ans= [1 -208 -10287]
+// 2. meyeraux([1 2 3;4 5 6])
+// ans= [1 -208 -10287 ; -118016 -709375 -2940624 ]
+
+funcprot(0);
+rhs=argn(2);
+if (rhs~=1) then
+ error ("Wrong number of input arguments.")
+else y=callOctave("meyeraux",x)
+end
+endfunction
diff --git a/macros/midcross.bin b/macros/midcross.bin
new file mode 100644
index 0000000..a5e182d
Binary files /dev/null and b/macros/midcross.bin differ
diff --git a/macros/midcross.sci b/macros/midcross.sci
new file mode 100755
index 0000000..445e5f4
--- /dev/null
+++ b/macros/midcross.sci
@@ -0,0 +1,428 @@
+function [midcrossvalue, midreference, levels, t, tolerance, Tinput]= midcross(x, varargin)
+
+
+ // This function estimate midcross values of real vector X.
+ // Calling Sequence
+ // midcrossvalue=midcross(x)
+ // midcrossvalue=midcross(x, Fs)
+ // midcrossvalue=midcross(x, t)
+ // midcrossvalue=midcross(x, t, 'MidPercentReferenceLevels', N )
+ // midcrossvalue=midcross(x, t, 'Tolerance', M)
+ // midcrossvalue=midcross(x, t,'StateLevels', O)
+ // [midcrossvalue midreference]=midcross(x)
+ // [midcrossvalue midreference]=midcross(x, Fs)
+ // [midcrossvalue midreference]=midcross(x, t)
+ // [midcrossvalue midreference]= midcross(x, t, 'MidPercentReferenceLevel', N )
+ // [midcrossvalue midreference]= midcross(x, t, 'Tolerance', M)
+ // [midcrossvalue midreference]= midcross(x, t,'StateLevels', O)
+ // [midcrossvalue midreference]= midcross(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.
+ // t: defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar
+ // MidPercentReferenceLevels: specify the midpercentreferenceleves as a percentage, default value of N is 50.
+ // Tolerance: define the tolerance value as real scaler value, where default value of M is 2.0.
+ // StateLevels: define the lower and upper state levels as two element real vector.
+ // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.
+ // midcrossvalues: return the midcross values
+ // midreference: return the midrefence values.
+ // levels: return statelevels values.
+ // t: return the instant sample time.
+ // tolerance: retunr the tolerance value
+ // Tinput: return t value, which given as input parameter.
+
+ // Examples
+ // x=[1.2, 5, 10, -20, 12]
+ //t=1:length(x)
+ // midcrossvalue=midcross(x, t)
+ // See also
+ // Authors
+ // Jitendra Singh
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+end
+
+ if length(x) < 2 then // checking the length of input datasat
+ error('X must be a vector with more than one element.'); // if length of X is less 2, it will give error
+end
+
+ if length(varargin) >9 then // checking the length of input datasat
+ error('Unexpected input/To many input'); // if length of X is less 2, it will give error
+end
+
+if length(varargin)==0 then
+ t=1:length(x);
+ Tinput=1:length(x);
+ [levels hist]=statelevels(x); // run statelevels function before running this function
+ midpercentval=50;
+ 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))/varargin(1);
+ Tinput=varargin(1);
+ elseif length(varargin(1))==length(x) then
+ t=varargin(1);
+ Tinput=varargin(1);
+ else
+ error('T must be a same length as X.')
+ end
+else
+ t=1:length(x);
+end
+
+
+
+
+if length(varargin)>=2 & type(varargin(1))==1 & type(varargin(2))==1 then
+ error ("Too many leading numeric arguments (at most 2 expected).");
+end
+
+
+index=[];
+if length(varargin)>=1 then
+a=1;
+
+for i=1:length(varargin)
+ if type(varargin(i))==10 then
+ index(a)=i;
+ a=a+1;
+ end
+end
+end
+
+
+if length(index)>5 then
+ error('Unexpected argument.')
+end
+
+
+Nindex=[];
+if length(varargin)>=1 then
+b=1;
+
+for i=1:length(varargin)
+ if type(varargin(i))==1 then
+ Nindex(b)=i;
+ b=b+1;
+ end
+end
+end
+
+
+ d=[];
+if length(Nindex)>=2 then
+ c=1;
+
+ for k=1:(length(Nindex)-1)
+ d(c)=Nindex(k+1)-Nindex(k);
+ c=c+1;
+ end
+end
+
+
+if length(d)>=1 then
+
+f_one=find(d==1);
+
+if length(f_one)>0 then
+ error('Unexpected input.')
+end
+end
+
+
+
+[levels hist]=statelevels(x);
+ midpercentval=50;
+ tolerance=2;
+ fig='OFF';
+
+
+if (~isempty(index)) then
+ for j=1:length(index)
+
+ select convstr(varargin(index(j)),'u')
+
+ case {'STATELEVELS'}
+ //////
+ if length(varargin) <=index(j) then
+ error(strcat(['parameter StateLevels required a value']));
+ end
+
+ if type(varargin(index(j)+1))==1 then
+ levels=varargin(index(j)+1);
+
+ elseif type(varargin(index(j)+1))==10 & convstr(varargin(index(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(index(j)+1),'u')== 'TOLERANCE' | convstr(varargin(index(j)+1), 'u')=='FIG' then
+
+ error('parameter StateLevels required a value.')
+
+
+ elseif type(varargin(index(j)+1))==10 then
+
+ error('Expected STATELEVELS to be one of these types: double, Instead its type was char.')
+ end
+
+ if length(levels)~=2 then
+ error ('Expected STATELEVELS to be of size 1x2')
+ end
+
+ if levels(2)<=levels(1) then
+ error('The state levels must be in increasing order.')
+ end
+ ///////
+
+ case {'MIDPERCENTREFERENCELEVEL'}
+
+
+ if length(varargin) <=index(j) then
+ error(strcat(['parameter MidPercentRefernceLevel required a value.']));
+ end
+
+ if type(varargin(index(j)+1))==1 then
+ midpercentval= varargin(index(j)+1);
+ elseif type(varargin(index(j)+1))==10 & convstr(varargin(index(j)+1), 'u')=='STATELEVELS' | convstr(varargin(index(j)+1),'u')== 'TOLERANCE' | convstr(varargin(index(j)+1), 'u')=='FIG' then
+ error('parameter MidPercentRefernceLevel required a value.')
+
+ elseif type(varargin(index(j)+1))==10 then
+ error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.')
+ end
+
+ if length( midpercentval)~=1 then
+ error ('Expected MidPercentRefernceLevel to be of size 1x1')
+ end
+
+
+ case {'FIG'}
+
+ if length(varargin) <=index(j) then
+ error(strcat(['parameter fig required a value.']));
+ end
+
+ if type(varargin(index(j)+1))==1 then
+ error ('Expected fig to match one of these strings: on or off');
+
+ elseif type(varargin(index(j)+1))==10 & convstr(varargin(index(j)+1), 'u')=='STATELEVELS' | convstr(varargin(index(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(index(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' then
+ error('parameter fig required a value.')
+ else
+ fig= convstr(varargin(index(j)+1), 'u');
+
+ end
+
+
+ if fig == 'OFF' | fig == 'ON' then
+ else
+ error('Expected fig to match one of these strings: on or off');
+ end
+
+
+
+ case{'ON'}
+
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(index(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(index(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+ case{'OFF'}
+
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(index(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(index(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+
+ //////
+ case {'TOLERANCE'}
+
+ if length(varargin) <=index(j) then
+ error(strcat(['parameter Tolerance required a value"]));
+
+ elseif type(varargin(index(j)+1))==1 then
+ tolerance= varargin(index(j)+1);
+
+ elseif type(varargin(index(j)+1))==10 & convstr(varargin(index(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(index(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(index(j)+1), 'u')=='FIG' then
+
+ error('parameter Tolerance required a value.');
+
+ elseif type(varargin(index(j)+1))==10 then
+
+ error('Expected Tolerance to be one of these types: double, Instead its type was char.');
+ end
+
+ if length(tolerance)~=1 then
+ error ('Expected Tolerance to be of size 1x1');
+
+ end
+
+ else
+ error(strcat(['Invalid optional argument'," ", varargin(index(j))]));
+ end // switch
+ end // for
+ end // if
+
+
+
+
+tolerance=tolerance;
+
+if tolerance>=50 then
+ error('Expected Toleracne to be an array with all of the values < 50.')
+end
+
+if tolerance>= midpercentval then
+ error ('The percent state level tolerance must be less than the mid/lower percent reference level.')
+end
+
+
+if tolerance+midpercentval>=100 then
+ error('The sum of the percent state level Tolerance and the mid/upper percent reference level must be less than 100.')
+end
+
+
+
+
+ midref=levels(1)+ (midpercentval/100)*(levels(2)-levels(1));
+ 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));
+
+
+ istate = find(xupperbound);
+ n=length(istate);
+ istatepre = istate(1:(n-1));
+ istatepost = istate(2:n);
+
+
+ itrans = find(x(istatepre) < lowerbound & upperbound < x(istatepost) | ...
+ x(istatepre) > upperbound & lowerbound > x(istatepost) );
+
+ ipre = istatepre(itrans);
+ ipost = istatepost(itrans);
+
+ polarity = 2 * (x(ipre) < lowerbound) - 1;
+
+
+ numtrans = length(itrans);
+ iRMid = zeros(numtrans, 1);
+
+
+ for i = 1:numtrans // define convenience indices for compactness
+ ia = ipre(i);
+ ib = ipost(i);
+
+ if polarity(i) > 0
+ // checking for first positive crossing of midrefence
+ iX = find((x(ia:ib-1) <= midref & midref < x(ia+1:ib)));
+
+
+
+ iRMid(i) = iX(1) + ia - 1;
+ else
+ // checking for negative crossing for midrefenrce
+
+ iX = find(x(ia:ib-1)>= midref & midref > x(ia+1:ib));
+ iRMid(i) = iX(1) + ia - 1;
+ end
+ end
+x=x(:);
+x=x';
+t=t(:);
+t=t';
+
+ if numtrans > 0
+ // interpolation to get instant values
+ midcrossvalue=t(iRMid)+(t(iRMid+1)-t(iRMid)).*(midref-x(iRMid))./( x(iRMid+1)-x(iRMid));
+
+ else
+ midcrossvalue = [];
+ end
+
+
+
+ midreference=midref;
+
+
+ if fig=='ON' then // if the defined output is only 1, the it will return the graphical representation of //levels
+
+
+
+ //////
+
+ if length(midcrossvalue)==0 then
+ plot(t,x, 'LineWidth',1, 'color', 'black' )
+
+plot(t,midref * ones(1, length(t)),'-r', 'LineWidth',0.5)
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,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)
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?')
+
+ else
+
+
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+
+ plot(t,midref * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(midcrossvalue, midreference*ones(midcrossvalue), "r*", 'MarkerSize',15);
+
+
+
+
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,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)
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [-10;5], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?')
+ //////////////
+
+
+end
+
+ end
+endfunction
diff --git a/macros/modulate.bin b/macros/modulate.bin
new file mode 100644
index 0000000..169b209
Binary files /dev/null and b/macros/modulate.bin differ
diff --git a/macros/modulate.sci b/macros/modulate.sci
new file mode 100644
index 0000000..bbce31a
--- /dev/null
+++ b/macros/modulate.sci
@@ -0,0 +1,184 @@
+function [y,t]=modulate(x,fc,fs,method,opt)
+//Modulates signal according to the modulation method
+//Calling Sequence
+//y=modulate(x,fc,fs,method,opt)
+//[y,t]=modulate(x,fc,fs,method,opt)
+//Parameters
+//x
+//A vector or a matrix
+//fc
+//Carrier frequency
+//fs
+//Sampling frequency
+//method
+//Modulation Method
+//opt
+//An optional parameter required by certain modulation methods
+//Description
+//[y,t]=modulate(x,fc,fs,method,opt)
+//Returns the modulated vector y and the time vector 't'
+//Modulation is performed according to the following table
+// METHOD MODULATION SCHEME
+// 'am', Amplitude modulation, double side-band, suppressed carrier
+// 'amdsb-sc' opt not used. This is the default method.
+// 'amdsb-tc' Amplitude modulation, double side-band, transmitted carrier
+// opt is a scalar subtracted from x before multiplying x
+// with the carrier wave. It defaults to min(min(x)) so that
+// the input signal after offset is always non-negative
+// 'amssb' Amplitude modulation, single side-band
+// OPT not used.
+// 'fm' Frequency modulation
+// opt is the constant of frequency modulation.
+// opt = (fc/fs)*2*pi/max(max(abs(x))) by default
+// 'pm' Phase modulation
+// OPT is the constant of phase modulation.
+// opt = pi/max(max(abs(x))) by default
+// Phase lies between -pi and +pi
+// 'pwm' Pulse width modulation
+// opt='left' corresponds to left justified pulses.
+// opt='centered' correspondes to centered pulses.
+// The default value of opt is 'left'.
+// 'ppm' Pulse position modulation
+// opt is a scalar between 0 and 1 which specifies the pulse
+// width in fractions of the carrier period with default value 0.1.
+// 'qam' Quadrature amplitude modulation
+// opt is a matrix of the same size as X which is modulated in
+// quadrature with x.
+//
+// If x is a matrix, its columns are modulated.
+//Example
+//y =
+//
+// 1. 1. 0. 0.
+//Author
+//Ankur Mallick
+ funcprot(0);
+ if (argn(2)<3|argn(2)>5) then
+ error('Incorrect number of input arguments.');
+ elseif (isreal(fc)&isreal(fs)&fc>fs/2)
+ error('The career frequency must be less than half the sampling frequency.')
+ else
+ flag1=0;
+ flag2=0;
+ if (argn(2)<4)
+ method='am';
+ end
+ [M,N]=size(x);
+ if(M==1)
+ flag1=1;
+ x=x(:);
+ [M,N]=size(x);
+ end
+ t=((0:M-1)/fs)';
+ t=t*ones(1,N);
+ if(method=='am'|method=='amdsb-sc')
+ y=x.*cos(2*%pi*fc*t);
+ elseif(method=='amdsb-tc')
+ if(argn(2)<5)
+ opt=min(min(x));
+ end
+ y=(x-opt).*cos(2*%pi*fc*t);
+ elseif(method=='amssb')
+ y=x.*cos(2*%pi*fc*t)+imag(hilbert(x)).*sin(2*%pi*fc*t);
+ elseif(method=='fm')
+ if(argn(2)<5)
+ opt=max(abs(x(:))); //if all elements of x are zero
+ if(opt>0)
+ opt=(fc/fs)*2*%pi/opt;
+ end
+ end
+ y=cos(2*%pi*fc*t + opt*cumsum(x,1));
+ elseif(method=='pm')
+ if(argn(2)<5)
+ opt=%pi/(max(abs(x(:))));
+ end
+ y=cos(2*%pi*fc*t + opt*x);
+ elseif(method=='qam')
+ if(argn(2)<5)
+ error('For qam, a 5th input parameter is required.')
+ else
+ if(size(opt,1)==1)
+ opt=opt(:);
+ end
+ S=sum(abs(size(opt)-size(x))); //S=0 only if opt and x have the same size
+ if(S==0)
+ y = x.*cos(2*%pi*fc*t) + opt.*sin(2*%pi*fc*t)
+ else
+ error('For qam input signals must be the same size')
+ end
+ end
+ elseif(method=='pwm')
+ if(argn(2)<5)
+ opt='left'
+ end
+ if(max(x(:))>1|min(x(:))<0)
+ error('x must lie between 0 and 1');
+ else
+ t=(0:(M*fs/fc-1))';
+ t=t*ones(1,N);
+ T=fs/fc;
+ y=zeros(t);
+ if(opt~='left'&opt~='centered')
+ error('5th input parameter not recognized');
+ else
+ if(opt=='left')
+ compar=(pmodulo(t,T))/T;
+ pos=floor(t/T)+1;
+ elseif(opt=='centered')
+ compar1=2*pmodulo(t,T)/T;
+ compar=min(compar1,2-compar1);
+ x(M+1,:)=zeros(1,N);
+ pos=floor(t/T)+1;
+ r1=ceil(T/2);
+ r2=floor(T/2);
+ pos=[pos(r1+1:length(pos));(M+1)*ones(r2,1)];
+ end
+ for i=1:N
+ //x1=matrix(ones(T,1)*x(:,i)',size(t,1),1);
+ x1=x(pos,i)
+ y(compar1|min(x(:))<0)
+ error('x must lie between 0 and 1');
+ elseif(~isscalar(opt)|opt<0|opt>1)
+ error('opt must be a scalar between 0 and 1')
+ else
+ if (max(x) > 1-opt)
+ warning('Overlapping pulses')
+ end
+ for i=1:N
+ x1=x(:,i)'
+ start=1+ceil((x1+(0:M-1))*T); //y(1) corresponds to t=0
+ L=floor(opt*T);
+ v=(0:1:L-1)';
+ p1=matrix(ones(L,1)*start,1,M*L)
+ p2=matrix(v*ones(1,M),1,M*L);
+ pos=p1+p2;
+ y(pos,i)=1;
+ end
+ y(length(t)+1:length(y),:)=[]; //Truncating vector
+ end
+ else
+ error('Method not recognised');
+ flag2=1;
+ end
+ if(flag2==0)
+ t=t(:,1); //only first column required
+ if(flag1==1)
+ //x is a row vector
+ y=conj(y');
+ t=t';
+ end
+ end
+ end
+endfunction
diff --git a/macros/morlet.bin b/macros/morlet.bin
new file mode 100644
index 0000000..f00e186
Binary files /dev/null and b/macros/morlet.bin differ
diff --git a/macros/morlet.sci b/macros/morlet.sci
new file mode 100644
index 0000000..0a160f0
--- /dev/null
+++ b/macros/morlet.sci
@@ -0,0 +1,27 @@
+function [psi,x] = morlet (lb,ub,n)
+
+// Generates Morlet wavelets
+// Calling Sequence
+// [psi,x]= morlet(lb,ub,n)
+// Parameters
+// lb: Real or complex valued vector or matrix
+// ub: Real or complex valued vector or matrix
+// n: Real strictly positive scalar number
+// Description
+// This is an Octave function
+// This function returns values of the Morlet wavelet in the specified interval for all the sample points.
+// Examples
+// 1. [a,b]=morlet(1,2,3)
+// a = [0.17205 0.11254 -0.11356]
+// b = [1.0000 1.5000 2.0000]
+// 2. [a,b]=morlet([1 2 3],[1 2 3],1)
+// a = [0.1720498; -0.1135560; -0.0084394]
+// b = [1; 2; 3]
+
+funcprot(0);
+rhs=argn(2);
+if (rhs<3) then
+ error ("Wrong number of input arguments.")
+else [psi,x] = callOctave("morlet",lb,ub,n)
+end
+endfunction
diff --git a/macros/movingrms.bin b/macros/movingrms.bin
new file mode 100644
index 0000000..720357d
Binary files /dev/null and b/macros/movingrms.bin differ
diff --git a/macros/movingrms.sci b/macros/movingrms.sci
new file mode 100644
index 0000000..231a9f1
--- /dev/null
+++ b/macros/movingrms.sci
@@ -0,0 +1,33 @@
+function [rmsx,w]=movingrms(x,w,rc,Fs)
+
+// Find moving RMS value of signal in x
+// Calling Sequence
+// [rmsx,w]=movingrms(x,w,rc,Fs=1)
+// Parameters
+// x: Real or complex valued vector or matrix
+// w: Real or complex scalar value
+// rc: Real or complex scalar value
+// Fs: Real or complex scalar value
+// Description
+// This is an Octave function.
+// The signal is convoluted against a sigmoid window of width w and risetime rc with the units of these parameters relative to the value of the sampling frequency given in Fs (Default value=1).
+// Examples
+// 1. [a,b]=movingrms ([4.4 94 1;-2 5i 5],1,-2)
+// a = 0.91237 17.71929 0.96254
+// 0.91237 17.71929 0.96254
+// b = 0.18877
+// 0.18877
+// 2. [a,b]=movingrms ([4.4 94 1;-2 5i 5],1,-2,2)
+// a = 4.8332 93.8669 5.0990
+// 4.8332 93.8669 5.0990
+// b = 1
+// 1
+
+funcprot(0);
+rhs=argn(2);
+if (rhs<3) then
+ error("Wrong number of input arguments.")
+elseif (rhs==3) then Fs=1;
+end
+[rmsx,w]=callOctave("movingrms",x,w,rc,Fs)
+endfunction
diff --git a/macros/musicBase.bin b/macros/musicBase.bin
new file mode 100644
index 0000000..884ae30
Binary files /dev/null and b/macros/musicBase.bin differ
diff --git a/macros/musicBase.sci b/macros/musicBase.sci
new file mode 100644
index 0000000..f915bbe
--- /dev/null
+++ b/macros/musicBase.sci
@@ -0,0 +1,198 @@
+// Date of creation: 19 Dec, 2015
+function [outputData,msg] = musicBase(inputData)
+ // Implements the core of the MUSIC algorithm
+ // Used by pmusic and rootmusic algorithm
+
+ // TODO: complete docs
+
+ msg = "";
+ outputData = struct();
+
+ [eigenvects,eigenvals, msg] = computeEig(inputData.x, ...
+ inputData.isCorrFlag, inputData.windowLength, ...
+ inputData.noverlap, inputData.windowVector, ...
+ inputData.isWindowSpecified);
+
+
+ // disp("eigenvects in musicBase");
+ // disp(eigenvects);
+ // disp("eigenvals in musicBase");
+ // disp(eigenvals);
+
+ if length(msg)~=0 then
+ return
+ end
+
+ pEffective = determineSignalSpace(inputData.p, eigenvals);
+
+ if length(msg)~=0 then
+ return
+ end
+
+ // Separating the eigenvects into signal and noise subspace
+ signalEigenvects = eigenvects(:,1:pEffective);
+ noiseEigenvects = eigenvects(:,pEffective+1:$);
+
+ outputData.signalEigenvects = signalEigenvects;
+ outputData.noiseEigenvects = noiseEigenvects;
+ outputData.eigenvals = eigenvals;
+ outputData.pEffective = pEffective;
+endfunction
+
+
+function [eigenvects,eigenvals,msg] = computeEig(x,isCorrFlag, windowLength, noverlap, window,isWindowSpecified)
+ // Computes the eigenvalues for the correlation matrix
+ // If x is a correlation matrix, which is specified using the isCorrFlag,
+ // spec() is used for eigenvalue decomposition.
+ // Otherwise, SVD is used for a proper restructure of x
+ // (i.e windowed version)
+
+ eigenvects = 0;
+ eigenvals = 0;
+ msg = "";
+
+ // determine if input is a matrix
+ xIsMatrix = ~or(size(x)==1);
+
+ if xIsMatrix & isCorrFlag then
+ // TODO: check the order of eigenvalues
+ [eigenvects,d] = spec((R+R')/2); // ensuring hermitian property
+ eigenvals = diag(d);
+ // sorting in decreasing order
+ [eigenvals,order] = gsort(eigenvals);
+ // TODO: nonnegative eigenvals check
+
+ // rearragning in decreasing order of eigenvalues
+ eigenvects = eigenvects(:,order);
+ else
+ if xIsMatrix then
+ // TODO: check for dimenion constraints
+ else
+ // x is vector
+ Lx = length(x);
+
+ if Lx<=windowLength then
+ msg = "Incorrrect value for window length; must be smaller than the signal length";
+ return
+ end
+
+ if ~isWindowSpecified then
+ // disp("window not specified");
+ // TODO: understand
+ [x,msg] = createBufferMatrix(x,Lx-windowLength+1,Lx-windowLength);
+ if length(msg)~=0 then
+ return
+ end
+ // reversing the column order and scaling
+ x = x(:,$:-1:1)./sqrt(Lx-windowLength+1);
+ else
+ // disp("window specified");
+ [x,msg] = createBufferMatrix(x, windowLength, noverlap);
+ if length(msg)~=0 then
+ return
+ end
+ // scaling so as to get the correct value of R
+ x = x'./sqrt(Lx-windowLength);
+ end
+
+ end
+
+
+ // **applying window to each row of the data matrix**
+ // replicating window along the rows
+ if ~isempty(window) then
+ window = repmat(window(:)',size(x,1),1);
+ x = x.*window;
+ end
+
+ // computing eignevals and eigenvectors of R using SVD of x
+
+ // disp("X = (before SVD)");
+ // disp(x);
+ [temp,S,eigenvects] = svd(x,0);
+ // squaering the eigenvalues
+ eigenvals = diag(S).^2;
+
+ // disp("eigenvals in computeEig");
+ // disp(eigenvals);
+ end
+endfunction
+
+
+function [xMat,msg] = createBufferMatrix(x,windowLength,noverlap)
+ // creates a matrix where each row represents a section which has to be
+ // windowed
+ //
+ // Input Arguments
+ // x - input signal as a column vector
+ // windowLength
+ // noverlap
+ //
+ // will perform task similar to that performed by MATLAB's
+ // buffer(x,windowLength,noverlap) with nodelay option
+
+ msg="";
+ xMat = [];
+
+ // check input to be a vector
+ xIsVector = or(size(x)==1) & ndims(x)==2;
+
+ if ~xIsVector then
+ msg = "createBufferMatrix: x should be a vector";
+ return
+ end
+
+ if size(x,2)~=1 then
+ // convert to column vector
+ x = x';
+ end
+
+ L = length(x);
+ temp = windowLength - noverlap;
+ numOfSections = ceil((L-noverlap)/temp);
+
+ // performing zero padding of x
+ zeroPadLength = numOfSections*temp + noverlap - L;
+ zeroPad = zeros(zeroPadLength,1);
+ x = [x;zeroPad];
+ xMat = zeros(windowLength, numOfSections);
+ // disp(size(xMat));
+ // disp(size(x));
+
+ for i=1:numOfSections
+ xMat(1:temp,i) = x(1+(i-1)*temp:i*temp,1);
+ xMat(temp+1:windowLength,i) = x(1+i*temp:i*temp+noverlap,1);
+ end
+
+endfunction
+
+function pEffective = determineSignalSpace(p, eigenvals)
+ // Determines the effective dimension of the signal subspace
+
+ // Inputs:
+ // p: p(1) - signal subspace dimension
+ // p(2) (optional) - desired threshold
+ // eigenvals: vector conatining eigenvalues of the correlation
+ // matrix in descreasing order
+ // Output:
+ // pEffective - the effective dimension of the signal subspace. If
+ // a threshold is given as p(2), the signal subspace will
+ // be equal to the number of eigenvalues greater than the
+ // threshold times the smallest eigenvalue. Also,
+ // pEffective<=p(1). So, minimum of the two values is
+ // considered. If the threshold criteria results in an
+ // empty signal subspace, we take pEffective = p(1).
+ //
+ if length(p)==2 then
+ threshold = p(2)*eigenvals($);
+ signalIndices = find(eigenvals>threshold);
+ if ~isempty(signalIndices) then
+ pEffective = min(p(1), length(signalIndices));
+ else
+ // dont change p
+ pEffective = p(1);
+ end
+ else
+ pEffective = p;
+ end
+endfunction
diff --git a/macros/names b/macros/names
new file mode 100644
index 0000000..76fc13d
--- /dev/null
+++ b/macros/names
@@ -0,0 +1,193 @@
+ac2poly
+ac2rc
+arParEst
+arburg
+arcov
+armcov
+aryule
+barthannwin
+bartlett
+besself
+bitrevorder
+blackman
+blackmanharris
+blackmannuttall
+bohmanwin
+boxcar
+buffer
+butter
+buttord
+cconv
+cell2sos
+cheb1ord
+cheb2ord
+chebwin
+cheby1
+cheby2
+check
+chirp
+clustersegment
+cmorwavf
+convmtx
+corrmtx
+cummax
+cummin
+db
+db2pow
+dctmtx
+decimate
+dftmtx
+diric
+downsample
+dutycycle
+ellip
+ellipord
+enbw
+eqtflength
+falltime
+fftfilt
+filternorm
+filtfilt
+filtic
+filtord
+firpmord
+firtype
+flattopwin
+fracshift
+fwhm
+fwhmjlt
+gauspuls
+gaussdesign
+gaussian
+gausswin
+gmonopuls
+goertzel
+grpdelay
+hann
+helperHarmonicDistortionAmplifier
+icceps
+iirlp2mb
+impinvar
+impz
+impzlength
+interp
+intfilt
+invimpinvar
+is2rc
+isallpass
+isfir
+islinphase
+ismaxphase
+isminphase
+isstable
+kaiser
+lar2rc
+latc2tf
+latcfilt
+latcfilt1
+levdown
+levin
+levinson
+lpc
+lsf2poly
+mag2db
+marcumq
+medfilt1
+mexihat
+meyeraux
+midcross
+modulate
+morlet
+movingrms
+musicBase
+nnls
+nuttallwin
+parzenwin
+pchip
+pchips
+peak2peak
+peak2rms
+peig
+periodogram
+phaseInputParseAs_ab
+phaseInputParseAs_sos
+phasedelay
+phasez
+pmusic
+poly2ac
+poly2lsf
+poly2rc
+polyscale
+polystab
+polyval
+pow2db
+primitive
+prony
+pulseperiod
+pulsesep
+pulsewidth
+pulstran
+rc2ac
+rc2is
+rc2lar
+rc2poly
+rcosdesign
+rectpuls
+rectwin
+resample
+residued
+residuez
+risetime
+rlevinson
+rms
+rooteig
+rootmusic
+rssq
+sampled2continuous
+sawtooth
+schtrig
+schurrc
+seqperiod
+sgolay
+sgolayfilt
+shanwavf
+shiftdata
+slewrate
+sos2cell
+sos2ss
+sos2tf
+sos2zp
+sosbreak
+sosfilt
+specgram
+ss2sos
+statelevels
+stmcb
+strips
+subspaceMethodsInputParser
+tf2sos
+tf2zp
+tf2zpk
+transpose
+trial_iirlp2mb
+triang
+tripuls
+truth
+tukeywin
+udecode
+uencode
+ultrwin
+unshiftdata
+upfirdn
+upsample
+upsamplefill
+var
+vco
+welchwin
+window
+wkeep
+wrev
+xcorr2
+zerocrossing
+zp2sos
+zplane
diff --git a/macros/names~ b/macros/names~
new file mode 100644
index 0000000..e69de29
diff --git a/macros/nnls.bin b/macros/nnls.bin
new file mode 100644
index 0000000..616c06a
Binary files /dev/null and b/macros/nnls.bin differ
diff --git a/macros/nnls.sci b/macros/nnls.sci
new file mode 100644
index 0000000..3e77d65
--- /dev/null
+++ b/macros/nnls.sci
@@ -0,0 +1,74 @@
+function x = nnls(E,f,x)
+ // Non Negative Least Squares (nnls) for Ex=f with the constraint x>=0
+
+ // Reference
+ // Lawson, C.L. and R.J. Hanson, Solving Least Squares Problems,
+ // Prentice-Hall, 1974, Chapter 23, p. 161.
+
+ m2 = size(E,1);
+ n = size(E,2);
+
+ iterMax = 3*n;
+
+
+ x = zeros(n,1);
+ z = zeros(n,1);
+ w = zeros(n,1);
+ wActive = w;
+ // P indicates if a variable is inactive
+ P = x~=0; // setting all to False
+
+ // z indiactes if a variable is active
+ Z = x==0; // setting all to True
+
+ Ep = zeros(size(E));
+
+ // Step 2
+ w = E'*(f-E*x);
+
+ iter = 0;
+ while or(Z) & or(w(Z)>0)
+ // Step 4
+ wActive(P) = -%inf;
+ wActive(Z) = w(Z);
+ [maxval,maxindex] = max(wActive);
+
+ // Step 5
+ P(maxindex) = %T;
+ Z(maxindex) = %F;
+
+ // Step 6
+ z(P)=E(:,P)\f;
+ z(Z)=0;
+
+ while or(z(P)<=0)
+ iter = iter+1;
+ if iter>iterM`ax then
+ x = z;
+ return;
+ end
+ // Step 8
+ Q = (z <= 0) & P;
+
+ // Step 9
+ alpha = min(x(P)./(x(P)-z(P)));
+
+ // Step 10
+ x = x+alpha*(z-x);
+
+ indices = find(x>=0);
+ P(indices) = %T;
+ W(indices) = %F;
+
+ // Step 6
+ z(P)=E(:,P)\f;
+ z(Z)=0;
+ end
+ x = z;
+
+ // Step 2
+ w = E'*(f-E*x);
+ wActive = w(Z);
+ end
+
+endfunction
diff --git a/macros/nuttallwin.bin b/macros/nuttallwin.bin
new file mode 100644
index 0000000..92c09d6
Binary files /dev/null and b/macros/nuttallwin.bin differ
diff --git a/macros/nuttallwin.sci b/macros/nuttallwin.sci
new file mode 100644
index 0000000..c066ef5
--- /dev/null
+++ b/macros/nuttallwin.sci
@@ -0,0 +1,34 @@
+function w = nuttallwin (m, opt)
+//This function returns the filter coefficients of a Blackman-Harris window.
+//Calling Sequence
+//w = nuttallwin (m)
+//w = nuttallwin (m, opt)
+//Parameters
+//m: positive integer value
+//opt: string value, takes in "periodic" or "symmetric"
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Blackman-Harris window defined by Nuttall of length m supplied as input, to the output vector w.
+//The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+//Examples
+//nuttallwin(2, "periodic")
+//ans =
+// - 2.429D-17
+// 1.
+
+
+
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 1 then
+ w = callOctave("nuttallwin",m)
+ case 2 then
+ w = callOctave("nuttallwin",m,opt)
+ end
+endfunction
+
diff --git a/macros/parzenwin.bin b/macros/parzenwin.bin
new file mode 100644
index 0000000..ce71bf1
Binary files /dev/null and b/macros/parzenwin.bin differ
diff --git a/macros/parzenwin.sci b/macros/parzenwin.sci
new file mode 100644
index 0000000..f51c924
--- /dev/null
+++ b/macros/parzenwin.sci
@@ -0,0 +1,26 @@
+function [y] = parzenwin (m)
+//This function returns the filter coefficients of a Parzen window.
+//Calling Sequence
+//y = parzenwin (m)
+//Parameters
+//m: positive integer value
+//y: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Parzen window of length m supplied as input, to the output vector y.
+//Examples
+//parzenwin(3)
+//ans =
+// 0.0740741
+// 1.
+// 0.0740741
+
+rhs = argn(2)
+
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+
+y = callOctave("parzenwin",m)
+
+endfunction
diff --git a/macros/pchip.bin b/macros/pchip.bin
new file mode 100644
index 0000000..b698e26
Binary files /dev/null and b/macros/pchip.bin differ
diff --git a/macros/pchip.sci b/macros/pchip.sci
new file mode 100644
index 0000000..4674929
--- /dev/null
+++ b/macros/pchip.sci
@@ -0,0 +1,138 @@
+function v = pchip(x,y,xx)
+
+//this function returns piecewise cubic hermite interpolating polynomial.
+
+// Calling Sequence
+// d=pchip(x,y)
+// d= 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).
+// xx: Points for interpolation
+// v: vector of interpolantant at xx
+
+// Examples
+// x=[0 1 2 3 4 5]
+// y=[1 0 1 0 1 0]
+// xx=linspace(0:10,800)
+// v=pchip(x, y)
+// v=pchip(x,y,xx)
+// See also
+ // Authors
+// Jitendra Singh
+
+// execute function "pchips" prior executing this function
+
+
+if argn(2)==3 & ~isreal(xx)
+ error('Points for interpolation must be real.')
+end
+
+
+nn=size(y,1);
+
+h = diff(x); m = prod(nn);
+
+
+
+delta = diff(y,1,2)./repmat(h,m,1);
+
+slopes = zeros(size(y,1),size(y,2));
+
+for r = 1:m
+ if isreal(delta)
+ slopes(r,:) = pchips(x,y(r,:),delta(r,:));
+ else
+ realslopes = pchips(x,y(r,:),real(delta(r,:)));
+ imagslopes = pchips(x,y(r,:),imag(delta(r,:)));
+ slopes(r,:) = complex(realslopes, imagslopes);
+ end
+end
+
+
+s=slopes;
+divdif=delta
+
+d = size(y,1);
+
+dx = diff(x(:).');
+dxd = repmat(dx,d,1);
+divdif = diff(y,1,2)./dxd;
+n = length(x);
+dzzdx = (divdif-s(:,1:n-1))./dxd; dzdxdx = (s(:,2:n)-divdif)./dxd;
+dnm1 = d*(n-1);
+
+c1=matrix((dzdxdx-dzzdx)./dxd,dnm1,1)
+c2=matrix(2*dzzdx-dzdxdx,dnm1,1)
+c3=matrix(s(:,1:n-1),dnm1,1)
+c4=matrix(y(:,1:n-1),dnm1,1)
+v=[c1,c2,c3,c4]
+
+
+if argn(2)==3
+ //v = ppval(v,xx);
+
+ b=x;
+ c=v;
+ l=length(b)-1;
+ dlk=length(c);
+ d = size(y,1)
+ dl=prod(d)*l;
+ eps=2.2204e-16;
+ k=fix(dlk/dl+100*eps);
+ dd=d;
+ lx = length(xx);
+ xs = matrix(xx,1,length(xx));
+
+ if lx, [cf,idx] = histc([-%inf,b(2:l),%inf], xs);
+ else idx=ones(1, length(xx));
+ end
+
+ infxs = find(xs==%inf);
+ if ~isempty(infxs)
+ index(infxs) = l;
+end
+ nogoodxs = find(idx==0);
+
+ if ~isempty (nogoodxs)
+ xs(nogoodxs) = %nan;
+ idx(nogoodxs) = 1;
+end
+
+
+ xs = xs-b(idx);
+
+ d = prod(dd);
+
+ sizexx = size(xx)
+
+ if d>1
+ xs = reshape(xs(ones(d,1),:),1,d*lx);
+ idx = d*idx; temp = (-d:-1).';
+ idx = reshape(1+idx(ones(d,1),:)+temp(:,ones(1,lx)), d*lx, 1 );
+ else
+ if length(sizexx)>1, dd = []; else dd = 1; end
+end
+
+
+v = c(idx,1);
+
+
+for i=2:k
+ v = xs(:).*v + c(idx,i);
+end
+
+
+if ~isempty(nogoodxs) & k==1 & l>1
+ v = matrix(v,d,lx); v(:,nogoodxs) = NaN;
+end
+v = matrix(v,[dd,sizexx]);
+
+end
+
+ endfunction
+
+
+
diff --git a/macros/pchips.bin b/macros/pchips.bin
new file mode 100644
index 0000000..37e0ef5
Binary files /dev/null and b/macros/pchips.bin differ
diff --git a/macros/pchips.sci b/macros/pchips.sci
new file mode 100644
index 0000000..78c7473
--- /dev/null
+++ b/macros/pchips.sci
@@ -0,0 +1,49 @@
+function d = pchips(x,y,delta)
+
+
+ n = length(x);
+
+ 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));
+ else
+
+ d(1) = ((2*h(1)+h(2))*delta(1) - h(1)*delta(2))/(h(1)+h(2));
+ if sign(d(1)) ~= sign(delta(1))
+ d(1) = 0;
+ elseif (sign(delta(1)) ~= sign(delta(2))) & (abs(d(1)) > abs(3*delta(1)))
+ d(1) = 3*delta(1);
+ end
+ d(n) = ((2*h(n-1)+h(n-2))*delta(n-1) - h(n-1)*delta(n-2))/(h(n-1)+h(n-2));
+ if sign(d(n)) ~= sign(delta(n-1))
+ d(n) = 0;
+ elseif (sign(delta(n-1)) ~= sign(delta(n-2))) & (abs(d(n)) > abs(3*delta(n-1)))
+ d(n) = 3*delta(n-1);
+ end
+ end
+
+
+
+
+ end
+
+ endfunction
diff --git a/macros/peak2peak.bin b/macros/peak2peak.bin
new file mode 100644
index 0000000..263e5aa
Binary files /dev/null and b/macros/peak2peak.bin differ
diff --git a/macros/peak2peak.sci b/macros/peak2peak.sci
new file mode 100644
index 0000000..9e664de
--- /dev/null
+++ b/macros/peak2peak.sci
@@ -0,0 +1,95 @@
+function [Y] = peak2peak(X, dim)
+funcprot(0);
+narginchk(1,2,argn(2));
+// peak2peak finds the maximum-to-minimum difference
+// Calling Sequence
+// Y=peak2peak(X)
+// Y=peak2peak(X,dim)
+// Parameters
+// X: Real or complex valued input vector or matrix.
+// dim: Dimension to compute maximum-to-minimum difference (Row/Column)
+// Description
+// Y= peak2peak(X) returns the difference between maximum and minimum values in X, operating along the first non-singleton
+// dimension of X by default.
+// Y= peak2peak(X,dim) returns the maximum-to-minimum difference in X, along dimension dim.
+// Examples
+// 1. t = 0:0.001:1-0.001;
+// x = cos(2*pi*100*t);
+// y = peak2peak(x)
+// 2. t = 0:0.001:1-0.001;
+// x = (1:4)'*cos(2*pi*100*t);
+// y = peak2peak(x,2)
+// Authors
+// Rahul Dalmia
+//function only accepts real values due to limitations of the 'max' function in Scilab
+//Modifications made by Debdeep Dey
+
+
+[nr, nc] = size (X); // Dimensions of Input calculated
+if(type(X)==10) then //if i/p is a char type vector or matrix or a string
+ w=X;
+ [nr,nc]=size(X);
+ if(nr==1 & nc==1) then
+ X=ascii(X);
+ X=matrix(X,length(w));
+ X=X';
+ else
+
+ X=ascii(X);
+ X=matrix(X,size(w));
+ end
+
+end
+
+if (~exists('dim','local')) then
+ if (nr==1) then
+ Y = zeros(nr, 1); // preset all output fields to 0
+ for i= 1:nr
+ maxim=max(X(i,:)); // maximum and minimum values are found
+ minim=min(X(i,:));
+ Y(i,1)=maxim-minim; // Peak to peak value is calculated from the difference of max and min
+ end
+ else
+ Y = zeros(1, nc); // preset all output fields to 0
+ for i= 1:nc
+ maxim=max(X(:,i)); // maximum and minimum values are found
+ minim=min(X(:,i));
+ Y(1,i)=maxim-minim; // Peak to peak value is calculated from the difference of max and min
+ end
+ end
+
+elseif (exists('dim','local')) then
+ if (dim<1) then
+ error("Dimension argument must be a positive integer scalar within indexing range.");
+ end
+ if (dim==1) then
+ Y = zeros(1, nc); // preset all output fields to 0
+ for i= 1:nc
+ maxim=max(X(:,i)); // maximum and minimum values are found
+ minim=min(X(:,i));
+ Y(1,i)=maxim-minim; // Peak to peak value is calculated from the difference of max and min
+ end
+
+ elseif (dim==2) then
+ Y = zeros(nr, 1); // preset all output fields to 0
+ for i= 1:nr
+ maxim=max(X(i,:)); // maximum and minimum values are found
+ minim=min(X(i,:));
+ Y(i,1)=maxim-minim; // Peak to peak value is calculated from the difference of max and min
+ end
+ else// for cases when dim >2
+ Y=zeros(nr,nc);
+
+ end
+end
+
+endfunction
+function narginchk(l,h,ni)
+if(nih) then
+ error("Too many input arguments");
+end
+endfunction
diff --git a/macros/peak2rms.bin b/macros/peak2rms.bin
new file mode 100644
index 0000000..75d11fa
Binary files /dev/null and b/macros/peak2rms.bin differ
diff --git a/macros/peak2rms.sci b/macros/peak2rms.sci
new file mode 100644
index 0000000..3a8df40
--- /dev/null
+++ b/macros/peak2rms.sci
@@ -0,0 +1,106 @@
+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
diff --git a/macros/peig.bin b/macros/peig.bin
new file mode 100644
index 0000000..88c349f
Binary files /dev/null and b/macros/peig.bin differ
diff --git a/macros/peig.sci b/macros/peig.sci
new file mode 100644
index 0000000..7529edc
--- /dev/null
+++ b/macros/peig.sci
@@ -0,0 +1,220 @@
+function [S,f,v,e] = peig(varargin)
+ // Psuedospectrum using the eigenvector method.
+ //
+ // Calling Sequence
+ // [S,w] = peig(x,p)
+ // [S,w] = peig(x,p,w)
+ // [S,w] = peig(x,p,nfft)
+ // [S,w] = peig(x,p,nfft,fs)
+ // [S,w] = peig(x,p,f,fs)
+ // [S,f] = peig(...,'corr')
+ // [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
+ // 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
+ // 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
+ // (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.
+ // 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
+ // computed. Three possible values - 'onesided', 'twosided', 'centered'
+ // 'corr' flag
+ // Presence indicates that the primary input x is actually a
+ // correlation matrix
+ //
+ // Examples:
+ // TODO:
+ //
+ // See also
+ // rooteig | pmusic | pmtm | pcov | pmcov | pburg | pyulear | pwelch | corrmtx
+ //
+ // Authors
+ // Ayush Baid
+ //
+ // 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.
+ // 2nd Ed., Macmillan, 1988.
+
+ funcprot(0);
+
+ exec('subspaceMethodsInputParser.sci',-1);
+ exec('musicBase.sci',-1);
+
+ [data, msg, err_num] = subspaceMethodsInputParser(varargin);
+
+ if length(msg)==0 then
+ // no error occured
+ else
+ error(err_num, "peig: " + msg);
+ end
+
+ [musicData,msg] = musicBase(data);
+
+ if length(msg)~=0 then
+ error("peig: " + msg);
+ end
+
+
+ // 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;
+
+endfunction
+
+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):$);
+
+ denominator = 0;
+
+ isFreqGiven = %F;
+
+
+ for i=1:size(noiseEigenvects,2);
+ // disp("looping in pseudospectrum");
+ if isempty(freqvector) then
+ [h,w] = computeFreqResponseByFFT(noiseEigenvects(:,i),nfft,fs,...
+ isFsSpecified);
+ else
+ [h,w] = computeFreqResponseByPolyEval(noiseEigenvects(:,i),...
+ freqvector,fs,isFsSpecified);
+ isFreqGiven = %T;
+ end
+ denominator = denominator + (abs(h).^2)./weights(i);
+ end
+
+ // 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
+ if modulo(nfft,2) then
+ // nfft is odd
+ range = 1:(1+nfft)/2;
+ else
+ range = 1:((nfft/2)+1);
+ 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
+ idx = [(nfft/2+2):nfft 1:(nfft/2+1)];
+ end
+ pspec = pspec(idx);
+ w = w(idx);
+
+ if rem then
+ w(1:(nfft-1)/2) = - w(nfft:-1:((nfft+1)/2+1));
+ else
+ w(1:(nfft/2-1)) = - w(nfft:-1:(nfft/2+2));
+ end
+ end
+ end
+
+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
+ // frequency response is done at n points in [0,fs) using fft algorithm
+ //
+ // Similar to MATLAB's freqz(b,a,n,'whole',fs)
+ if isempty(fs) then
+ fs=1;
+ end
+ 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);
+ b = [b; zeroPad];
+
+
+ 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.bin b/macros/periodogram.bin
new file mode 100644
index 0000000..39bdd96
Binary files /dev/null and b/macros/periodogram.bin differ
diff --git a/macros/periodogram.sci b/macros/periodogram.sci
new file mode 100755
index 0000000..33e15af
--- /dev/null
+++ b/macros/periodogram.sci
@@ -0,0 +1,20 @@
+function [d,n]=periodogram(a,b,c,d,e)
+ funcprot(0);
+ [nargout,nargin]=argn();
+ select nargin
+ 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);
+ else
+ error("Incorrect no. of Input Arguments");
+ end
+
+endfunction
+
diff --git a/macros/phaseInputParseAs_ab.bin b/macros/phaseInputParseAs_ab.bin
new file mode 100644
index 0000000..6e216df
Binary files /dev/null and b/macros/phaseInputParseAs_ab.bin differ
diff --git a/macros/phaseInputParseAs_ab.sci b/macros/phaseInputParseAs_ab.sci
new file mode 100644
index 0000000..b5235fa
--- /dev/null
+++ b/macros/phaseInputParseAs_ab.sci
@@ -0,0 +1,107 @@
+function [a,b,w,cas1,fs]=phaseInputParseAs_ab(arg,nargin)
+ fs=0;
+ if nargin<2 then
+ error('no. of inputs not valid');
+ end
+ v=size(arg(2));
+ if size(v)>2 then
+ error ('invalid input dimension');
+ end
+ a=arg(1);
+ b=arg(2);
+ [n,k]=size(arg(2))
+ if nargin==2 then //(a,b) is the input
+ w=[0:(1/512):(511/512)]*%pi;
+ cas1=1;
+ elseif nargin==3 then //(a,b,n) or (a,b,w) or (a,b,'whole')
+ cas1=1;
+ v=size(arg(3));
+ if type(arg(3))==10 then
+ if arg(3)=='whole' then
+ n=512;
+ w=[0:(1/n):((n-1)/n)]*(2*%pi);
+ cas1=1;
+ else
+ error('invalid input');
+ end
+ elseif (type(arg(3))==1)
+ if (v==[1,1])&(floor(arg(3))==arg(3))&(arg(3)>0) then //i.e. the entry is a single integer
+ n=arg(3);
+ w=[0:(1/n):((n-1)/n)]*%pi;
+ elseif (v(1)==1) then //(sos,w) w must be one dimensional
+ w=arg(3);
+ elseif (v(2)==1) then //w to row matrix
+ w=(arg(3))';
+ else
+ error ('dimension of input is invalid');
+ end
+ else
+ error ('invalid input');
+ end
+ elseif nargin==4 then //(a,b,n,fs) or (a,b,f,fs) or (a,b,n,'whole')
+ if type(arg(4))==10 then
+ cas1=1;
+ if (arg(4)=='whole') then
+ v=size(arg(3));
+ if (v==[1,1])&(floor(arg(3))==arg(3))&(arg(3)>0) then //i.e. the entry is a single integer
+ n=arg(3);
+ w=[0:(1/n):((n-1)/n)]*(2*%pi);
+ else
+ error ('dimension of input is invalid');
+ end
+ else
+ error('invalid input');
+ end
+ elseif (type(arg(4))==1) then
+ v=size(arg(4));
+ if v~=[1,1] then
+ error ('dimension of input is invalid');
+ end
+ cas1=2;
+ fs=arg(4);
+ v=size(arg(3));
+ if (v==[1,1])&(floor(arg(3))==arg(3))&(arg(3)>0) then //i.e. the entry is a single integer
+ n=arg(3);
+ w=[0:(1/n):((n-1)/n)]*(%pi);
+ elseif (v(1)==1) then //(sos,w) w must be one dimensional
+ w=2*arg(3)*%pi/fs;
+ elseif (v(2)==1) then //w to row matrix
+ w=2*%pi*(arg(3))'/fs;
+ else
+ error ('dimension of input is invalid');
+ end
+ else
+ error ('input format is invalid');
+ end
+ elseif nargin==5 //(a,b,n,fs,'whole') or (a,b,f,fs,'whole')
+ if arg(5)=='whole' then
+ v=size(arg(4));
+ if v~=[1,1] then
+ error ('dimension of input is invalid');
+ end
+ cas1=2;
+ v=size(arg(3));
+ if (v==[1,1])&(floor(arg(3))==arg(3))&(arg(3)>0) then //i.e. the entry is a single integer
+ n=arg(3);
+ w=[0:(1/n):((n-1)/n)]*(2*%pi);
+ elseif (v(1)==1) then //(sos,w) w must be one dimensional
+ w=2*arg(3)*%pi/fs;
+ elseif (v(2)==1) then //w to row matrix
+ w=2*%pi*(arg(3))'/fs;
+ else
+ error ('dimension of input is invalid');
+ end
+ else
+ error ('input format is invalid');
+ end
+ end
+ //so that a,b are row vectors
+ [n,k]=size(a);
+ if k==1 then
+ a=a';
+ end
+ [n,k]=size(b);
+ if k==1 then
+ b=b';
+ end
+endfunction
diff --git a/macros/phaseInputParseAs_sos.bin b/macros/phaseInputParseAs_sos.bin
new file mode 100644
index 0000000..fedc3ac
Binary files /dev/null and b/macros/phaseInputParseAs_sos.bin differ
diff --git a/macros/phaseInputParseAs_sos.sci b/macros/phaseInputParseAs_sos.sci
new file mode 100644
index 0000000..d3bf13d
--- /dev/null
+++ b/macros/phaseInputParseAs_sos.sci
@@ -0,0 +1,92 @@
+function [sos,w,cas1,fs]=phaseInputParseAs_sos(arg,nargin)
+ fs=0;
+ if nargin<1 then
+ error('no. of inputs not valid');
+ end
+ sos=arg(1);
+ if nargin==1 then //(sos) is the input
+ w=[0:(1/512):(511/512)]*%pi;
+ cas1=1;
+ elseif nargin==2 then //(sos,n) or (sos,w) or (sos,'whole')
+ cas1=1;
+ v=size(arg(2));
+ if type(arg(2))==10 then
+ if arg(2)=='whole' then
+ n=512;
+ w=[0:(1/n):((n-1)/n)]*(2*%pi);
+ cas1=1;
+ else
+ error('invalid input');
+ end
+ elseif (type(arg(2))==1)
+ if (v==[1,1])&(floor(arg(2))==arg(2))&(arg(2)>0) then //i.e. the entry is a single integer
+ n=arg(2);
+ w=[0:(1/n):((n-1)/n)]*(%pi);
+ elseif (v(1)==1) then //(sos,w) w must be one dimensional
+ w=arg(2);
+ elseif (v(2)==1) then //w to row matrix
+ w=(arg(2))';
+ else
+ error ('dimension of input is invalid');
+ end
+ else
+ error ('invalid input');
+ end
+ elseif nargin==3 then //(sos,n,fs) or (sos,f,fs) or (sos,n,'whole')
+ if type(arg(3))==10 then
+ cas1=1;
+ if (arg(3)=='whole') then
+ v=size(arg(2));
+ if (v==[1,1])&(floor(arg(2))==arg(2))&(arg(2)>0) then //i.e. the entry is a single integer
+ n=arg(2);
+ w=[0:(1/n):((n-1)/n)]*(2*%pi);
+ else
+ error ('dimension of input is invalid');
+ end
+ else
+ error('invalid input');
+ end
+ elseif (type(arg(3))==1) then
+ v=size(arg(3));
+ if v~=[1,1] then
+ error ('dimension of input is invalid');
+ end
+ cas1=2;
+ fs=arg(3);
+ v=size(arg(2));
+ if (v==[1,1])&(floor(arg(2))==arg(2))&(arg(2)>0) then //i.e. the entry is a single integer
+ n=arg(2);
+ w=[0:(1/n):((n-1)/n)]*(%pi);
+ elseif (v(1)==1) then //(sos,w) w must be one dimensional
+ w=2*arg(2)*%pi/fs;
+ elseif (v(2)==1) then //w to row matrix
+ w=2*%pi*(arg(2))'/fs;
+ else
+ error ('dimension of input is invalid');
+ end
+ else
+ error ('input type is invalid');
+ end
+ elseif nargin==4 //(sos,n,fs,'whole') or (sos,f,fs,'whole')
+ if arg(4)=='whole' then
+ v=size(arg(3));
+ if v~=[1,1] then
+ error ('dimension of input is invalid');
+ end
+ cas1=2;
+ v=size(arg(2));
+ if (v==[1,1])&(floor(arg(2))==arg(2))&(arg(2)>0) then //i.e. the entry is a single integer
+ n=arg(2);
+ [0:(1/n):((n-1)/n)]*(2*%pi);
+ elseif (v(1)==1) then //(sos,w) w must be one dimensional
+ w=2*arg(2)*%pi/fs;
+ elseif (v(2)==1) then //w to row matrix
+ w=2*%pi*(arg(2))'/fs;
+ else
+ error ('dimension of input is invalid');
+ end
+ else
+ error ('input format is invalid');
+ end
+ end
+ endfunction
diff --git a/macros/phasedelay.bin b/macros/phasedelay.bin
new file mode 100644
index 0000000..01e0684
Binary files /dev/null and b/macros/phasedelay.bin differ
diff --git a/macros/phasedelay.sci b/macros/phasedelay.sci
new file mode 100644
index 0000000..19aeded
--- /dev/null
+++ b/macros/phasedelay.sci
@@ -0,0 +1,72 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function [phi, varargout]=phasedelay(varargin)
+ //cas variable is 2 if sos form is involved and 1 if direct rational form is given
+ //(sos,n) or (sos,w) or (sos,'whole')or (b,a) is the input
+ //cas variable is 2 if sos form is involved and 1 if direct rational form is given
+ //cas1 variable is 1 if f is to be given as output, 2 other wise
+ [nargout,nargin]=argn();
+ //do not forget to execute 'phaseInputParseAs_sos' and 'phaseInputParseAs_ab' before running
+ v=size(varargin(1));
+ if size(v)>2 then
+ error ('invalid input dimension');
+ end
+ [n,k]=size(varargin(1));
+ if type(varargin(1))~=1 then
+ error ('check the input type');
+ end
+ if (n==1 & k==6) then //not clear if sos or (a,b)
+ v=size(varargin(2));
+ if (nargin==1) //(sos) is the input
+ cas=2;
+ [sos,w,cas1,fs]=phaseInputParseAs_sos(varargin,nargin);
+ elseif (varargin(2)=='whole') //(sos,'whole')is the input
+ cas=2;
+ [sos,w,cas1,fs]=phaseInputParseAs_sos(varargin,nargin);
+ else //taking it as (a,b)
+ cas=1;
+ [a,b,w,cas1,fs]=phaseInputParseAs_ab(varargin,nargin);
+ end
+ elseif (n==1 | k==1) then
+ cas=1;
+ [a,b,w,cas1,fs]=phaseInputParseAs_ab(varargin,nargin);
+ elseif k==6 then //first variable is sos
+ cas=2;
+ [sos,w,cas1,fs]=phaseInputParseAs_sos(varargin,nargin);
+ end
+ //cas,cas1,fs,w,[(a,b),sos]
+ if cas==1 then
+ [m,n]=size(a);
+ N=[0:n-1];
+ M=N'*w;//computing matrix Mij=(i-1)*wj
+ num=(a*exp(%i*M));//the operation computes phase of sum(ak*exp(i*w*k))
+ num_dot=(%i*(a.*N)*exp(%i*M));//computing the derivative on those points
+ phdel_num=(imag(num_dot).*real(num)-imag(num).*real(num_dot))./(abs(num).*abs(num));
+
+ [m,n]=size(b);
+ N=[0:n-1];
+ M=N'*w;
+ den=(b*exp(%i*M));//the operation computes phase of sum(ak*exp(i*w*k))
+ den_dot=(%i*(b.*N)*exp(%i*M));//computing the derivative on those points
+ phdel_den=(imag(den_dot).*real(den)-imag(den).*real(den_dot))./(abs(den).*abs(den));
+ phi=(phdel_num-phdel_den);
+ 0;
+ else
+ [n,k]=size(sos)
+ N=[0,1,2];
+ M=N'*w;
+ num=(sos(:,4:6)*exp(%i*M));//the operation computes phase of sum(ak*exp(i*w*k))
+ num_dot=(%i*(sos(:,4:6).*(ones(n,1)*N))*exp(%i*M));//computing the derivative on those points
+ phdel_num=(imag(num_dot).*real(num)-imag(num).*real(num_dot))./(abs(num).*abs(num));
+
+ den=(sos(:,1:3)*exp(%i*M));//the operation computes phase of sum(ak*exp(i*w*k))
+ den_dot=(%i*(sos(:,1:3).*(ones(n,1)*N))*exp(%i*M));//computing the derivative on those points
+ phdel_den=(imag(den_dot).*real(den)-imag(den).*real(den_dot))./(abs(den).*abs(den));
+
+ phi_mat=phdel_num-phdel_den;
+ phi=sum(phi_mat,1);//summing each of the componenet second order system phases
+ end
+ if cas1==1 then
+ varargout(2)=w*fs/(2*%pi);
+ end
+endfunction
diff --git a/macros/phasez.bin b/macros/phasez.bin
new file mode 100644
index 0000000..6b0a1e7
Binary files /dev/null and b/macros/phasez.bin differ
diff --git a/macros/phasez.sci b/macros/phasez.sci
new file mode 100644
index 0000000..38421ab
--- /dev/null
+++ b/macros/phasez.sci
@@ -0,0 +1,92 @@
+//phasez Phase response of digital filter
+//Calling Syntax
+//[phi,w] = phasez(b,a,n)
+//[phi,w] = phasez(sos,n)
+///[phi,w] = phasez(b,a,n) returns
+//the n-point unwrapped phase response vector, phi,
+//in radians and the frequency vector, w, in radians/sample
+//for the filter coefficients specified in b and a.
+//The values of the frequency vector, w, range from
+//0 to π. If n is omitted,
+//the length of the phase response vector defaults to 512. For best
+//results, set n to a value greater than the filter
+//order.
+//[phi,w] = phasez(sos,n) returns the unwrapped
+//phase response for the second order sections matrix, sos. sos is
+//a K-by-6 matrix, where the number of sections, K,
+//must be greater than or equal to 2. If the number of sections is less
+//than 2, phasez considers the input to be the
+//numerator vector, b. Each row of sos corresponds
+//to the coefficients of a second-order (biquad) filter. The ith
+//row of the sos matrix corresponds to [bi(1)
+//bi(2) bi(3) ai(1) ai(2) ai(3)].
+////Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function [phi, varargout]=phasez(varargin)
+ //cas variable is 2 if sos form is involved and 1 if direct rational form is given
+ //(sos,n) or (sos,w) or (sos,'whole')or (b,a) is the input
+ //cas variable is 2 if sos form is involved and 1 if direct rational form is given
+ //cas1 variable is 1 if f is to be given as output, 2 other wise
+ [nargout,nargin]=argn();
+ //do not forget to execute 'phaseInputParseAs_sos' and 'phaseInputParseAs_ab' before running
+ v=size(varargin(1));
+ if size(v)>2 then
+ error ('invalid input dimension');
+ end
+ [n,k]=size(varargin(1));
+ if type(varargin(1))~=1 then
+ error ('check the input type');
+ end
+ if (n==1 & k==6) then //not clear if sos or (a,b)
+ v=size(varargin(2));
+ if (nargin==1) //(sos) is the input
+ cas=2;
+ [sos,w,cas1,fs]=phaseInputParseAs_sos(varargin,nargin);
+ elseif (varargin(2)=='whole') //(sos,'whole')is the input
+ cas=2;
+ [sos,w,cas1,fs]=phaseInputParseAs_sos(varargin,nargin);
+ else //taking it as (a,b)
+ cas=1;
+ [a,b,w,cas1,fs]=phaseInputParseAs_ab(varargin,nargin);
+ end
+ elseif (n==1 | k==1) then
+ cas=1;
+ [a,b,w,cas1,fs]=phaseInputParseAs_ab(varargin,nargin);
+ elseif k==6 then //first variable is sos
+ cas=2;
+ [sos,w,cas1,fs]=phaseInputParseAs_sos(varargin,nargin);
+ end
+ //cas,cas1,fs,w,[(a,b),sos]
+ if cas==1 then
+ [m,n]=size(a);
+ N=[0:n-1];
+ M=N'*w;//computing matrix Mij=(i-1)*wj
+ ph_num=phasemag(a*exp(%i*M));//the operation computes phase of sum(ak*exp(i*w*k))
+
+ [m,n]=size(b);
+ N=[0:n-1];
+ M=N'*w;
+ ph_den=phasemag(b*exp(%i*M));//similar result for denominator
+ [m,n]=size(w);
+ phi=pmodulo(ph_num-ph_den,360);//takes the difference in phase modulo 360
+ else
+ N=[0,1,2];
+ M=N'*w;
+ ph_num=phasemag(sos(:,4:6)*exp(%i*M));
+ ph_den=phasemag(sos(:,1:3)*exp(%i*M));//the numerator phases for each second order componenet
+ phi_mat=ph_num-ph_den;
+ [m,n]=size(w);
+ phi=pmodulo(sum(phi_mat,1),360);//summing each of the componenet second order system phases
+ end
+ if cas1==1 then
+ varargout(2)=w*fs/(2*%pi);
+ if nargout>2 then
+ varargout(3)=struct('plot', 'both', 'fvflag', 0, 'yunits','degrees','xunit','Hz','fs',fs);
+ end
+ else
+ varargout(2)=w;
+ if nargout>2 then
+ varargout(3)=struct('plot', 'both', 'fvflag', 0, 'yunits','degrees','xunit','radian/sample','fs',[]);
+ end
+ end
+endfunction
diff --git a/macros/pmusic.bin b/macros/pmusic.bin
new file mode 100644
index 0000000..1533f71
Binary files /dev/null and b/macros/pmusic.bin differ
diff --git a/macros/pmusic.sci b/macros/pmusic.sci
new file mode 100644
index 0000000..0891bb9
--- /dev/null
+++ b/macros/pmusic.sci
@@ -0,0 +1,253 @@
+// Date of creation: 18 Dec, 2015
+function varargout = pmusic(varargin)
+ // Psuedospectrum using MUSIC algorithm
+ //
+ // Note: does not implement the plotting functionality as in matlab
+ // Calling Sequence
+ // [S,w] = pmusic(x,p)
+ // [S,w] = pmusic(x,p,w)
+ // [S,w] = pmusic(x,p,nfft)
+ // [S,w] = pmusic(x,p,nfft,fs)
+ // [S,w] = pmusic(x,p,f,fs)
+ // [S,f] = pmusic(...,'corr')
+ // [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
+ // 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
+ // 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
+ // (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.
+ // 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
+ // computed. Three possible values - 'onesided', 'twosided', 'centered'
+ // 'corr' flag
+ // Presence indicates that the primary input x is actually a
+ // correlation matrix
+ //
+ // Examples:
+ // TODO:
+ //
+ // See also
+ // pburg | peig | periodogram | pmtm | prony | pwelch | rooteig | rootmusic
+ //
+ // Authors
+ // Ayush Baid
+ //
+ // 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.
+ // 2nd Ed., Macmillan, 1988.
+
+ funcprot(0);
+
+ exec('subspaceMethodsInputParser.sci',-1);
+ exec('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";
+ error(78,msg);
+ end
+
+ // ("**start**");
+ [data, msg, err_num] = subspaceMethodsInputParser(varargin);
+
+ if length(msg)==0 then
+ // no error occured
+ else
+ error(err_num, "pmusic: " + msg);
+ end
+
+ //disp(data);
+
+ [musicData,msg] = musicBase(data);
+
+ //disp(musicData);
+ //disp(musicData.noiseEigenvects);
+ //disp(musicData.signalEigenvects);
+
+ if length(msg)~=0 then
+ error(msg);
+ end
+
+
+ // 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
+
+endfunction
+
+function [pspec,w] = pseudospectrum(noiseEigenvects, eigenvals, freqvector, ...
+ nfft, fs, freqrange,isFsSpecified)
+ // 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");
+ if isempty(freqvector) then
+ [h,w] = computeFreqResponseByFFT(noiseEigenvects(:,i),nfft,fs,...
+ isFsSpecified);
+ else
+ [h,w] = computeFreqResponseByPolyEval(noiseEigenvects(:,i),...
+ freqvector,fs,isFsSpecified);
+ isFreqGiven = %T;
+ end
+ denominator = denominator + (abs(h).^2)./weights(i);
+ // disp(h(1:10));
+ end
+
+ // 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
+ if modulo(nfft,2) then
+ // nfft is odd
+ range = 1:(1+nfft)/2;
+ else
+ range = 1:((nfft/2)+1);
+ 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
+ idx = [nfft/2+2:nfft 1:nfft/2+1];
+ end
+ pspec = pspec(idx);
+ w = w(range);
+
+ if rem then
+ w(1:(nfft-1)/2) = w(1:(nfft-1)/2) - fs;
+ else
+ w(1:nfft/2-1) = w(1:nfft/2-1) - fs;
+ end
+ end
+ end
+
+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
+ // frequency response is done at n points in [0,fs) using fft algorithm
+ //
+ // Similar to MATLAB's freqz(b,a,n,'whole',fs)
+ if isempty(fs) then
+ fs=1;
+ end
+ 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);
+ b = [b; zeroPad];
+
+
+ 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/poly2ac.bin b/macros/poly2ac.bin
new file mode 100644
index 0000000..5bdccd5
Binary files /dev/null and b/macros/poly2ac.bin differ
diff --git a/macros/poly2ac.sci b/macros/poly2ac.sci
new file mode 100644
index 0000000..8b74b5c
--- /dev/null
+++ b/macros/poly2ac.sci
@@ -0,0 +1,42 @@
+function r = poly2ac(a,efinal)
+// Convert prediction polynomial to autocorrelation sequence.
+//Run rlevinson.sci before running this
+// Calling Sequence
+// R = poly2ac(a,efinal)
+//
+// Parameters
+// a: input prediction polynomial with 1st element 1 (if not, poly2ac normalizes it to 1 before proceeding).
+// efinal: input prediction error
+// r: output autocorrelation sequence
+//
+// Description
+// This function obtains the underlying autocorrelation sequence that would best fit a linear prediction filter described by the
+// denominator polynomial and the numerator scaling. The filter is H(z) = efinal/(a(1) + a(2) x z a(3) x z^2 ... a(n) x z^n-1)
+//
+// Examples
+// a = [1.0000 0.4288 0.76 0.0404 -0.02];
+// efinal = 0.2; // Step prediction error
+// r = poly2ac(a,efinal) // Autocorrelation sequence
+//
+// See also
+// ac2poly
+// poly2rc
+// rc2poly
+// rc2ac
+// ac2rc
+//
+// Author: Parthe Pandit
+//
+// Bibliography
+// S. Kay, Modern Spectral Estimation, Prentice Hall, N.J., 1987, Chapter 6.
+
+ //errcheck 1: Check for input format of polynomial
+ if (size(a,1) > 1 & size(a,2) > 1) then
+ error("Input polynomial has to be a 1-dimensional array")
+ end
+ if (length(efinal) > 1) then
+ error("Input efinal has to be a scalar")
+ end
+ r = rlevinson(a,efinal);
+
+endfunction
diff --git a/macros/poly2lsf.bin b/macros/poly2lsf.bin
new file mode 100644
index 0000000..35db930
Binary files /dev/null and b/macros/poly2lsf.bin differ
diff --git a/macros/poly2lsf.sci b/macros/poly2lsf.sci
new file mode 100644
index 0000000..69288f3
--- /dev/null
+++ b/macros/poly2lsf.sci
@@ -0,0 +1,111 @@
+function lsf=poly2lsf(a)
+
+
+//poly2lsf Prediction polynomial to line spectral frequencies.
+
+// Calling Sequence
+// lsf = poly2lsf(a)
+// Parameters
+// 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];
+// lsf = poly2lsf(X)
+// See also
+//
+// Author
+// Jitendra Singh
+//modified to match MATLAb o/p
+if(find(a(1,1)==0)==1) then
+ error ("Input to ROOTS must not contain NaN or Inf");
+end //end of modification
+
+
+if or(type(a)==10) then
+ error ('The polynomial must have all roots inside of the unit circle.')
+end
+
+
+
+if (size(a,1) > 1) & (size(a,2) > 1)
+ error('The prediction polynomial must be stored in a vector.')
+end
+
+
+if ~isreal(a) then
+ error('Line spectral frequencies are not defined for complex polynomials.')
+end
+
+if (max(abs(roots(a))) >= 1) then
+ error('The polynomial must have all roots inside of the unit circle.');
+end
+
+if a(1) ~= 1 then
+ a = a./a(1);
+end
+
+a=a(:);
+p = length(a)-1;
+a1 = [a;0];
+a2 = a1($:-1:1);
+pp = a1-a2;
+qq = a1+a2;
+
+if (p-fix(p./2).*2)~=0 then // Odd order
+ //////////////////////////////
+ aa=[1 0 -1];
+ [m,n] = size(pp);
+ n = max(m,n);
+ 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);
+ 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
+
+ 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);
+
+ap =atan(imag(r_p(1:2:$)),real(r_p(1:2:$)));
+aq = atan(imag(r_q(1:2:$)),real(r_q(1:2:$)));
+
+lsf = mtlb_sort([ap;aq]);
+endfunction
diff --git a/macros/poly2rc.bin b/macros/poly2rc.bin
new file mode 100644
index 0000000..69952b4
Binary files /dev/null and b/macros/poly2rc.bin differ
diff --git a/macros/poly2rc.sci b/macros/poly2rc.sci
new file mode 100644
index 0000000..cfdbec6
--- /dev/null
+++ b/macros/poly2rc.sci
@@ -0,0 +1,75 @@
+function [kr, R0]=poly2rc(a, efinal)
+
+//poly2rc function convert prediction polynomial to reflection coefficients.
+// Calling Sequence
+// kr = poly2rc(a)
+// [kr, R0] = rc2poly(a, efinal)
+
+// Parameters
+// a: prediction polynomial.
+// efinal: final prediction error.
+// kr: Return refelection coefficient.
+// R0: Return the zero lag autocorrelation, R0.
+
+// Examples
+//X = [7 6 5 8 3 6]
+// [kr, R0] = poly2rc(X)
+//
+// See also
+//
+// Author
+// Jitendra Singh
+// modified to handle empty vector as i/p by Debdeep Dey
+ if or(type(a)==10) then
+ error ('Input arguments must be double.')
+end
+
+
+ if (size(a,1) > 1) & (size(a,2) > 1)
+ error ('The prediction polynomial must be stored in a vector.')
+ end
+
+ if argn(2)==1 | isempty(efinal) then
+ efinal=0;
+ end
+
+ if length(a)<=1 then
+ kr= [];
+ R0=efinal;
+ end
+
+ if a(1) ==0 then
+ error ('Leading coefficient cannot be zero.')
+ end
+ a=a(:)./a(1);
+
+ n=length(a)-1;
+ e=zeros(n,1);
+ if(n>=1) then
+ e(n)=efinal;
+ kr(n)=a($);
+ a=a';
+ end
+
+ if(n>=1) then
+ for j= (n-1):-1:1
+
+ ee=a($)
+
+ a = (a-kr(j+1)*flipdim(a,2,1))/(1-kr(j+1)^2);
+
+ a=a(1:$-1)
+ kr(j)=a($);
+
+ econj=conj(ee)
+ econj=econj'
+ e(j) = e(j+1)/(1.-(econj.*ee));
+
+ end
+ R0 = e(1)./(1-abs(kr(1))^2);
+ else
+ R0=efinal;
+ end
+
+
+endfunction
diff --git a/macros/polyscale.bin b/macros/polyscale.bin
new file mode 100644
index 0000000..7d77a5c
Binary files /dev/null and b/macros/polyscale.bin differ
diff --git a/macros/polyscale.sci b/macros/polyscale.sci
new file mode 100644
index 0000000..9073e7a
--- /dev/null
+++ b/macros/polyscale.sci
@@ -0,0 +1,21 @@
+// polyscale Scaling roots of a polynomial
+// scales the roots of a polynomial in the z plane
+//Syntax:
+//b = polyscale(a,alpha)
+// where
+//a is the vector containing the polynomial coefficients
+// alpha is the scaling vector
+
+// Author
+//Debdeep Dey
+function b = polyscale(a,alpha)
+//errcheck1
+if(min(size(a))>1) then
+ error('Input polynomial must be an array')
+end
+if type(a)==10 then
+ error("Input cannot be of type char");
+end
+ b = a .* (alpha .^ (0:length(a)-1));
+
+endfunction
diff --git a/macros/polystab.bin b/macros/polystab.bin
new file mode 100644
index 0000000..09a8acb
Binary files /dev/null and b/macros/polystab.bin differ
diff --git a/macros/polystab.sci b/macros/polystab.sci
new file mode 100644
index 0000000..84e42d4
--- /dev/null
+++ b/macros/polystab.sci
@@ -0,0 +1,21 @@
+function b = polystab(a)
+//This function stabilizes the polynomial transfer function.
+//Calling Sequence
+//b = polystab(a)
+//Parameters
+//a:
+//Description
+//This is an Octave function.
+//This function stabilizes the polynomial transfer function by replacing all roots outside the unit circle with their reflection inside the unit circle.
+//Examples
+//polystab([1,3,5])
+//ans =
+// 1. 0.6 0.2
+
+funcprot(0);
+rhs = argn(2)
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+b = callOctave("polystab",a)
+endfunction
diff --git a/macros/polyval.bin b/macros/polyval.bin
new file mode 100644
index 0000000..1375c8e
Binary files /dev/null and b/macros/polyval.bin differ
diff --git a/macros/polyval.sci b/macros/polyval.sci
new file mode 100755
index 0000000..bcd5dfb
--- /dev/null
+++ b/macros/polyval.sci
@@ -0,0 +1,70 @@
+function [y, delta] = polyval(p,x,S,mu)
+
+// Check input is a vector
+if ~(isvector(p) | isempty(p))
+ error(message('polyval:InvalidP'));
+end
+
+nc = length(p);
+if isscalar(x) & (argn(2) < 3) & nc>0 & isfinite(x) & all(isfinite(p(:)))
+ // Make it scream for scalar x. Polynomial evaluation can be
+ // implemented as a recursive digital filter.
+ y = filter(1,[1 -x],p);
+ y = y(nc);
+ return
+end
+
+siz_x = size(x);
+if argn(2) == 4
+ x = (x - mu(1))/mu(2);
+end
+
+// Use Horner's method for general case where X is an array.
+y = zeros(size(x,1),size(x,2));
+if nc>0, y(:) = p(1); end
+for i=2:nc
+ y = x .* y + p(i);
+end
+
+if argn(1) > 1
+ if argn(2) < 3 | isempty(S)
+ error(message('polyval:RequiresS'));
+ end
+
+ // Extract parameters from S
+ if isstruct(S), // Use output structure from polyfit.
+ R = S.R;
+ df = S.df;
+ normr = S.normr;
+ else // Use output matrix from previous versions of polyfit.
+ [ms,ns] = size(S);
+ if (ms ~= ns+2) | (nc ~= ns)
+ error(message('polyval:SizeS'));
+ end
+ R = S(1:nc,1:nc);
+ df = S(nc+1,1);
+ normr = S(nc+2,1);
+ end
+
+ // Construct Vandermonde matrix for the new X.
+ x = x(:);
+ V(:,nc) = ones(length(x),1,class(x));
+ for j = nc-1:-1:1
+ V(:,j) = x.*V(:,j+1);
+ end
+
+ // S is a structure containing three elements: the triangular factor of
+ // the Vandermonde matrix for the original X, the degrees of freedom,
+ // and the norm of the residuals.
+ E = V/R;
+ e = sqrt(1+sum(E.*E,2));
+ if df == 0
+ warning(message('polyval:ZeroDOF'));
+ delta = Inf(size(e));
+ else
+ delta = normr/sqrt(df)*e;
+ end
+ delta = reshape(delta,siz_x);
+end
+endfunction
+
diff --git a/macros/polyval.sci~ b/macros/polyval.sci~
new file mode 100755
index 0000000..8301ff5
--- /dev/null
+++ b/macros/polyval.sci~
@@ -0,0 +1,69 @@
+function [y, delta] = polyval(p,x,S,mu)
+
+// Check input is a vector
+if ~(isvector(p) | isempty(p))
+ error(message('polyval:InvalidP'));
+end
+
+nc = length(p);
+if isscalar(x) & (argn(2) < 3) & nc>0 & isfinite(x) & all(isfinite(p(:)))
+ // Make it scream for scalar x. Polynomial evaluation can be
+ // implemented as a recursive digital filter.
+ y = filter(1,[1 -x],p);
+ y = y(nc);
+ return
+end
+
+siz_x = size(x);
+if argn(2) == 4
+ x = (x - mu(1))/mu(2);
+end
+
+// Use Horner's method for general case where X is an array.
+y = zeros(size(x,1),size(x,2));
+if nc>0, y(:) = p(1); end
+for i=2:nc
+ y = x .* y + p(i);
+end
+
+if argn(1) > 1
+ if argn(2) < 3 | isempty(S)
+ error(message('polyval:RequiresS'));
+ end
+
+ // Extract parameters from S
+ if isstruct(S), // Use output structure from polyfit.
+ R = S.R;
+ df = S.df;
+ normr = S.normr;
+ else // Use output matrix from previous versions of polyfit.
+ [ms,ns] = size(S);
+ if (ms ~= ns+2) | (nc ~= ns)
+ error(message('polyval:SizeS'));
+ end
+ R = S(1:nc,1:nc);
+ df = S(nc+1,1);
+ normr = S(nc+2,1);
+ end
+
+ // Construct Vandermonde matrix for the new X.
+ x = x(:);
+ V(:,nc) = ones(length(x),1,class(x));
+ for j = nc-1:-1:1
+ V(:,j) = x.*V(:,j+1);
+ end
+
+ // S is a structure containing three elements: the triangular factor of
+ // the Vandermonde matrix for the original X, the degrees of freedom,
+ // and the norm of the residuals.
+ E = V/R;
+ e = sqrt(1+sum(E.*E,2));
+ if df == 0
+ warning(message('polyval:ZeroDOF'));
+ delta = Inf(size(e));
+ else
+ delta = normr/sqrt(df)*e;
+ end
+ delta = reshape(delta,siz_x);
+end
+
diff --git a/macros/pow2db.bin b/macros/pow2db.bin
new file mode 100644
index 0000000..7cc69ea
Binary files /dev/null and b/macros/pow2db.bin differ
diff --git a/macros/pow2db.sci b/macros/pow2db.sci
new file mode 100644
index 0000000..5be0941
--- /dev/null
+++ b/macros/pow2db.sci
@@ -0,0 +1,32 @@
+//POW2DB Power to dB conversion
+//YDB = POW2DB(Y) convert the data Y into its corresponding dB value YDB
+//Example:
+//Calculate ratio of 2000W to 2W in decibels
+//y1 = pow2db(2000/2) //Answer in db
+//Author : Debdeep Dey
+function [ydb]=pow2db(y)
+rhs = argn(2)
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+[r,c]=size(y);
+if (find(real(y(:))<0))==[] then
+ if abs(y(:))>=0 then
+ for i=1:r
+ for j=1:c
+ if abs(y(i,j))>0 then
+ ydb(i,j)=10*log10(y(i,j));
+ else
+ ydb(i,j)=-%inf;
+ end
+ end
+ end
+
+
+ end
+else
+ error("The power value must be non-negative")
+end
+
+endfunction
+
diff --git a/macros/primitive.bin b/macros/primitive.bin
new file mode 100644
index 0000000..d83a446
Binary files /dev/null and b/macros/primitive.bin differ
diff --git a/macros/primitive.sci b/macros/primitive.sci
new file mode 100644
index 0000000..bdb4560
--- /dev/null
+++ b/macros/primitive.sci
@@ -0,0 +1,32 @@
+function y = primitive (f, t, x)
+//This function calculates the primitive of a given function supplied as input.
+//Calling Sequence
+//y = primitive(f, t)
+//y = primitive(f, t, x)
+//Parameters
+//f:
+//t:
+//x
+//Description
+//This is an Octave function.
+//This function calculates the primitive of a given function supplied as input.
+//The second parameter t is a vector at which the output is evaluated (at the points t). This vector should be ascending and ordered.
+//The function approximates the primitive (indefinite integral) of the univariate function handle f with constant of integration x.
+//Examples
+//primitive([1,4,5],3,9)
+//ans =
+// 9.
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<2 | rhs>3)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 2 then
+ y = callOctave("primitive",f, t)
+ case 3 then
+ y = callOctave("primitive",f, t, x)
+ end
+endfunction
+
diff --git a/macros/prony.bin b/macros/prony.bin
new file mode 100644
index 0000000..12ea4f9
Binary files /dev/null and b/macros/prony.bin differ
diff --git a/macros/prony.sci b/macros/prony.sci
new file mode 100644
index 0000000..9f0fb9c
--- /dev/null
+++ b/macros/prony.sci
@@ -0,0 +1,39 @@
+//Prony's method for time-domain design of IIR Filters
+//[b,a]=prony(h,nb,na)
+//where b= coefficients of the numerator of the TF
+// a=coefficients of the denominator of the TF
+// h=impulse response of the digital filter
+// nb=number of zeros
+// na=number of poles
+//Reference : T.W. Parks and C.S. Burrus, Digital Filter Design,
+// John Wiley and Sons, 1987, p226.
+//Author
+//Debdeep Dey
+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
+ K = max(M,N)+1;
+ h(K+1) = 0;
+end
+c = h(1);
+if c==0 //avoid division by zero
+ c=1;
+end
+H = toeplitz(h/c,[1 zeros(1,K)]);
+//K+1 by N+1
+if (K > N)
+ H(:,(N+2):(K+1)) = [];
+end
+//Partition H matrix
+H1 = H(1:(M+1),:); //M+1 by N+1
+h1 = H((M+2):(K+1),1); //K-M by 1
+H2 = H((M+2):(K+1),2:(N+1)); //K-M by N
+a = [1; -H2\h1].';
+b = c*a*H1.';
+
+endfunction
+
diff --git a/macros/pulseperiod.bin b/macros/pulseperiod.bin
new file mode 100644
index 0000000..b995439
Binary files /dev/null and b/macros/pulseperiod.bin differ
diff --git a/macros/pulseperiod.sci b/macros/pulseperiod.sci
new file mode 100644
index 0000000..aa43455
--- /dev/null
+++ b/macros/pulseperiod.sci
@@ -0,0 +1,416 @@
+function [p, initialcross, finalcross, nextcross, midreference]= pulseperiod(x, varargin)
+
+ // This function estimate pulse period of real vector X.
+ // Calling Sequence
+ // p=pulseperiod(x)
+ // p=pulseperiod(x, Fs)
+ // p=pulseperiod(x, t)
+ // p=pulseperiod (x, t, 'Polarity', pol)
+ // p=pulseperiod(x, t, 'MidPercentReferenceLevel', N )
+ // p=pulseperiod(x, t, 'Tolerance', M)
+ // p=pulseperiod(x, t,'StateLevels', O)
+
+ // [p initialcross finalcross nextcross midreference]=pulseperiod(x)
+ // [p initialcross finalcross nextcross midreference]=pulseperiod(x, t)
+ // [p initialcross finalcross nextcross midreference]=pulseperiod(x, t)
+ // [p initialcross finalcross nextcross midreference]=pulseperiod(x, t, 'Polarity', pol)
+ // [p initialcross finalcross nextcross midreference]=pulseperiod(x, t, 'MidPercentReferenceLevel', N )
+ // [p initialcross finalcross nextcross midreference]= pulseperiod(x, t, 'Tolerance', M)
+ // [p initialcross finalcross nextcross midreference]= pulseperiod(x, t,'StateLevels', O)
+ // [p initialcross finalcross nextcross midreference]= pulseperiod(x, t,'StateLevels', O, 'fig', 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.
+ // t: defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.
+ // Polarity: specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive'
+ // MidPercentReferenceLevel: specify the mid percent reference leves as a percentage, default value of N is 50.
+ // Tolerance: define the tolerance value as real scaler value, where default value of M is 2.0.
+ // StateLevels: define the lower and upper state levels as two element real vector.
+ // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.
+ // p: returns a vector of difference between the mid-crossings of the initial transition of each positive-polarity pulse and the next positive-going transition
+ // initialcross: returns a vector of initial cross values of bilevel waveform transitions X
+ // finalcross: returns a vector of final cross values of bilevel waveform transitions X
+ // nextcross: returns a vector of next cross values of bilevel waveform transitions X
+ // midreference: return mid reference value corrosponding to mid percenr reference value.
+
+ // Examples
+ // x=[1.2, 5, 10, -20, 12]
+ //t=1:length(x)
+ //p=pulseperiod(x, t)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+ // run statelevels and midcross function before running risetime function.
+
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+end
+
+ if length(varargin)==0 then
+ varargin=varargin;
+ end
+
+ sindex=[];
+if length(varargin)>=1 then
+a=1;
+for i=1:length(varargin)
+ if type(varargin(i))==10 then
+ sindex(a)=i;
+ a=a+1;
+ end
+end
+end
+
+
+pol='POSITIVE';
+polidx=[];
+fig='OFF'
+index_on=[];
+if (~isempty(sindex)) then
+ for j=1:length(sindex)
+ select convstr(varargin(sindex(j)), 'u') // validating input variable names
+ 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);
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+
+ error('parameter StateLevels required a value.')
+
+
+ elseif type(varargin(sindex(j)+1))==10 then
+
+ error('Expected STATELEVELS to be one of these types: double, Instead its type was char.')
+ end
+
+ case {'MIDPERCENTREFERENCELEVEL'}
+
+ if length(varargin) <=sindex(j) then
+ error(strcat(['parameter MidPercentRefernceLevel required a value.']));
+ end
+
+ if type(varargin(sindex(j)+1))==1 then
+ midpercentval= varargin(sindex(j)+1);
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+ error('parameter MidPercentRefernceLevel required a value.')
+
+ elseif type(varargin(sindex(j)+1))==10 then
+ error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.')
+ end
+
+
+ case {'TOLERANCE'}
+
+ 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);
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+
+ error('parameter Tolerance required a value.');
+
+ elseif type(varargin(sindex(j)+1))==10 then
+
+ error('Expected Tolerance to be one of these types: double, Instead its type was char.');
+ end
+
+
+ case {'FIG'}
+
+ if length(varargin) <=sindex(j) then
+ error(strcat(['parameter fig required a value.']));
+ end
+
+ if type(varargin(sindex(j)+1))==1 then
+ error ('Expected fig to match one of these strings: on or off');
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+ error('parameter fig required a value.')
+ else
+ fig= convstr(varargin(sindex(j)+1), 'u');
+
+ end
+
+
+ if fig == 'OFF' | fig == 'ON' then
+ else
+ error('Expected fig to match one of these strings: on or off');
+ end
+
+
+
+ case{'ON'}
+ index_on=sindex(j)
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(sindex(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+ case{'OFF'}
+
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(sindex(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+
+
+
+ case{'POLARITY'}
+
+ if length(varargin)<=sindex(j) then
+ error ('Parameter polarity requires a value.')
+ end
+
+ if type( varargin(sindex(j)+1))==1 then
+ error ('POLARITY must be either ''Positive'' or ''Negative''.')
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' then
+
+ error ('Parameter polarity requires a value.')
+
+
+ elseif convstr(varargin(sindex(j)+1), 'u') ~= 'POSITIVE' & convstr(varargin(sindex(j)+1), 'u')~= 'NEGATIVE' then
+
+ error ('POLARITY must be either ''Positive'' or ''Negative''.');
+
+ else
+ polidx=sindex(j);
+ end
+
+
+ case {'POSITIVE'}
+
+ if j==1 then
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY'
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ else
+ polinputidx= sindex(j);
+
+ pol= convstr(varargin (sindex(j)), 'u') ;
+ end
+
+ case {'NEGATIVE'}
+
+ if j==1 then
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY'
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ else
+ polinputidx= sindex(j);
+
+ pol= convstr(varargin (sindex(j)), 'u') ;
+ end
+
+ else
+ error(strcat(['Invalid optional argument'," ", varargin(sindex(j))]));
+ end // switch
+ end // for
+ end // if
+//
+
+if length(index_on)>0 then
+ varargin(index_on)='OFF';
+end
+
+
+if length(polidx)>0 then
+ varargin(polidx)=null();
+ varargin(polinputidx-1)=null();
+end
+
+
+ [crossval midref levels t tolerance]= midcross(x, varargin(:));
+
+ upperbound= levels(2)- (tolerance/100)*(levels(2)-levels(1));
+ mostupperbound=levels(2)+ (tolerance/100)*(levels(2)-levels(1));
+ lowerbound= levels(1)+ (tolerance/100)*(levels(2)-levels(1));
+ mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1));
+
+ int_pos=[];
+ final_pos=[];
+ int_neg=[];
+ final_neg=[];
+ nextcross_pos=[];
+nextcross_neg=[];
+
+if length(crossval)>=2 then
+
+if x(1)>midref then
+
+ int_pos=crossval(2:2:$);
+ final_pos=crossval(3:2:$);
+ int_neg=crossval(1:2:$);
+ final_neg=crossval(2:2:$);
+
+else
+
+ int_pos=crossval(1:2:$);
+ final_pos=crossval(2:2:$);
+ int_neg=crossval(2:2:$);
+ final_neg-crossval(3:2:$);
+
+end
+
+
+
+if length(int_pos)>=2 then
+ nextcross_pos=int_pos(2:$);
+end
+
+if length(int_neg)>=2 then
+ nextcross_neg=int_neg(2:$);
+ end
+
+
+
+
+if length(int_pos)>length(final_pos) then
+ int_pos=int_pos(1:($-1))
+elseif length(int_neg)>length(final_neg) then
+ int_neg=int_neg(1:($-1))
+ end
+
+
+
+
+
+
+ if length(int_pos)>length(nextcross_pos) then
+ int_pos=int_pos(1:($-1))
+
+ end
+ if length(final_pos)>length(nextcross_pos)
+ final_pos=final_pos(1:($-1))
+
+ end
+
+ if length(int_neg)>length(nextcross_neg) then
+ int_neg=int_neg(1:($-1));
+ end
+ if length(final_neg)>length(nextcross_neg) then
+ final_neg=final_neg(1:($-1));
+ end
+
+
+end
+
+
+p=[];
+
+ if pol=='POSITIVE' then // checking the input variable polarity
+
+ p= nextcross_pos-int_pos;
+
+
+ initialcross=int_pos;
+ finalcross=final_pos;
+ nextcross=nextcross_pos;
+ else
+ p= nextcross_neg-int_neg;
+
+
+ initialcross=int_neg;
+ finalcross=final_neg;
+ nextcross=nextcross_neg;
+
+
+ end
+
+midreference=midref; // return midreference value
+
+ if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels
+
+ if length(p)==0 then
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+ // xtitle('', 'Time (second)','Level (Volts)' );
+ plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,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)
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?')
+
+
+ else
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+
+ plot(t,midreference * ones(1, length(t)),'-g', 'LineWidth',0.5)
+
+
+ //n=length(finalcross);
+
+
+ rects=[initialcross(1:2:$); levels(2)*ones(p(1:2:$)); p(1:2:$); (levels(2)-levels(1))*ones(p(1:2:$))]
+
+
+ col=-10*ones(p(1:2:$));
+
+ midc=[nextcross, initialcross, finalcross];
+ midcross=gsort(midc, 'c','i' )
+
+ plot(midcross, midreference*ones(midcross), "r*", 'MarkerSize',15);
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5)
+
+ plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5)
+
+ xrects(rects, col);
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["pulse period"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;5], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?')
+
+ end
+ end
+//
+//
+endfunction
diff --git a/macros/pulsesep.bin b/macros/pulsesep.bin
new file mode 100644
index 0000000..3da9b7a
Binary files /dev/null and b/macros/pulsesep.bin differ
diff --git a/macros/pulsesep.sci b/macros/pulsesep.sci
new file mode 100644
index 0000000..f64494b
--- /dev/null
+++ b/macros/pulsesep.sci
@@ -0,0 +1,412 @@
+function [s, initialcross, finalcross, nextcross, midreference]= pulsesep(x, varargin)
+
+ // This function estimate pulse separation between bilevel waveform pulses.
+ // Calling Sequence
+ // s=pulsesep(x)
+ // s=pulsesep(x, Fs)
+ // s=pulsesep(x, t)
+ // s=pulsesep (x, t, 'Polarity', pol)
+ // s=pulsesep(x, t, 'MidPercentReferenceLevel', N )
+ // s=pulsesep(x, t, 'Tolerance', M)
+ // s=pulsesep(x, t,'StateLevels', [O 1])
+
+ // [s initialcross finalcross nextcross midreference]=pulsesep(x)
+ // [s initialcross finalcross nextcross midreference]=pulsesep(x, Fs)
+ // [s initialcross finalcross nextcross midreference]=pulsesep(x, t)
+ // [s initialcross finalcross nextcross midreference]=pulsesep(x, t, 'Polarity', pol)
+ // [s initialcross finalcross nextcross midreference]=pulsesep(x, t, 'MidPercentReferenceLevel', N )
+ // [s initialcross finalcross nextcross midreference]= pulsesep(x, t, 'Tolerance', M)
+ // [s initialcross finalcross nextcross midreference]= pulsesep(x, t,'StateLevels', O)
+ // [s initialcross finalcross nextcross midreference]= pulsesep(x, t,'StateLevels', O, 'fig', 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.
+ // t: defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.
+ // Polarity: specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive'
+ // MidPercentReferenceLevel: specify the mid percent reference leves as a percentage, default value of N is 50.
+ // Tolerance: define the tolerance value as real scaler value, where default value of M is 2.0.
+ // StateLevels: define the lower and upper state levels as two element real vector.
+ // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.
+ // s: returns a vector of differences between the mid-crossings of each final negative-going transition of every positive-polarity pulse and the next positive-going transition.
+ // initialcross: returns a vector of initial cross values of bilevel waveform transitions X
+ // finalcross: returns a vector of final cross values of bilevel waveform transitions X
+ // nextcross: returns a vector of next cross values of bilevel waveform transitions X
+ // midreference: return mid reference value corrosponding to mid percenr reference value.
+
+ // Examples
+ // x=[1.2, 5, 10, -20, 12]
+ //t=1:length(x)
+ //s=pulsesep(x, t)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+ // run statelevels and midcross function before running risetime function.
+
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+end
+
+ if length(varargin)==0 then
+ varargin=varargin;
+ end
+
+ sindex=[];
+if length(varargin)>=1 then
+a=1;
+for i=1:length(varargin)
+ if type(varargin(i))==10 then
+ sindex(a)=i;
+ a=a+1;
+ end
+end
+end
+
+
+pol='POSITIVE';
+polidx=[];
+fig='OFF'
+index_on=[];
+if (~isempty(sindex)) then
+ for j=1:length(sindex)
+ select convstr(varargin(sindex(j)), 'u') // validating input variable names
+ 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);
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+
+ error('parameter StateLevels required a value.')
+
+
+ elseif type(varargin(sindex(j)+1))==10 then
+
+ error('Expected STATELEVELS to be one of these types: double, Instead its type was char.')
+ end
+
+ case {'MIDPERCENTREFERENCELEVEL'}
+ if length(varargin) <=sindex(j) then
+ error(strcat(['parameter MidPercentRefernceLevel required a value.']));
+ end
+
+ if type(varargin(sindex(j)+1))==1 then
+ midpercentval= varargin(sindex(j)+1);
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+ error('parameter MidPercentRefernceLevel required a value.')
+
+ elseif type(varargin(sindex(j)+1))==10 then
+ error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.')
+ end
+
+ case {'TOLERANCE'}
+
+ 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);
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+
+ error('parameter Tolerance required a value.');
+
+ elseif type(varargin(sindex(j)+1))==10 then
+
+ error('Expected Tolerance to be one of these types: double, Instead its type was char.');
+ end
+
+
+
+ case {'FIG'}
+
+ if length(varargin) <=sindex(j) then
+ error(strcat(['parameter fig required a value.']));
+ end
+
+ if type(varargin(sindex(j)+1))==1 then
+ error ('Expected fig to match one of these strings: on or off');
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+ error('parameter fig required a value.')
+ else
+ fig= convstr(varargin(sindex(j)+1), 'u');
+
+ end
+
+
+ if fig == 'OFF' | fig == 'ON' then
+ else
+ error('Expected fig to match one of these strings: on or off');
+ end
+
+
+
+ case{'ON'}
+ index_on=sindex(j)
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(sindex(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+ case{'OFF'}
+
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(sindex(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+
+
+
+ case{'POLARITY'}
+
+ if length(varargin)<=sindex(j) then
+ error ('Parameter polarity requires a value.')
+ end
+
+ if type( varargin(sindex(j)+1))==1 then
+ error ('POLARITY must be either ''Positive'' or ''Negative''.')
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' then
+
+ error ('Parameter polarity requires a value.')
+
+
+ elseif convstr(varargin(sindex(j)+1), 'u') ~= 'POSITIVE' & convstr(varargin(sindex(j)+1), 'u')~= 'NEGATIVE' then
+
+ error ('POLARITY must be either ''Positive'' or ''Negative''.');
+
+ else
+ polidx=sindex(j);
+ end
+
+
+ case {'POSITIVE'}
+
+ if j==1 then
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY'
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ else
+ polinputidx= sindex(j);
+
+ pol= convstr(varargin (sindex(j)), 'u') ;
+ end
+
+ case {'NEGATIVE'}
+
+ if j==1 then
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY'
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ else
+ polinputidx= sindex(j);
+
+ pol= convstr(varargin (sindex(j)), 'u') ;
+ end
+
+ else
+ error(strcat(['Invalid optional argument'," ", varargin(sindex(j))]));
+ end // switch
+ end // for
+ end // if
+//
+
+if length(index_on)>0 then
+ varargin(index_on)='OFF';
+end
+
+
+if length(polidx)>0 then
+ varargin(polidx)=null();
+ varargin(polinputidx-1)=null();
+end
+
+
+ [crossval midref levels t tolerance]= midcross(x, varargin(:));
+
+ upperbound= levels(2)- (tolerance/100)*(levels(2)-levels(1));
+ mostupperbound=levels(2)+ (tolerance/100)*(levels(2)-levels(1));
+ lowerbound= levels(1)+ (tolerance/100)*(levels(2)-levels(1));
+ mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1));
+
+ int_pos=[];
+ final_pos=[];
+ int_neg=[];
+ final_neg=[];
+ nextcross_pos=[];
+nextcross_neg=[];
+
+if length(crossval)>=2 then
+
+if x(1)>midref then
+
+ int_pos=crossval(2:2:$);
+ final_pos=crossval(3:2:$);
+ int_neg=crossval(1:2:$);
+ final_neg=crossval(2:2:$);
+
+else
+
+ int_pos=crossval(1:2:$);
+ final_pos=crossval(2:2:$);
+ int_neg=crossval(2:2:$);
+ final_neg-crossval(3:2:$);
+
+end
+
+
+
+if length(int_pos)>=2 then
+ nextcross_pos=int_pos(2:$);
+end
+
+if length(int_neg)>=2 then
+ nextcross_neg=int_neg(2:$);
+ end
+
+
+
+
+if length(int_pos)>length(final_pos) then
+ int_pos=int_pos(1:($-1))
+elseif length(int_neg)>length(final_neg) then
+ int_neg=int_neg(1:($-1))
+ end
+
+
+
+
+
+
+ if length(int_pos)>length(nextcross_pos) then
+ int_pos=int_pos(1:($-1))
+
+ end
+ if length(final_pos)>length(nextcross_pos)
+ final_pos=final_pos(1:($-1))
+
+ end
+
+ if length(int_neg)>length(nextcross_neg) then
+ int_neg=int_neg(1:($-1));
+ end
+
+ if length(final_neg)>length(nextcross_neg) then
+ final_neg=final_neg(1:($-1));
+ end
+
+
+end
+
+
+
+s=[];
+
+
+ if pol=='POSITIVE' then
+ s=nextcross_pos-final_pos;
+ initialcross=int_pos;
+ finalcross=final_pos;
+ nextcross=nextcross_pos;
+
+ else
+
+ s=nextcross_neg-final_neg;
+ initialcross=int_neg;
+ finalcross=final_neg;
+ nextcross=nextcross_neg;
+
+ end
+
+midreference=midref;
+
+ if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels
+
+ if length(s)==0 then
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+ // xtitle('', 'Time (second)','Level (Volts)' );
+ plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,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)
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?')
+
+
+ else
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+
+ plot(t,midreference * ones(1, length(t)),'-g', 'LineWidth',0.5)
+
+
+ //n=length(finalcross);
+
+
+ rects=[finalcross; levels(2)*ones(s); s; (levels(2)-levels(1))*ones(s)]
+
+
+ col=-10*ones(s);
+
+ midc=[nextcross, finalcross, initialcross];
+ midcross=gsort(midc, 'c','i' )
+
+ plot(midcross, midreference*ones(midcross), "r*", 'MarkerSize',15);
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5)
+
+ plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5)
+
+ xrects(rects, col);
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["pulse seperation"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;5], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?')
+
+ end
+ end
+//
+//
+endfunction
diff --git a/macros/pulsewidth.bin b/macros/pulsewidth.bin
new file mode 100644
index 0000000..6bb29af
Binary files /dev/null and b/macros/pulsewidth.bin differ
diff --git a/macros/pulsewidth.sci b/macros/pulsewidth.sci
new file mode 100644
index 0000000..dad4a66
--- /dev/null
+++ b/macros/pulsewidth.sci
@@ -0,0 +1,371 @@
+function [w, initialcross, finalcross, midreference]=pulsewidth(x, varargin)
+
+ // This function estimate pulse width of real vector X.
+ // Calling Sequence
+ // w=pulsewidth(x)
+ // w=pulsewidth(x, Fs)
+ // w=pulsewidth(x, t)
+ // w=pulsewidth (x, t, 'Polarity', pol)
+ // w=pulsewidth(x, t, 'MidPercentReferenceLevel', N )
+ // w=pulsewidth(x, t, 'Tolerance', M)
+ // w=pulsewidth(x, t,'StateLevels', O)
+
+ // [w initialcross finalcross midreference]=pulsewidth(x)
+ // [w initialcross finalcross midreference]=pulsewidth(x, Fs)
+ // [w initialcross finalcross midreference]=pulsewidth(x, t)
+ // [w initialcross finalcross midreference]=pulsewidth(x, t, 'Polarity', pol)
+ // [w initialcross finalcross midreference]=pulsewidth(x, t, 'MidPercentReferenceLevel', N )
+ // [w initialcross finalcross midreference]= pulsewidth(x, t, 'Tolerance', M)
+ // [w initialcross finalcross midreference]= pulsewidth(x, t,'StateLevels', O)
+ // [w initialcross finalcross midreference]= pulsewidth(x, t,'StateLevels', O, 'fig', on or off)
+ //
+ // Parameters
+ // x: real vector.
+ // Fs: specifies the sample rate, Fs, as a positive scalar, where the first sample instant corresponds to a time of zero.
+ // t: defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.
+ // Polarity: specify the polarity of the pulse as either 'positive' or 'negative', where the default value is 'positive'.
+ // MidPercentReferenceLevel: specify the mid percent reference leves as a percentage, default value of N is 50.
+ // Tolerance: define the tolerance value as real scaler value, where default value of M is 2.0.
+ // StateLevels: define the lower and upper state levels as two element real vector.
+ // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.
+ // w: returns a vector of difference between the mid-crossings of the initial and final transitions of each positive-polarity pulse found in the input signal.
+ // initialcross: returns a vector of initial cross values of bilevel waveform transitions X.
+ // finalcross: returns a vector of final cross values of bilevel waveform transitions X.
+ // midreference: return mid reference value corrosponding to mid percenr reference value.
+
+ // Examples
+ // x=[1.2, 5, 10, -20, 12]
+ //t=1:length(x)
+ //w=pulsewidth(x, t)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+ // run statelevels and midcross function before running risetime function.
+
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+end
+
+
+ if length(varargin)==0 then
+ varargin=varargin;
+ end
+
+ sindex=[];
+if length(varargin)>=1 then
+a=1;
+for i=1:length(varargin)
+ if type(varargin(i))==10 then
+ sindex(a)=i;
+ a=a+1;
+ end
+end
+end
+
+
+pol='POSITIVE';
+polidx=[];
+fig='OFF'
+index_on=[];
+if (~isempty(sindex)) then
+ for j=1:length(sindex)
+ select convstr(varargin(sindex(j)), 'u') // validating input variable names
+ 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);
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+
+ error('parameter StateLevels required a value.')
+
+
+ elseif type(varargin(sindex(j)+1))==10 then
+
+ error('Expected STATELEVELS to be one of these types: double, Instead its type was char.')
+ end
+
+
+ case {'MIDPERCENTREFERENCELEVEL'}
+
+ if length(varargin) <=sindex(j) then
+ error(strcat(['parameter MidPercentRefernceLevel required a value.']));
+ end
+
+ if type(varargin(sindex(j)+1))==1 then
+ midpercentval= varargin(sindex(j)+1);
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1),'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+ error('parameter MidPercentRefernceLevel required a value.')
+
+ elseif type(varargin(sindex(j)+1))==10 then
+ error('Expected MidPercentRefernceLevel to be one of these types: double, Instead its type was char.')
+ end
+
+
+
+ case {'TOLERANCE'}
+
+ 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);
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='FIG' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+
+ error('parameter Tolerance required a value.');
+
+ elseif type(varargin(sindex(j)+1))==10 then
+
+ error('Expected Tolerance to be one of these types: double, Instead its type was char.');
+ end
+
+
+ case {'FIG'}
+
+ if length(varargin) <=sindex(j) then
+ error(strcat(['parameter fig required a value.']));
+ end
+
+ if type(varargin(sindex(j)+1))==1 then
+ error ('Expected fig to match one of these strings: on or off');
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')=='STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')=='POLARITY' then
+ error('parameter fig required a value.')
+ else
+ fig= convstr(varargin(sindex(j)+1), 'u');
+
+ end
+
+
+ if fig == 'OFF' | fig == 'ON' then
+ else
+ error('Expected fig to match one of these strings: on or off');
+ end
+
+
+
+ case{'ON'}
+ index_on=sindex(j)
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(sindex(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+ case{'OFF'}
+
+ if length(varargin) == 1 then
+ error ('Unexpected input.')
+
+
+ elseif type(varargin(sindex(j)-1))==1 then
+ error ('Unexpected input.');
+ elseif convstr(varargin(sindex(j)-1), 'u')~='FIG' then
+ error('Unexpected input');
+ end
+
+
+
+
+ case{'POLARITY'}
+
+ if length(varargin)<=sindex(j) then
+ error ('Parameter polarity requires a value.')
+ end
+
+ if type( varargin(sindex(j)+1))==1 then
+ error ('POLARITY must be either ''Positive'' or ''Negative''.')
+
+ elseif type(varargin(sindex(j)+1))==10 & convstr(varargin(sindex(j)+1), 'u')== 'STATELEVELS' | convstr(varargin(sindex(j)+1), 'u')== 'MIDPERCENTREFERENCELEVEL' | convstr(varargin(sindex(j)+1), 'u')== 'TOLERANCE' | convstr(varargin(sindex(j)+1), 'u')=='FIG' then
+
+ error ('Parameter polarity requires a value.')
+
+
+ elseif convstr(varargin(sindex(j)+1), 'u') ~= 'POSITIVE' & convstr(varargin(sindex(j)+1), 'u')~= 'NEGATIVE' then
+
+ error ('POLARITY must be either ''Positive'' or ''Negative''.');
+
+ else
+ polidx=sindex(j);
+ end
+
+
+ case {'POSITIVE'}
+
+ if j==1 then
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY'
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ else
+ polinputidx= sindex(j);
+
+ pol= convstr(varargin (sindex(j)), 'u') ;
+ end
+
+ case {'NEGATIVE'}
+
+ if j==1 then
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ elseif convstr(varargin(sindex(j)-1), 'u') ~= 'POLARITY'
+ error(strcat(['Unexpected option:', " ", varargin(sindex(j))]));
+ else
+ polinputidx= sindex(j);
+
+ pol= convstr(varargin (sindex(j)), 'u') ;
+ end
+
+ else
+ error(strcat(['Invalid optional argument'," ", varargin(sindex(j))]));
+ end // switch
+ end // for
+ end // if
+//
+
+if length(index_on)>0 then
+ varargin(index_on)='OFF';
+end
+
+
+if length(polidx)>0 then
+ varargin(polidx)=null();
+ varargin(polinputidx-1)=null();
+end
+
+
+ [crossval midref levels t tolerance]= midcross(x, varargin(:));
+
+ upperbound= levels(2)- (tolerance/100)*(levels(2)-levels(1));
+ mostupperbound=levels(2)+ (tolerance/100)*(levels(2)-levels(1));
+ lowerbound= levels(1)+ (tolerance/100)*(levels(2)-levels(1));
+ mostlowerbound=levels(1)- (tolerance/100)*(levels(2)-levels(1));
+
+ int_pos=[];
+ final_pos=[];
+ int_neg=[];
+ final_neg=[];
+
+
+if length(crossval)>=2 then
+
+if x(1)>midref then
+
+ int_pos=crossval(2:2:$);
+ final_pos=crossval(3:2:$);
+ int_neg=crossval(1:2:$);
+ final_neg=crossval(2:2:$);
+
+else
+
+ int_pos=crossval(1:2:$);
+ final_pos=crossval(2:2:$);
+ int_neg=crossval(2:2:$);
+ final_neg=crossval(3:2:$);
+
+end
+
+if length(int_pos)>length(final_pos) then
+ int_pos=int_pos(1:($-1))
+elseif length(int_neg)>length(final_neg) then
+ int_neg=int_neg(1:($-1))
+ end
+
+
+end
+
+ //////////////////////////////////////////////////////////////////////////////////////////
+
+w=[];
+
+ if pol=='POSITIVE' then
+ w=final_pos-int_pos;
+ initialcross=int_pos;
+ finalcross=final_pos;
+ else
+ w=final_neg-int_neg;
+ initialcross=int_neg;
+ finalcross=final_neg;
+
+ end
+
+midreference=midref; // return midreference value
+
+ if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels
+
+
+ if length(w)==0 then
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+ // xtitle('', 'Time (second)','Level (Volts)' );
+ plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,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)
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["Signal"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[1;1], [5;2], [1;2], [5;2], [5;1], [3;2], [1;2], [3;2]], opt='?')
+
+
+ else
+
+ plot(t,x, 'LineWidth',1, 'color', 'black')
+
+ plot(t,midreference * ones(1, length(t)),'-g', 'LineWidth',0.5)
+
+ rects=[initialcross; levels(2)*ones(w); w; (levels(2)-levels(1))*ones(w)]
+
+ col=-10*ones(w);
+
+ midc=[initialcross, finalcross];
+ midcross=gsort(midc, 'c','i' )
+
+ plot(midcross, midreference*ones(midcross), "r*", 'MarkerSize',15);
+ plot(t,mostupperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,levels(2) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,upperbound * ones(1, length(t)),'--r', 'LineWidth',0.5)
+
+ plot(t,midreference * ones(1, length(t)),'-r', 'LineWidth',0.5)
+
+ plot(t,lowerbound *ones(1, length(t)),'--g', 'LineWidth',0.5)
+
+ plot(t,levels(1) * ones(1, length(t)),'--k', 'LineWidth',0.5)
+
+ plot(t,mostlowerbound * ones(1, length(t)),'--g', 'LineWidth',0.5)
+
+ xrects(rects, col);
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["pulsewidth"; "Signal"; "mid cross"; "upper boundary"; "upper state"; "lower boundary"; "mid reference"; "upper boundary"; "lower state"; "lower boundary"], [[-11; 2] , [1;1], [-10;3], [5;2], [1;2], [5;2], [5;1], [3;2],[1;2], [3;2]], opt='?')
+
+ end
+ end
+//
+//
+endfunction
diff --git a/macros/pulstran.bin b/macros/pulstran.bin
new file mode 100644
index 0000000..0bfe42a
Binary files /dev/null and b/macros/pulstran.bin differ
diff --git a/macros/pulstran.sci b/macros/pulstran.sci
new file mode 100644
index 0000000..5aaea5c
--- /dev/null
+++ b/macros/pulstran.sci
@@ -0,0 +1,41 @@
+function y = pulstran(t, d, p, varargin)
+//This function generates the signal y = sum(func(t+d,...)) for each d.
+//Calling Sequence
+//y = pulstran (t, d, func, ...)
+//y = pulstran (t, d, p)
+//y = pulstran (t, d, p, fs)
+//y = pulstran (t, d, p, Ffs, meth)
+//Parameters
+//t:
+//d: vector or matrix
+//p:
+//fs: default value 1Hz
+//func: function which accepts vector (of times)
+//Description
+//This is an Octave function.
+//This function generates the signal y = sum(func(t+d,...)) for each d. If d is a matrix of two columns, the first column is the delay d and the second column is the amplitude a, and y = sum(a*func(t+d)) for each d, a. Here, func is a function which accepts a vector of times.
+//If a pulse shape sampled at frequency Fs (default 1 Hz) is supplied instead of a function name, an interpolated version of the pulse is added at each delay d.
+//Examples
+//pulstran([0.5,9,8,7],[4,6],[-7,0.5])
+//ans =
+// 0. 0. 0. 0.5
+funcprot(0);
+
+rhs=argn(2)
+
+if (rhs<3 | rhs>5)
+ error("Wrong input arguments.")
+end
+ select(rhs)
+ case 1 then
+ y = callOctave("pulstran",t)
+ case 2 then
+ y = callOctave("pulstran",t,d)
+ case 3 then
+ y = callOctave("pulstran",t, d, p)
+ case 4 then
+ y = callOctave("pulstran",t, d, p, varargin(1))
+ case 5 then
+ y = callOctave("pulstran",t, d, p, varargin(1),varargin(2))
+ end
+endfunction
diff --git a/macros/rc2ac.bin b/macros/rc2ac.bin
new file mode 100644
index 0000000..b50257c
Binary files /dev/null and b/macros/rc2ac.bin differ
diff --git a/macros/rc2ac.sci b/macros/rc2ac.sci
new file mode 100644
index 0000000..7d59af5
--- /dev/null
+++ b/macros/rc2ac.sci
@@ -0,0 +1,44 @@
+function R=rc2ac(k, R0)
+
+//rlevinson function convert reflection coefficients to autocorrelation sequence.
+// Calling Sequence
+// a = rc2ac(k, R0)
+
+// Parameters
+// k: input argument reflection coefficients.
+// R0: input argument zero lag autocorrelation
+// R: return autocorrelation sequence.
+
+// Examples
+//X = [7 6 5 8 3 6]
+// R = rc2ac(X, 0.3)
+
+// See also
+//
+// Author
+// Jitendra Singh
+//
+
+ // load rc2poly and rlevinson before running this function
+
+ if or(type(k)==10) then
+ error ('Input arguments must be double.')
+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
+ 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)
+
+
+endfunction
diff --git a/macros/rc2is.bin b/macros/rc2is.bin
new file mode 100644
index 0000000..eda8763
Binary files /dev/null and b/macros/rc2is.bin differ
diff --git a/macros/rc2is.sci b/macros/rc2is.sci
new file mode 100644
index 0000000..a41a79e
--- /dev/null
+++ b/macros/rc2is.sci
@@ -0,0 +1,48 @@
+function isin = rc2is(k)
+// Convert reflection coefficients to inverse sine parameters
+//
+// Calling Sequence
+// isin = rc2is(K)
+//
+// Parameters
+// k: input reflection coefficients. Needs to be an array of real numbers between -1 and 1
+// isin: inverse sine parameters corresponding to the reflection coefficients in input
+//
+// Description
+// This function returns the inverse sine parameters corresponding to the input reflection coefficients K.
+// output array has isin(i) = 2/pi*asin(k(i))
+//
+// Example
+// k = [0.3090 0.9801 0.0031 0.0082 -0.0082];
+// isin = rc2is(k) //Gives inverse sine parameters
+//
+// See also
+// is2rc
+// rc2poly
+// rc2ac
+// rc2lar
+//
+// Authors
+// Parthe Pandit
+//
+// Bibliography
+// J.R. Deller, J.G. Proakis, J.H.L. Hansen, "Discrete-Time Processing of Speech Signals", Prentice Hall, Section 7.4.5
+//modified function to handle char i/p and also changed error statements to match those of MATLAB by Debdeep Dey
+//convert char i/p to their respective ascii values
+if(type(k)==10) then
+ w=k;
+ k=ascii(k);
+ k=matrix(k,size(w));
+end
+// errchk1
+if (~isreal(k)),
+ error('Inverse sine parameters not defined for complex reflection coefficients.');
+end
+
+if max(abs(k)) >= 1,
+ error('All reflection coefficients should have magnitude less than unity.');
+end
+
+isin = (2/%pi)*asin(k);
+
+endfunction
diff --git a/macros/rc2lar.bin b/macros/rc2lar.bin
new file mode 100644
index 0000000..c8e33b7
Binary files /dev/null and b/macros/rc2lar.bin differ
diff --git a/macros/rc2lar.sci b/macros/rc2lar.sci
new file mode 100644
index 0000000..015b42c
--- /dev/null
+++ b/macros/rc2lar.sci
@@ -0,0 +1,33 @@
+function g=rc2lar(k)
+
+//rc2lar convert reflection coefficient to log area ratios.
+
+// Calling Sequence
+// g = rc2lar(k)
+// Parameters
+// k: define the reflection coefficients.
+// g: returns log area ratios.
+// Examples
+//X = [0.5 0.3 0.8 0.9 0.4 0.05];
+// g = rc2lar(X)
+// See also
+//
+// Author
+// Jitendra Singh
+//
+
+ if or(type(k)==10) then
+ error ('All reflection coefficients should have magnitude less than unity. ')
+end
+
+
+
+ if ~isreal(k) then
+ error('Log area ratios not defined for complex reflection coefficients.')
+ end
+
+ if max(abs(k)) >= 1 then
+ error ('All reflection coefficients should have magnitude less than unity.')
+end
+g=-2*atanh(-k);
+endfunction
diff --git a/macros/rc2poly.bin b/macros/rc2poly.bin
new file mode 100644
index 0000000..187d0cd
Binary files /dev/null and b/macros/rc2poly.bin differ
diff --git a/macros/rc2poly.sci b/macros/rc2poly.sci
new file mode 100644
index 0000000..19eed2a
--- /dev/null
+++ b/macros/rc2poly.sci
@@ -0,0 +1,56 @@
+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.
+// 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)
+//
+// See also
+//
+// Author
+// Jitendra Singh
+//
+ if or(type(kr)==10) then
+ error ('Input arguments must be double.')
+end
+
+if (size(kr,1) > 1) & (size(kr,2) > 1)
+ error ('The reflection coefficients must be stored in a vector.')
+end
+
+kr=kr(:);
+
+if argn(2)<2 & argn(1)==2 then
+ error ('Zero lag autocorrelation, R0, not specified.')
+end
+
+
+if argn(2)<2 then
+ e=0;
+else
+ e=R0;
+end
+
+ee(1) = e.*(1-kr(1)'.*kr(1));
+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));
+end
+
+a=[1 a];
+efinal=ee;
+
+endfunction
diff --git a/macros/rcosdesign.bin b/macros/rcosdesign.bin
new file mode 100644
index 0000000..652e766
Binary files /dev/null and b/macros/rcosdesign.bin differ
diff --git a/macros/rcosdesign.sci b/macros/rcosdesign.sci
new file mode 100644
index 0000000..b3218c1
--- /dev/null
+++ b/macros/rcosdesign.sci
@@ -0,0 +1,189 @@
+function h = rcosdesign(rollof_factor, num_of_symb, samp_per_symb, varargin)
+// RCOSDESIGN computes the raised cosine FIR filter
+// 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:
+// 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.
+
+
+ // 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'];
+ checkIpValidity(rollof_factor, valid_class_ROF, properties_ROF);
+ if rollof_factor > 1 then
+ error('roll-off factor should be <= 1');
+ end
+
+ if rollof_factor == 0 then
+ rollof_factor = number_peroperties("tiny");
+ end
+
+ 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
+endfunction
+
+
+function checkIpValidity(variable, valid_class, properties)
+// Function to check the validity of the input variable
+// Inputs:
+// valid_class: vector of valid classes for the input variable
+// properties: vector of necessary properties of the input variable
+
+ for idx = 1:length(length(valid_class))
+ if ~strcmpi(valid_class(idx), 'double') | ~strcmpi(valid_class(idx), 'single') then
+ if type(variable) ~= 1 then
+ 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
+ error('Input variable should be of type scalar');
+ end
+ end
+
+ if ~strcmpi(properties(jdx), 'nonempty') then
+ if isempty(variable) then
+ 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
+
+
+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
+
+endfunction
diff --git a/macros/rectpuls.bin b/macros/rectpuls.bin
new file mode 100644
index 0000000..a61a830
Binary files /dev/null and b/macros/rectpuls.bin differ
diff --git a/macros/rectpuls.sci b/macros/rectpuls.sci
new file mode 100644
index 0000000..2796ef0
--- /dev/null
+++ b/macros/rectpuls.sci
@@ -0,0 +1,28 @@
+function [y]=rectpuls(t,w)
+
+// Generates a Rectangular pulse based on the width and sampling times.
+// Calling Sequence
+// [y]=rectpuls(t)
+// [y]=rectpuls(t,w)
+// Parameters
+// t: Real or complex valued vector or matrix
+// w: Real or complex valued vector or matrix
+// Description
+// This is an Octave function
+// y = rectpuls(t) returns a continuous, aperiodic, unity-height rectangular pulse depending upon input t, centered about t=0 and having default width of 1.
+// y = rectpuls(t,w) generates a rectangle of width w.
+// Examples
+// 1. rectpuls([10 100 1000 13 839],27)
+// ans = 1 0 0 1 0
+// 2. rectpuls([1000 1000 100 100])
+// ans = 0 0 0 0
+
+funcprot(0);
+rhs=argn(2);
+if (rhs<1) then
+ error ("Wrong number of input arguments.")
+elseif (rhs==1)
+ y=callOctave("rectpuls",t)
+else y=callOctave("rectpuls",t,w)
+end
+endfunction
diff --git a/macros/rectwin.bin b/macros/rectwin.bin
new file mode 100644
index 0000000..88d68f5
Binary files /dev/null and b/macros/rectwin.bin differ
diff --git a/macros/rectwin.sci b/macros/rectwin.sci
new file mode 100644
index 0000000..c296d42
--- /dev/null
+++ b/macros/rectwin.sci
@@ -0,0 +1,25 @@
+function [y] = rectwin (m)
+//This function returns the filter coefficients of a rectangular window.
+//Calling Sequence
+//y = rectwin (m)
+//Parameters
+//m: positive integer value
+//y: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a rectangular window of length m supplied as input, to the output vector y.
+//Examples
+//rectwin(3)
+//ans =
+// 1.
+// 1.
+// 1.
+rhs = argn(2)
+
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+
+y = callOctave("rectwin",m)
+
+endfunction
diff --git a/macros/resample.bin b/macros/resample.bin
new file mode 100644
index 0000000..d70f8df
Binary files /dev/null and b/macros/resample.bin differ
diff --git a/macros/resample.sci b/macros/resample.sci
new file mode 100644
index 0000000..3e0e878
--- /dev/null
+++ b/macros/resample.sci
@@ -0,0 +1,44 @@
+function [y, h] = resample( x, p, q, h )
+//This function resamples in the input sequence x supplied by a factor of p/q.
+//Calling Sequence
+//y = resample(x, p, q)
+//y = resample(x, p, q, h)
+//[y, h] = resample(...)
+//Parameters
+//x: scalar, vector or matrix of real or complex numbers
+//p: positive integer value
+//q: positive integer value
+//h: scalar, vector or matrix of real or complex numbers
+//Description
+//This is an Octave function.
+//This function resamples in the input sequence x supplied by a factor of p/q. If x is a matrix, then every column is resampled.hange the sample rate of x by a factor of p/q.
+//This is performed using a polyphase algorithm. The impulse response h, given as parameter 4, of the antialiasing filter is either specified or designed with a Kaiser-windowed sinecard.
+//Examples
+//resample(1,2,3)
+//ans = 0.66667
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+if(rhs<3 | rhs>4)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 3 then
+ if(lhs==1)
+ y = callOctave("resample",x,p,q)
+ elseif(lhs==2)
+ [y,h] = callOctave("resample",x,p,q)
+ end
+ case 4 then
+ if(lhs==1)
+ y = callOctave("resample",x,p,q,h)
+ elseif(lhs==2)
+ [y,h] = callOctave("resample",x,p,q,h)
+ end
+ end
+endfunction
+
+
+
diff --git a/macros/residued.bin b/macros/residued.bin
new file mode 100644
index 0000000..222dc28
Binary files /dev/null and b/macros/residued.bin differ
diff --git a/macros/residued.sci b/macros/residued.sci
new file mode 100644
index 0000000..182b9ca
--- /dev/null
+++ b/macros/residued.sci
@@ -0,0 +1,25 @@
+function [r,p,f,m]=residued(b,a)
+
+// 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]
+
+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.bin b/macros/residuez.bin
new file mode 100644
index 0000000..5a04712
Binary files /dev/null and b/macros/residuez.bin differ
diff --git a/macros/residuez.sci b/macros/residuez.sci
new file mode 100644
index 0000000..ee67a21
--- /dev/null
+++ b/macros/residuez.sci
@@ -0,0 +1,25 @@
+function [r,p,f,m]=residuez(b,a)
+
+// 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
+
+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/risetime.bin b/macros/risetime.bin
new file mode 100644
index 0000000..d8af143
Binary files /dev/null and b/macros/risetime.bin differ
diff --git a/macros/risetime.sci b/macros/risetime.sci
new file mode 100644
index 0000000..e39396f
--- /dev/null
+++ b/macros/risetime.sci
@@ -0,0 +1,375 @@
+function [r, lowercrossvalue, uppercrossvalue, lowerreference, upperreference]=risetime(x, varargin)
+
+
+ // This function estimate risetime values of real vector X.
+ // Calling Sequence
+ // r=risetime(x)
+ // r=risetime(x, Fs)
+ // r=risetime(x, t)
+ // r=risetime(x, t, 'PercentReferenceLevels', N )
+ // r=risetime(x, t, 'Tolerance', M)
+ // r=risetime(x, t,'StateLevels', O)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]=risetime(x)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]=risetime(x, Fs)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]=risetime(x, t)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]=risetime(x, t, 'PercentReferenceLevels', N )
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]= risetime(x, t, 'Tolerance', M)
+ // [r lowercrossvalue uppercrossvalue lowerreference upperreference]= risetime(x, t,'StateLevels', O)
+ // // [r lowercrossvalue uppercrossvalue lowerreference upperreference]= risetime(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.
+ // t: defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.
+ // PercentReferenceLevels: specify the percentreferenceleves 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'.
+ // r: return rise time of positive-going bilevel waveform transitions X.
+ // lowercrossvalue: return the lowerc cross value.
+ // uppercrossvalue: return the upper cross value.
+ // lowerreference: return lower reference value corrosponding to lower percenr reference value.
+ // upperreference: return lower reference value corrosponding to upper percenr reference value.
+
+ // Examples
+ // x=[1.2, 5, 10, -20, 12]
+ //t=1:length(x)
+ //r=risetime(x, t)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+
+ // run statelevels and midcross function before running risetime function.
+
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+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
+else
+ t=1:length(x);
+end
+
+
+if length(varargin)>=2 & type(varargin(1))==1 & type(varargin(2))==1 then
+ error ("Too many leading numeric arguments (at most 2 expected).");
+end
+
+
+
+
+sindex=[];
+if length(varargin)>=1 then
+a=1;
+
+for i=1:length(varargin)
+ if type(varargin(i))==10 then
+ sindex(a)=i;
+ a=a+1;
+ end
+end
+end
+
+
+if length(sindex)>5 then
+ error('Unexpected argument.')
+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')
+
+end
+
+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);
+
+ 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.')
+
+
+ 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'}
+ if length(varargin) <=sindex(j) then
+ 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.')
+ end
+
+ if length( midpercentval)~=2 then
+ 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
+ fig= convstr(varargin(sindex(j)+1), 'u');
+
+ end
+
+
+ if fig == 'OFF' | fig == 'ON' then
+ else
+ error('Expected fig to match one of these strings: on or off');
+ end
+
+
+
+ case{'ON'}
+
+
+
+ case{'OFF'}
+
+ case {'TOLERANCE'}
+ //disp('jitend')
+ 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);
+
+ 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
+ error(strcat(['Invalid optional argument'," ", varargin(sindex(j))]));
+ end // switch
+ end // for
+ end // if
+
+
+ indexx=[];
+if length(sindex)>=1 then
+a=1;
+for i=1:length(sindex)
+
+ indexx(a)=find(convstr(varargin(sindex(i)), 'u')=='MIDPERCENTREFERENCELEVEL')
+ a=a+1;
+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;
+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')
+
+ a=a+1;
+
+end
+end
+
+if sum(index_on)>0 then
+ Lvarargin(sindex(find(index_on>0)))='OFF';
+ Uvarargin(sindex(find(index_on>0)))='OFF';
+end
+
+
+
+
+ [lcrossval lref levels t tolerance]= midcross(x, Lvarargin(:)); // calling midcross function to get lower cross values
+
+ [ucrossval uref]=midcross(x, Uvarargin(:)); // calling midcross function to get upper cross values
+
+
+ if length(lcrossval)==length(ucrossval) then
+ dff=ucrossval-lcrossval
+ r=dff(dff>0)
+ elseif length(lcrossval)>length(ucrossval)
+ n=length(ucrossval);
+ dff=ucrossval-lcrossval(1:n);
+ r=dff(dff>0)
+ else
+ n=length(lcrossval);
+ dff=ucrossval(1:n)-lcrossval;
+ r=dff(dff>0)
+
+ end
+
+ difference=ucrossval-lcrossval;
+ Pindex=find(difference>0);
+
+
+
+ uppercrossvalue=ucrossval(Pindex);
+ lowercrossvalue=lcrossval(Pindex);
+
+ lowerreference=lref;
+ upperreference=uref;
+
+
+ upperbound= levels(2)- (tolerance/100)*(levels(2)-levels(1)); // estimating bounds
+ 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));
+
+
+
+
+
+ if fig=='ON' then // if the defined output is only 1, the it will provide the graphical representation of //levels
+
+ if length(r)==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,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)
+
+ xlabel("Time (second)", "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='?')
+
+ 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); r; (upperreference-lowerreference)*ones(r)]
+
+ col=-10*ones(r);
+
+ 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,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)
+
+ xlabel("Time (second)", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+
+
+ legends(["risetime"; "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
+
+
+endfunction
diff --git a/macros/rlevinson.bin b/macros/rlevinson.bin
new file mode 100644
index 0000000..864f1db
Binary files /dev/null and b/macros/rlevinson.bin differ
diff --git a/macros/rlevinson.sci b/macros/rlevinson.sci
new file mode 100644
index 0000000..3007234
--- /dev/null
+++ b/macros/rlevinson.sci
@@ -0,0 +1,127 @@
+function [R, U, kr, e] = rlevinson(a, efinal)
+
+//rlevinson function computes the autocorrelation coefficients using prediction polynomial.
+// Calling Sequence
+// a = rlevinson(a, efinal)
+// [a, U] = rlevinson(a, efinal)
+// [a, U, kr] = rlevinson(a, efinal)
+// [a, U, kr, e] = rlevinson(a, efinal)
+
+// Parameters
+// a: input argument prediction polynomial.
+// 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.
+// e: Return the vector of prediction error.
+
+
+// Examples
+//X = [7 6 5 8 3 6]
+// R = rlevinson(X, 0.3)
+//
+// See also
+//
+// Author
+// Jitendra Singh
+//
+
+
+ if or(type(a)==10) then
+ error ('Input arguments must be numeric.')
+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
+
+ 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);
+ l=tril(zeros(xx,xx),-1);
+ d=diag(ones(1,xx));
+ u=triu(repmat(%nan,[xx,xx]),1);
+ U=l+d+u;
+ U(xx,xx)=%nan;
+ U(1:xx-1,xx)=(repmat(%inf,[1,xx-1]))'
+ kr=repmat(%nan,[xx-2,1]);
+ 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
+
+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;
+ 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));
+
+
+
+ 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));
+ 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];
+ end
+
+
+endfunction
diff --git a/macros/rms.bin b/macros/rms.bin
new file mode 100644
index 0000000..c757115
Binary files /dev/null and b/macros/rms.bin differ
diff --git a/macros/rms.sci b/macros/rms.sci
new file mode 100644
index 0000000..39abd44
--- /dev/null
+++ b/macros/rms.sci
@@ -0,0 +1,36 @@
+//Root mean squared value \
+//Y=rms(X);
+//Y=rms(X,dim);
+//For vectors, RMS(X) is the root mean squared value in X. For matrices,
+// RMS(X) is a row vector containing the RMS value from each column. For
+// N-D arrays, RMS(X) operates along the first non-singleton dimension.
+//
+// Y = RMS(X,DIM) operates along the dimension DIM.
+//
+// When X is complex, the RMS is computed using the magnitude
+// RMS(ABS(X)).
+//Author Debdeep Dey
+
+function y = rms(x, dim)
+//convert i/p values to their ascii values if they are of type char
+if(type(x)==10) then
+ xa=x;
+ x=ascii(x);
+ x=matrix(x,size(xa));
+end
+
+if argn(2)==1
+ [rm,cm]=size(x);
+ if(rm>1) then
+ y = sqrt(mean((x .* conj(x)),'r'));
+ else
+ y=sqrt(mean((x.*conj(x))));
+ end
+else
+ if(dim==1)
+ y = sqrt(mean((x .* conj(x)),'r'));
+ else
+ y = sqrt(mean((x .* conj(x)),'c'));
+ end
+end
+endfunction
diff --git a/macros/rooteig.bin b/macros/rooteig.bin
new file mode 100644
index 0000000..a07e660
Binary files /dev/null and b/macros/rooteig.bin differ
diff --git a/macros/rooteig.sci b/macros/rooteig.sci
new file mode 100644
index 0000000..e4f59c0
--- /dev/null
+++ b/macros/rooteig.sci
@@ -0,0 +1,350 @@
+
+// Date of creation: 20 Jan, 2016
+function [w,pow] = rooteig(x,p,varargin)
+ // Frequencies and power of sinusoids using eigenvector algorithm
+ //
+ // Calling Sequence
+ // w = rooteig(x,p)
+ // [w,pow] = rooteig(x,p)
+ // [f,pow] = rooteig(...,fs)
+ // [w,pow] = rooteig(...,'corr')
+ //
+ // Parameters
+ // x - int|double - vector|matrix
+ // 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.
+ // p - int|double - scalar|2 element vector
+ // 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
+ // matrix.
+ // fs - int|double - scalar
+ // Sampling frequency (in Hz)
+ // If fs is specified by an empty vector or unspecified, it defaults
+ // 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
+ // 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] = rooteig(s,3);
+ //
+ // Author
+ // Ayush
+ //
+ // See also
+ // corrmtx | peig | pmusic | rootmusic
+ //
+ // References
+ // 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);
+
+
+ // **** 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);
+ if length(fs)==1 then
+ if ~IsIntOrDouble(fs, %T) then
+ msg = "rooteig: Wrong type for argument #4 (fs); Positive scalar expected";
+ error(msg,10084);
+ end
+ fs = double(fs);
+ isFsSpecified = %T;
+ elseif length(fs)>1 then
+ msg = "rooteig: Wrong type for argument #4 (fs); Positive scalar expected";
+ error(msg,10084);
+ end
+ elseif length(varargin)>1 then
+ msg = "rooteig: Wrong type for argument #4 (fs); Positive scalar expected";
+ error(msg,10084);
+ end
+
+ // extracting primary input x/R
+ primaryInput = x;
+
+ if ndims(primaryInput)<1 | ndims(primaryInput)>2 then
+ msg = "rooteig: Wrong dimension for argument #1; Vector or a matrix expected";
+ error(msg,10053);
+ end
+ if ~IsIntOrDouble(primaryInput, %F) then
+ msg = "rooteig: Wrong type for argument #1; Numeric vector or a matrix expected";
+ error(msg,10053);
+ end
+ // covert to a column vector
+ if ndims(primaryInput)==1 then
+ primaryInput = primaryInput(:);
+ end
+ // casting to double
+ primaryInput = double(primaryInput);
+
+
+ //****extracting p****
+ // p must be either scalar or a 2-element vector
+ if length(p)~=1 & length(p)~=2 then
+ msg = "rooteig: Wrong type for argument #2 (p); " + ...
+ "A scalar or a 2-element vector expected";
+ error(msg,10053);
+ end
+ // first argument of p must be an integer
+ if ~IsIntOrDouble(p(1),%T) then
+ msg = "rooteig: Wrong input argument #2 p(1); " + ...
+ "positive integer expected";
+ error(msg,10036);
+ return
+ end
+ p(1) = int(p(1));
+ // TODO: check if positive required
+ // 2nd argument, if exists, must be a positive integer'
+ 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);
+ end
+ end
+
+ isXReal = isreal(x)
+ if ~isCorrFlag then
+ // check that p(1) should be even if x is real
+ if isXReal & modulo(p(1),2)~=0 then
+ msg = "rooteig: Wrong input argument #2 p(1); " + ...
+ " An even value expected for real input x";
+ error(msg,10036);
+ end
+ end
+
+
+
+ // **** calling pmusic ****
+ data= struct();
+ data.x = primaryInput;
+ data.p = p;
+ data.nfft = 256;
+ data.w = [];
+ data.fs = fs;
+ data.isWindowSpecified = %F;
+ data.windowLength = 2*p(1);
+ data.windowVector = [];
+ data.noverlap = [];
+ data.isCorrFlag = isCorrFlag;
+ data.isFsSpecified = isFsSpecified;
+ data.freqrange = "twosided";
+
+
+
+ [outData,msg] = musicBase(data);
+ if length(msg)~=0 then
+ // throw error
+ 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
+ // the polynomial formed with the noise eigenvectors
+ //
+ // Parameters
+ // noiseEigenvects -
+ // A matrix where noise eigenvectors are represented by each column
+ // pEffective -
+ // The effective dimension of the signal subspace
+ // EVFlag -
+ // Flag to indicate weighting to be used for rooteig
+ // eigenvals -
+ // Eigenvals of the correlation matrix
+ //
+ // Output arguments
+ // w -
+ // A vector with frequencies of the complex sinusoids
+
+
+ numOfNoiseEigenvects = size(noiseEigenvects,2);
+ if EVFlag then
+ // weights are the eigenvalues in the noise subspace
+ weights = eigenvals($-numOfNoiseEigenvects+1:$);
+ 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
+ // 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
+ // 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
+ // normalizing the f vector
+ w = f*2*%pi/fs;
+ 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
+
+
+function result = IsIntOrDouble(inputNum, isPositiveCheck)
+ // Checks if The Input Is Integer Or Double
+ // Also Checks if It Is Greater Than 0 For IsPositiveCheck = True
+
+ if ~(type(inputNum)==1 | type(inputNum)==8) then
+ result = %F;
+ return
+ end
+ if isPositiveCheck & or(inputNum<=0) then
+ result = %F;
+ return
+ end
+
+ result = %T;
+ return
+endfunction
diff --git a/macros/rootmusic.bin b/macros/rootmusic.bin
new file mode 100644
index 0000000..8d40df3
Binary files /dev/null and b/macros/rootmusic.bin differ
diff --git a/macros/rootmusic.sci b/macros/rootmusic.sci
new file mode 100644
index 0000000..34c3ff6
--- /dev/null
+++ b/macros/rootmusic.sci
@@ -0,0 +1,349 @@
+// Date of creation: 20 Jan, 2016
+function [w,pow] = rootmusic(x,p,varargin)
+ // Frequencies and power of sinusoids using the root MUSIC algorithm
+ //
+ // Calling Sequence
+ // w = rootmusic(x,p)
+ // [w,pow] = rootmusic(x,p)
+ // [f,pow] = rootmusc(...,fs)
+ // [w,pow] = rootmusic(...,'corr')
+ //
+ // Parameters
+ // x - int|double - vector|matrix
+ // 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.
+ // p - int|double - scalar|2 element vector
+ // 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
+ // matrix.
+ // fs - int|double - scalar
+ // Sampling frequency (in Hz)
+ // If fs is specified by an empty vector or unspecified, it defaults
+ // 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
+ // 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);
+ //
+ // Author
+ // Ayush
+ //
+ // See also
+ // corrmtx | peig | pmusic | rooteig
+ //
+ // References
+ // 1) Monson H. Hayes, Statistical Digital Signal Processing And Modeling,
+ // Wiley & Sons, Inc, [Section 8.6.3]
+ //
+ //
+ // 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);
+
+
+ // **** 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);
+ if length(fs)==1 then
+ if ~IsIntOrDouble(fs, %T) then
+ msg = "rootmusic: Wrong type for argument #4 (fs); Positive scalar expected";
+ error(msg,10084);
+ end
+ fs = double(fs);
+ isFsSpecified = %T;
+ elseif length(fs)>1 then
+ msg = "rootmusic: Wrong type for argument #4 (fs); Positive scalar expected";
+ error(msg,10084);
+ end
+ elseif length(varargin)>1 then
+ msg = "rootmusic: Wrong type for argument #4 (fs); Positive scalar expected";
+ error(msg,10084);
+ end
+
+ // extracting primary input x/R
+ primaryInput = x;
+
+ if ndims(primaryInput)<1 | ndims(primaryInput)>2 then
+ msg = "rootmusic: Wrong dimension for argument #1; Vector or a matrix expected";
+ error(msg,10053);
+ end
+ if ~IsIntOrDouble(primaryInput, %F) then
+ msg = "rootmusic: Wrong type for argument #1; Numeric vector or a matrix expected";
+ error(msg,10053);
+ end
+ // covert to a column vector
+ if ndims(primaryInput)==1 then
+ primaryInput = primaryInput(:);
+ end
+ // casting to double
+ primaryInput = double(primaryInput);
+
+
+ //****extracting p****
+ // p must be either scalar or a 2-element vector
+ if length(p)~=1 & length(p)~=2 then
+ msg = "rootmusic: Wrong type for argument #2 (p); " + ...
+ "A scalar or a 2-element vector expected";
+ error(msg,10053);
+ end
+ // first argument of p must be an integer
+ if ~IsIntOrDouble(p(1),%T) then
+ msg = "rootmusic: Wrong input argument #2 p(1); " + ...
+ "positive integer expected";
+ error(msg,10036);
+ return
+ end
+ p(1) = int(p(1));
+ // TODO: check if positive required
+ // 2nd argument, if exists, must be a positive integer'
+ 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);
+ end
+ end
+
+ isXReal = isreal(x)
+ if ~isCorrFlag then
+ // check that p(1) should be even if x is real
+ if isXReal & modulo(p(1),2)~=0 then
+ msg = "rootmusic: Wrong input argument #2 p(1); " + ...
+ " An even value expected for real input x";
+ error(msg,10036);
+ end
+ end
+
+
+
+ // **** calling pmusic ****
+ data= struct();
+ data.x = primaryInput;
+ data.p = p;
+ data.nfft = 256;
+ data.w = [];
+ data.fs = fs;
+ data.isWindowSpecified = %F;
+ data.windowLength = 2*p(1);
+ data.windowVector = [];
+ data.noverlap = [];
+ data.isCorrFlag = isCorrFlag;
+ data.isFsSpecified = isFsSpecified;
+ data.freqrange = "twosided";
+
+
+
+ [outData,msg] = musicBase(data);
+ if length(msg)~=0 then
+ // throw error
+ 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
+ // the polynomial formed with the noise eigenvectors
+ //
+ // Parameters
+ // noiseEigenvects -
+ // A matrix where noise eigenvectors are represented by each column
+ // pEffective -
+ // The effective dimension of the signal subspace
+ // EVFlag -
+ // Flag to indicate weighting to be used for rooteig
+ // eigenvals -
+ // Eigenvals of the correlation matrix
+ //
+ // Output arguments
+ // w -
+ // A vector with frequencies of the complex sinusoids
+
+
+ numOfNoiseEigenvects = size(noiseEigenvects,2);
+ if EVFlag then
+ // weights are the eigenvalues in the noise subspace
+ weights = eigenvals($-numOfNoiseEigenvects+1:$);
+ 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
+ // 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
+ // 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
+ // normalizing the f vector
+ w = f*2*%pi/fs;
+ 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
+
+
+function result = IsIntOrDouble(inputNum, isPositiveCheck)
+ // Checks if The Input Is Integer Or Double
+ // Also Checks if It Is Greater Than 0 For IsPositiveCheck = True
+
+ if ~(type(inputNum)==1 | type(inputNum)==8) then
+ result = %F;
+ return
+ end
+ if isPositiveCheck & or(inputNum<=0) then
+ result = %F;
+ return
+ end
+
+ result = %T;
+ return
+endfunction
diff --git a/macros/rssq.bin b/macros/rssq.bin
new file mode 100644
index 0000000..3401b22
Binary files /dev/null and b/macros/rssq.bin differ
diff --git a/macros/rssq.sci b/macros/rssq.sci
new file mode 100644
index 0000000..e04050e
--- /dev/null
+++ b/macros/rssq.sci
@@ -0,0 +1,72 @@
+
+function out = rssq(in, orientation)
+//This function calculates the square root of the sum of values of input vector IN.
+//
+//Calling Sequence
+//OUT=rssq(IN)
+//OUT=rssq(IN,orientation)
+//
+//Parameters
+//in:Vector or Matrix of real or complex elements.
+//orientation: A string with possible values "r", "c" or "m" or numericals such as '1' or '2',giving the dimension along which the rssq value is to be calculated.
+//out:A scalar with real value when input is a vector.When input is a matrix, out is the root sum squared value along the orientation specified or the default one when not specified.
+//
+//Description
+//For vector as input, the output is real valued scalar containing the rssq value. The rssq value can be calculated by taking the square root of the squared sum of the elements.
+//If the input IN is a matrix, the output of function is rssq value of each column stored in a row vector OUT.
+//
+//When the elements of IN are COMPLEX, the absolute value of the element is used to calculate the output.
+//When the orientation is not specified for N dimensional array, it is taken as the index of the first dimension of IN that is greater than 1 and calculation is done along that orientation.
+//
+//When the orientation is specified the output is calculated along that dimension.
+//The orientation can be specified as 1 for rssq value of columns of matrix IN or as r.
+//For rssq value of rows of matrix orientation should be 2 or c.
+//
+//Examples
+//To calculate rssq of a vector:
+//IN=[2 4 6]
+//OUT=rssq(IN)
+//The output is 7.4833148
+//
+//Examples
+//To calculate rssq of rows of matrix:
+//IN=[1 3 5;2 4 6;7 8 9]
+//OUT=rssq(IN,2)
+//The output should be OUT=
+ //5.9160798
+ //7.4833148
+ //13.928388
+//
+//Examples
+//To calculate rssq of a columns of complex matrix:
+//
+//IN=[5+%i*3 2+%i*4; 3+%i*6 1+%i*2]
+//OUT=rssq(IN,1)
+//The output should be OUT= 8.8881944 5.
+//See also
+//abs
+//mean
+//sqrt
+//isempty
+//
+//Authors
+//Indira Askaukar
+//
+//Bibliography
+//Matlab help document.
+
+
+if argn(2)==1//when the orienatation is not specified
+ a=abs(in)//This calculates the absolute value of complex numbers
+ a=a.^2
+ s=sum(a,"m")
+ out=sqrt(s)
+
+else
+ a=abs(in)
+ a=a.^2
+ s=sum(a,orientation)
+ out=sqrt(s)
+
+end
+endfunction
diff --git a/macros/sampled2continuous.bin b/macros/sampled2continuous.bin
new file mode 100644
index 0000000..49a325a
Binary files /dev/null and b/macros/sampled2continuous.bin differ
diff --git a/macros/sampled2continuous.sci b/macros/sampled2continuous.sci
new file mode 100644
index 0000000..25738c4
--- /dev/null
+++ b/macros/sampled2continuous.sci
@@ -0,0 +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.
+//Calling Sequence
+//x = sampled2continuous (n, s, t)
+//Parameters
+//n:
+//s:
+//t:
+//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.
+//The third parameter t is all the instants where output x is needed from intput n and this time is relative to x(0).
+//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)
+
+endfunction
diff --git a/macros/sawtooth.bin b/macros/sawtooth.bin
new file mode 100644
index 0000000..19e5aeb
Binary files /dev/null and b/macros/sawtooth.bin differ
diff --git a/macros/sawtooth.sci b/macros/sawtooth.sci
new file mode 100644
index 0000000..50d093d
--- /dev/null
+++ b/macros/sawtooth.sci
@@ -0,0 +1,27 @@
+function [y]=sawtooth (t,width)
+
+// Generates a Sawtooth wave
+// Calling Sequence
+// [y]=sawtooth(t)
+// [y]=sawtooth(t,width)
+// Parameters
+// t: Real valued vector or matrix
+// width: Real number between 0 and 1
+// Description
+// This is an Octave function
+// This function returns a sawtooth wave with period 2*pi with +1/-1 as the maximum and minimum values for elements of t. If width is specified, it determines where the maximum is in the interval [0,2*pi].
+// Examples
+// 1. sawtooth([1 2 3 4 5],0.5)
+// ans = [-0.36338 0.27324 0.90986 0.45352 -0.18310]
+// 2. sawtooth([1 2; 4 5])
+// ans = [-0.68169 -0.36338; 0.27324 0.59155]
+
+funcprot(0);
+rhs=argn(2);
+if (rhs<1) then
+ error ("Wrong number of input arguments.")
+elseif (rhs==1)
+ y=callOctave("sawtooth",t)
+else y=callOctave("sawtooth",t,width)
+end
+endfunction
diff --git a/macros/schtrig.bin b/macros/schtrig.bin
new file mode 100644
index 0000000..d89c725
Binary files /dev/null and b/macros/schtrig.bin differ
diff --git a/macros/schtrig.sci b/macros/schtrig.sci
new file mode 100644
index 0000000..90286e2
--- /dev/null
+++ b/macros/schtrig.sci
@@ -0,0 +1,30 @@
+function v = schtrig (x, lev, rs)
+//This function implements a multisignal Schmitt triggers with lev levels supplied as input.
+//Calling Sequence
+//v = schtrig (x, lev)
+//v = schtrig (x, lev, rs)
+//Parameters
+//x: vector or matrix of real numbers
+//lev: real number
+//rs: default value 1
+//Description
+//This is an Octave function.
+//This function implements a multisignal Schmitt triggers with lev levels supplied as input.
+//The argument 1 is a matrix (or a vector) and this trigger works along its first dimension.
+//Examples
+//schtrig([0.2,-3,5],-4)
+//ans =
+// 0. 0. 1.
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<2 | rhs>3)
+error("Wrong number of input arguments.")
+end
+if(rhs==2)
+v = callOctave("schtrig", x, lev)
+elseif(rhs==3)
+v = callOctave("schtrig",x, lev, rs)
+end
+
+endfunction
diff --git a/macros/schurrc.bin b/macros/schurrc.bin
new file mode 100644
index 0000000..c484ac0
Binary files /dev/null and b/macros/schurrc.bin differ
diff --git a/macros/schurrc.sci b/macros/schurrc.sci
new file mode 100644
index 0000000..0a5e6ce
--- /dev/null
+++ b/macros/schurrc.sci
@@ -0,0 +1,50 @@
+//schurrc - Schur algorithm.
+//K = SCHURRC(R) computes the reflection coefficients from autocorrelation vector R. If R is a matrix, SCHURRC finds coefficients for each column of R, and returns them in the columns of K.
+//[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
+function [k,e] = schurrc(R)
+ narginchk(1,1,argn(2));
+if(type(R)==10) then
+ w=R;
+ [nr,nc]=size(R);
+ if(nr==1 & nc==1) then
+ R=ascii(R);
+ R=matrix(R,length(w));
+ else
+
+ R=ascii(R);
+ R=matrix(R,size(w));
+ end
+
+end
+if(type(R) > 1) then
+ error('Input R is not a matrix')
+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
+ X = R(:,j).';
+ // Schur's iterative algorithm on a row vector of autocorrelation values
+ 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 = [1 k(i-1,j); conj(k(i-1,j)) 1]*U;
+ end
+
+ e(j,1) = U(2,$);
+end
+endfunction
+function narginchk(l,h,t)
+ if tl then
+ error("Too many input arguments");
+ end
+endfunction
diff --git a/macros/schurrc.sci~ b/macros/schurrc.sci~
new file mode 100644
index 0000000..71beb39
--- /dev/null
+++ b/macros/schurrc.sci~
@@ -0,0 +1,49 @@
+//schurrc - Schur algorithm.
+//K = SCHURRC(R) computes the reflection coefficients from autocorrelation vector R. If R is a matrix, SCHURRC finds coefficients for each column of R, and returns them in the columns of K.
+//[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
+function [k,e] = schurrc(R)
+ narginchk(1,1,argn(2));
+if(type(R)==10) then
+ w=R;
+ [nr,nc]=size(R);
+ if(nr==1 & nc==1) then
+ R=ascii(R);
+ R=matrix(R,length(w));
+ else
+
+ R=ascii(R);
+ R=matrix(R,size(w));
+ end
+
+end
+if(type(R) > 1) then
+ error('Input R is not a matrix')
+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
+ X = R(:,j).';
+ // Schur's iterative algorithm on a row vector of autocorrelation values
+ 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 = [1 k(i-1,j); conj(k(i-1,j)) 1]*U;
+ end
+
+ e(j,1) = U(2,$);
+end
+endfunction
+function narginchk(l,h,t)
+ if tl then
+ error("Too many i/p arguments");
+ end
diff --git a/macros/seqperiod.bin b/macros/seqperiod.bin
new file mode 100644
index 0000000..8c9af6f
Binary files /dev/null and b/macros/seqperiod.bin differ
diff --git a/macros/seqperiod.sci b/macros/seqperiod.sci
new file mode 100644
index 0000000..aa51d06
--- /dev/null
+++ b/macros/seqperiod.sci
@@ -0,0 +1,81 @@
+function [p,num]=seqperiod(x)
+//Calculates the period of a sequence
+//Calling Sequence
+//[p,num]=seqperiod(x)
+//Parameters
+//x: A vector matrix or n-dimensional array
+//Description
+//[p,num]=seqperiod(x)
+//Returns an integer p such that x(1:p) is the smallest subsequence that repeats in x
+//The number of times the subsequence repeats is returned in num (may not be an integer)
+//Repetitions may be incomplete at the end of the sequence but no breaks are permitted between repetitions
+//If there is no subsequence that repeats in x then p=length(x)
+//If x is a matrix or n-dimesnional array, the function operates along the first non-singleton dimension of x
+//Examples
+//x = [4 0 1 5;
+// 1 1 2 5;
+// 2 0 3 5;
+// 3 1 1 5];
+//p = seqperiod(x)
+//p =
+//
+// 4. 2. 3. 1.
+//A=zeros(4,1,4);
+//A(:,1,:)=x;
+//p1=seqperiod(A);
+//p1 =
+//
+//(:,:,1)
+//
+//4.
+//(:,:,2)
+//
+//2.
+//(:,:,3)
+//
+//3.
+//(:,:,4)
+//
+//1.
+//Authors
+//Ankur Mallick
+ funcprot(0);
+ if(argn(2)~=1)
+ error('Incorrect number of input arguments.');
+ else
+ S=size(x);
+ S1=S(S>1);
+ if(length(S1)==1)
+ u=0,v=0;
+ x=matrix(x,S1,1);
+ for i=1:S1
+ if(S1>=2*i)
+ L=ceil((S1-i)/i);
+ v=matrix(x(1:i)*ones(1,L),i*L,1);
+ u=x(i+1:S1);
+ v=v(1:length(u));
+ else
+ u=x(i+1:S1);
+ v=x(1:length(u));
+ end
+ if(v==u|i==S1)
+ p=i;
+ num=S1/p;
+ break;
+ end
+ end
+ else
+ x1=squeeze(x);
+ S2=size(x1);
+ p=zeros(sum(x1,1)); //summing x along first dimension gives p a leading singleton dimensionn
+ num=zeros(p);
+ for i=1:prod(S2(2:length(S2)))
+ [p1,num1]=seqperiod(x1(:,i));
+ p(i)=p1; //Linear indexing
+ num(i)=num1; //Linear indexing
+ end
+ p=matrix(p,[1,S(2:length(S))]);
+ num1=matrix(num,[1,S(2:length(S))]);
+ end
+ end
+endfunction
diff --git a/macros/sgolay.bin b/macros/sgolay.bin
new file mode 100644
index 0000000..14ab743
Binary files /dev/null and b/macros/sgolay.bin differ
diff --git a/macros/sgolay.sci b/macros/sgolay.sci
new file mode 100644
index 0000000..1156d40
--- /dev/null
+++ b/macros/sgolay.sci
@@ -0,0 +1,40 @@
+function F = sgolay (p, n, m, ts)
+//This function computes the filter coefficients for all Savitzsky-Golay smoothing filters.
+//Calling Sequence
+//F = sgolay (p, n)
+//F = sgolay (p, n, m)
+//F = sgolay (p, n, m, ts)
+//Parameters
+//p: polynomial
+//n: odd integer value, larger than polynomial p
+//m: positive integer less than 2^31 or logical
+//ts: real or complex value
+//Description
+//This is an Octave function.
+//This function computes the filter coefficients for all Savitzsky-Golay smoothing filters of order p for length n (odd).
+//m can be used in order to get directly the mth derivative; ts is a scaling factor.
+//Examples
+//y = sgolay(1,3,0)
+//y =
+// 0.83333 0.33333 -0.16667
+// 0.33333 0.33333 0.33333
+// -0.16667 0.33333 0.83333
+
+funcprot(0);
+rhs = argn(2)
+
+if(rhs<2 | rhs>4)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 2 then
+ F = callOctave("sgolay",p,n)
+ case 3 then
+ F = callOctave("sgolay",p,n,m)
+ case 4 then
+ F = callOctave("sgolay",p,n,m,ts)
+ end
+endfunction
+
+
diff --git a/macros/sgolayfilt.bin b/macros/sgolayfilt.bin
new file mode 100644
index 0000000..a834dab
Binary files /dev/null and b/macros/sgolayfilt.bin differ
diff --git a/macros/sgolayfilt.sci b/macros/sgolayfilt.sci
new file mode 100644
index 0000000..8f58f5f
--- /dev/null
+++ b/macros/sgolayfilt.sci
@@ -0,0 +1,54 @@
+function y = sgolayfilt (x, p, n, m, ts)
+
+//This function applies a Savitzky-Golay FIR smoothing filter to the data
+//Calling Sequence
+//y = sgolayfilt (x)
+//y = sgolayfilt (x, p)
+//y = sgolayfilt (x, p, n)
+//y = sgolayfilt (x, p, n, m)
+//y = sgolayfilt (x, p, n, m, ts)
+//Parameters
+//x: vector or matrix of real or complex numbers
+//p: polynomial order, real number less than n, default value 3
+//n: integer, odd number greater than p
+//m: vector of real positive valued numbers, length n
+//ts: real number, default value 1
+//Description
+//This function applies a Savitzky-Golay FIR smoothing filter to the data given in the vector x; if x is a matrix, this function operates
+//on each column.
+//The polynomial order p should be real, less than the size of the frame given by n.
+//m is a weighting vector with default value identity matrix.
+//ts is the dimenstion along which the filter operates. If not specified, the function operates along the first non singleton dimension.
+//Examples
+//sgolayfilt([1;2;i;4;7], 0.3, 3, 0, 0)
+//ans =
+// 1.0000 + 0.3333i
+// 1.0000 + 0.3333i
+// 2.0000 + 0.3333i
+// 3.6667 + 0.3333i
+// 3.6667 + 0.3333i
+//This function is being called from Octave
+
+
+
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<1 | rhs>5)
+error("Wrong number of input arguments.")
+end
+
+
+select(rhs)
+case 1 then
+y = callOctave("sgolayfilt",x)
+case 2 then
+y = callOctave("sgolayfilt",x, p)
+case 3 then
+y = callOctave("sgolayfilt",x, p, n)
+case 4 then
+y = callOctave("sgolayfilt",x, p, n, m)
+case 5 then
+y = callOctave("sgolayfilt",x, p, n, m, ts)
+end
+endfunction
diff --git a/macros/shanwavf.bin b/macros/shanwavf.bin
new file mode 100644
index 0000000..300bc07
Binary files /dev/null and b/macros/shanwavf.bin differ
diff --git a/macros/shanwavf.sci b/macros/shanwavf.sci
new file mode 100644
index 0000000..a597214
--- /dev/null
+++ b/macros/shanwavf.sci
@@ -0,0 +1,30 @@
+function [psi,x]=shanwavf(lb,ub,n,fb,fc)
+
+// Complex Shannon Wavelet
+// Calling Sequence
+// [psi,x]=shanwavf(lb,ub,n,fb,fc)
+// Parameters
+// lb: Real or complex valued vector or matrix
+// ub: Real or complex valued vector or matrix
+// n: Real valued integer strictly positive
+// fb: Real or complex valued vector or matrix, strictly positive value for scalar input
+// fc: Real or complex valued vector or matrix, strictly positive value for scalar input
+// Description
+// This is an Octave function
+// This function implements the complex Shannon wavelet function and returns the value obtained. The complex Shannon wavelet is defined by a bandwidth parameter FB, a wavelet center frequency FC on an N point regular grid in the interval [LB,UB].
+// Examples
+// 1. [a,b]=shanwavf (2,8,3,1,6)
+// a = [-3.8982e-17 + 1.1457e-31i 3.8982e-17 - 8.4040e-31i -3.8982e-17 + 4.5829e-31i]
+// b = [2 5 8]
+// 2. [a,b]=shanwavf(1,2,1,[2,2;i,2],[-1,2;-i,i])
+// a = [-5.5128e-17 - 2.7005e-32i -5.5128e-17 + 5.4010e-32i;
+// 8.6404e+06 + 8.6404e+06i -1.9225e-22 - 0.0000e+00i]
+// b = 2
+
+funcprot(0);
+rhs=argn(2);
+if (rhs~=5) then
+ error ("Wrong number of input arguments.")
+else [psi,x]=callOctave("shanwavf",lb,ub,n,fb,fc)
+end
+endfunction
diff --git a/macros/shiftdata.bin b/macros/shiftdata.bin
new file mode 100644
index 0000000..ef78b01
Binary files /dev/null and b/macros/shiftdata.bin differ
diff --git a/macros/shiftdata.sci b/macros/shiftdata.sci
new file mode 100644
index 0000000..8817e24
--- /dev/null
+++ b/macros/shiftdata.sci
@@ -0,0 +1,77 @@
+function [y,perm,nshifts] = shiftdata(x,dim)
+//Shifts data by rearranging dimensions
+//Calling sequence
+//[y,perm,nshifts]=shiftdata(x,dim)
+//[y,perm,nshifts]=shiftdata(x)
+//Parameters
+//x
+//A vector matrix or n-dimensional array
+//dim
+//The dimension to be shifted to the first column
+//Description
+//[y,perm,nshifts]=shiftdata(x,dim)
+//Shifts the entries along dimension dim in x to the first column and returns the permutation vector in perm
+//[y,perm,nshifts]=shiftdata(x)
+//Shifts the entries along dimension dim in x to the first column and returns the number of shifts in nshifts
+//Examples
+// //When dim is specified:
+//x=testmatrix('magi',3)
+//x =
+//
+// 8. 1. 6.
+// 3. 5. 7.
+// 4. 9. 2.
+//[y,perm,nshifts] = shiftdata(x,2)
+//nshifts =
+//
+// []
+// perm =
+//
+// 2. 1.
+// y =
+//
+// 8. 3. 4.
+// 1. 5. 9.
+// 6. 7. 2.
+// //When dim is not specified:
+//x=1:5
+//x =
+//
+// 1. 2. 3. 4. 5.
+// [y,perm,nshifts] = shiftdata(x)
+//nshifts =
+//
+// 1.
+// perm =
+//
+// []
+// y =
+//
+// 1.
+// 2.
+// 3.
+// 4.
+// 5.
+//See also
+//permute
+//unshiftdata
+//Author
+//Ankur Mallick
+ funcprot(0);
+ if(argn(2)<1|argn(2)>2)
+ error('Incorrect number of input arguments.');
+ elseif(argn(2)==1|size(dim)==0)
+ perm=[];
+ S=size(x);
+ v=find(S>1,1);
+ y=matrix(x,S(v:length(S)));
+ nshifts=v-1;
+ else
+ S=size(x);
+ perm=1:1:length(S);
+ perm(dim)=[];
+ perm=[dim perm];
+ y=permute(x,perm);
+ nshifts=[];
+ end
+endfunction
diff --git a/macros/slewrate.bin b/macros/slewrate.bin
new file mode 100644
index 0000000..55c9162
Binary files /dev/null and b/macros/slewrate.bin differ
diff --git a/macros/slewrate.sci b/macros/slewrate.sci
new file mode 100644
index 0000000..5b83327
--- /dev/null
+++ b/macros/slewrate.sci
@@ -0,0 +1,387 @@
+function [s, lowercrossvalue, uppercrossvalue, lowerreference, upperreference]=slewrate(x, varargin)
+
+
+ // This function estimate slew rate of bilevel waveform transitions
+ // Calling Sequence
+ // 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)
+ //
+ // 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.
+ // t: defiene instant sample time t as vector with same length of x, or specifies the sample rate, t, as a positive scalar.
+ // 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'.
+ // 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
+ // x=[1.2, 5, 10, -20, 12]
+ //t=1:length(x)
+ //s=slewrate(x, t)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+ // run statelevels and midcross function before running risetime function.
+
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+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
+else
+ t=1:length(x);
+end
+
+
+if length(varargin)>=2 & type(varargin(1))==1 & type(varargin(2))==1 then
+ error ("Too many leading numeric arguments (at most 2 expected).");
+end
+
+
+
+
+sindex=[];
+if length(varargin)>=1 then
+a=1;
+
+for i=1:length(varargin)
+ if type(varargin(i))==10 then
+ sindex(a)=i;
+ a=a+1;
+ end
+end
+end
+
+
+if length(sindex)>5 then
+ error('Unexpected argument.')
+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')
+
+end
+
+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);
+
+ 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.')
+
+
+ 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'}
+ if length(varargin) <=sindex(j) then
+ 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.')
+ end
+
+ if length( midpercentval)~=2 then
+ 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
+ fig= convstr(varargin(sindex(j)+1), 'u');
+
+ end
+
+
+ if fig == 'OFF' | fig == 'ON' then
+ else
+ error('Expected fig to match one of these strings: on or off');
+ 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);
+
+ 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
+ error(strcat(['Invalid optional argument'," ", varargin(sindex(j))]));
+ end // switch
+ end // for
+ end // if
+
+/////////////////////////////////////////////
+
+
+
+ indexx=[];
+if length(sindex)>=1 then
+a=1;
+for i=1:length(sindex)
+
+ indexx(a)=find(convstr(varargin(sindex(i)), 'u')=='MIDPERCENTREFERENCELEVEL')
+ a=a+1;
+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;
+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')
+
+ a=a+1;
+
+end
+end
+
+if sum(index_on)>0 then
+ Lvarargin(sindex(find(index_on>0)))='OFF';
+ Uvarargin(sindex(find(index_on>0)))='OFF';
+end
+
+
+
+
+ [lcrossval lref levels t tolerance]= midcross(x, Lvarargin(:));
+
+ [ucrossval uref]=midcross(x, Uvarargin(:));
+
+
+ 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;
+
+ lowerreference=lref;
+ 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));
+
+
+
+
+
+ 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,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)
+
+ xlabel("Time (second)", "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='?')
+
+
+ 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,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)
+//
+ xlabel("Time (second)", "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
+
+
+endfunction
diff --git a/macros/sos2cell.bin b/macros/sos2cell.bin
new file mode 100644
index 0000000..924a4b6
Binary files /dev/null and b/macros/sos2cell.bin differ
diff --git a/macros/sos2cell.sci b/macros/sos2cell.sci
new file mode 100644
index 0000000..be40667
--- /dev/null
+++ b/macros/sos2cell.sci
@@ -0,0 +1,93 @@
+function c = sos2cell(s,g)
+//Converts a second order section matrix to a cell array
+//Calling Sequences
+//c=sos2cell(s)
+//c=sos2cell(s,g)
+//Parameters
+//s
+//An L-by-6 matrix where L is the number of sections
+//g
+//The scalar gain
+//Description
+//c=sos2cell(s) converts an L-by-6 second-order-section matrix s given by:
+// s = [B1 A1
+// B2 A2
+// ...
+// BL AL]
+//to a cell array c = { {B1},{A1}, {B2},{A2}, ... {BL},{AL}} where each
+//numerator vector Bi and denominator vector Ai contains the coefficients of a
+//linear or quadratic polynomial. If the polynomial is linear, the coefficients
+//zero-padded on the right
+//c=sos2cell(s,g) adds a leading gain term to the start of the cell array as:
+//c={ {[g,1]},{B1},{A1}, {B2},{A2}, ... {BL},{AL}}
+//Example
+//s=rand(2,6)
+// s =
+//
+//
+// column 1 to 5
+//
+// 0.0437334 0.2639556 0.2806498 0.7783129 0.1121355
+// 0.4818509 0.4148104 0.1280058 0.2119030 0.6856896
+//
+// column 6
+//
+// 0.1531217
+// 0.6970851
+//
+//sos2cell(s,2)
+// ans =
+//
+//
+//
+// column 1 to 3
+//
+//![2,1] [0.0437334,0.2639556,0.2806498] [0.7783129,0.1121355,0.1531217] !
+//
+// column 4 to 5
+//
+//![0.4818509,0.4148104,0.1280058] [0.2119030,0.6856896,0.6970851] !
+//Author
+//Ankur Mallick
+ if(argn(2)<2)
+ g=[];
+ end
+ if g==1
+ g=[];
+ end
+ if(~or(type(s)==[1 5 8])|ndims(s)~=2|size(s,2)~=6)
+ error('Invalid Entry');
+ end
+ L=size(s,1);
+ if ((L==1)&(~isempty(g))&(s==[1, 0, 0, 1, 0, 0]))
+ s=g*s;
+ g=[];
+ end
+ c=cell(1,2*L);
+ k=0;
+ if(~isempty(g))
+ c=cell(1,2*L+1);
+ c(1,1).entries=[g, 1];
+ k=1;
+ end
+ for i=1:2:2*L
+ j=ceil(i/2);
+ sa=s(j,1:3);
+ ma=max(find(sa~=0));
+ sb=s(j,4:6);
+ mb=max(find(sb~=0));
+ cs=cell(1,2);
+ if(~isempty(ma))
+ cs(1,1).entries=sa(1:ma);
+ else
+ cs(1,1).entries=[];
+ end
+ if(~isempty(mb))
+ cs(1,2).entries=sb(1:mb);
+ else
+ cs(1,2).entries=[];
+ end
+ c(k+i)=cs(1,1);
+ c(k+i+1)=cs(1,2);
+ end
+endfunction
diff --git a/macros/sos2ss.bin b/macros/sos2ss.bin
new file mode 100644
index 0000000..03d1147
Binary files /dev/null and b/macros/sos2ss.bin differ
diff --git a/macros/sos2ss.sci b/macros/sos2ss.sci
new file mode 100644
index 0000000..c13f688
--- /dev/null
+++ b/macros/sos2ss.sci
@@ -0,0 +1,44 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function [A,B,C,D]=sos2ss(sos,g)
+ [nargout,nargin]=argn();
+ if nargin==1 then
+ g=1;
+ end
+ if type(sos)~=1 | type(g)~=1 then
+ error('check the data type of input'); //to check if the inputs are real/complex arrays
+ end
+ if size(g)~=[1,1] then
+ error('check the data type of input'); //to check that n is single dimensional
+ end
+ //checking if sos is a 6 column matrix
+ [d,j]=size(sos);
+ 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
+ for i=[1:d]
+ num=convol(num,sos(i,1:3));
+ den=convol(den,sos(i,4:6));
+ end
+
+ if den(t)==0 then
+ error('improper transfer function check input');
+ end
+
+ 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);
+ 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.bin b/macros/sos2tf.bin
new file mode 100644
index 0000000..31a8c0e
Binary files /dev/null and b/macros/sos2tf.bin differ
diff --git a/macros/sos2tf.sci b/macros/sos2tf.sci
new file mode 100644
index 0000000..0ee0d3e
--- /dev/null
+++ b/macros/sos2tf.sci
@@ -0,0 +1,35 @@
+function [B,A] = sos2tf(sos, g)
+//This function converts series second-order sections to direct H(z) = B(z)/A(z) form.
+//Calling Sequence
+//[B] = sos2tf(sos)
+//[B] = sos2tf(sos, g)
+//[B,A] = sos2tf(...)
+//Parameters
+//sos: matrix of real or complex numbers
+//g: real or complex value, default value is 1
+//Description
+//This is an Octave function.
+//This function converts series second-order sections to direct H(z) = B(z)/A(z) form.
+//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])
+//a =
+// 1 2 3
+//b =
+// 4 5 6
+funcprot(0);
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+
+
+
+ select(rhs)
+ case 1 then
+ [B,A] = callOctave("sos2tf",sos)
+ case 2 then
+ [B,A] = callOctave("sos2tf",sos,g)
+ end
+endfunction
diff --git a/macros/sos2zp.bin b/macros/sos2zp.bin
new file mode 100644
index 0000000..34e81b4
Binary files /dev/null and b/macros/sos2zp.bin differ
diff --git a/macros/sos2zp.sci b/macros/sos2zp.sci
new file mode 100644
index 0000000..98abc36
--- /dev/null
+++ b/macros/sos2zp.sci
@@ -0,0 +1,41 @@
+function [z,p,k] = sos2zp (sos, g)
+//This function converts series second-order sections to zeros, poles, and gains (pole residues).
+//Calling Sequence
+//z = sos2zp (sos)
+//z = sos2zp (sos, g)
+//[z, p] = sos2zp (...)
+//[z, p, k] = sos2zp (...)
+//Parameters
+//sos: matrix of real or complex numbers
+//g: real or complex value, default value is 1
+//z: column vector
+//p: column vector
+//Description
+//This is an Octave function.
+//This function converts series second-order sections to zeros, poles, and gains (pole residues).
+//The input is the sos matrix and the second parameter is the overall gain, default value of which is 1.
+//The outputs are z, p, k. z and p are column vectors containing zeros and poles respectively, and k is the overall gain.
+//Examples
+//[a,b,c]=sos2zp([1,2,3,4,5,6])
+//a =
+// -1.0000 + 1.4142i
+// -1.0000 - 1.4142i
+//b =
+// -0.6250 + 1.0533i
+// -0.6250 - 1.0533i
+//c = 1
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 1 then
+ [z,p,k] = callOctave("sos2zp",sos)
+ case 2 then
+ [z,p,k] = callOctave("sos2zp",sos,g)
+ end
+endfunction
+
diff --git a/macros/sosbreak.bin b/macros/sosbreak.bin
new file mode 100644
index 0000000..de8d621
Binary files /dev/null and b/macros/sosbreak.bin differ
diff --git a/macros/sosbreak.sci b/macros/sosbreak.sci
new file mode 100644
index 0000000..dc78f95
--- /dev/null
+++ b/macros/sosbreak.sci
@@ -0,0 +1,34 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+function [zerosort,g]=sosbreak(p)
+//function for breaking a polynomial in second order polynomials (and an extra linear)
+ [zero,g]=factors(p);//factorising into real coefficient polynomials
+ degn=degree(p);
+ zerosort=list();
+ //to segregate linear and quadratic factors
+ for i=[1:length(zero)]
+ q=zero(i);
+ //putting the quadratic factor at the front
+ if degree(q)==2 then
+ zerosort(0)=q;
+ //putting the linear factor at the end
+ else
+ zerosort($+1)=q;
+ end
+ end
+
+ if (modulo(degn,2))==0 then
+ e=length(zerosort);
+ //leave the last linear element if an odd degree polynomial
+ else
+ e=length(zerosort)-1;
+ end
+ for i=[e:-2:1]
+ q=zerosort(i);
+ if degree(q)==2 then
+ break;
+ end
+ 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/sosfilt.bin b/macros/sosfilt.bin
new file mode 100644
index 0000000..3d70709
Binary files /dev/null and b/macros/sosfilt.bin differ
diff --git a/macros/sosfilt.sci b/macros/sosfilt.sci
new file mode 100644
index 0000000..cff4d58
--- /dev/null
+++ b/macros/sosfilt.sci
@@ -0,0 +1,20 @@
+function [y]=sosfilt(sos,x)
+
+// Second order section IIR filtering of x.
+// Calling Sequence
+// [y]=sosfilt(sos,x)
+// Parameters
+// sos: Real or complex valued Lx6 vector or matrix
+// x: Real or complex valued vector or matrix
+// Description
+// This is an Octave function
+// Second order section digital filter sos is applied to the input vector and the output vector obtained is of the same length.
+// Examples
+// 1. sosfilt([1 2 3 4 5 6],[-1 10i;1 2])
+// ans =[ -0.25000 0.00000; 0.06250 0.50000]
+// 2. sosfilt([32 28 84 47 2 29],-1)
+// ans = -0.68085
+
+funcprot(0);
+y=callOctave("sosfilt",sos,x)
+endfunction
diff --git a/macros/specgram.bin b/macros/specgram.bin
new file mode 100644
index 0000000..9ce781f
Binary files /dev/null and b/macros/specgram.bin differ
diff --git a/macros/specgram.sci b/macros/specgram.sci
new file mode 100644
index 0000000..3af24f1
--- /dev/null
+++ b/macros/specgram.sci
@@ -0,0 +1,21 @@
+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
+endfunction
diff --git a/macros/ss2sos.bin b/macros/ss2sos.bin
new file mode 100644
index 0000000..9dd7ba3
Binary files /dev/null and b/macros/ss2sos.bin differ
diff --git a/macros/ss2sos.sci b/macros/ss2sos.sci
new file mode 100644
index 0000000..caf2def
--- /dev/null
+++ b/macros/ss2sos.sci
@@ -0,0 +1,63 @@
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+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
+ error('check input types');
+ end
+ if (length(size(A))~=2 | length(size(B))~=2 | length(size(C))~=2 | length(size(D))~=2) then
+ error('input must be 2d matrices');
+ end
+ if (norm(imag(A))~=0 | norm(imag(B))~=0 | norm(imag(C))~=0 | norm(imag(D))~=0) then
+ error('input must be real matrices');
+ end
+ //cross checking dimensions of matrix
+ if size(D)~=[1,1] then
+ error('for single input single output, D must be 1 by 1');
+ end
+ [n,k]=size(B);
+ if k~=1 then
+ error('for single input single output, B must be column matrix');
+ end
+ [n,k]=size(C);
+ if n~=1 then
+ error('for single input single output, C must be row matrix');
+ end
+ if size(A)~=[1,1] then
+ error('A must be square matrix');
+ end
+ //obtaining the transfer function(continuous)
+ tf=ss2tf(syslin('c',A,B,C,D));
+ //factorising the numerator and the denominator into second order systems
+ [zero,gn]=sosbreak(numer(tf));//function is defined in the same folder
+ [pole,gd]=sosbreak(denom(tf));
+ //reducing each pair of second order in the necessary form
+ sos=[];
+ for i=[1:length(pole)]
+ den=pole(i);
+ // if no polynomial is left in the numerator
+ if i>length(zero) then
+ //z^(-1) is in the numerator if the denominator in linear
+ if degree(den)==1 then
+ b=[0,1,0];
+ //z^(-2) is in the numerator if the denominator is quadratic
+ else
+ b=[0,0,1];
+ end
+ //if polynomial is left
+ else
+ b=coeff(zero(i));//obtain coefficient of the polynomial
+ b=[b,zeros(1,degree(den)+1-length(b))];//add a zero in the end if the numerator is linear and denominator is quadratic
+ b=b($:-1:1);//reverse the coefficients
+ b=[b,zeros(1,3-length(b))];//add a zero if both numerator and denominator are linear
+ end
+ a=coeff(den);//coefficient of the denominator
+ a=a($:-1:1);//reversing the coefficients
+ a=[a,zeros(1,3-length(a))];//adding zeros if the denominator is linear
+ v=[b,a];
+ sos=[sos;v]//adding the second order sub-system
+ end
+
+ g=gn/gd;//computing the gain
+
+endfunction
diff --git a/macros/statelevels.bin b/macros/statelevels.bin
new file mode 100644
index 0000000..acdb468
Binary files /dev/null and b/macros/statelevels.bin differ
diff --git a/macros/statelevels.sci b/macros/statelevels.sci
new file mode 100755
index 0000000..d21a4f8
--- /dev/null
+++ b/macros/statelevels.sci
@@ -0,0 +1,310 @@
+function [levels, histogram, bins] = statelevels (x, varargin) // defining function
+
+ // This function estimate statelevels of real vector X via histogram.
+ // Calling Sequence
+ // levels=statelevels(x, nbins, method, bounds)
+ // [levels histogram]=statelevels(x, nbins, method, bounds)
+ // [levels histogram bins]=statelevels(x, nbins, method, bounds)
+ // [levels histogram bins]=statelevels(x, nbins, method, bounds, 'fig', On or Off)
+ // Parameters
+ // x: real vector
+ // nbins: number of histogram bins to use in the histogram as a positive scalar, where the default value is 100
+ // method: method to estimate the statelevels using specified METHOD as one of 'mean' or 'mode', where the default value is 'mode'
+ // bounds: specify the lower and upper bound for the histogram as a two-element row vector
+ // fig: specify the logical input value to display figure as one of 'on' or 'off', where the default input in 'off'.
+ // levels: return lower and upper level values
+ // histogram: return histogram values
+ // bins: return binlevels values
+ // Examples
+ // x=[1.2, 5, 10, -20, 12]
+ // nbins=10
+ // method='mode'
+ // bounds=[1 10]
+ // levels=statelevels(x, nbins, method, bounds)
+ // See also
+ // Authors
+ // Jitendra Singh
+
+
+
+
+
+ if or(type(x)==10) then
+ error ('Input arguments must be double.')
+end
+if size(x,2)==1 | size(x,1)==1 then
+else
+ error("Input x should be a vector");
+end
+if length(x) < 2 then // checking the length of input datasat
+ error('X must be a vector with more than one element.'); // if length of X is less 2, it will give error
+end
+
+if length(varargin)>5 then
+ error('Wrong number on input arguments.')
+end
+
+if length(varargin)==0 then
+ nbins=100; // defining the default value of no of bins
+ method='mode'; // defing the defualt method 'mode'
+ bounds=[min(x) max(x)];
+ fig='off';
+end
+
+
+if length(varargin)==1 then
+
+ if varargin(1) =='fig' then
+ error('input argument fig required a values.')
+ else
+ nbins=varargin(1);
+ method='mode'; // defing the defualt method 'mode'
+ bounds=[min(x) max(x)];
+ fig='off';
+
+ end
+end
+
+
+if length(varargin)==2 then
+ nbins=100;
+ fig='off';
+ bounds=[min(x) max(x)];
+ method='mode';
+ if varargin(1)=='fig'
+ fig=varargin(2)
+ elseif varargin(2)=='fig' then
+ nbins=varargin(1);
+ error ('input argument fig required a values.')
+
+elseif varargin(1)~='fig' & varargin(2)~='on' | varargin(2)~='off' then
+ nbins=varargin(1);
+ method=varargin(2);
+
+end
+
+end
+
+
+if length(varargin)==3 then
+ nbins=varargin(1);
+ method='mode';
+ bounds=[min(x) max(x)];
+ fig='off';
+ if varargin(2)== 'fig' then
+ fig=varargin(3)
+ elseif varargin(3)=='fig' then
+ error ('input argument fig required a values.')
+ else
+ method=varargin(2);
+ bounds=varargin(3);
+ end
+
+
+ end
+
+
+if length(varargin)==4 then
+ nbins=varargin(1);
+ method=varargin(2);
+ bounds=[min(x) max(x)];
+ fig='off';
+
+ if varargin(3)=='fig' then
+ fig=varargin(4)
+ elseif varargin(4)=='fig' then
+ error ('input argument fig required a values.')
+ elseif varargin(4)~='fig' then
+ error('Unexpected input argument.')
+ else
+ bounds=varargin(3);
+ end
+
+end
+
+
+if length(varargin)==5 then
+ nbins=varargin(1);
+ method=varargin(2);
+ bounds=varargin(3);
+ if varargin(4)=='fig' then
+ fig=varargin(5);
+ else
+ error('Wrong input argument.')
+ end
+
+end
+
+
+ if and(x==0) then
+ levels=zeros(1,2)
+ histogram1=13;
+ xx=zeros(1, (nbins-1));
+ histogram=[histogram1,xx];
+ bins=zeros(1,nbins);
+
+ else
+
+ if type(nbins)==10 then // checking, if nbins if numeric aur charactr
+ error ('Expected NBINS to be one of these types: double, Instead its type was char.');
+ end
+if pmodulo(nbins,1)==0 then // checking, if nbins is integert or not
+else
+ error ('Size inputs must be integers.')
+end
+
+if length(nbins)~=1 then
+ error('Expected NBINS to be a scalar.')
+end
+
+
+
+ if method == 'mode' | method == 'mean' then // method should be either mean or mode
+ else
+ error('Expected METHOD to match one of these strings: mean or mode');
+ end
+
+
+
+
+ if type(bounds)==10 then // checking, if nbins if numeric aur charactr
+ error ('Expected BOUNDS to be one of these types: double, Instead its type was char.');
+end
+
+if length(bounds)~=2 then
+ s=size(bounds);
+ error(strcat(["Expected BOUNDS to be of size 1x2 when it is actually size", " ", string(s(1)), "x", string(s(2))]))
+end
+
+
+//if bounds(2)>0 | bounds (1)>0 then
+//
+//if bounds(2)>bounds(1) then
+// lower=bounds(1)
+// upper=bounds(2);
+// else
+// error('BOUNDS must be strictly increasing.')
+//end
+//end
+
+if bounds(2)<=bounds(1) then
+ error('BOUNDS must be strictly increasing.')
+else
+ lower=bounds(1);
+ upper=bounds(2);
+end
+
+if bounds(2)==0 & bounds (1)==0 then
+ lower=0;
+ upper=0;
+end
+
+ if fig == 'off' | fig == 'on' then // method should be either mean or mode
+ else
+ error('Expected fig to match one of these strings: on or off');
+ end
+
+ denomm = upper-lower;
+ if denomm==0 then
+ denomm = 2.220D-16 ;
+ end
+
+ idx = nbins * (x-lower)/denomm;
+ idx = ceil(idx) + (idx==0);
+ idx = idx(idx>=1 & idx<=nbins);
+ histo = zeros(nbins, 1);
+ for i=1:length(idx)
+ histo(idx(i)) = histo(idx(i)) + 1; // calculationf histogram
+ end
+
+
+
+
+dy = (upper - lower) / length(histo);
+index=find(histo>0);
+
+if isempty(index) then
+ iLowerRegion=[]
+ iUpperRegion=[]
+
+else
+ nn=length(index);
+ iLowerRegion = index(1);
+
+ iUpperRegion = index(nn);
+end
+
+ if isempty(iLowerRegion) | isempty(iUpperRegion) then
+ levels = ['NaN' 'NaN'];
+ else
+
+
+ iLow = iLowerRegion(1);
+ iHigh = iUpperRegion(1);
+
+ // define the lower and upper histogram regions halfway
+ //between the lowest and highest nonzero bins.
+ lLow = iLow;
+ lHigh = iLow + floor((iHigh - iLow)/2);
+ uLow = iLow + floor((iHigh - iLow)/2);
+ uHigh = iHigh;
+
+ lHist = histo(lLow:lHigh); // defing lower and upper histogram
+ uHist = histo(uLow:uHigh);
+
+ levels = zeros(1,2);
+ if (method == 'mode') then // if method is mode, calculate upper and lower levels
+ [j iMax] = max(lHist);
+ [k iMin] = max(uHist);
+ levels(1) = lower + dy * (lLow + iMax(1) - 1.5);
+ levels(2) = lower + dy * (uLow + iMin(1) - 1.5);
+ elseif (method=='mean') then // if method is mean, calculate lower and upper levels
+ levels(1) = lower + dy * sum(((lLow:lHigh)-0.5).* (lHist)') / sum(lHist);
+ levels(2) = lower + dy * sum(((uLow:uHigh)-0.5).* (uHist)') / sum(uHist);
+ end
+
+ // calculation bins
+
+ end
+
+ histogram=histo;
+ bins = lower + ((1:nbins) - 0.5)' * (upper - lower) / nbins;
+
+
+
+ if fig=='on' then // if the defined output is only 1, the it will provide the graphical representation of //levels
+
+ if levels(1)=='NaN' | levels(2)=='NaN' then
+ subplot(2,1,1)
+ plot(x, '-k', 'LineWidth',2)
+ xlabel("Samples", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+ title("Signal", "fontsize",3)
+
+ subplot(2,1,2)
+ plot(bins,histogram, '-k', 'LineWidth',2)
+ xlabel("Level (Volts)", "fontsize",3, "color", "black" )
+ ylabel("Count", "fontsize",3, "color", "black" )
+ title("Histogram of the signal levels", "fontsize",3)
+
+ else
+ subplot(2,1,1)
+ plot(x, '-k', 'LineWidth',2)
+ plot([1 length(x)],levels(1) * [1 1],'-.r', 'LineWidth',2)
+ plot([1 length(x)],levels(2) * [1 1],'-.r', 'LineWidth',2)
+ xlabel("Samples", "fontsize",3, "color", "black" )
+ ylabel("Level (Volts)", "fontsize",3, "color", "black" )
+ title("Signal", "fontsize",3)
+
+ subplot(2,1,2)
+ plot(bins,histogram, '-k', 'LineWidth',2)
+ xlabel("Level (Volts)", "fontsize",3, "color", "black" )
+ ylabel("Count", "fontsize",3, "color", "black" )
+
+ title("Histogram of the signal levels", "fontsize",3)
+ end
+ end
+ end
+
+
+ endfunction
diff --git a/macros/stmcb.bin b/macros/stmcb.bin
new file mode 100644
index 0000000..3fecc2b
Binary files /dev/null and b/macros/stmcb.bin differ
diff --git a/macros/stmcb.sci b/macros/stmcb.sci
new file mode 100644
index 0000000..938bc77
--- /dev/null
+++ b/macros/stmcb.sci
@@ -0,0 +1,92 @@
+//Compute linear model using Steiglitz-McBride iteration
+//calling syntax
+//[b,a] = stmcb(h,nb,na)
+//[b,a] = stmcb(y,x,nb,na)
+//[b,a] = stmcb(h,nb,na,niter)
+//[b,a] = stmcb(y,x,nb,na,niter)
+//[b,a] = stmcb(h,nb,na,niter,ai)
+//[b,a] = stmcb(y,x,nb,na,niter,ai)
+//b,a : coefficients of the system b(z)/a(z)
+//h:impulse response of the system
+//x,y: input and output of same length given to the system
+//niter: no of iterations
+//ai:initial estimate of the denominator coefficients
+//Accepts only real i/ps , imaginary i/ps are not accepted due to limitations of the 'filter' function in Scilab
+function [b,a] = stmcb( x, u_in, q, p, niter, a_in )
+
+ narginchk(3, 6, argn(2));
+ //modify stmcb to handle exceptions when i/p is char
+ if(type(x)==10 | type(u_in)==10) then
+ error("Input in stmcb must be double/single, instead it was char");
+ end
+ if length(u_in) == 1 then
+ if argn(2) == 3 then
+ niter = 5;
+ p = q;
+ q = u_in;
+ a_in = prony(x, 0, p);
+
+ elseif argn(2) == 4
+ niter = p;
+ p = q;
+ q = u_in;
+ a_in = prony(x, 0, p);
+
+ elseif argn(2) == 5
+ a_in = niter;
+ niter = p;
+ p = q;
+ q = u_in;
+
+ end
+ [x_row, x_col] = size(x);
+ u_in = zeros(x_row, x_col);
+ u_in(1) = 1;
+
+ else
+ if length(u_in) ~= length(x) then
+ error('Input Signal x and Output Signal Y must have the same length');
+ end
+
+ if argn(2) < 6 then
+ [b, a_in] = prony(x, 0, p);
+ end
+
+ if argn(2) < 5 then
+ niter = 5;
+ end
+
+ end
+
+ a = a_in;
+ N = length(x);
+
+ for i = 1:niter
+ u = filter(1, a, x);
+ v = filter(1, a, u_in);
+ C1 = convmtx(u(:),p+1);
+ C2 = convmtx(v(:),q+1);
+ T = [ -C1(1:N,:) C2(1:N,:)];
+ c = T(:,2:p+q+2)\(-T(:,1));
+ a = [1; c(1:p)];
+ b = c(p+1:p+q+1);
+
+ end
+
+ a = a.';
+ b = b.';
+
+
+
+endfunction
+
+function narginchk(min_argin, max_argin, num_of_argin)
+ if num_of_argin < min_argin then
+ error('Not enough input arguments')
+ end
+
+ if num_of_argin > max_argin then
+ error('Too many input arguments')
+ end
+
+endfunction
diff --git a/macros/strips.bin b/macros/strips.bin
new file mode 100644
index 0000000..45199f3
Binary files /dev/null and b/macros/strips.bin differ
diff --git a/macros/strips.sci b/macros/strips.sci
new file mode 100644
index 0000000..007787a
--- /dev/null
+++ b/macros/strips.sci
@@ -0,0 +1,113 @@
+function strips(x,sd,Fs,scale)
+//Plots vector or matrix in strips
+//Calling Sequence
+//strips(x);
+//strips(x,sd);
+//strips(x,sd,fs);
+//strips(x,sd,fs,scale);
+//Parameters
+//x
+//A vector or a matrix
+//sd
+//Strip duration
+//fs
+//Sampling frequency
+//scale
+//Scaling parameter for vertical axis
+//Description
+//strips(x)
+//Plots a vector x in horizontal strips of length 250
+//If x is a matrix, it plots each column of x on a separate strip with the leftmost
+//column as the topmost strip
+//strips(x,sd)
+//Plots x in strips of length sd samples each
+//strips(x,sd,fs)
+//Plots x in strips of duration sd seconds with sampling frequency fs (in Hz)
+//strips(x,sd,fs,scale)
+//Plots x in strips as above, and scales the vertical axis by scale
+//If x is a matrix, strips uses a column vector of all the elements of x for the strip plot
+//If x has complex entries, only the real part of those entries are considered
+//Author
+//Ankur Mallick
+ funcprot(0);
+ if(argn(2)<1|argn(2)>4)
+ error('Incorrect number of input arguments.');
+ else
+ if(or(imag(x)~=0))
+ warning('Only real parts will be considered');
+ x=real(x);
+ end
+ S=size(x);
+ if(min(S)==1)
+ x=x(:);
+ S=size(x);
+ end
+ if(argn(2)<4)
+ scale=1
+ end
+ if(argn(2)<3)
+ Fs=1;
+ end
+ if(argn(2)<2)
+ if(min(S)==1)
+ sd=250;
+ else
+ sd=S(1);
+ end
+ end
+ Lstrip=ceil(sd*Fs); //Length of each strip
+ if(pmodulo(S(1),Lstrip)==1)
+ x=x(1:S(1)-1,:); //If only 1 point is left in each row, then it is discarded
+ S=size(x);
+ end
+ Nstrip=ceil(S(1)/Lstrip);
+ x1=x(~isnan(x));
+ xmin=min(x1(:));
+ xmax=max(x1(:));
+ x0=(xmin+xmax)/2;
+ x=scale*x;
+ //adding NaNs
+ if (Lstrip*Nstrip>S(1))
+ x(S(1)+1:Lstrip*Nstrip,:)=%nan*ones(Lstrip*Nstrip-S(1),S(2));
+ end
+ //Computing vertical deviations to add to x
+ del=(xmax-xmin)/4
+ sep =5*(xmax-xmin)/4;
+ if(sep == 0)
+ sep = 1;
+ end
+ dev=(Nstrip-1:-1:0)*sep;
+ y=zeros((Lstrip+1)*Nstrip,S(2));
+ for i = 1:S(2)
+ y1=[matrix(x(:,i),Lstrip,Nstrip); %nan*ones(1,Nstrip)];
+ //Adding vertical deviation to x
+ y1=y1-x0+dev(ones(Lstrip+1,1),:);
+ y(:,i) = y1(:);
+ end
+ //Computing horizontal (time) axis
+ t=[((0:Lstrip-1)'/Fs)*ones(1,Nstrip); %nan*ones(1,Nstrip)];
+ t = t(:);
+ //Computing yticks and yticklabels
+ yt=((0:Nstrip-1)*sep)'; //yticks
+ width=32;
+ s1=ones(Nstrip, width)*ascii(' ');
+ s=matrix(char(s1(:)),Nstrip,width);
+ col=width+1;
+ for i=1:Nstrip
+ str=string((i-1)*sd);
+ str1=(strsplit(str))'
+ s(i,width-length(str)+1:width)=str1;
+ col=min(col,width-length(str)+1);
+ end
+ s=s($:-1:1,:)
+ s=char(s(:,col:width)); //yticklabels
+ //Plotting and setting axes properties
+ figure
+ plot(t,y)
+ a=gca();
+ a.y_ticks=tlist(['ticks','locations','labels'],yt,s)
+ a.data_bounds=[0,xmin-x0-del;sd,xmin-x0+sep*Nstrip];
+ a.tight_limits='on';
+ a.grid=[-1,1]
+ end
+endfunction
diff --git a/macros/subspaceMethodsInputParser.bin b/macros/subspaceMethodsInputParser.bin
new file mode 100644
index 0000000..e2ae41b
Binary files /dev/null and b/macros/subspaceMethodsInputParser.bin differ
diff --git a/macros/subspaceMethodsInputParser.sci b/macros/subspaceMethodsInputParser.sci
new file mode 100644
index 0000000..1396c86
--- /dev/null
+++ b/macros/subspaceMethodsInputParser.sci
@@ -0,0 +1,396 @@
+// Date of creation: 17 Dec, 2015
+function [data, msg, err_num] = subspaceMethodsInputParser(inputArgsList)
+ // Input parser to be used by pmusic and peig
+
+ // primaryInput, p, w, nfft, fs, nwin, noverlap, freqrange, isCorrFlag
+
+ // NOTE: not accepting as it is indistinguishable from
+
+ // Input combinations
+ // x, p
+ // x, p, w
+ // x, p, nfft
+ // x, p, nfft, fs
+ // x, p, f, fs
+ // x, p, nfft, fs, nwin, noverlap
+
+ // 'corr' flag with everyone
+ // freqrange string
+
+
+
+ // Output arguments description:
+ // data - struct with the following arguments
+ // x - input signal or correlation matrix
+ // p - scalar|2-element vector - signal subspace parameters
+ // w/f - vector
+ // nfft - positive scalar
+ // fs - positive scalar
+ // isWindowSpecified - boolean indicating if window specified in the
+ // input params
+ // windowLength - positive scalar
+ // windowVector - vector
+ // noverlap - scalar
+ // freqrange - string
+ // 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)
+
+
+ msg = "";
+ err_num = -1;
+ data = struct();
+
+ numOfInputArgs = length(inputArgsList);
+
+ // ****getting indices of all string input arguments****
+ stringIndices = list();
+ for i=1:numOfInputArgs
+ e = inputArgsList(i);
+ if type(e)==10 then
+ stringIndices($+1)=i;
+ end
+ end
+
+
+ isCorrFlag = %F;
+ isOneSided = %F;
+ isTwoSided = %F;
+ isCentered = %F;
+
+ if ~isempty(stringIndices) then
+ // ****checking for corr flag****
+ isCorrFlag = or(strcmpi(inputArgsList(stringIndices),"corr")==0);
+
+ // ****checking for freqrange****
+ isOneSided = or(strcmpi(inputArgsList(stringIndices),"onesided")==0);
+ isTwoSided = or(strcmpi(inputArgsList(stringIndices),"twosided")==0 ...
+ | strcmpi(inputArgsList(stringIndices),"whole")==0);
+ isCentered = or(strcmpi(inputArgsList(stringIndices),"centered")==0);
+ end
+
+ freqrange = "";
+ if isTwoSided then
+ freqrange = "twosided";
+ elseif isCentered then
+ freqrange = "centered";
+ else
+ freqrange = "onesided";
+ end
+
+ // deleting the string arguments from inputArgsList
+ for index=stringIndices
+ inputArgsList(index) = null();
+ end
+
+
+ L = length(inputArgsList);
+ if L<2 then
+ msg = "Input arguments must have x (signal) or R (corr. matrix)" + ...
+ "as 1st argument and p as 2nd argument";
+ err_num = 72;
+ return
+ elseif L>6 then
+ msg = "Atmost 6 numeric arguments expected";
+ err_num = 72;
+ return
+ end
+
+
+ // **** extracting x/R (signal/corr. matrix)
+ primaryInput = inputArgsList(1);
+
+ if ndims(primaryInput)<1 | ndims(primaryInput)>2 then
+ msg = "Wrong dimensions for argument #1; must be a vector or a matrix";
+ err_num = 60;
+ return
+ end
+ if ~IsIntOrDouble(primaryInput, %F) then
+ msg = "Wrong type for argument #1; int or double expected";
+ err_num = 84;
+ return
+ end
+ // covert to a column vector
+ if ndims(primaryInput)==1 then
+ primaryInput = primaryInput(:);
+ end
+ // casting to double
+ primaryInput = double(primaryInput);
+
+
+ //****extracting p****
+ p = inputArgsList(2);
+
+ // p must be either scalar or a 2-element vector
+ if length(p)~=1 & length(p)~=2 then
+ msg = "Wrong size of argument #2 (p); " + ...
+ "must be a scalar or a 2-element vector";
+ err_num = 60;
+ return
+ end
+ // first argument of p must be an integer
+ if ~IsIntOrDouble(p(1),%T) then
+ msg = "Wrong type for p(1); must be a positive integer";
+ err_num = 84;
+ return
+ end
+ p(1) = int(p(1));
+ // TODO: check if positive required
+ // 2nd argument, if exists, must be a positive integer'
+ if length(p)==2 then
+ if ~IsIntOrDouble(p(2),%F) then
+ msg = "Wrong type for p(2); must be a scalar";
+ err_num = 84;
+ return
+ end
+ end
+
+ // ****extracting the remaining arguments****
+
+ // assigning default values
+ w = [];
+ fs = 1;
+ isFsSpecified = %F;
+ nfft = 256;
+ windowLength = 2*p(1);
+ isWindowSpecified = %F;
+ windowVector = [];
+ if windowLength==%inf then
+ windowLength=[];
+ end
+
+ noverlap = [];
+
+
+ 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
+ msg = "Wrong dimension for argument #3; must be a scalar|vector";
+ err_num = 60;
+ return
+ end
+
+ if isempty(temp3) then
+ nfft = 256;
+ elseif length(temp3)==1 then
+ // must be nfft
+
+ // positive integer check
+ if ~type(temp3)==8 | temp3<=0 then
+ msg = "Wrong type for argument #3 (nfft); must be a positive integer";
+ err_num = 84;
+ return
+ end
+
+ nfft = temp3;
+ else
+ // must be w
+
+ // numeric type check
+ if ~IsIntOrDouble(temp3, %F) & or(temp3<0) then
+ msg = "Wrong type for argument #3 (w); must be int or double";
+ err_num = 82;
+ return
+ end
+ w = double(temp3(:)); // converting to column vector
+ end
+
+ elseif L==4 then
+ // (x, p, nfft, fs), and (x, p, f, fs) are candidates
+ temp3 = inputArgsList(3);
+ temp4 = inputArgsList(4);
+
+ // should be a vector
+ if size(temp3, 1)~=1 & size(temp3, 2)~=1 then
+ msg = "Wrong dimension for argument #3; must be a scalar/vector";
+ err_num = 60;
+ return
+ end
+
+
+ if isempty(temp3) then
+ // nfft and fs
+ nfft = 256;
+
+ if length(temp4)==1 then
+ if ~IsIntOrDouble(temp4, %T) then
+ msg = "Wrong type for argument #4 (fs); must be a positive scalar";
+ err_num = 84;
+ return
+ end
+ fs = double(temp4);
+ isFsSpecified = %T;
+ end
+ elseif length(temp3)==1 then
+ // nfft, fs
+
+ // positive integer check
+ if ~(type(temp3)==1 | type(temp3)==8) | temp3<=0 then
+ msg = "Wrong type for argument #3 (nfft); must be a positive integer";
+ err_num = 84;
+ return
+ end
+ nfft = temp3;
+
+ if length(temp4)==1 then
+ if ~IsIntOrDouble(temp4, %T) then
+ msg = "Wrong type for argument #4 (fs); must be a positive scalar";
+ err_num = 84;
+ return
+ end
+ fs = double(temp4);
+ isFsSpecified = %T;
+ end
+ else
+ // (f,fs)
+
+ // numeric type check
+ if ~IsIntOrDouble(temp3, %F) & or(temp3<0) then
+ msg = "Wrong type for argument #3 (f); must be int or double";
+ err_num = 82;
+ return
+ end
+ w = double(temp3(:));
+
+ if length(temp4)~=1 then
+ msg = "Wrong dimension for argument #4 (fs); must be a positive scalar";
+ err_num = 84;
+ return
+ else
+ if ~IsIntOrDouble(temp4, %F) then
+ msg = "Wrong type for argument #4 (fs); must be a positive scalar";
+ err_num = 84;
+ return
+ end
+ fs = double(temp4);
+ isFsSpecified = %T;
+ end
+ end
+
+ elseif L>=5 then
+ // nfft, fs, nwin, noverlap
+ nfft = inputArgsList(3);
+ fs = inputArgsList(4);
+ temp5 = inputArgsList(5);
+ if L==6 then
+ noverlap = inputArgsList(6);
+ end
+
+ if isempty(nfft) then
+ nfft = 256;
+ elseif ~length(nfft)==1 | ~IsIntOrDouble(nfft,%T) then
+ msg = "Wrong type for argument #3 (nfft); must be a positive integer";
+ err_num = 84;
+ return
+ end
+
+ if isempty(fs) then
+ fs = 1;
+ elseif ~length(fs)==1 | ~IsIntOrDouble(fs, %T) then
+ msg = "Wrong type for argument #4 (fs); must be a positive scalar";
+ err_num = 84;
+ return
+ else
+ isFsSpecified = %T;
+ end
+
+ // parsing window paramater
+ if length(temp5)==1 then
+ // window length is specified
+ if ~IsIntOrDouble(temp5,%T) then
+ msg = "Wrong type for argument #5 (nwin); must be a positive integer or a numeric vector";
+ err_num = 40;
+ return
+ end
+ windowLength = int(temp5);
+ isWindowSpecified = %T;
+ // windowVector = window('re',windowLength);
+ elseif ndims(temp5)==1 then
+ // window is specified
+ if ~IsIntOrDouble(temp5, %F) then
+ msg = "Wrong type for argument #5 (nwin); must be a positive integer or a numeric vector";
+ err_num = 40;
+ return
+ end
+ windowVector = double(temp5(:));
+ windowLength = length(windowVector);
+ isWindowSpecified = %T;
+ elseif ~isempty(temp5) then
+ msg = "Wrong type for argument #5 (nwin); must be a positive integer or a numeric vector";
+ err_num = 40;
+ return
+ end
+
+
+ // noverlap
+ if isempty(noverlap) then
+ 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);
+ 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
+ freqrange = "onesided";
+ else
+ 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;
+ data.nfft = nfft;
+ data.fs = fs;
+ data.isWindowSpecified = isWindowSpecified;
+ data.windowLength = windowLength;
+ data.windowVector = windowVector;
+ data.noverlap = noverlap;
+ data.freqrange = freqrange;
+ data.isCorrFlag = isCorrFlag;
+ data.isFsSpecified = isFsSpecified;
+
+
+endfunction
+
+function result = IsIntOrDouble(inputNum, isPositiveCheck)
+ // Checks if The Input Is Integer Or Double
+ // Also Checks if It Is Greater Than 0 For IsPositiveCheck = True
+
+ if ~(type(inputNum)==1 | type(inputNum)==8) then
+ result = %F;
+ return
+ end
+ if isPositiveCheck & or(inputNum<=0) then
+ result = %F;
+ return
+ end
+
+ result = %T;
+ return
+endfunction
diff --git a/macros/taylorwin.sci~ b/macros/taylorwin.sci~
new file mode 100644
index 0000000..85ab015
--- /dev/null
+++ b/macros/taylorwin.sci~
@@ -0,0 +1,83 @@
+//Taylor Window
+TAYLORWIN(N) returns an N-point Taylor window in a column vector.
+//
+// TAYLORWIN(N,NBAR) returns an N-point Taylor window with NBAR nearly
+// constant-level sidelobes adjacent to the mainlobe. NBAR must be an
+// integer greater than or equal to one.
+//
+// TAYLORWIN(N,NBAR,SLL) returns an N-point Taylor window with SLL maximum
+// sidelobe level in dB relative to the mainlobe peak. SLL must be a
+// negative value, e.g., -30 dB.
+//
+//NBAR should satisfy NBAR >= 2*A^2+0.5, where A is equal to
+//acosh(10^(-SLL/20))/pi, otherwise the sidelobe level specified is not
+//guaranteed. If NBAR is not specified it defaults to 4. SLL defaults to
+//-30 dB if not specified.
+
+//Author: Parthasarathi Panda
+//parthasarathipanda314@gmail.com
+//the function is for application on vectors only
+//Modified function to reject negative window length and no of constant level sidelobes with appropriate error messages
+function [w]=taylorwin(n,nbar,sll)
+ [nargout,nargin]=argn();
+ if nargin<1 then
+ error("Not enough input arguments")
+ end
+ if nargin==1 then
+ nbar=4;
+ sll=-30;
+ elseif nargin==2
+ sll=-30;
+ end
+ if type(n)~=1 | type(nbar)~=1 | type(sll)~=1 then
+ error('check the data type of input'); //to check if the inputs are real/complex arrays
+ end
+
+ if size(n)~=[1,1] then
+ error('check the data type of input'); //to check that n is single dimensional
+ end
+ if floor(n)~=n | imag(n)~=0 then
+ error('check that n is an integer');//to check if n is an integer
+ end
+
+ if size(nbar)~=[1,1] then
+ error('check the data type of input'); //to check that nbar is single dimensional
+ end
+ if floor(nbar)~=nbar | imag(nbar)~=0 then
+ error('check that nbar is an integer');//to check if nbar is an integer
+ end
+
+ if size(sll)~=[1,1] then
+ error('check the data type of input'); //to check that sll is single dimensional
+ end
+ if sll>0 | imag(sll)~=0 then
+ error('The sidelobe level SLL must be a negative number.');//to check if sll is a negative no.
+ end
+ //check if window length is positive
+ if(n<0) then
+ error("The window length must be a positive integer");
+ end
+ //check if no of constant level sidelobes is positive
+ if (nbar<=0) then
+ error("The number of nearly constant-level sidelobes NBAR must be a positive integer greater than 0.");
+ end
+ B=10^(-sll/20);
+ A=log(B+sqrt(B*B-1))/%pi;
+ sig=nbar*nbar/(A*A+(nbar-0.5)*(nbar-0.5));
+ //computing Fm (the coefficients for the cosines
+ m=ones(nbar-1,1)*[1:nbar-1];
+ i=([1:nbar-1])'*ones(1,nbar-1);
+ M=((1-((m.*m/sig)./(A*A+(i-0.5).*(i-0.5)))));//./(1-(m.*m)./(i.*i)));
+ m=[1:nbar-1];
+ F=prod(M,1).*((-1)^(m+1));
+ for m=1:nbar-1
+ j=[[1:m-1],[m+1:nbar-1]];
+ F(m)=F(m)/prod((1-(m.*m)./(j.*j)));
+ end
+ //computing the window
+ nv=ones(nbar-1,1)*([0:n-1]);
+ m=([1:nbar-1])'*ones(1,n);
+ M=cos(2*%pi*m.*(nv-(n-1)/2)/n);
+ w=ones(1,n)+F*M;
+ w=w';
+endfunction
diff --git a/macros/tf2sos.bin b/macros/tf2sos.bin
new file mode 100644
index 0000000..e0e70a9
Binary files /dev/null and b/macros/tf2sos.bin differ
diff --git a/macros/tf2sos.sci b/macros/tf2sos.sci
new file mode 100644
index 0000000..7570707
--- /dev/null
+++ b/macros/tf2sos.sci
@@ -0,0 +1,35 @@
+function [sos,varargout] = tf2sos (b, a)
+//This function converts direct-form filter coefficients to series second-order sections.
+//Calling Sequence
+//[sos] = tf2sos (b, a)
+//[sos, g] = tf2sos (b, a)
+//Parameters
+//b: matrix of real numbers
+//a: matrix of real numbers
+//Description
+//This is an Octave function.
+//This function converts direct-form filter coefficients to series second-order sections.
+//The input parameters b and a are vectors specifying the digital filter H(z) = B(z)/A(z).
+//The output is the sos matrix and the overall gain.
+//If there is only one output argument, the overall filter gain is applied to the first second-order section in the sos matrix.
+//Examples
+//tf2sos([1,2,3,4,5,6],2)
+//ans =
+// 0.50000 0.80579 1.07239 1.00000 0.00000 0.00000
+// 1.00000 -1.10337 1.87524 1.00000 0.00000 0.00000
+// 1.00000 1.49180 -0.00000 1.00000 0.00000 0.00000
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+
+if(rhs~=2)
+error("Wrong number of input arguments.")
+end
+ select(lhs)
+ case 1 then
+ sos = callOctave("tf2sos",b,a)
+ case 2 then
+ [sos,g] = callOctave("tf2sos",b,a)
+ end
+endfunction
diff --git a/macros/tf2zp.bin b/macros/tf2zp.bin
new file mode 100644
index 0000000..2cfc2ce
Binary files /dev/null and b/macros/tf2zp.bin differ
diff --git a/macros/tf2zp.sci b/macros/tf2zp.sci
new file mode 100644
index 0000000..7c482d5
--- /dev/null
+++ b/macros/tf2zp.sci
@@ -0,0 +1,72 @@
+// Transfer function to zero pole conversion
+//[z,p,k]= tf2zp(b,a);
+//z=zeros of the corrsponding tf
+//p=poles of the corresponding tf
+//k=gain of the tf
+//b=vector containing the numerator coefficients of the transfer function in descending powers of s
+//a=vector containing the denominator coefficients of the transfer function in descending powers of s
+//For discrete-time transfer functions, it is highly recommended to
+//make the length of the numerator and denominator equal to ensure
+//correct results. You can do this using the function EQTFLENGTH in
+//the Signal Processing Toolbox.
+//
+//
+//Author
+//Debdeep Dey
+
+function [z,p,k]=tf2zp(num,den)
+numop=argn(1);
+//take only the first row of numerator into consideration
+num=num(1,:);
+//remove leading columns of zeros from numerator
+if ~isempty(num) then
+ while(num(:,1)==0 & length(num)>1)
+ num(:,1)=[];
+ end
+end
+[rd,cod]=size(den);
+[ny,np]=size(num);
+
+if(rd>1) then
+ error("Denominator must be row vector");
+elseif np>cod then
+ error("Improper transfer function");
+end
+if (~isempty(den)) then
+ coef=den(1);
+else
+ coef=1;
+end
+if coef ==0 then
+ error("Denominator must have non zero leading coefficient");
+end
+//remove leading columns of zeros from numerator
+if ~isempty(num) then
+ while(num(:,1)==0 & length(num)>1)
+ num(:,1)=[];
+ end
+end
+
+if (find(den==%inf) ~= [] | find(num==%inf) ~= []) then
+ error("Input to ROOTS must not contain NaN or Inf")
+end
+//poles
+
+p=roots(den);
+//zeros and gain
+
+k=zeros(ny,1);
+linf=%inf;
+
+z=linf(ones(np-1,1),ones(ny,1));
+for i=1:ny
+ zz=roots(num(i,:));
+ if ~isempty(zz), z(1:length(zz), i) = zz; end
+ ndx = find(num(i,:)~=0);
+ if ~isempty(ndx), k(i,1) = num(i,ndx(1))./coef; end
+end
+z=roots(num);
+endfunction
+
+
+
diff --git a/macros/tf2zpk.bin b/macros/tf2zpk.bin
new file mode 100644
index 0000000..ed110d1
Binary files /dev/null and b/macros/tf2zpk.bin differ
diff --git a/macros/tf2zpk.sci b/macros/tf2zpk.sci
new file mode 100644
index 0000000..f919316
--- /dev/null
+++ b/macros/tf2zpk.sci
@@ -0,0 +1,20 @@
+//tf2zpk Convert transfer function filter parameters to zero-pole-gain
+//form
+//Calling Syntax :
+// [z,p,k] = tf2zpk(b,a)
+//where
+//z=zeros of the corrsponding tf
+//p=poles of the corresponding tf
+//k=gain of the tf
+//b=vector containing the numerator coefficients of the transfer function in descending powers of s
+//a=vector containing the denominator coefficients of the transfer function in descending powers of s
+
+function [zero, pole, gain] = tf2zpk(num, den)
+
+ if argn(2)< 2 | isempty(den) then
+ den = 1;
+ end
+ [num, den] = eqtflength(num, den);
+ [zero, pole, gain] = tf2zp(num, den);
+
+endfunction
diff --git a/macros/transpose.bin b/macros/transpose.bin
new file mode 100644
index 0000000..4531927
Binary files /dev/null and b/macros/transpose.bin differ
diff --git a/macros/transpose.sci b/macros/transpose.sci
new file mode 100644
index 0000000..53b2d4a
--- /dev/null
+++ b/macros/transpose.sci
@@ -0,0 +1,6 @@
+function [y] = transpose(x)
+funcprot(0);
+
+y = callOctave("transpose",x)
+
+endfunction
diff --git a/macros/trial_iirlp2mb.bin b/macros/trial_iirlp2mb.bin
new file mode 100644
index 0000000..89171e5
Binary files /dev/null and b/macros/trial_iirlp2mb.bin differ
diff --git a/macros/trial_iirlp2mb.sci b/macros/trial_iirlp2mb.sci
new file mode 100644
index 0000000..9419184
--- /dev/null
+++ b/macros/trial_iirlp2mb.sci
@@ -0,0 +1,44 @@
+function [Num,Den,AllpassNum,AllpassDen] = iirlp2mb(varargin)
+B = varargin(1)
+A = varargin(2)
+Wo = varargin(3)
+Wt = varargin(4)
+rhs = argn(2)
+lhs = argn(1)
+if(rhs < 4 | rhs > 5)
+error("Wrong number of input arguments.")
+end
+if(rhs == 5)
+Pass = varargin(5);
+ if(Pass == 'pass')
+ pass_stop = -1
+ elseif(Pass == 'stop')
+ pass_stop = 1
+ else
+ error("Pass must be pass or stop.")
+ end
+else
+pass_stop = -1
+end
+if(Wo <= 0)
+error("Wo is <= 0.")
+end
+if(Wo >= 1)
+error("Wo is >= 1.");
+end
+oWt = 0;
+for i = 1 : length(Wt)
+ if(Wt(i) <= 0)
+ error("Wt is <= 0.");
+ end
+ if(Wt(i) >= 1)
+ error("Wt is >= 1.");
+ end
+ if(Wt(i) <= oWt)
+ error("Wt not monotonically increasing.");
+ else
+ oWt = Wt(i);
+ end
+end
+endfunction
+
diff --git a/macros/triang.bin b/macros/triang.bin
new file mode 100644
index 0000000..67e8d99
Binary files /dev/null and b/macros/triang.bin differ
diff --git a/macros/triang.sci b/macros/triang.sci
new file mode 100644
index 0000000..6bbca69
--- /dev/null
+++ b/macros/triang.sci
@@ -0,0 +1,28 @@
+function [y] = triang (m)
+//This function returns the filter coefficients of a triangular window.
+//Calling Sequence
+//y = triang (m)
+//Parameters
+//m: positive integer value
+//y: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a triangular window of length m supplied as input, to the output vector y.
+//Examples
+//triang(5)
+//ans =
+// 0.3333333
+// 0.6666667
+// 1.
+// 0.6666667
+// 0.3333333
+
+funcprot(0);
+rhs = argn(2)
+if(rhs~=1)
+error("Wrong number of input arguments.")
+end
+
+y = callOctave("triang",m)
+
+endfunction
diff --git a/macros/tripuls.bin b/macros/tripuls.bin
new file mode 100644
index 0000000..644e9f3
Binary files /dev/null and b/macros/tripuls.bin differ
diff --git a/macros/tripuls.sci b/macros/tripuls.sci
new file mode 100644
index 0000000..498160b
--- /dev/null
+++ b/macros/tripuls.sci
@@ -0,0 +1,44 @@
+function [y] = tripuls(t,w,skew)
+
+//This function generates a triangular pulse over the interval [-w/2,w/2] sampled at times t
+//Calling Sequence
+//[y] = tripuls(t)
+//[y] = tripuls(t,w)
+//[y] = tripuls(t,w,skew)
+//Parameters
+//t: vector of real or complex numbers
+//w: real or complex number
+//skew: real number, -1 <= s <= 1
+//Description
+//This function generates a triangular pulse which is sampled at times t over the interval [-w/2,w/2]. The value of skew lies between -1
+//and 1.
+//The value of skew represents the relative placement of the peak in the given width.
+//Examples
+//tripuls([0, .5, .6, 1], 0.9)
+//ans =
+// 1 0 0 0
+//This function is being called from Octave
+
+funcprot(0);
+
+rhs = argn(2)
+
+if(rhs<1 | rhs>3)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 1 then
+ y = callOctave("tripuls",t)
+ case 2 then
+ y = callOctave("tripuls",t,w)
+ case 3 then
+ //tip = type(skew)
+ //if(tip==1)
+ y = callOctave("tripuls",t,w,skew)
+ //else
+ //error("Wrong arguments.")
+ //end
+ end
+endfunction
+
+
diff --git a/macros/truth.bin b/macros/truth.bin
new file mode 100644
index 0000000..492d7d9
Binary files /dev/null and b/macros/truth.bin differ
diff --git a/macros/truth.sci b/macros/truth.sci
new file mode 100644
index 0000000..e4e967e
--- /dev/null
+++ b/macros/truth.sci
@@ -0,0 +1,4 @@
+function f = truth()
+y = %t
+f = y
+endfunction
diff --git a/macros/tukeywin.bin b/macros/tukeywin.bin
new file mode 100644
index 0000000..f625c8b
Binary files /dev/null and b/macros/tukeywin.bin differ
diff --git a/macros/tukeywin.sci b/macros/tukeywin.sci
new file mode 100644
index 0000000..7ac8641
--- /dev/null
+++ b/macros/tukeywin.sci
@@ -0,0 +1,34 @@
+function w = tukeywin (m, r)
+//This function returns the filter coefficients of a Tukey window.
+//Calling Sequence
+//w = tukeywin (m)
+//w = tukeywin (m, r)
+//Parameters
+//m: positive integer
+//r: positive real number, between 0 and 1
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Tukey window of length m supplied as input, to the output vector w.
+//The second parameter r defines the ratio between the constant and cosine section and its value has to be between 0 and 1, with default value 0.5.
+//Examples
+//tukeywin(5, 2)
+//ans =
+// 0.
+// 0.5
+// 1.
+// 0.5
+// 0.
+
+funcprot(0);
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 1 then
+ w = callOctave("tukeywin",m)
+ case 2 then
+ w = callOctave("tukeywin",m,r)
+ end
+endfunction
+
diff --git a/macros/udecode.bin b/macros/udecode.bin
new file mode 100644
index 0000000..10ee70d
Binary files /dev/null and b/macros/udecode.bin differ
diff --git a/macros/udecode.sci b/macros/udecode.sci
new file mode 100644
index 0000000..323cd8e
--- /dev/null
+++ b/macros/udecode.sci
@@ -0,0 +1,64 @@
+function y=udecode(u,n,v,saturatemode)
+//Decodes the input uniformly quantized values
+//Calling Sequence
+//y=uencode(u,n,v,'saturatemode')
+//Parameters
+//u
+//A vector, matrix or n-dimensional array of integers
+//n
+//An integer between 2 and 32
+//v
+//A positive real scalar
+//'saturatemode'
+//A string which can take only 2 values 'saturate' or 'wrap'
+//Description
+//Uniformly decodes the input vector or n-dimensional array of integers u with peak values +/- v
+//If u has only positive values, the range of integers is assumed to be [0,2^n-1]
+//If u has positive and negative values the range of integers is assumed to be [-2^(n-1),2^(n-1)-1]
+//If v is not specified, its default value is 1
+//If saturatemode='wrap' the output is wrapped using modulo arithmetic if overflow occurs
+//If saturatemode='saturate' the output is saturated if overflow accors
+//Example
+//u = int8([-1 1 2 -5]);
+//ysat = udecode(u,3)
+//ysat =
+//
+// - 0.25 0.25 0.5 - 1.
+//Author
+//Ankur Mallick
+//[1] International Telecommunication Union. General Aspects of Digital Transmission Systems: Vocabulary of Digital Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms. ITU-T Recommendation G.701. March, 1993.
+//See also
+//uencode
+//floor
+ funcprot(0);
+ if(argn(2)<4)
+ saturatemode='saturate';
+ if(argn(2)<3)
+ v=1;
+ end
+ end
+ if(argn(2)>4|argn(2)<2)
+ error('Incorrect number of input arguments.');
+ elseif(saturatemode~='saturate'&saturatemode~='wrap')
+ error('Saturate mode must be saturate or wrap');
+ elseif(~isscalar(v)|abs(v)~=v)
+ error('Peak value must be a positive real scalar');
+ elseif(~isscalar(n)|round(n)~=n|n<2|n>32)
+ error('n must be an integer between 2 and 32')
+ elseif(type(u)~=8)
+ error('Input value must be an integer');
+ else
+ if(inttype(u)==1|inttype(u)==2|inttype(u)==4)
+ u=u+2^(n-1); //Converting signed to unsigned
+ end
+ if(saturatemode=='wrap')
+ u=pmodulo(double(u),2^n);
+ end
+ u(u<0)=0;
+ u(u>(2^n-1))=2^n-1;
+ L=2*v/(2^n);
+ y=L*double(u)-v;
+// y(y<-v)=-v;
+// y(y>v)=v;
+ end
+endfunction
diff --git a/macros/uencode.bin b/macros/uencode.bin
new file mode 100644
index 0000000..3edffa8
Binary files /dev/null and b/macros/uencode.bin differ
diff --git a/macros/uencode.sci b/macros/uencode.sci
new file mode 100644
index 0000000..4814998
--- /dev/null
+++ b/macros/uencode.sci
@@ -0,0 +1,85 @@
+function y=uencode(u,n,v,signflag)
+ //Performs uniform quantization of the input into 2^n levels
+ //Calling Sequence
+ //y=uencode(u,n,v,'signflag')
+ //Parameters
+ //u
+ //A vector, matrix or n-dimensional array
+ //n
+ //An integer between 2 and 32
+ //v
+ //A positive real scalar
+ //'signflag'
+ //A string which can take only 2 values 'signed' or 'unsigned'
+ //Description
+ //Uniformly quantizes the input vector or n-dimensional array u into 2^n levels in the interval [-v,v]
+ //If v is not specified, its default value is 1
+ //'signflag' is a string that determines the nature of the quantization
+ //If signflag='unsigned' then y contains unsigned integers in the range [0,2^n-1] corresponding to the 2^n levels
+ //If signflag='unsigned' then y contains signed integers in the range [-2^(n-1),2^(n-1)-1] corresponding to the 2^n levels
+ //The size of the integers in y in bits(8,16, or 32) depends on the value of n
+ //If the input lies beyond +/- v it is saturated
+ //Example
+ //y=uencode(-1:0.5:1,3)
+ // y =
+ //
+ // 0 2 4 6 7
+ //Author
+ //Ankur Mallick
+ //References
+ //[1] International Telecommunication Union. General Aspects of Digital Transmission Systems: Vocabulary of Digital Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms. ITU-T Recommendation G.701. March, 1993.
+ //See also
+ //udecode
+ //floor
+ funcprot(0);
+ if(argn(2)<4)
+ signflag='unsigned';
+ if(argn(2)<3)
+ v=1;
+ end
+ end
+ if(argn(2)>4|argn(2)<2)
+ error('Incorrect number of input arguments.');
+ elseif(signflag~='signed'&signflag~='unsigned')
+ error('Sign flag must be signed or unsigned');
+ elseif(~isscalar(v)|abs(v)~=v)
+ error('Peak value must be a positive real scalar');
+ elseif(~isscalar(n)|round(n)~=n|n<2|n>32)
+ error('n must be an integer between 2 and 32')
+ else
+ if(or(imag(u(:))~=0))
+ //Complex Number
+ u_real=real(u);
+ y_real=uencode(u_real,n,v,signflag);
+ disp(type(y_real));
+ u_imag=imag(u);
+ y_imag=uencode(u_imag,n,v,signflag);
+ y=double(y_real)+%i*double(y_imag);
+ else
+ //Real Numbers
+ y=zeros(u);
+ L=2*v/(2^n);
+ y=floor((u+v)/L);
+ y(y<0)=0;
+ y(y>(2^n-1))=2^n-1;
+ if(signflag=='signed')
+ y=y-2^(n-1);
+ if(n>=2&n<=8)
+ y=int8(y);
+ elseif(n>=9&n<=16)
+ y=int16(y);
+ else
+ y=int32(y);
+ end
+ else
+ if(n>=2&n<=8)
+ y=uint8(y);
+ elseif(n>=9&n<=16)
+ y=uint16(y);
+ else
+ y=uint32(y);
+ end
+ end
+ end
+ end
+endfunction
diff --git a/macros/ultrwin.bin b/macros/ultrwin.bin
new file mode 100644
index 0000000..6bd2dbe
Binary files /dev/null and b/macros/ultrwin.bin differ
diff --git a/macros/ultrwin.sci b/macros/ultrwin.sci
new file mode 100644
index 0000000..91119eb
--- /dev/null
+++ b/macros/ultrwin.sci
@@ -0,0 +1,53 @@
+function [w, xmu] = ultrwin (m, mu, par, key, norm)
+//This function returns the coefficients of an Ultraspherical window.
+//Calling Sequence
+//w = ultrwin (m, mu, par)
+//w = ultrwin (m, mu, par, key)
+//w = ultrwin (m, mu, par, key, norm)
+//[w, xmu] = ultrwin (...)
+//Parameters
+//m: positive integer value
+//mu:
+//par:
+//key:
+//norm:
+//Description
+//This is an Octave function.
+//This function returns the coefficients of an Ultraspherical window of length m supplied as input, to the output vector w.
+//The second parameter controls the ratio between side lobe to side lobe of the window's Fourier transform.
+//The third parameter controls the ratio between main lobe width to side lobe. The default value is beta.
+//The value of xmu is also returned for given beta, att or latt.
+//Examples
+//ultrwin(3,-0.4,0.5)
+//ans =
+// - 1.
+// 1.
+// - 1.
+
+rhs = argn(2)
+lhs = argn(1)
+if(rhs<3 | rhs>5)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 3 then
+ if(lhs==1)
+ [w] = callOctave("ultrwin", m, mu, par)
+ elseif(lhs==2)
+ [w,xmu] = callOctave("ultrwin", m, mu, par)
+ end
+ case 4 then
+ if(lhs==1)
+ [w] = callOctave("ultrwin", m, mu, par, key)
+ elseif(lhs==2)
+ [w,xmu] = callOctave("ultrwin", m, mu, par, key)
+ end
+ case 5 then
+ if(lhs==1)
+ [w] = callOctave("ultrwin", m, mu, par, key, norm)
+ elseif(lhs==2)
+ [w,xmu] = callOctave("ultrwin", m, mu, par, key, norm)
+ end
+ end
+endfunction
diff --git a/macros/unshiftdata.bin b/macros/unshiftdata.bin
new file mode 100644
index 0000000..08df42c
Binary files /dev/null and b/macros/unshiftdata.bin differ
diff --git a/macros/unshiftdata.sci b/macros/unshiftdata.sci
new file mode 100644
index 0000000..46c3777
--- /dev/null
+++ b/macros/unshiftdata.sci
@@ -0,0 +1,81 @@
+function y = unshiftdata(x,perm,nshifts)
+//Inverts the effect of shiftdata
+//Calling sequence
+//y=unshiftdata(x,perm,nshifts)
+//Parameters
+//x
+//A vector matrix or n-dimensional array
+//perm
+//Permutation applied by shiftdata to obtain x
+//nshifts
+//The number of shifts applied by shiftdata to obtain x
+//Description
+//y=unshiftdata(x,perm,nshifts)
+//Applies the permutation perm or number of shifts nshifts on x to invert shiftdata
+//Examples
+//x=testmatrix('magi',3)
+//x =
+//
+// 8. 1. 6.
+// 3. 5. 7.
+// 4. 9. 2.
+//[y,perm,nshifts] = shiftdata(x,2) //Shifts dimension 2
+//nshifts =
+//
+// []
+// perm =
+//
+// 2. 1.
+// y =
+//
+// 8. 3. 4.
+// 1. 5. 9.
+// 6. 7. 2.
+//z=unshiftdata(y,perm,nshifts)
+//z =
+//
+// 8. 1. 6.
+// 3. 5. 7.
+// 4. 9. 2.
+//
+//x=1:5
+//x =
+//
+// 1. 2. 3. 4. 5.
+// [y,perm,nshifts] = shiftdata(x) //Shifts first non-singleton dimension
+//nshifts =
+//
+// 1.
+// perm =
+//
+// []
+// y =
+//
+// 1.
+// 2.
+// 3.
+// 4.
+// 5.
+////z=unshiftdata(y,perm,nshifts)
+//z =
+//
+// 1. 2. 3. 4. 5.
+//See Also
+//permute
+//shiftdata
+//Author
+//Ankur Mallick
+ funcprot(0);
+ if(argn(2)<1|argn(2)<2|(argn(2)<3&size(perm)==0)|argn(2)>3)
+ error('Incorrect number of input arguments.');
+ else
+ if(size(perm)==0)
+ S=size(x);
+ S1=[ones(1,nshifts),S]
+ y=matrix(x,S1);
+ else
+ iperm(perm)=1:length(perm);
+ y=permute(x,iperm);
+ end
+ end
+endfunction
diff --git a/macros/upfirdn.bin b/macros/upfirdn.bin
new file mode 100644
index 0000000..8d5a99d
Binary files /dev/null and b/macros/upfirdn.bin differ
diff --git a/macros/upfirdn.sci b/macros/upfirdn.sci
new file mode 100644
index 0000000..7f0215d
--- /dev/null
+++ b/macros/upfirdn.sci
@@ -0,0 +1,26 @@
+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 =
+//
+// 2. 0.
+funcprot(0);
+rhs = argn(2)
+if(rhs~=4)
+error("Wrong number of input arguments.")
+end
+
+y = callOctave("upfirdn",x, h, p, q)
+
+endfunction
diff --git a/macros/upsample.bin b/macros/upsample.bin
new file mode 100644
index 0000000..5195035
Binary files /dev/null and b/macros/upsample.bin differ
diff --git a/macros/upsample.sci b/macros/upsample.sci
new file mode 100644
index 0000000..cb5d7ae
--- /dev/null
+++ b/macros/upsample.sci
@@ -0,0 +1,33 @@
+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
+
+endfunction
+
diff --git a/macros/upsamplefill.bin b/macros/upsamplefill.bin
new file mode 100644
index 0000000..b447000
Binary files /dev/null and b/macros/upsamplefill.bin differ
diff --git a/macros/upsamplefill.sci b/macros/upsamplefill.sci
new file mode 100644
index 0000000..60ca1da
--- /dev/null
+++ b/macros/upsamplefill.sci
@@ -0,0 +1,32 @@
+function y = upsamplefill (x, w, cpy)
+//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
+//w: scalar or vector of real or complex values
+//cpy: can take in "true" or "false", default is false
+//Description
+//This is an Octave function.
+//This function upsamples a vector interleaving given values or copies of the vector elements.
+//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
+endfunction
diff --git a/macros/var.bin b/macros/var.bin
new file mode 100644
index 0000000..ca8d571
Binary files /dev/null and b/macros/var.bin differ
diff --git a/macros/var.sci b/macros/var.sci
new file mode 100644
index 0000000..9496da1
--- /dev/null
+++ b/macros/var.sci
@@ -0,0 +1,173 @@
+function y = var(x,w,dim)
+
+ // This function var estimate the variance of the values in X.
+ // Calling Sequence
+ // y=var(x)
+ // y=var(x,w)
+ // y=var(x,w,dim)
+ // Parameters
+ // x: a vector or matrix.
+ // w: weight vector W of length X, or may take the value of 0 and 1. The default value is 0. Consider only non-negative values.
+ // dim: consider the variance along the dimension of X. 1 for clumun wise variamce and 2 for row wise variance.
+ // y: returns the variance of the values in X.
+
+ // Examples
+ // x=[1.2, 5, 10, -20, 12,10,5,20,32,20];
+ // w=1:10;
+ // dim=2;
+ // y=var(x, w, dim) ;
+ // See also
+ // Authors
+ // Jitendra Singh
+
+ if argn(2)==1 then
+
+ if type(x)==10 then
+ x=ascii(x)
+ end
+ if size(x,1)==1 |size(x,2)==1 then
+ sd=stdev(x)
+ else
+ sd=stdev(x,1)
+ end
+ y=sd.^2;
+ end
+
+ if argn(2)<=3 & argn(2)>1 then
+
+
+ if size(x,1)==1 |size(x,2)==1 then
+ sd=stdev(x);
+ n=length(x);
+ y1= sd.^2;
+ if length(w)==1 & w==0 then
+ y=y1;
+ elseif length(w)==1 & w==1 then
+ y=y1*((n-1)/n);
+ elseif length(w)==n & and(w>=0) then
+ if size(x,1)~=size(w,1) then
+ w=w';
+ end
+ wmean=sum(x.*w)/sum(w);
+ x1=(x-wmean).^2;
+
+ l=length(find(w>0));
+
+
+ sd=((sum(w.*x1))/(((l-1)/l)*sum(w)));
+ y=(sd)*((n-1)/n);
+ elseif length(w)~=size(x)& length(w)>1 then
+ error ('The length of W must be compatible with X.')
+
+ else
+ error('W must be a vector of nonnegative weights, or a scalar 0 or 1.')
+ end
+
+ else
+ n=size(x,1)
+ sd=stdev(x,1)
+ y1=sd.^2;
+ if length(w)==1 & w==0 then
+ y=y1;
+ elseif length(w)==1 & w==1 then
+ y=y1*((n-1)/n);
+ elseif length(w)==n & and(w>=0) then
+
+ for i=1:size(x,2)
+ xx=(x(:,i))
+ if size(xx,1)~=size(w,1) then
+ w=w';
+ end
+ wmean=sum(xx.*w)/sum(w);
+ x1=(x(:,i)-wmean).^2;
+ l=length(find(w>0));
+ sd(i)=sum((w.*x1)/(((l-1)/l)*sum(w)));
+ end
+ y=sd*((l-1)/l);
+
+elseif length(w)~=size(x,1) & length(w)>1 then
+ error ('The length of W must be compatible with X.')
+
+ else
+ error('W must be a vector of nonnegative weights, or a scalar 0 or 1.')
+
+ end
+ end
+
+end
+
+
+
+if argn(2)==3 then
+
+ if dim==2 then
+
+ if size(x,1)==1 | size(x,2)==1 then
+
+ if size(x,1)==1 then
+ y=y;
+ elseif size(x,2)==1 & length(w)== length(x) then
+ error ('The length of W must be compatible with X.')
+ else
+ y=zeros(size(x,1),size(x,2))
+ end
+ else
+ n=size(x,2)
+ sd=stdev(x,2)
+ y1=sd.^2;
+ if length(w)==1 & w==0 then
+ y=y1;
+ elseif length(w)==1 & w==1 then
+ y=y1*((n-1)/n);
+ elseif length(w)==n & and(w>=0) then
+ for i=1:size(x,1)
+ xx=(x(:,i))
+ if size(xx,1)~=size(w,1) then
+ w=w';
+ end
+ wmean=sum(xx.*w)/sum(w);
+ x1=(x(:,i)-wmean).^2;
+ l=length(find(w>0));
+ sd(i)=sum((w.*x1)/(((l-1)/l)*sum(w)));
+ end
+ y=sd*((l-1)/l);
+ else
+ error('The length of W must be compatible with X.')
+ end
+ end
+end
+
+ if dim==1 then
+
+
+ if size(x,1)==1 | size(x,2)==1 then
+
+ if size(x,2)==1 then
+
+ y=y;
+ elseif size(x,1)==1 & length(w)== length(x) then
+ error ('The length of W must be compatible with X.')
+ else
+ y=zeros(size(x,1),size(x,2))
+ end
+
+ end
+
+ end
+
+ if dim>2 then
+ if length(w)==1 & w==1 | w==0 then
+ y=zeros(size(x,1), size(x,2))
+ else
+ error ('The length of W must be compatible with X.')
+ end
+
+ end
+
+
+ if dim<=0 then
+ error('Dimension argument must be a positive integer scalar within indexing range.')
+ end
+ end
+
+ endfunction
diff --git a/macros/vco.bin b/macros/vco.bin
new file mode 100644
index 0000000..5c063f2
Binary files /dev/null and b/macros/vco.bin differ
diff --git a/macros/vco.sci b/macros/vco.sci
new file mode 100644
index 0000000..36b704c
--- /dev/null
+++ b/macros/vco.sci
@@ -0,0 +1,64 @@
+function y = vco(x,frange,fs)
+//Voltage Controlled Oscillator
+//Calling Sequence
+//y=vco(x,fc,fs)
+//y=vco(x,[fmin fmax],fs)
+//Parameters
+//x
+//A vector or a matrix
+//fc
+//Carrier frequency
+//fs
+//fmin
+//Minimum frequency of the frequency range
+//fmax
+//Maximum frequency of the frequency range
+//Description
+//y=vco(x,fc,fs)
+//Creates a frequency modulated cosine wave y whose frequency varies as the magnitude of x
+//x lies in [-1,1]. x=-1 corresponds to a frequency of 0, x=0 corresponds to a frequency of fc
+//and x=1 corresponds to a frequency of 2fc.
+//y=vco(x,[fmin fmax],fs)
+//Scales the frequency range so that x=-1 corresponds to a frequency of fmin and
+//x=1 corresponds to a frequency of fmax
+//If x is a matrix the same operation is performed on the columns on x
+//Size of y is the same as the size of x
+//Example
+//x=rand()
+// x =
+//
+// 0.2113249
+// y=vco(x,2000,8000)
+// y =
+//
+// 0.9454092
+//Author
+//Ankur Mallick
+ funcprot(0);
+ if (argn(2)<3|argn(2)>5) then
+ error('Incorrect number of input arguments.');
+ else
+ if(argn(2)<3)
+ fs=1;
+ end
+ if(argn(2)<2)
+ fc=fs/4;
+ frange=fc;
+ end
+ if(max(abs(x(:)))>1)
+ error('x must lie between -1 and 1');
+ end
+ if(length(frange)==1)
+ fc = frange(1);
+ opt = (fc/fs)*2*%pi;
+ else
+ fc = mean(frange);
+ opt = (frange(2) - fc)/fs*2*%pi;
+ end
+ if (fc>fs/2)
+ error('The career frequency must be less than half the sampling frequency.')
+ else
+ y = modulate(x,fc,fs,'fm',opt);
+ end
+ end
+endfunction
diff --git a/macros/welchwin.bin b/macros/welchwin.bin
new file mode 100644
index 0000000..3323c77
Binary files /dev/null and b/macros/welchwin.bin differ
diff --git a/macros/welchwin.sci b/macros/welchwin.sci
new file mode 100644
index 0000000..a871a59
--- /dev/null
+++ b/macros/welchwin.sci
@@ -0,0 +1,37 @@
+function w = welchwin (m, opt)
+//This function returns the filter coefficients of a Welch window.
+//Calling Sequence
+//w = welchwin (m)
+//w = welchwin (m, opt)
+//Parameters
+//m: positive integer value
+//opt: string value, takes "periodic" or "symmetric"
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function returns the filter coefficients of a Welch window of length m supplied as input, to the output vector w.
+//The second parameter can take the values "periodic" or "symmetric", depending on which the corresponding form of window is returned. The default is symmetric.
+//For symmetric, the length should be an integer>2. For periodic, the length should be an integer>1.
+//Examples
+//welchwin(4,"symmetric")
+//ans =
+// 0.
+// 0.8888889
+// 0.8888889
+// 0.
+
+
+
+rhs = argn(2)
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 1 then
+ w = callOctave("welchwin",m)
+ case 2 then
+ w = callOctave("welchwin",m,opt)
+ end
+
+endfunction
diff --git a/macros/window.bin b/macros/window.bin
new file mode 100644
index 0000000..fe7e1ef
Binary files /dev/null and b/macros/window.bin differ
diff --git a/macros/window.sci b/macros/window.sci
new file mode 100644
index 0000000..5bf3982
--- /dev/null
+++ b/macros/window.sci
@@ -0,0 +1,35 @@
+function [w] = window (f, m, varargin)
+//This function creates an m-point window from the function f given as input.
+//Calling Sequence
+//w = window(f, m)
+//w = window(f, m, opts)
+//Parameters
+//f: string value
+//m: positive integer value
+//opts: string value, takes in "periodic" or "symmetric"
+//w: output variable, vector of real numbers
+//Description
+//This is an Octave function.
+//This function creates an m-point window from the function f given as input, in the output vector w.
+//f can take any valid function as a string, for example "blackmanharris".
+//Examples
+//window("hanning",5)
+//ans =
+// 0.
+// 0.5
+// 1.
+// 0.5
+// 0.
+funcprot(0);
+rhs = argn(2)
+if(rhs<2)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 2 then
+ [w] = callOctave("window",f,m)
+ case 3 then
+ [w] = callOctave("window",f,m,varargin(1))
+ end
+endfunction
+
diff --git a/macros/wkeep.bin b/macros/wkeep.bin
new file mode 100644
index 0000000..a659931
Binary files /dev/null and b/macros/wkeep.bin differ
diff --git a/macros/wkeep.sci b/macros/wkeep.sci
new file mode 100644
index 0000000..e4e4506
--- /dev/null
+++ b/macros/wkeep.sci
@@ -0,0 +1,29 @@
+function [y] = wkeep(x,l,opt)
+
+// Extracts a vector from the given vector of length l
+// Calling Sequence
+// [y]=wkeep(x,l)
+// [y]=wkeep(x,l,opt)
+// Parameters
+// x: Real, complex or string type input vector or matrix
+// l: Length of matrix required
+// opt: Character input to determine which side to extract from
+// Description
+// This is an Octave function
+// [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).
+// Examples
+// 1. [y]=wkeep([1 2 3;4 5 6],[2 2])
+// y= 1 2
+// 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
+endfunction
diff --git a/macros/wrev.bin b/macros/wrev.bin
new file mode 100644
index 0000000..f4baf3d
Binary files /dev/null and b/macros/wrev.bin differ
diff --git a/macros/wrev.sci b/macros/wrev.sci
new file mode 100644
index 0000000..a01ed77
--- /dev/null
+++ b/macros/wrev.sci
@@ -0,0 +1,23 @@
+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 function reverses the order of elements of the input vector x.
+// Examples
+// 1. wrev([1 2 3])
+// ans= 3 2 1
+// 2. wrev(['a','b','c'])
+// ans= cba
+
+funcprot(0);
+rhs=argn(2);
+if (rhs~=1) then
+ error("Wrong number of input arguments.")
+else y=callOctave("wrev",x)
+end
+endfunction
diff --git a/macros/xcorr2.bin b/macros/xcorr2.bin
new file mode 100644
index 0000000..795bfe4
Binary files /dev/null and b/macros/xcorr2.bin differ
diff --git a/macros/xcorr2.sci b/macros/xcorr2.sci
new file mode 100644
index 0000000..e73f00f
--- /dev/null
+++ b/macros/xcorr2.sci
@@ -0,0 +1,36 @@
+function c = xcorr2 (a, b, biasflag)
+//
+//Calling Sequence
+//c = xcorr2 (a)
+//c = xcorr2 (a, b)
+//c = xcorr2 (a, b, biasflag)
+
+//Parameters
+//a:
+//b:
+//biasflag:
+
+//Description
+//This is an Octave function.
+
+//Examples
+//xcorr2(5,0.8,'coeff')
+//ans = 1
+
+funcprot(0);
+
+rhs = argn(2)
+if(rhs<1 | rhs>3)
+error("Wrong number of input arguments.")
+end
+
+ select(rhs)
+ case 1 then
+ c = callOctave("xcorr2",a)
+ case 2 then
+ c = callOctave("xcorr2",a,b)
+ case 3 then
+ c = callOctave("xcorr2",a,b,biasflag)
+ end
+endfunction
+
diff --git a/macros/zerocrossing.bin b/macros/zerocrossing.bin
new file mode 100644
index 0000000..d6b1655
Binary files /dev/null and b/macros/zerocrossing.bin differ
diff --git a/macros/zerocrossing.sci b/macros/zerocrossing.sci
new file mode 100644
index 0000000..41b51d6
--- /dev/null
+++ b/macros/zerocrossing.sci
@@ -0,0 +1,22 @@
+function x = zerocrossing (w, y)
+//This function estimates the points at which a given waveform crosses the x-axis.
+//Calling Sequence
+//x = zerocrossing (w, y)
+//Parameters
+//w:
+//y:
+//x:
+//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
+
+
+funcprot(0);
+rhs = argn(2)
+if(rhs~=2)
+error("Wrong number of input arguments.")
+end
+x = callOctave("zerocrossing", w, y)
+
+endfunction
diff --git a/macros/zp2sos.bin b/macros/zp2sos.bin
new file mode 100644
index 0000000..08c8b1f
Binary files /dev/null and b/macros/zp2sos.bin differ
diff --git a/macros/zp2sos.sci b/macros/zp2sos.sci
new file mode 100644
index 0000000..6bb9426
--- /dev/null
+++ b/macros/zp2sos.sci
@@ -0,0 +1,51 @@
+function [sos,g] = zp2sos(z,p,k)
+//This function converts filter poles and zeros to second-order sections.
+//Calling Sequence
+//[sos] = zp2sos(z)
+//[sos] = zp2sos(z, p)
+//[sos] = zp2sos(z, p, k)
+//[sos, g] = zp2sos(...)
+//Parameters
+//z: column vector
+//p: column vector
+//k: real or complex value, default value is 1
+//Description
+//This is an Octave function.
+//This function converts filter poles and zeros to second-order sections.
+//The first and second parameters are column vectors containing zeros and poles. The third parameter is the overall filter gain, the default value of which is 1.
+//The output is the sos matrix and the overall gain.
+//If there is only one output argument, the overall filter gain is applied to the first second-order section in the sos matrix.
+//Examples
+//zp2sos([1, 2, 3], 2, 6)
+//ans =
+// 6 -18 12 1 -2 0
+// 1 -3 0 1 0 0
+
+
+funcprot(0);
+rhs = argn(2)
+lhs = argn(1)
+if(rhs<1 | rhs>3)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 1 then
+ if (lhs<2)
+ sos=callOctave("zp2sos",z)
+ else
+ [sos,g]=callOctave("zp2sos",z)
+ end
+ case 2 then
+ if(lhs<2)
+ [sos]=callOctave("zp2sos",z,p)
+ else
+ [sos,g]=callOctave("zp2sos",z,p)
+ end
+ case 3 then
+ if(lhs<2)
+ sos=callOctave("zp2sos",z,p,k)
+ else
+ [sos,g]=callOctave("zp2sos",z,p,k)
+ end
+ end
+endfunction
diff --git a/macros/zplane.bin b/macros/zplane.bin
new file mode 100644
index 0000000..43396b8
Binary files /dev/null and b/macros/zplane.bin differ
diff --git a/macros/zplane.sci b/macros/zplane.sci
new file mode 100644
index 0000000..bfa9285
--- /dev/null
+++ b/macros/zplane.sci
@@ -0,0 +1,16 @@
+function [y] = zplane(z,p)
+funcprot(0);
+
+rhs = argn(2)
+
+if(rhs<1 | rhs>2)
+error("Wrong number of input arguments.")
+end
+ select(rhs)
+ case 1 then
+ callOctave("zplane",z)
+ case 2 then
+ callOctave("zplane",z,p)
+ end
+endfunction
+
diff --git a/sci_gateway/builder_gateway.sce~ b/sci_gateway/builder_gateway.sce~
new file mode 100644
index 0000000..2b192bb
--- /dev/null
+++ b/sci_gateway/builder_gateway.sce~
@@ -0,0 +1,18 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the BSD.
+// This source file is licensed as described in the file LICENSE, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// https://opensource.org/licenses/BSD-3-Clause
+// Author: Harpreet Singh
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+sci_gateway_dir = get_absolute_file_path('builder_gateway.sce');
+
+tbx_builder_gateway_lang('cpp', sci_gateway_dir);
+tbx_build_gateway_loader(['cpp'], sci_gateway_dir);
+
+clear tbx_builder_gateway_lang tbx_build_gateway_loader;
+clear sci_gateway_dir;
diff --git a/unloader.sce b/unloader.sce
new file mode 100644
index 0000000..dea8f22
--- /dev/null
+++ b/unloader.sce
@@ -0,0 +1,14 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce: Please, do not edit this file
+
+try
+ getversion("scilab");
+catch
+ error("Scilab 5.4 or more is required.");
+end;
+
+fileQuit = get_absolute_file_path("unloader.sce") + "etc/" + "FOSSEE_Signal_Processing_Toolbox.quit";
+if isfile(fileQuit) then
+ exec(fileQuit);
+end
+
--
cgit