Numerical Utilities - Num-UtilGeneral Purpose Vector and Matrix Math Utilities
The Numerical Utilities perform common mathematical operations on files containing lists of numbers. Files may represent vectors or matrices. The files may be plotted by various tools, such as XGRAPH, and the utilities may be considered a means to manipulate data to be plotted.
The Num-Utils are useful for anyone studying Digital Signal Processing (DSP), linear algebra, statistics, or numerical analysis in general, as well any field dealing with numerical data. The utilities form a simple and inexpensive alternative to-, or can be used to complement-, more extensive environments such as Octave, Matlab, or programming libraries such as LAPACK by leveraging the familiar capabilities of the operating system's command-line and/or script files. Num-Util enables file-names to be treated as variable-names.
List of Num-Utils: Scaling / Shifting scale - Scales a real or complex vector file by a scalar. shift - Adds a scalar to a real or complex vector file. normalize - Normalize a vector. Makes sum (or max) of terms equal 1.0. Generating Functions sine_gen - Generates sinusoidal vectors. rand_gen - Generates random vectors, noise. enter_vec - Creates new vector or matrix by keyboard prompts/input. identity_matrix - Generates identity matrix. Conversions abs - Computes absolute value, or complex magnitude. cmag - Converts a complex vector file into real (magnitude) vector. db - Converts a real vector file from linear to deciBells (dB). phase - Converts a complex vector file into magnitude and phase. real2cmplx - Converts a real vector to a complex vector. extract_real - Extracts real part of complex vector to real vector. extract_imaginary - Extracts imaginary part of complex vector to real vector. barchart - Converts real vector to bar-chart graph. image2matrix - Convert an image file to a matrix file. mat2image - Convert matrix to an image file. num2vec - Converts simple number list to NumUtils Vector format. vec2nums - Converts real or complex vector files to simple number list files. Operations / Transforms add - Adds two real or complex vectors or matrices. sub - Subtracts one vector or matrix from another. conjg - Conjugates a complex vector. dotpr - Computes the dot-product (inner-product) of two vectors. cdotpr - Complex-conjugate dot-product of two complex vectors. matmul - Matrix-matrix or Matrix-vector multiply, real or complex. multpbp - Multiplies real or complex vector by vector (point by point). outpr - Outer-product multiply. Multiplies two vectors, produces matrix. zfill - zero-fills a vector to arbitrary length. convolve - Convolves two complex or real vectors. (FIR filter) correlate - Computes the correlation of two complex or real vectors. fft - Computes FFT on a complex or real vector (of any length). window - Computes windowing functions, hamming, hanning, bartlet, blackman. transpose - Transposes real matrix, or conjugate-transposes complex matrices. ucirc - Produces Unit Circle points for Z-plane plots. fft2D - Computes the 2D-FFT on a complex or real matrix. eigen - Computes Eigen vectors and values. svd - Computes Singular Value Decomposition. z_trans - Z-transform, finds roots of arbitrary polynomials. matinvert - Invert a real or complex matrix. matXvec - Extract matrix row or column to a vector. mdeterm - Compute the matrix determinant, real or complex. augmatvec - Augment matrix by vector. Adds row or column to matrix. join2xy - Joins 2 Real Vectors into one Vector, becoming x and y. Useful for plotting one file against another. differentiate - Differentiates a real vector. integrate - Integrates a real vector. decimate - Decimates (sub-samples) a real or complex vector. Statistics statistics - Computes mean, variance, min, max, and optionally the median, of a real vector. histogram - Plots the histogram of real vectors. TBD: convolve2d, more examples, tutorials, etc.. Any volunteers?
The Num-Util are provided as source-code, and are conveniently compiled on most any platform with a C compiler. The utilities are simple and self-contained. No additional tools or libraries are needed. A simple Build.com script is provided to automatically compile the utilities, or to show the suggested compilation commands. Most of the Num-Util programs are under 100 lines of code. (grep ";" xx.c | wc)
Num-Util is consistent with the convention of other file utilities, such as copy, diff, cat, sort, zip, grep, awk, xgraph, latex, etc.. All data files are ASCII text files, (not binary) which are readable, printable, and convenient to produce, edit, or read with other programs. Being file-based utilities, data is not limited by memory (RAM size).
Because each Num-Util tool is an independent utility, they can be called from programs without risk of library or symbol conflicts. (eg. system() call.) They can also be called directly from the command-line, -interactively-, without need of writing a program. Although many of the functions are trivial, the collection has value by virtue of it's consistency and completeness.
Num-Util presently supports four formats for data files:
(1) Real Vector, (2) Complex Vector, (3) Real Matrix, (4) Complex Matrix.A simple XML-like convention in the data-file's first line indicates the file's type, and enables the tools to operate consistently on either kind of data-file. The header also specifies the file's dimension(s), as either vector or 2D matrix. See below for format specification. The utilities include extensive checking and are fully documented.
The venerable Num-Util have been in use by several groups of researchers for more than a decade. We noticed others often re-inventing common functions on projects without knowledge of the Num-Util, and realized they may be beneficial to share with others. Therefore, we hope these utilities and conventions will be helpful, and that contributors might combine efforts by adding additional functions and utilities consistent with the initial set, as well as to help in improving and enhancing them, or that it serves as the basis or template for other endeavors. Num-Util are released under GPL, included in gpl.txt. So that everyone may share in combined efforts, we request that improvements/comments be directed back to email@example.com for centralized re-distribution with credit.
Click (or right-click) Download NumUtil.tar.gz . Vers-1.2 (44 KB)
Click (or right-click) Download NumUtil.zip . Vers-1.2 (122 KB)
Try: source script_fft.com
sine_gen -f 3.0 -n 100 swA.dat
sine_gen -f 11.0 -n 100 swB.dat
add swA.dat swB.dat composite.dat
xgraph -a -pl composite.dat time.title &
fft composite.dat composite.fft
cmag composite.fft composite.spectrum
xgraph composite.spectrum spectrum.title &
Try: source script_convolve.com
convolve sequenceA.dat sequenceB.dat sequenceC.dat
Try: source script_image.com
sine_gen -n 100 -f 2 -realvec v.dat
outpr v.dat v.dat m.dat
mat2image m.dat m.ppm
Try: source script_color_image.com
With this scheme, other formats could be defined, such as integer vectors, or higher dimensional matrices, but no such formats are presently used.
Optional comment fields can be added by starting with "!". Everything after the "!" until end of line is considered a comment.
Comment fields can also be added by using the C-style comment designators, "/*" and "*/". These may span multiple lines.
(Questions, Comments, & Suggestions: firstname.lastname@example.org)