Debian Codegraph @

doc/part13.html

raw
1 <!DOCTYPE html>
2 <html><head><title>Linear Prediction Analysis and Synthesis</title>
3 <link rel="stylesheet" type="text/css" href="nyquiststyle.css">
4 <link rel="icon" href="nyquist-icon.png" />
5 <link rel="shortcut icon" href="nyquist-icon.png" />
6 </head>
7 <body bgcolor="ffffff">
8 <a href = "part12.html">Previous Section</a> | <a href = "part14.html">Next Section</a> | <a href = "title.html#toc">Table of Contents</a> | <a href = "indx.html">Index</a> | <a href = "title.html">Title Page</a>
9 <hr>
10 <a name = "151"><h2>Linear Prediction Analysis and Synthesis</h2></a><a name="index1116"></a><a name="index1117"></a>
11 <p>Nyquist provides functions to perform Linear Prediction Coding (LPC)
12 analysis and synthesis. In simple terms, LPC analysis assumes that a
13 sound is the result of an all-pole filter applied to a source with a
14 flat spectrum. LPC is good for characterizing the general spectral
15 shape of a signal, which may be time-varying as in speech sounds.
16 For synthesis, any source can be filtered, allowing the general
17 spectral shape of one signal (used in analysis) to be applied to
18 any source (used in synthesis). A popular effect is to give vowel-like
19 spectra to musical tones, creating an artificial (or sometimes natural)
20 singing voice.</p>
21
22 <p>Examples of LPC analysis and synthesis can be found in the file
23 <code>nyquist/lib/lpc/lpc_tutorial.html</code><a name="index1118"></a><a name="index1119"></a><a name="index1120"></a>,
24 which is part of the standard Nyquist release.</p>
25
26 <p>As with FFT processing, LPC analysis takes a sound as input and returns
27 a stream of frames. Frames are returned from an object using the <code>:next</code>
28 selector just as with FFT frames. An LPC frame is a list consisting of:
29 <i>RMS1</i>, the energy of the input signal, <i>RMS2</i>, the energy of the
30 residual signal, <i>ERR</i>, the square root of <i>RMS1</i>/<i>RMS2</i>, and
31 <i>FILTER-COEFS</i>, an array of filter coefficients. To make code more
32 readable and to avoid code dependence on the exact format of a frame,
33 the functions <code>lpc-frame-rms1</code><a name="index1121"></a>,
34 <code>lpc-frame-rms2</code><a name="index1122"></a>,
35 <code>lpc-frame-err</code><a name="index1123"></a>, and
36 <code>lpc-frame-filter-coefs</code><a name="index1124"></a> can be
37 applied to a frame to obtain the respective fields.</p>
38
39 <p>The <i>z</i> transform
40 of the filter is <i>H</i>(<i>z</i>) = 1/<i>A</i>(<i>z</i>), where <i>A</i>(<i>z</i>) is a
41 polynomial of the form <i>A</i>(<i>z</i>) = 1 + <i>a<sub>1</sub></i><i>z</i><sup T>-1</sup> +
42 <i>a<sub>2</sub></i><i>z</i><sup T>-2</sup> + ... + <i>a<sub>p</sub></i><i>z</i><sup T>-p</sup>. The <i>FILTER-COEFS</i> array has
43 the form <code>#(</code><i>a<sub>p</sub></i> <i>a<sub>p-1</sub></i> ... <i>a<sub>3</sub></i>
44 <i>a<sub>2</sub></i> <i>a<sub>1</sub></i><code>)</code>.</p>
45
46 <p>The file <code>lpc.lsp</code> defines some useful classes and functions. The file
47 is <i>not</i> automatically loaded with Nyquist, so you must execute
48 <code>(load "lpc")</code> before using them.</p>
49 <a name = "152"><h3>LPC Classes and Functions</h3></a><dl>
50 <dt>
51 <code>make-lpanal-iterator(<a name="index1125"></a><i>sound</i>, <i>framedur</i>, <i>skiptime</i>, <i>npoles</i>)</code> [SAL]<br>
52
53 <code>(make-lpanal-iterator <i>sound</i> <i>framedur</i> <i>skiptime</i> <i>npoles</i>)</code> [LISP]</dt>
54 <dd>Makes an iterator
55 object, an instance of <code>lpanal-class</code>,
56 that returns LPC frames from successive frames of samples in
57 <i>sound</i>. The duration (in seconds)
58 of each frame is given by <i>framedur</i>, a
59 <code>FLONUM</code>. The skip size (in seconds) between successive frames
60 is given by <i>skiptime</i>, a <code>FLONUM</code>. Typical values for
61 <i>framedur</i> and <i>skiptime</i> are 0.08 and 0.04, giving 25 frames
62 per second and a 50% frame overlap. The number of poles is given
63 by <i>npoles</i>, a <code>FIXNUM</code>. The result is an object that
64 responds to the <code>:next</code> selector by returning a frame as
65 described above. <code>NIL</code> is returned when <i>sound</i> terminates.
66 (Note that one or more of the last analysis windows may be
67 padded with zeros. <code>NIL</code> is only returned when the corresponding
68 window would begin after the termination time of the sound.)<br><br>
69 <dt><code>make-lpc-file-iterator(<a name="index1126"></a><i>filename</i>)</code> [SAL]<br>
70
71 <code>(make-lpc-file-iterator <i>filename</i>)</code> [LISP]</dt>
72 <dd>Another way to get LPC frames is to read them from a
73 file. This function opens an ASCII file containing LPC frames and
74 creates an iterator object, an instance of class <code>lpc-file-class</code>
75 to access them. Create a file using <code>save-lpc-file</code> (see below).<br><br>
76 <dt><code>save-lpc-file(<a name="index1127"></a><i>lpc-iterator</i>, <i>filename</i>)</code> [SAL]<br>
77
78 <code>(save-lpc-file <i>lpc-iterator</i> <i>filename</i>)</code> [LISP]</dt>
79 <dd>Create a file containing LPC frames.
80 This file can be read by <code>make-lpc-file-iterator</code> (see above).<br><br>
81 <dt><code>show-lpc-data(<a name="index1128"></a><i>lpc-iterator</i>,
82 <i>iniframe</i>, <i>endframe</i> [, <i>poles?</i>])</code> [SAL]<br>
83
84 <code>(show-lpc-data <i>lpc-iterator</i> <i>iniframe</i> <i>endframe</i>
85 [<i>poles?</i>])</code> [LISP]</dt>
86 <dd>Print values of LPC
87 frames from an LPC iterator object. The object is <i>lpc-iterator</i>,
88 which is typically an instance of <code>lpanal-class</code> or
89 <code>lpc-file-class</code>. Frames are numbered from zero, and only
90 files starting at <i>iniframe</i> (a <code>FIXNUM</code>) and ending before
91 <i>endframe</i> (also a <code>FIXNUM</code>) are printed. By default, only
92 the values for <i>RMS1</i>, <i>RMS2</i>, and <i>ERR</i> are printed, but
93 if optional parameter <i>poles?</i> is non-<code>NIL</code>, then
94 the LPC coefficients are also printed.<br><br>
95 <dt><code>allpoles-from-lpc(<a name="index1129"></a><i>snd</i>, <i>lpc-frame</i>)</code> [SAL]<br>
96
97 <code>(allpoles-from-lpc <i>snd</i> <i>lpc-frame</i>)</code> [LISP]</dt>
98 <dd>A single LPC frame defines a filter.
99 Use <code>allpoles-from-lpc</code> to apply this filter to <i>snd</i>,
100 a <code>SOUND</code>. To obtain <i>lpc-frame</i>, a <code>LIST</code>
101 containing an LPC frame, either send <code>:next</code> to an
102 LPC iterator, or use <code>nth-frame</code> (see below). The result
103 is a <code>SOUND</code> whose duration is the same as that of <i>snd</i>.<br><br>
104 <dt><code>nth-frame(<a name="index1130"></a><i>lpc-iterator</i>, <i>numframe</i>)</code> [SAL]<br>
105
106 <code>(nth-frame <i>lpc-iterator</i> <i>numframe</i>)</code> [LISP]</dt>
107 <dd>Get the <i>n</i><sup T>th</sup>
108 frame from an lpc iterator by skipping <i>n</i> frames and getting the next one. Typical use
109 is to construct a filter using the <i>n</i><sup T>th</sup> frame from an LPC data file using something like this to filter <code>snd</code>:
110 <code>allpoles-from-lpc(snd, nth-frame(make-lpc-file-iterator(filename), n))</code>.<br><br>
111 <dt><code>lpreson(<a name="index1131"></a><i>snd</i>, <i>lpc-iterator</i>,
112 <i>skiptime</i>)</code> [SAL]<br>
113
114 <code>(lpreson <i>snd</i> <i>lpc-iterator</i> <i>skiptime</i>)</code> [LISP]</dt>
115 <dd>Implements a time-varying all-pole filter
116 controlled by a sequence of LPC frames from an iterator. The
117 <code>SOUND</code> to be filtered is <i>snd</i>, and the source of
118 LPC frames is <i>lpc-iterator</i>, typically an instance of
119 <code>lpanal-class</code> or <code>lpc-file-class</code>. The frame
120 period (in seconds) is given by <i>skiptime</i> (a <code>FLONUM</code>).
121 This number does not have to agree with the <i>skiptime</i> used
122 to analyze the frames. (Greater values will cause the filter
123 evolution slow down, and smaller values will cause it to
124 speed up.) The result is a <code>SOUND</code>. The duration of the
125 result is the minimum of the duration of <i>snd</i> and that of
126 the sequence of frames. <br><br>
127 <dt><code>lpc-frame-rms1(<a name="index1132"></a><i>frame</i>)</code> [SAL]<br>
128
129 <code>(lpc-frame-rms1 <i>frame</i>)</code> [LISP]</dt>
130 <dd>Get the energy of the input signal from a frame.<br><br>
131 <dt><code>lpc-frame-rms2(<a name="index1133"></a><i>frame</i>)</code> [SAL]<br>
132
133 <code>(lpc-frame-rms2 <i>frame</i>)</code> [LISP]</dt>
134 <dd>Get the energy of the residual from a frame.<br><br>
135 <dt><code>lpc-frame-err(<a name="index1134"></a><i>frame</i>)</code> [SAL]<br>
136
137 <code>(lpc-frame-err <i>frame</i>)</code> [LISP]</dt>
138 <dd>Get the square root of <i>RMS1</i>/<i>RMS2</i> from a frame.<br><br>
139 <dt><code>lpc-frame-filter-coefs(<a name="index1135"></a><i>frame</i>)</code> [SAL]<br>
140
141 <code>(lpc-frame-filter-coefs <i>frame</i>)</code> [LISP]</dt>
142 <dd>Get the filter coefficients from a frame.
143 </dd></dl>
144 <a name = "153"><h3>Low-level LPC Functions</h3></a>
145 <p>The lowest-level Nyquist functions for LPC are
146 <ul>
147 <li>
148 <code>snd-lpanal</code> for analysis,</li>
149 <li><code>snd-allpoles</code>, an all-pole filter with fixed coefficients, and</li>
150 <li><code>snd-lpreson</code>, an all-pole filter that takes frames from an LPC iterator.
151 </li></ul></p>
152 <dl>
153 <dt>
154 <code>snd-lpanal(<a name="index1136"></a><i>samps</i>, <i>npoles</i>)</code> [SAL]<br>
155
156 <code>(snd-lpanal <i>samps</i> <i>npoles</i>)</code> [LISP]</dt>
157 <dd>Compute
158 an LPC frame with <i>npoles</i> (a <code>FIXNUM</code>) poles from an
159 <code>ARRAY</code> of samples (<code>FLONUMS</code>). Note that <code>snd-fetch-array</code>
160 can be used to fetch a sequence of frames from a sound. Ordinarily, you
161 should not use this function. Use <code>make-lpanal-iterator</code> instead.<br><br>
162 <dt><code>snd-allpoles(<a name="index1137"></a><i>snd</i>, <i>lpc-coefs</i>, <i>gain</i>)</code> [SAL]<br>
163
164 <code>(snd-allpoles <i>snd</i> <i>lpc-coefs</i> <i>gain</i>)</code> [LISP]</dt>
165 <dd>A fixed all-pole filter. The input is
166 <i>snd</i>, a <code>SOUND</code>. The filter coefficients are given by <i>lpc-coefs</i>
167 (an <code>ARRAY</code>), and the filter gain is given by <i>gain</i>, a <code>FLONUM</code>.
168 The result is a <code>SOUND</code> whose duration matches that of <i>snd</i>.
169 Ordinarily, you should use <code>allpoles-from-lpc</code> instead (see above).<br><br>
170 <dt><code>snd-lpreson(<a name="index1138"></a><i>snd</i>, <i>lpc-iterator</i>,
171 <i>skiptime</i>)</code> [SAL]<br>
172
173 <code>(snd-lpreson <i>snd</i> <i>lpc-iterator</i> <i>skiptime</i>)</code> [LISP]</dt>
174 <dd>This function is identical to <code>lpreson</code> (see above).
175 </dd></dl><hr>
176 <a href = "part12.html">Previous Section</a> | <a href = "part14.html">Next Section</a> | <a href = "title.html#toc">Table of Contents</a> | <a href = "indx.html">Index</a> | <a href = "title.html">Title Page</a>
177 </body></html>