singen
star in the sinMod
application has the following parameter screen:Notice that the frequency parameter is given as an expression, "PI/100" (PI represents the constant ). This section describes the expression language for specifying parameter values.
The parameter screen can be kept open while you experiment with different values of the parameters. Try changing the value "PI/100" to "PI/200". Click "Apply" in the parameter window, and then "GO" in the run control panel. How does this change the display? Clicking "Cancel" in the parameter window will restore the parameter values to the last saved values and dismiss the parameter window. Clicking "Close" will dismiss the parameter window without restoring the parameter values.
State
is a data-structure associated with a star and is used to remember data values from one invocation to the next. For example, the gain of an automatic gain control is a state. A state need not be dynamic since its value may not change during the course of a simulation. Technically, a parameter is the initial value of a state. Pigi
is responsible for defining parameter values and storing them in the design database.
pigi
permits the user to set the initial value of a settable state of any star (lowest level block) and to define and set parameters for a galaxy (composite block) or universe (complete application).
sinMod
application shown in figure
2-4. The parameter screen for the modulator
block is shown below:singen
block inside modulator
, you will see
Parameter expressions
Parameter values set through pigi
can be arithmetic expressions. This is particularly useful for propagating values down from a universe parameter to star parameters somewhere down in the hierarchy. An example of a valid parameter expression is:PI/(2*order)
where order
is a parameter defined in the galaxy or universe. The basic arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^). These operators work on integers and floating-point numbers. Currently all intermediate expressions are converted to the type of the parameter being computed. Hence, it is necessary to be very careful when, for example, using floating-point values to compute an integer parameter. In an integer parameter specification, all intermediate expressions will be converted to integers. Complex-valued parameters
When defining complex values, the basic syntax is(real, imag)
where real
and imag
evaluate to integers or floats. Fixed-point parameters
Fixed-point parameters may be assigned a precision directly. To do this, the parameter is given in the syntax "(value, precision)", where value is an ordinary number and precision is given by either of two syntaxes:
Syntax 1
: As a string like "3.2", or more generally "m.n", where m is the number of integer bits (to the left of the binary point) and n is the number of fractional bits (to the right of the binary point). Thus length is m+n.
Syntax 2
: A string like "24/32" which means 24 fraction bits from a total length of 32. This format is often more convenient because the word length often remains constant while the number of fraction bits changes with the normalization being used.
Thus, for example, a fixed-point parameter might be defined as "(0.8, 2/4)." This means that a 4-bit word will be used with two fraction bits. Since the value "0.8" cannot be represented precisely in this precision, the actual value of the parameter will be rounded to "0.75".
A fixed-point parameter can also be given a value without a precision. In this case, the default precision is used. This has a total word length of 24 bits with the number of integer bits set as required to store the value. For example, the number 1.0 creates a fixed-point object with precision 2.22, and a value like 0.5 would create one with precision 1.23.
The precision of internal computations in a star is typically given by a parameter of type
precision
. A precision parameter has a value specified using either of the two syntaxes above.
<
as in the following example:
< filenameFirst, any parameters appearing in the
filename
in the form of {parameter}
are replaced with their values. Then, any references to environment variables or home directories are substituted to generate a complete path name. Finally, the contents of the file are then read and spliced into the parameter expression and reparsed. File inputs can be very useful for array parameters which may require a large amount of data. Other expression may come before or after the <filename
syntax (any white space that appears after the <
character is ignored).
#
symbol. Everything after the #
until the end of the line is discarded when the parameter is evaluated. Comments are especially useful in combination with files as they can help remind the user of which galaxy or star parameter the file was written.For example, a comment could be added to the frequency parameter above:
freq # This is set to the Galaxy parameterComments are not supported for the String parameter or String Array parameter types. In fact, when the image processing stars use String states to represent a filename, the
#
character is used to denote the frame number of the image being processed.
! "expression"First, parameters in the form of
{parameter}
appearing in the expression are replaced by their values. Then, the string is sent to the pigiRpc Tcl interpreter for evaluation. Finally, the result is spliced into the parameter expression and reparsed. The pigiRpc Tcl interpreter is the same interpreter that appears as a window when pigi
is started by using pigi -console
.This facility is general and supports both numeric and symbolic computing of expressions. Through Tcl, one can access all of its math functions, which generally behave as the ANSI C functions of the same name:
abs
, acos
, asin
, atan
, atan2
, ceil
, cos
, cosh
, double
, exp
, floor
, fmod
, hypot
, int
, log
, log10
, pow
, round
, sin
, sinh
, sqrt
, tan
, and tanh
. So, a parameter expression could be
! "expr sqrt(2.0 / {BitDuration})"for the amplitude of the oscillators in a binary frequency shift keying system, in which
BitDuration
is a parameter. The expr
command is a Tcl command that treats its arguments as a single mathematical expression that must evaluate to a number.The Tcl mechanism can be used to return symbolic expressions:
! "join 2*gain1"Because
gain1
is not surrounded by curly braces, its value is not substituted before passing the expression to the Tcl interpreter. The Tcl interpreter will return 2*gain1
which is then evaluated by the parameter parser.Note that whitespace between
!
and "
is permitted in numeric parameters, but not in string parameters: to get a Tcl call to be recognized in a string parameter you must write:
!"list /users/ptolemy/myfile"There are several Tcl commands embedded in
pigiRpc
that help support parameter calculations. They are: listApplyExpression
, max
, min
, range
, rangeApplyExpression
, and sign
. For example,
! "min [max 1 2 3] [sign -2]"first evaluates to
min 3 -1
and then to -1
. The procedure range
returns a consecutive sequence of numbers:
! "range 0 5"returns
0 1 2 3 4 5
. The rangeApplyExpression
procedure generates a sequence of values by applying a consecutive sequence of numbers to a Tcl expression that is a function of i
. For example, you can generate the taps of an FIR filter that is a sampled sinusoid by using
! "rangeApplyExpression { cos(2*{PI}*$i/5) } 0 4"generates one period of sinusoidal function and returns
1.0 0.309042 -0.808986 -0.809064 0.308916The
listApplyExpression
is similar to rangeApplyExpression
except that it only takes two arguments: the second argument is a list of numbers to substitute for i
in the expression. The command
! "listApplyExpression { cos(2*{PI}*$i/5) } [range 0 4]"is equivalent to the previous example of the
rangeApplyExpression
function.If you are running Tycho TclShell from within
pigi
or pigi -console
, you can receive help on the new Tcl procedures listApplyExpression
, max
, min
, range
, rangeApplyExpression
, and sign
, by typing
help signat the prompt. To start Tycho from within
pigi
, type a y
while the mouse is over a vem
facet or palette.The Tycho TclShell and the
pigiRpc
console includes the Ptolemy interpreter (ptcl
) which defines the help mechanism. Help is available on all of the commands we have added to the Tcl language.
! "matlab getpairs c {c=remez(32, [0 0.4 0.6 1], [1 1 0 0])}"Similarly, we can use Mathematica to derive formulas to be used as parameters:
! "mathematica get c {c=Integrate[A x, {x, 0, 1}]}"This command returns the symbolic expression A/2 which is reparsed by Ptolemy. Matlab and Mathematica can be used to keep track of how parameter values are computed. Mathematica can also be used to return symbolic expressions that can be used in conjunction with higher-order functions to define scalable systems [Eva95].
The Ptolemy interface to Matlab and Mathematica can also be accessed from the pigiRpc console window, and the Tycho editor offers console windows that mimic the Matlab and Mathematica teletype (tty) interfaces. More information about the options of the Tcl commands
matlab
and mathematica
can be found by using the help facility described above.
1 2 3 4 5defines an integer array with five elements. The elements can be expressions if they are surrounded by parentheses:
1 2 PI (2*PI)Repetition can be indicated using the following syntax:
value[n]where
n
evaluates to an integer. An array or portion of an array can be input from a file using the symbol <
as in the following example:
1 2 < filename 3 4Here the first two elements of the array will be 1 and 2, the next elements will be read from file
filename,
and the last two elements will be 3 and 4. This latter capability can be used in combination with the WaveForm
star to read a signal from a file.
This string has the word {word} taken from another parameterHere
{word}
represents the value of a string universe or galaxy parameter. This capability is especially useful for constructing labels for output plots. When using string states to specify options for a Unix command, as in the options parameter in Xgraph
stars, you can use either double quotes or single quotes to include white space within a single word:
-0 'original signal' -1 'estimated signal'String arrays have a few more special restrictions. Each word (separated by white space) is a separate entry in the array. To include white space in an element of the array, use quotation marks. Thus, the following string array
first "the second element" thirdhas three elements in it. The string array
repeat[10]has ten separate copies of the string "repeat" in 10 separate entries in the array. Curly braces are used to substitute in values from galaxy parameters. Thus, in
{paramname}
paramname
must be the name of either a string array or a scalar-valued parameter (an integer, float or complex array, for example, is not permitted). If it is a string array, then each element of paramname
becomes an element of the parameter. If it is some other kind of parameter the value becomes a single element of the string array.To use one of
[
, ]
, {
, or }
literally, quote them with double quotes. To turn off the special meaning of a double quote, precede it with a backslash: \"
. Similarly, use \\
to get a single backslash.String array values may also be read from files using the
<
symbol. For details on how to use file references, see section
2.4.3 above. Note that for string arrays, the filename can be a
< $PTOLEMY/data/filename
as well as a string that refers to parameters such as< $PTOLEMY/{data_dir}/data_file
in which case the value of the parameter data_dir would be substituted. Ptolemy does not perform expansion of filenames such as file.{1,2}
into file1
file2
as a Unix shell might do.