Formulas 8. Attributes of objects

You can refer to several attributes of objects that are visible in the List of Objects. To do so, use either the unique ID of the object, or the type and the name of the object. Thus, object[113] refers to the object that has the number 113 in the list, and object["Sound hallo"] refers to an existing Sound object whose name is “hallo” (if there is more than one such object, it refers to the one that was created last).

To refer to an attribute, you use the period ("."). Thus, object["Sound hallo"].nx is the number of samples of the Sound called hallo, and 1/object["Sound hallo"].dx is its sampling frequency.

Attributes in the calculator

Record a Sound (read the Intro if you do not know how to do that), and name it mysound (or anything else). An object with a name like 3. Sound mysound will appear in the list. Then type into the calculator the formula

object[3].nx

or

object["Sound mysound"].nx

After you click OK, the Info window will show the number of samples. Since you could have got this result by simply selecting the object and choosing Get number of samples from the Query submenu, these attribute tricks are not very useful in the calculator. We will see that they are much more useful in creation and modification formulas and in scripts.

List of possible attributes

The following attributes are available:

xmin
the start of the time domain (usually 0) for a Sound, Pitch, Formant, Spectrogram, Intensity, Cochleagram, PointProcess, or Harmonicity object, in seconds; the lowest frequency (always 0) for a Spectrum object, in hertz; the lowest frequency (usually 0) for an Excitation object, in Bark; the left edge of the x domain for a Matrix object.
xmax
the end of the time domain (usually the duration, if xmin is zero) for a Sound, Pitch, Formant, Spectrogram, Intensity, Cochleagram, PointProcess, or Harmonicity object, in seconds; the highest frequency (Nyquist frequency) for a Spectrum object, e.g. 11025 hertz; the highest frequency for an Excitation object, often 25.6 Bark; the right edge of the x domain for a Matrix object.
ncol
the number of columns in a Matrix, TableOfReal, or Table object.
nrow
the number of rows in a Matrix, TableOfReal, or Table object.
col$ [i]
the name of column i in a TableOfReal or Table object.
row$ [i]
the name of row i in a TableOfReal object.
nx
the number of samples in a Sound object; the number of analysis frames in a Pitch, Formant, Spectrogram, Intensity, Cochleagram, or Harmonicity object; the number of frequency bins in a Spectrum or Excitation object; the number of divisions of the x domain for a Matrix object (= ncol).
dx
the sample period (time distance between consecutive samples) in a Sound object (the inverse of the sampling frequency), in seconds; the time step between consecutive frames in a Pitch, Formant, Spectrogram, Intensity, Cochleagram, or Harmonicity object, in seconds; the width of a frequency bin in a Spectrum object, in hertz; the width of a frequency bin in an Excitation object, in Bark; the horizontal distance between cells in a Matrix object.
ymin
the lowest frequency (usually 0) for a Spectrogram object, in hertz; the lowest frequency (usually 0) for a Cochleagram object, in Bark; the bottom of the y domain for a Matrix object.
ymax
the highest frequency for a Spectrogram object, e.g. 5000 hertz; the highest frequency for a Cochleagram object, often 25.6 Bark; the top of the y domain for a Matrix object.
ny
the number of frequency bands in a Spectrogram or Cochleagram object; for a Spectrum object: always 2 (first row is real part, second row is imaginary part) the number of divisions of the y domain for a Matrix object (= nrow).
dy
the distance between adjacent frequency bands in a Spectrogram object, in hertz; the distance between adjacent frequency bands in a Cochleagram object, in Bark; the vertical distance between cells in a Matrix object.

Attributes in a creation formula

In formulas for creating a new object, you can refer to the attributes of any object, but you will often want to refer to the attributes of the object that is just being created. You can do that in two ways.

The first way is to use the name of the object, as above. Choose Create Sound from formula..., supply hello for its name, supply arbitrary values for the starting and finishing time, and type the following formula:

(x - object["Sound hello"].xmin) / (object["Sound hello"].xmax - object["Sound hello"].xmin)

When you edit this sound, you can see that it creates a straight line that rises from 0 to 1 within the time domain.

The formula above will also work if the Sound under creation is called goodbye, and a Sound called hello already exists; of course, in such a case object["Sound hello"].xmax refers to a property of the already existing sound.

If a formula refers to an object under creation, there is a shorter way: you do not have to supply the name of the object at all, so you can simply write

(x - xmin) / (xmax - xmin)

The attributes that you can use in this implicit way are xmin, xmax, ncol, nrow, nx, dx, ny, and dy. To disambiguate in case there exists a script variable xmin as well (Praat will complain if this is the case), you can write Self.xmin.

Attributes in a modification formula

In formulas for modifying an existing object, you refer to attributes in the same way as in creation formulas, i.e., you do not have to specify the name of the object that is being modified. The formula

self * 20 ^ (- (x - xmin) / (xmax - xmin))

causes the sound to decay exponentially in such a way that it has only 5 percent of its initial amplitude at the end. If you apply this formula to multiple Sound objects at the same time, xmax will refer to the finishing time of each Sound separately as that Sound is modified.

More examples of the use of attributes are on the next page.

Links to this page


© ppgb 20221202