| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>Formulas 1.7. Formulas for modification</title> |
| 3 |
<style> |
| 4 |
td { padding-left: 5pt; padding-right: 5pt; } |
| 5 |
th { padding-left: 5pt; padding-right: 5pt; } |
| 6 |
code { white-space: pre-wrap; } |
| 7 |
dd { white-space: pre-wrap; } |
| 8 |
</style> |
| 9 |
</head><body bgcolor="#FFFFFF"> |
| 10 |
|
| 11 |
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b> |
| 12 |
Formulas 1.7. Formulas for modification |
| 13 |
</b></font></table></table> |
| 14 |
<p>Analogously to the formulas that you can use for creating new objects (see the previous page), you can use formulas for modifying existing objects. You do this with the command <b>Formula...</b> that you can find in the <a href="Modify.html">Modify</a> menu when you select an object.</p> |
| 15 |
<h2>Modifying a Sound with a formula</h2> |
| 16 |
<p>Record a sound with your microphone and talk very lowly. If you don't know how to record a sound in Praat, consult the <a href="Intro.html">Intro</a>. Once the Sound object is in the list, click <b>Play</b>. The result will sound very soft. Then choose <b>Formula...</b> from the Modify menu and type</p> |
| 17 |
<code> self * 3<br></code> |
| 18 |
<p>Click OK, then click <b>Play</b> again. The sound is much louder now. You have multiplied the amplitude of every sample in the sound with a factor of 3.</p> |
| 19 |
<h2>Replacing the contents of a Sound with a formula</h2> |
| 20 |
<p>If you don’t use <code><font size=+1>self</font></code> in your formula, the formula does not refer to the existing contents of the Sound. Hence, the formula </p> |
| 21 |
<code> 1/2 * sin (2 * pi * 377 * x)<br></code> |
| 22 |
<p>will simply replace your recorded speech with a 377-Hz sine wave.</p> |
| 23 |
<h2>Modifying a Matrix with a formula</h2> |
| 24 |
<p>Many objects can be thought of as matrices: they consist of a number of rows and columns with data in every cell:</p> |
| 25 |
<dl> |
| 26 |
<dd style="position:relative;padding-left:1em;text-indent:-2em"><a href="Sound.html">Sound</a>: one row; columns represent samples.</dd> |
| 27 |
<dd style="position:relative;padding-left:1em;text-indent:-2em"><a href="Spectrum.html">Spectrum</a>: two rows (first row is real part, second row is imaginary part); columns represent frequencies.</dd> |
| 28 |
<dd style="position:relative;padding-left:1em;text-indent:-2em"><a href="Spectrogram.html">Spectrogram</a>, <a href="Cochleagram.html">Cochleagram</a>: rows represent frequencies; columns represent times.</dd> |
| 29 |
<dd style="position:relative;padding-left:1em;text-indent:-2em"><a href="Excitation.html">Excitation</a>: one row; columns represent frequency bands.</dd> |
| 30 |
<dd style="position:relative;padding-left:1em;text-indent:-2em"><a href="Harmonicity.html">Harmonicity</a>: one row; columns represent time frames.</dd> |
| 31 |
</dl> |
| 32 |
<p>The formula is performed on every column of every row. The formula</p> |
| 33 |
<code> self^2<br></code> |
| 34 |
<p>will square all matrix elements.</p> |
| 35 |
<p>The formula first works on the first row, and in that row from the first column on; this can work recursively. The formula</p> |
| 36 |
<code> self + self [row, col - 1]<br></code> |
| 37 |
<p>integrates each row.</p> |
| 38 |
<h2>Referring to the current position in the object</h2> |
| 39 |
<p>You can refer to the current position in a Matrix (or Sound, etc.) by index or by <i>x</i> and <i>y</i> values:</p> |
| 40 |
<dl> |
| 41 |
<dt><b><code><font size=+1>row</font></code></b> |
| 42 |
<dd>the current row</dd> |
| 43 |
<dt><b><code><font size=+1>col</font></code></b> |
| 44 |
<dd>the current column</dd> |
| 45 |
<dt><b><code><font size=+1>x</font></code></b> |
| 46 |
<dd>the <i>x</i> value associated with the current column:</dd> |
| 47 |
<dd> for a Sound, Spectrogram, Cochleagram, or Harmonicity: time, as in the 377-Hz sine wave example above</dd> |
| 48 |
<dd> for a Spectrum: frequency (Hz)</dd> |
| 49 |
<dd> for an Excitation: frequency (Bark)</dd> |
| 50 |
<dt><b><code><font size=+1>y</font></code></b> |
| 51 |
<dd>the <i>y</i> value associated with the current row:</dd> |
| 52 |
<dd> for a Spectrogram: frequency (Hz)</dd> |
| 53 |
<dd> for a Cochleagram: frequency (Bark)</dd> |
| 54 |
</dl> |
| 55 |
<h2>Referring to the contents of the object itself</h2> |
| 56 |
<p>You can refer to values in the current Matrix (or Sound, etc.) by index.</p> |
| 57 |
<dl> |
| 58 |
<dt><b><code><font size=+1>self</font></code></b> |
| 59 |
<dd>refers to the value in the current Matrix at the current row and column, or to the value in the current Sound at the current sample.</dd> |
| 60 |
<dt><b><code><font size=+1>self</font></code></b> [<i><code><font size=+1>column-expression</font></code></i>] |
| 61 |
<dd>refers to the value in the current Sound (or Intensity etc.) at the current sample (or frame). The <i><code><font size=+1>column-expression</font></code></i> is rounded to the nearest integer. If the index is out of range (less than 1 or greater than <i>n</i><sub><i>x</i></sub>), the expression evaluates as 0.</dd> |
| 62 |
</dl> |
| 63 |
<p><b>Example</b>. An integrator is</p> |
| 64 |
<code> self [col - 1] + self * dx<br></code> |
| 65 |
<dl> |
| 66 |
<dt><b><code><font size=+1>self</font></code></b> [<i><code><font size=+1>row-expression</font></code></i>, <i><code><font size=+1>column-expression</font></code></i>] |
| 67 |
<dd>refers to the value in the current Matrix (or Spectrogram etc.) at the specified row and column. The expressions are rounded to the nearest integers.</dd> |
| 68 |
</dl> |
| 69 |
<p>You can refer to values in the current Matrix (or Spectrogram, etc.) by <i>x</i> and <i>y</i> position:</p> |
| 70 |
<dl> |
| 71 |
<dt><b><code><font size=+1>self</font></code></b> (<i><code><font size=+1>x-expression</font></code></i>, <i><code><font size=+1>y-expression</font></code></i>) |
| 72 |
<dd>the expressions are linearly interpolated between the four nearest matrix points.</dd> |
| 73 |
</dl> |
| 74 |
<p>You can refer to values in the current Sound (or Intensity etc.) by <i>x</i> position:</p> |
| 75 |
<dl> |
| 76 |
<dt><b><code><font size=+1>self</font></code></b> (<i><code><font size=+1>x-expression</font></code></i>) |
| 77 |
<dd>the expression is linearly interpolated between the two nearest samples (or frames).</dd> |
| 78 |
</dl> |
| 79 |
<h3>Links to this page</h3> |
| 80 |
<ul> |
| 81 |
<li><a href="_col_.html"><code><font size=+1>col</font></code></a> |
| 82 |
<li><a href="_row_.html"><code><font size=+1>row</font></code></a> |
| 83 |
<li><a href="_x_.html"><code><font size=+1>x</font></code></a> |
| 84 |
<li><a href="_y_.html"><code><font size=+1>y</font></code></a> |
| 85 |
<li><a href="Formulas.html">Formulas</a> |
| 86 |
<li><a href="Formulas_1__My_first_formulas.html">Formulas 1. My first formulas</a> |
| 87 |
<li><a href="Formulas_1_8__Formulas_in_scripts.html">Formulas 1.8. Formulas in scripts</a> |
| 88 |
</ul> |
| 89 |
<hr> |
| 90 |
<address> |
| 91 |
<p>© ppgb 20170916</p> |
| 92 |
</address> |
| 93 |
</body> |
| 94 |
</html> |