home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
octa21eb.zip
/
octave
/
doc
/
octave.i10
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
GNU Info File
|
1999-05-13
|
48.5 KB
|
1,516 lines
This is Info file octave, produced by Makeinfo-1.64 from the input file
octave.tex.
START-INFO-DIR-ENTRY
* Octave: (octave). Interactive language for numerical computations.
END-INFO-DIR-ENTRY
Copyright (C) 1996, 1997 John W. Eaton.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions.
File: octave, Node: cacsd, Next: misc, Prev: sysfreq, Up: Control Theory
Controller Design
=================
- Function File : dgkfdemo ( )
Octave Controls toolbox demo: H2/Hinfinity options demos
- Function File : hinfdemo ( )
Non-trivial H_infinity design demo.
H_infinity optimal controller for the jet707 plant; Linearized
state space model of a Boeing 707-321 aircraft at v=80m/s. (M =
0.26, Ga0 = -3 deg, alpha0 = 4 deg, kappa = 50 deg) inputs: (1)
thrust and (2) elevator angle outputs: (1) airspeed and (2)
pitch angle
The optimal controller minimizes the H_infinity norm of the
augmented plant P (mixed-sensitivity problem):
w
1 -----------+
| +----+
+---------------------->| W1 |----> z1
w | | +----+
2 ------------------------+
| | |
| v +----+ v +----+
+--*-->o-->| G |-->o--*-->| W2 |---> z2
| +----+ | +----+
| |
^ v
u (from y (to K)
controller
K)
+ + + +
| z | | w |
| 1 | | 1 |
| z | = [ P ] * | w |
| 2 | | 2 |
| y | | u |
+ + + +
- Function File: [L, M, P, E] = dlqe (A, G, C, SIGW, SIGV, Z)
Construct the linear quadratic estimator (Kalman filter) for the
discrete time system
x[k+1] = A x[k] + B u[k] + G w[k]
y[k] = C x[k] + D u[k] + w[k]
where W, V are zero-mean gaussian noise processes with respective
intensities `SIGW = cov (W, W)' and `SIGV = cov (V, V)'.
If specified, Z is `cov (W, V)'. Otherwise `cov (W, V) = 0'.
The observer structure is
z[k+1] = A z[k] + B u[k] + k (y[k] - C z[k] - D u[k])
The following values are returned:
L
The observer gain, (A - ALC). is stable.
M
The Riccati equation solution.
P
The estimate error covariance after the measurement update.
E
The closed loop poles of (A - ALC).
- Function File: [K, P, E] = dlqr (A, B, Q, R, Z)
Construct the linear quadratic regulator for the discrete time
system
x[k+1] = A x[k] + B u[k]
to minimize the cost functional
J = Sum (x' Q x + u' R u)
Z omitted or
J = Sum (x' Q x + u' R u + 2 x' Z u)
Z included.
The following values are returned:
K
The state feedback gain, (A - BK) is stable.
P
The solution of algebraic Riccati equation.
E
The closed loop poles of (A - BK). *References*
1. Anderson and Moore, Optimal Control: Linear Quadratic Methods,
Prentice-Hall, 1990, pp. 56-58
2. Kuo, Digital Control Systems, Harcourt Brace Jovanovich, 1992,
section 11-5-2.
- Function File : [K , GAIN, KC, KF, PC, PF] = h2syn(ASYS, NU, NY, TOL)
Design H2 optimal controller per procedure in Doyle, Glover,
Khargonekar, Francis, "State Space Solutions to Standard H2 and
Hinf Control Problems", IEEE TAC August 1989
*Inputs* input system is passed as either
ASYS
system data structure (see ss2sys, sys2ss)
* controller is implemented for continuous time systems
* controller is NOT implemented for discrete time systems
NU
number of controlled inputs
NY
number of measured outputs
TOL
threshhold for 0. Default: 200*eps
*Outputs*
K
system controller
GAIN
optimal closed loop gain
KC
full information control (packed)
KF
state estimator (packed)
PC
ARE solution matrix for regulator subproblem
PF
ARE solution matrix for filter subproblem
- Function File : K = hinf_ctr(DGS, F, H, Z, G)
Called by `hinfsyn' to compute the H_inf optimal controller.
*Inputs*
DGS
data structure returned by `is_dgkf'
F, H
feedback and filter gain (not partitioned)
G
final gamma value *Outputs* controller K (system data
structure)
Do not attempt to use this at home; no argument checking performed.
- Function File : [K, G, GW, XINF, YINF] = hinfsyn(ASYS, NU, NY, GMIN,
GMAX, GTOL{, PTOL, TOL})
*Inputs* input system is passed as either
ASYS
system data structure (see ss2sys, sys2ss)
* controller is implemented for continuous time systems
* controller is NOT implemented for discrete time systems
(see bilinear transforms in `c2d', `d2c')
NU
number of controlled inputs
NY
number of measured outputs
GMIN
initial lower bound on H-infinity optimal gain
GMAX
initial upper bound on H-infinity optimal gain
GTOL
gain threshhold. Routine quits when gmax/gmin < 1+tol
PTOL
poles with abs(real(pole)) < ptol*||H|| (H is appropriate
Hamiltonian) are considered to be on the imaginary axis.
Default: 1e-9
TOL
threshhold for 0. Default: 200*eps
GMAX, MIN, TOL, and TOL must all be postive scalars.
*Outputs*
K
system controller
G
designed gain value
GW
closed loop system
XINF
ARE solution matrix for regulator subproblem
YINF
ARE solution matrix for filter subproblem
1. Doyle, Glover, Khargonekar, Francis, "State Space Solutions
to Standard H2 and Hinf Control Problems," IEEE TAC August
1989
2. Maciejowksi, J.M., "Multivariable feedback design,"
Addison-Wesley, 1989, ISBN 0-201-18243-2
3. Keith Glover and John C. Doyle, "State-space formulae for all
stabilizing controllers that satisfy and h-infinity-norm
bound and relations to risk sensitivity," Systems &
Control Letters 11, Oct. 1988, pp 167-172.
- Function File : [XX, ERR] = hinfsyn_c (NN, PTOL, S1{, S2})
used internally in hinfsyn to evaluate hamiltonian/symplectic
eigenvalue problems.
*WARNING* Argument checking not performed.
*Inputs*
S1 (ALONE)
hamiltonian matrix
(S1,S2) AS A PAIR
symplectic matrix pencil *Outputs*
XX: POSITIVE (SEMI-)DEFINITE SOLUTION OF DARE (SET TO 0 IF ERR <=2)
CODE: ERROR:
*0*
no error
*1*
(s1): eigenvalues on imaginary axis
(s1,s2): gen. eigenvalues on unit circle
*2*
unequal number of stable/antistable (generalized)
eigenvalues
*3*
(s1): infinite entries in solution x
(s1,s2): infinite entires in solution x or (I + R X)
singular
*4*
x is not symmetric
*5*
x has negative eigenvalues
Solution method: Either Laub's schur method or Symplectic GEP
approach; uses Van Dooren's code to re-order qz decompostion
(www.netlib.com - toms/590)
See also: Ran and Rodman, "Stable Hermitian Solutions of Discrete
Algebraic Riccati Equations," Mathematics of Control, Signals and
Systems, Vol 5, no 2 (1992) pp 165-194.
- Function File: [RETVAL, PC, PF] = hinfsyn_chk(A, B1, B2, C1, C2,
D12, D21, G, PTOL)
Called by `hinfsyn' to see if gain G satisfies conditions in
Theorem 3 of Doyle, Glover, Khargonekar, Francis, "State Space
Solutions to Standard H2 and Hinf Control Problems", IEEE TAC
August 1989
*Warning* Do not attempt to use this at home; no argument checking
performed.
*Inputs* as returned by `is_dgkf', except for:
G
candidate gain level
PTOL
as in `hinfsyn'
Outputs: retval: = 1 if g exceeds optimal Hinf closed loop
gain, else 0 Pc: solution of "regulator" H-inf ARE Pf:
solution of "filter" H-inf ARE
- Function File: [K, P, E] = lqe (A, G, C, SIGW, SIGV, Z)
Construct the linear quadratic estimator (Kalman filter) for the
continuous time system
dx
-- = a x + b u
dt
y = c x + d u
where W and V are zero-mean gaussian noise processes with
respective intensities
sigw = cov (w, w)
sigv = cov (v, v)
The optional argument Z is the cross-covariance `cov (W, V)'. If
it is omitted, `cov (W, V) = 0' is assumed.
Observer structure is `dz/dt = A z + B u + k (y - C z - D u)'
The following values are returned:
K
The observer gain, (A - KC) is stable.
P
The solution of algebraic Riccati equation.
E
The vector of closed loop poles of (A - KC).
- Function File : [K, Q, P, EE, ER] = lqg(SYS, SIGW, SIGV, Q, R,
IN_IDX)
Design a linear-quadratic-gaussian optimal controller for the
system
dx/dt = A x + B u + G w [w]=N(0,[Sigw 0 ])
y = C x + v [v] ( 0 Sigv ])
or
x(k+1) = A x(k) + B u(k) + G w(k) [w]=N(0,[Sigw 0 ])
y(k) = C x(k) + v(k) [v] ( 0 Sigv ])
*Inputs*
SYS
system data structure
SIGW, SIGV
intensities of independent Gaussian noise processes (as above)
Q, R
state, control weighting respectively. Control ARE is
IN_IDX
indices of controlled inputs
default: last dim(R) inputs are assumed to be controlled
inputs, all others are assumed to be noise
inputs. *Outputs*
K
system data structure format LQG optimal controller (Obtain
A,B,C matrices with `sys2ss', `sys2tf', or `sys2zp' as
appropriate)
P
Solution of control (state feedback) algebraic Riccati
equation
Q
Solution of estimation algebraic Riccati equation
EE
estimator poles
ES
controller poles
- Function File: [K, P, E] = lqr (A, B, Q, R, Z)
construct the linear quadratic regulator for the continuous time
system
dx
-- = A x + B u
dt
to minimize the cost functional
infinity
/
J = | x' Q x + u' R u
/
t=0
Z omitted or
infinity
/
J = | x' Q x + u' R u + 2 x' Z u
/
t=0
Z included.
The following values are returned:
K
The state feedback gain, (A - BK) is stable.
P
The stabilizing solution of appropriate algebraic Riccati
equation.
E
The vector of the closed loop poles of (A - BK).
- Function File : lsim (SYS, U, T{,X0})
Produce output for a linear simulation of a system
Produces a plot for the output of the system, sys.
U is an array that contains the system's inputs. Each column in u
corresponds to a different time step. Each row in u corresponds
to a different input. T is an array that contains the time index
of the system. T should be regularly spaced. If initial
conditions are required on the system, the x0 vector should be
added to the argument list.
When the lsim function is invoked with output parameters: [y,x] =
lsim(sys,u,t,[x0]) a plot is not displayed, however, the data is
returned in y = system output and x = system states.
- Function File : K = place (SYS, P)
Computes the matrix K such that if the state is feedback with
gain K, then the eigenvalues of the closed loop system (i.e.
A-BK) are those specified in the vector P.
Version: Beta (May-1997): If you have any comments, please let me
know. (see the file place.m for my
address)
Written by: Jose Daniel Munoz Frias.
File: octave, Node: misc, Prev: cacsd, Up: Control Theory
Miscellaneous Functions (Not yet properly filed/documented)
===========================================================
- Function File : AXVEC = axis2dlim (AXDATA)
determine axis limits for 2-d data(column vectors); leaves a 10%
margin around the plots. puts in margins of +/- 0.1 if data is
one dimensional (or a single point)
*Inputs* AXDATA nx2 matrix of data [x,y]
*Outputs* AXVEC vector of axis limits appropriate for call to
axis() function
- Function File : outputs = mb ( inputs )
$Revision: 1.9 $
- Function File : outputs = moddemo ( inputs )
Octave Controls toolbox demo: Model Manipulations demo
Written by David Clem August 15, 1994
- Function File : outputs = prompt ( inputs )
function prompt([str])
Prompt user to continue
str: input string. Default value: "\n ---- Press a key to continue ---"
Written by David Clem August 15, 1994
Modified A. S. Hodel June 1995
- Function File : outputs = rldemo ( inputs )
- Function File : outputs = rlocus ( inputs )
[rldata, k] = rlocus(sys[,increment,min_k,max_k])
Displays root locus plot of the specified SISO system.
----- --- --------
--->| + |---|k|---->| SISO |----------->
----- --- -------- |
- ^ |
|_____________________________|
inputs: sys = system data structure
min_k, max_k,increment: minimum, maximum values of k and
the increment used in computing gain values
Outputs: plots the root locus to the screen.
rldata: Data points plotted column 1: real values, column 2: imaginary
values)
k: gains for real axis break points.
- Function File : outputs = sortcom ( inputs )
[yy,idx] = sortcom(xx[,opt]): sort a complex vector
xx: complex vector
opt: sorting option:
"re": real part (default)
"mag": by magnitude
"im": by imaginary part
if opt != "im" then complex conjugate pairs are grouped together,
a - jb followed by a + jb.
yy: sorted values
idx: permutation vector: yy = xx(idx)
- Function File : outputs = ss2tf ( inputs )
[num,den] = ss2tf(a,b,c,d)
Conversion from tranfer function to state-space.
The state space system
.
x = Ax + Bu
y = Cx + Du
is converted to a transfer function
num(s)
G(s)=-------
den(s)
used internally in system data structure format manipulations
- Function File : outputs = ss2zp ( inputs )
Converts a state space representation to a set of poles and zeros.
[pol,zer,k] = ss2zp(a,b,c,d) returns the poles and zeros of the state space
system (a,b,c,d). K is a gain associated with the zeros.
used internally in system data structure format manipulations
- Function File : outputs = starp ( inputs )
[sys] = starp(P, K, ny, nu)
Redheffer star product or upper/lower LFT, respectively.
+-------+
--------->| |--------->
| P |
+--->| |---+ ny
| +-------+ |
+-------------------+
| |
+----------------+ |
| |
| +-------+ |
+--->| |------+ nu
| K |
--------->| |--------->
+-------+
If ny and nu "consume" all inputs and outputs of K then the result
is a lower fractional transformation. If ny and nu "consume" all
inputs and outputs of P then the result is an upper fractional
transformation.
ny and/or nu may be negative (= negative feedback)
- Function File : outputs = susball ( inputs )
- Function File : outputs = swap ( inputs )
[a1,b1] = swap(a,b)
interchange a and b
- Function File : outputs = swapcols ( inputs )
function B = swapcols(A)
permute columns of A into reverse order
- Function File : outputs = swaprows ( inputs )
function B = swaprows(A)
permute rows of A into reverse order
- Function File : outputs = tf2ss ( inputs )
Conversion from tranfer function to state-space.
The state space system
.
x = Ax + Bu
y = Cx + Du
is obtained from a transfer function
num(s)
G(s)=-------
den(s)
via the function call [a,b,c,d] = tf2ss(num,den).
The vector 'den' must contain only one row, whereas the vector 'num'
may contain as many rows as there are outputs of the system 'y'.
The state space system matrices obtained from this function will be
in controllable canonical form as described in "Modern Control Theory",
[Brogan, 1991].
- Function File : outputs = tf2zp ( inputs )
Converts transfer functions to poles / zeros.
[zer,pol,k] = tf2zp(num,den) returns the zeros and poles of the SISO system
defined by num/den. K is a gain associated with the system zeros.
- Function File : zp2ss
Conversion from zero / pole to state space. The state space system
.
x = Ax + Bu
y = Cx + Du
is obtained from a vector of zeros and a vector of poles via the
function call `[a,b,c,d] = zp2ss(zer,pol,k)'. The vectors `zer'
and `pol' may either be row or column vectors. Each zero and pole
that has an imaginary part must have a conjugate in the list. The
number of zeros must not exceed the number of poles. `k' is
`zp'-form leading coefficient.
- Function File : [POLY, RVALS] = zp2ssg2 (RVALS)
Used internally in `zp2ss' Extract 2 values from RVALS (if
possible) and construct a polynomial with those roots.
- Function File : zp2tf
Converts zeros / poles to a transfer function.
`[num,den] = zp2tf(zer,pol,k)' forms the transfer function
`num/den' from the vectors of poles and zeros.
File: octave, Node: Signal Processing, Next: Image Processing, Prev: Control Theory, Up: Top
Signal Processing
*****************
I hope that someday Octave will include more signal processing
functions. If you would like to help improve Octave in this area,
please contact (bug-octave@bevo.che.wisc.edu).
- Function File: detrend (X, P)
If X is a vector, `detrend (X, P)' removes the best fit of a
polynomial of order P from the data X.
If X is a matrix, `detrend (X, P)' does the same for each column
in X.
The second argument is optional. If it is not specified, a value
of 1 is assumed. This corresponds to removing a linear trend.
- Function: fft (A, N)
Compute the FFT of A using subroutines from FFTPACK. If A is a
matrix, `fft' computes the FFT for each column of A.
If called with two arguments, N is expected to be an integer
specifying the number of elements of A to use. If A is a matrix,
N specifies the number of rows of A to use. If N is larger than
the size of A, A is resized and padded with zeros.
- Loadable Function: ifft (A, N)
Compute the inverse FFT of A using subroutines from FFTPACK. If A
is a matrix, `fft' computes the inverse FFT for each column of A.
If called with two arguments, N is expected to be an integer
specifying the number of elements of A to use. If A is a matrix,
N specifies the number of rows of A to use. If N is larger than
the size of A, A is resized and padded with zeros.
- Loadable Function: fft2 (A, N, M)
Compute the two dimensional FFT of A.
The optional arguments N and M may be used specify the number of
rows and columns of A to use. If either of these is larger than
the size of A, A is resized and padded with zeros.
- Loadable Function: ifft2 (A, N, M)
Compute the two dimensional inverse FFT of A.
The optional arguments N and M may be used specify the number of
rows and columns of A to use. If either of these is larger than
the size of A, A is resized and padded with zeros.
- Built-in Function: fftconv (A, B, N)
Return the convolution of the vectors A and B, as a vector with
length equal to the `length (a) + length (b) - 1'. If A and B are
the coefficient vectors of two polynomials, the returned value is
the coefficient vector of the product polynomial.
The computation uses the FFT by calling the function `fftfilt'. If
the optional argument N is specified, an N-point FFT is used.
- Function File: fftfilt (B, X, N)
With two arguments, `fftfilt' filters X with the FIR filter B
using the FFT.
Given the optional third argument, N, `fftfilt' uses the
overlap-add method to filter X with B using an N-point FFT.
- Loadable Function: y = filter (B, A, X)
Return the solution to the following linear, time-invariant
difference equation:
N M
SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k) for 1<=n<=length(x)
k=0 k=0
where N=length(a)-1 and M=length(b)-1. An equivalent form of
this equation is:
N M
y(n) = - SUM c(k+1) y(n-k) + SUM d(k+1) x(n-k) for 1<=n<=length(x)
k=1 k=0
where c = a/a(1) and d = b/a(1).
In terms of the z-transform, y is the result of passing the
discrete- time signal x through a system characterized by the
following rational system function:
M
SUM d(k+1) z^(-k)
k=0
H(z) = ----------------------
N
1 + SUM c(k+1) z(-k)
k=1
- Loadable Function: [Y, SF] = filter (B, A, X, SI)
This is the same as the `filter' function described above, except
that SI is taken as the initial state of the system and the final
state is returned as SF. The state vector is a column vector
whose length is equal to the length of the longest coefficient
vector minus one. If SI is not set, the initial state vector is
set to all zeros.
- Function File: [H, W] = freqz (B, A, N, "whole")
Return the complex frequency response H of the rational IIR filter
whose numerator and denominator coefficients are B and A,
respectively. The response is evaluated at N angular frequencies
between 0 and 2*pi.
The output value W is a vector of the frequencies.
If the fourth argument is omitted, the response is evaluated at
frequencies between 0 and pi.
If N is omitted, a value of 512 is assumed.
If A is omitted, the denominator is assumed to be 1 (this
corresponds to a simple FIR filter).
For fastest computation, N should factor into a small number of
small primes.
- Function File: sinc (X)
Return sin(pi*x)/(pi*x).
File: octave, Node: Image Processing, Next: Audio Processing, Prev: Signal Processing, Up: Top
Image Processing
****************
Octave can display images with the X Window System using the
`xloadimage' program. You do not need to be running X in order to
manipulate images, however, so some of these functions may be useful
even if you are not able to view the results.
Loading images only works with Octave's image format (a file with a
matrix containing the image data, and a matrix containing the
colormap). Contributions of robust, well-written functions to read
other image formats are welcome. If you can provide them, or would like
to improve Octave's image processing capabilities in other ways, please
contact (bug-octave@bevo.che.wisc.edu).
- Function File: colormap (MAP)
- Function File: colormap ("default")
Set the current colormap.
`colormap (MAP)' sets the current colormap to MAP. The color map
should be an N row by 3 column matrix. The columns contain red,
green, and blue intensities respectively. All entries should be
between 0 and 1 inclusive. The new colormap is returned.
`colormap ("default")' restores the default colormap (a gray scale
colormap with 64 entries). The default colormap is returned.
With no arguments, `colormap' returns the current color map.
- Function File: gray (N)
Return a gray colormap with N entries corresponding to values from
0 to N. The argument N should be a scalar. If it is omitted, 64
is assumed.
- Function File: [IMG, MAP] = gray2ind ()
Convert a gray scale intensity image to an Octave indexed image.
- Function File: image (X, ZOOM)
Display a matrix as a color image. The elements of X are indices
into the current colormap and should have values between 1 and the
length of the colormap. If ZOOM is omitted, a value of 4 is
assumed.
- Function File: imagesc (X, ZOOM)
Display a scaled version of the matrix X as a color image. The
matrix is scaled so that its entries are indices into the current
colormap. The scaled matrix is returned. If ZOOM is omitted, a
value of 4 is assumed.
- Function File: imshow (X, MAP)
- Function File: imshow (X, N)
- Function File: imshow (I, N)
- Function File: imshow (R, G, B)
Display images.
`imshow (X)' displays an indexed image using the current colormap.
`imshow (X, MAP)' displays an indexed image using the specified
colormap.
`imshow (I, N)' displays a gray scale intensity image.
`imshow (R, G, B)' displays an RGB image.
- Function File: ind2gray (X, MAP)
Convert an Octave indexed image to a gray scale intensity image.
If MAP is omitted, the current colormap is used to determine the
intensities.
- Function File: [R, G, B] = ind2rgb (X, MAP)
Convert an indexed image to red, green, and blue color components.
If MAP is omitted, the current colormap is used for the conversion.
- Function File: [X, MAP] = loadimage (FILE)
Load an image file and it's associated color map from the specified
FILE. The image must be stored in Octave's image format.
- Function File: rgb2ntsc (RGB)
Image format conversion.
- Function File: ntsc2rgb (YIQ)
Image format conversion.
- Function File: ocean (N)
Create color colormap. The argument N should be a scalar. If it
is omitted, 64 is assumed.
- Function File: [X, MAP] = rgb2ind (R, G, B)
Convert and RGB image to an Octave indexed image.
- Function File: saveimage (FILE, X, FMT, MAP)
Save the matrix X to FILE in image format FMT. Valid values for
FMT are
`"img"'
Octave's image format. The current colormap is also saved in
the file.
`"ppm"'
Portable pixmap format.
`"ps"'
PostScript format. Note that images saved in PostScript
format can not be read back into Octave with loadimage.
If the fourth argument is supplied, the specified colormap will
also be saved along with the image.
Note: if the colormap contains only two entries and these entries
are black and white, the bitmap ppm and PostScript formats are
used. If the image is a gray scale image (the entries within each
row of the colormap are equal) the gray scale ppm and PostScript
image formats are used, otherwise the full color formats are used.
- Built-in Variable: IMAGEPATH
A colon separated list of directories in which to search for image
files.
File: octave, Node: Audio Processing, Next: System Utilities, Prev: Image Processing, Up: Top
Audio Processing
****************
Octave provides a few functions for dealing with audio data. An
audio `sample' is a single output value from an A/D converter, i.e., a
small integer number (usually 8 or 16 bits), and audio data is just a
series of such samples. It can be characterized by three parameters:
the sampling rate (measured in samples per second or Hz, e.g. 8000 or
44100), the number of bits per sample (e.g. 8 or 16), and the number of
channels (1 for mono, 2 for stereo, etc.).
There are many different formats for representing such data.
Currently, only the two most popular, *linear encoding* and *mu-law
encoding*, are supported by Octave. There is an excellent FAQ on audio
formats by Guido van Rossum <guido@cwi.nl> which can be found at any
FAQ ftp site, in particular in the directory
`/pub/usenet/news.answers/audio-fmts' of the archive site
`rtfm.mit.edu'.
Octave simply treats audio data as vectors of samples (non-mono data
are not supported yet). It is assumed that audio files using linear
encoding have one of the extensions `lin' or `raw', and that files
holding data in mu-law encoding end in `au', `mu', or `snd'.
- Function File: lin2mu (X)
If the vector X represents mono audio data in 8- or 16-bit linear
encoding, `lin2mu (X)' is the corresponding mu-law encoding.
- Function File: mu2lin (X, BPS)
If the vector X represents mono audio data in mu-law encoding,
`mu2lin' converts it to linear encoding. The optional argument
BPS specifies whether the input data uses 8 bit per sample
(default) or 16 bit.
- Function File: loadaudio (NAME, EXT, BPS)
Loads audio data from the file `NAME.EXT' into the vector X.
The extension EXT determines how the data in the audio file is
interpreted; the extensions `lin' (default) and `raw' correspond
to linear, the extensions `au', `mu', or `snd' to mu-law encoding.
The argument BPS can be either 8 (default) or 16, and specifies
the number of bits per sample used in the audio file.
- Function File: saveaudio (NAME, X, EXT, BPS)
Saves a vector X of audio data to the file `NAME.EXT'. The
optional parameters EXT and BPS determine the encoding and the
number of bits per sample used in the audio file (see
`loadaudio'); defaults are `lin' and 8, respectively.
The following functions for audio I/O require special A/D hardware
and operating system support. It is assumed that audio data in linear
encoding can be played and recorded by reading from and writing to
`/dev/dsp', and that similarly `/dev/audio' is used for mu-law
encoding. These file names are system-dependent. Improvements so that
these functions will work without modification on a wide variety of
hardware are welcome.
- Function File: playaudio (NAME, EXT)
- Function File: playaudio (X)
Plays the audio file `NAME.EXT' or the audio data stored in the
vector X.
- Function File: record (SEC, SAMPLING_RATE)
Records SEC seconds of audio input into the vector X. The default
value for SAMPLING_RATE is 8000 samples per second, or 8kHz. The
program waits until the user types RET and then immediately starts
to record.
- Function File: setaudio (TYPE)
- Function File: setaudio (TYPE, VALUE)
Set or display various properties of your mixer hardware.
For example, if `vol' corresponds to the volume property, you can
set it to 50 (percent) by `setaudio ("vol", 50)'.
This is an simple experimental program to control the audio
hardware settings. It assumes that there is a `mixer' program
which can be used as `mixer TYPE VALUE', and simply executes
`system ("mixer TYPE VALUE")'. Future releases might get rid of
this assumption by using the `fcntl' interface.
File: octave, Node: System Utilities, Next: Tips, Prev: Audio Processing, Up: Top
System Utilities
****************
This chapter describes the functions that are available to allow you
to get information about what is happening outside of Octave, while it
is still running, and use this information in your program. For
example, you can get information about environment variables, the
current time, and even start other programs from the Octave prompt.
* Menu:
* Timing Utilities::
* Filesystem Utilities::
* Controlling Subprocesses::
* Process ID Information::
* Environment Variables::
* Current Working Directory::
* Password Database Functions::
* Group Database Functions::
* System Information::
File: octave, Node: Timing Utilities, Next: Filesystem Utilities, Prev: System Utilities, Up: System Utilities
Timing Utilities
================
Octave's core set of functions for manipulating time values are
patterned after the corresponding functions from the standard C library.
Several of these functions use a data structure for time that includes
the following elements:
`usec'
Microseconds after the second (0-999999).
`sec'
Seconds after the minute (0-61). This number can be 61 to account
for leap seconds.
`min'
Minutes after the hour (0-59).
`hour'
Hours since midnight (0-23).
`mday'
Day of the month (1-31).
`mon'
Months since January (0-11).
`year'
Years since 1900.
`wday'
Days since Sunday (0-6).
`yday'
Days since January 1 (0-365).
`isdst'
Daylight Savings Time flag.
`zone'
Time zone.
In the descriptions of the following functions, this structure is
referred to as a TM_STRUCT.
- Loadable Function: time ()
Return the current time as the number of seconds since the epoch.
The epoch is referenced to 00:00:00 CUT (Coordinated Universal
Time) 1 Jan 1970. For example, on Monday February 17, 1997 at
07:15:06 CUT, the value returned by `time' was 856163706.
- Function File: ctime (T)
Convert a value returned from `time' (or any other nonnegative
integer), to the local time and return a string of the same form as
`asctime'. The function `ctime (time)' is equivalent to `asctime
(localtime (time))'. For example,
ctime (time ())
=> "Mon Feb 17 01:15:06 1997"
- Loadable Function: gmtime (T)
Given a value returned from time (or any nonnegative integer),
return a time structure corresponding to CUT. For example,
gmtime (time ())
=> {
usec = 0
year = 97
mon = 1
mday = 17
sec = 6
zone = CST
min = 15
wday = 1
hour = 7
isdst = 0
yday = 47
}
- Loadable Function: localtime (T)
Given a value returned from time (or any nonnegative integer),
return a time structure corresponding to the local time zone.
localtime (time ())
=> {
usec = 0
year = 97
mon = 1
mday = 17
sec = 6
zone = CST
min = 15
wday = 1
hour = 1
isdst = 0
yday = 47
}
- Loadable Function: mktime (TM_STRUCT)
Convert a time structure corresponding to the local time to the
number of seconds since the epoch. For example,
mktime (localtime (time ())
=> 856163706
- Function File: asctime (TM_STRUCT)
Convert a time structure to a string using the following five-field
format: Thu Mar 28 08:40:14 1996. For example,
asctime (localtime (time ())
=> "Mon Feb 17 01:15:06 1997\n"
This is equivalent to `ctime (time ())'.
- Loadable Function: strftime (TM_STRUCT)
Format a time structure in a flexible way using `%' substitutions
similar to those in `printf'. Except where noted, substituted
fields have a fixed size; numeric fields are padded if necessary.
Padding is with zeros by default; for fields that display a single
number, padding can be changed or inhibited by following the `%'
with one of the modifiers described below. Unknown field
specifiers are copied as normal characters. All other characters
are copied to the output without change. For example,
strftime ("%r (%Z) %A %e %B %Y", localtime (time ())
=> "01:15:06 AM (CST) Monday 17 February 1997"
Octave's `strftime' function supports a superset of the ANSI C
field specifiers.
Literal character fields:
`%'
% character.
`n'
Newline character.
`t'
Tab character.
Numeric modifiers (a nonstandard extension):
`- (dash)'
Do not pad the field.
`_ (underscore)'
Pad the field with spaces.
Time fields:
`%H'
Hour (00-23).
`%I'
Hour (01-12).
`%k'
Hour (0-23).
`%l'
Hour (1-12).
`%M'
Minute (00-59).
`%p'
Locale's AM or PM.
`%r'
Time, 12-hour (hh:mm:ss [AP]M).
`%R'
Time, 24-hour (hh:mm).
`%s'
Time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard
extension).
`%S'
Second (00-61).
`%T'
Time, 24-hour (hh:mm:ss).
`%X'
Locale's time representation (%H:%M:%S).
`%Z'
Time zone (EDT), or nothing if no time zone is determinable.
Date fields:
`%a'
Locale's abbreviated weekday name (Sun-Sat).
`%A'
Locale's full weekday name, variable length (Sunday-Saturday).
`%b'
Locale's abbreviated month name (Jan-Dec).
`%B'
Locale's full month name, variable length (January-December).
`%c'
Locale's date and time (Sat Nov 04 12:02:33 EST 1989).
`%C'
Century (00-99).
`%d'
Day of month (01-31).
`%e'
Day of month ( 1-31).
`%D'
Date (mm/dd/yy).
`%h'
Same as %b.
`%j'
Day of year (001-366).
`%m'
Month (01-12).
`%U'
Week number of year with Sunday as first day of week (00-53).
`%w'
Day of week (0-6).
`%W'
Week number of year with Monday as first day of week (00-53).
`%x'
Locale's date representation (mm/dd/yy).
`%y'
Last two digits of year (00-99).
`%Y'
Year (1970-).
Most of the remaining functions described in this section are not
patterned after the standard C library. Some are available for
compatiblity with MATLAB and others are provided because they are
useful.
- Function File: clock ()
Return a vector containing the current year, month (1-12), day
(1-31), hour (0-23), minute (0-59) and second (0-61). For example,
clock ()
=> [ 1993, 8, 20, 4, 56, 1 ]
The function clock is more accurate on systems that have the
`gettimeofday' function.
- Function File: date ()
Return the date as a character string in the form DD-MMM-YY. For
example,
date ()
=> "20-Aug-93"
- Function File: etime (T1, T2)
Return the difference (in seconds) between two time values
returned from `clock'. For example:
t0 = clock ();
# many computations later...
elapsed_time = etime (clock (), t0);
will set the variable `elapsed_time' to the number of seconds since
the variable `t0' was set.
- Built-in Function: [TOTAL, USER, SYSTEM] = cputime ();
Return the CPU time used by your Octave session. The first output
is the total time spent executing your process and is equal to the
sum of second and third outputs, which are the number of CPU
seconds spent executing in user mode and the number of CPU seconds
spent executing in system mode, respectively. If your system does
not have a way to report CPU time usage, `cputime' returns 0 for
each of its output values. Note that because Octave used some CPU
time to start, it is reasonable to check to see if `cputime' works
by checking to see if the total CPU time used is nonzero.
- Function File: is_leap_year (YEAR)
Return 1 if the given year is a leap year and 0 otherwise. If no
arguments are provided, `is_leap_year' will use the current year.
For example,
is_leap_year (2000)
=> 1
- Function File: tic ()
- Function File: toc ()
These functions set and check a wall-clock timer. For example,
tic ();
# many computations later...
elapsed_time = toc ();
will set the variable `elapsed_time' to the number of seconds since
the most recent call to the function `tic'.
If you are more interested in the CPU time that your process used,
you should use the `cputime' function instead. The `tic' and
`toc' functions report the actual wall clock time that elapsed
between the calls. This may include time spent processing other
jobs or doing nothing at all. For example,
tic (); sleep (5); toc ()
=> 5
t = cputime (); sleep (5); cputime () - t
=> 0
(This example also illustrates that the CPU timer may have a fairly
coarse resolution.)
- Built-in Function: pause (SECONDS)
Suspend the execution of the program. If invoked without any
arguments, Octave waits until you type a character. With a
numeric argument, it pauses for the given number of seconds. For
example, the following statement prints a message and then waits 5
seconds before clearing the screen.
fprintf (stderr, "wait please...\n");
pause (5);
clc;
- Built-in Function: sleep (SECONDS)
Suspend the execution of the program for the given number of
seconds.
- Built-in Function: usleep (MICROSECONDS)
Suspend the execution of the program for the given number of
microseconds. On systems where it is not possible to sleep for
periods of time less than one second, `usleep' will pause the
execution for `round (MICROSECONDS / 1e6)' seconds.
File: octave, Node: Filesystem Utilities, Next: Controlling Subprocesses, Prev: Timing Utilities, Up: System Utilities
Filesystem Utilities
====================
Octave includes the following functions for renaming and deleting
files, creating, deleting, and reading directories, and for getting
information about the status of files.
- Built-in Function: [ERR, MSG] = rename (OLD, NEW)
Change the name of file OLD to NEW.
If successful, ERR is 0 and MSG is an empty string. Otherwise,
ERR is nonzero and MSG contains a system-dependent error message.
- Built-in Function: [ERR, MSG] = unlink (FILE)
Delete FILE.
If successful, ERR is 0 and MSG is an empty string. Otherwise,
ERR is nonzero and MSG contains a system-dependent error message.
- Built-in Function: [FILES, ERR, MSG] = readdir (DIR)
Return names of the files in the directory DIR as an array of
strings. If an error occurs, return an empty matrix in FILES.
If successful, ERR is 0 and MSG is an empty string. Otherwise,
ERR is nonzero and MSG contains a system-dependent error message.
- Built-in Function: [ERR, MSG] = mkdir (DIR)
Create a directory named DIR.
If successful, ERR is 0 and MSG is an empty string. Otherwise,
ERR is nonzero and MSG contains a system-dependent error message.
- Built-in Function: [ERR, MSG] = rmdir (DIR)
Remove the directory named DIR.
If successful, ERR is 0 and MSG is an empty string. Otherwise,
ERR is nonzero and MSG contains a system-dependent error message.
- Built-in Function: [ERR, MSG] = mkfifo (NAME)
Create a FIFO special file.
If successful, ERR is 0 and MSG is an empty string. Otherwise,
ERR is nonzero and MSG contains a system-dependent error message.
- Built-in Function: umask (MASK)
Set the permission mask for file creation. The parameter MASK is
interpreted as an octal number.
- Built-in Function: [INFO, ERR, MSG] = stat (FILE)
- Built-in Function: [INFO, ERR, MSG] = lstat (FILE)
Return a structure S containing the following information about
FILE.
`dev'
ID of device containing a directory entry for this file.
`ino'
File number of the file.
`modestr'
File mode, as a string of ten letters or dashes as would be
returned by `ls -l'.
`nlink'
Number of links.
`uid'
User ID of file's owner.
`gid'
Group ID of file's group.
`rdev'
ID of device for block or character special files.
`size'
Size in bytes.
`atime'
Time of last access in the same form as time values returned
from `time'. *Note Timing Utilities::.
`mtime'
Time of last modification in the same form as time values
returned from `time'. *Note Timing Utilities::.
`ctime'
Time of last file status change in the same form as time
values returned from `time'. *Note Timing Utilities::.
`blksize'
Size of blocks in the file.
`blocks'
Number of blocks allocated for file.
If the call is successful ERR is 0 and MSG is an empty string. If
the file does not exist, or some other error occurs, S is an empty
matrix, ERR is -1, and MSG contains the corresponding system error
message.
If FILE is a symbolic link, `stat' will return information about
the actual file the is referenced by the link. Use `lstat' if you
want information about the symbolic link itself.
For example,
[s, err, msg] = stat ("/vmlinuz")
=> s =
{
atime = 855399756
rdev = 0
ctime = 847219094
uid = 0
size = 389218
blksize = 4096
mtime = 847219094
gid = 6
nlink = 1
blocks = 768
modestr = -rw-r--r--
ino = 9316
dev = 2049
}
=> err = 0
=> msg =
- Built-in Function: glob (PATTERN)
Given an array of strings in PATTERN, return the list of file
names that any of them, or an empty string if no patterns match.
Tilde expansion is performed on each of the patterns before
looking for matching file names. For example,
glob ("/vm*")
=> "/vmlinuz"
Note that multiple values are returned in a string matrix with the
fill character set to ASCII NUL.
- Built-in Function: fnmatch (PATTERN, STRING)
Return 1 or zero for each element of STRING that matches any of
the elements of the string array PATTERN, using the rules of
filename pattern matching. For example,
fnmatch ("a*b", ["ab"; "axyzb"; "xyzab"])
=> [ 1; 1; 0 ]
- Built-in Function: file_in_path (PATH, FILE)
Return the absolute name name of FILE if it can be found in PATH.
The value of PATH should be a colon-separated list of directories
in the format described for the built-in variable `LOADPATH'.
If the file cannot be found in the path, an empty matrix is
returned. For example,
file_in_path (LOADPATH, "nargchk.m")
=> "/share/octave/2.0/m/general/nargchk.m"
- Built-in Function: tilde_expand (STRING)
Performs tilde expansion on STRING. If STRING begins with a tilde
character, (`~'), all of the characters preceding the first slash
(or all characters, if there is no slash) are treated as a
possible user name, and the tilde and the following characters up
to the slash are replaced by the home directory of the named user.
If the tilde is followed immediately by a slash, the tilde is
replaced by the home directory of the user running Octave. For
example,
tilde_expand ("~joeuser/bin")
=> "/home/joeuser/bin"
tilde_expand ("~/bin")
=> "/home/jwe/bin"