-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
231 lines (231 loc) · 14.3 KB
/
index.html
File metadata and controls
231 lines (231 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<h1>Pitch Synchronous Time-Aliased-Hann FFTs for Speech Recognition</h1>
<p>By Bill Cox, waywardgeek@gmail.com</p>
<p>Intuitively, a Time-Aliased-Hann window is a sound sample that starts playing in the
middle, and slowly fades to zero, while at the same time we start playing
samples from beginning and slowly fade in. It is a waveform that smoothly feeds
into itself. If the signal is a single pitch period of a harmonic signal, like a
voice or a single note of an instrument, then this signal can be played over and
over, and will sound like the note has been extended indefinitely, without
noticeable distortion. This exact algorithm is commonly used in time-domain
techniques used in the TD-PSOLA class of algorithms. I wrote a Linux package called
"sonic", which is used for speeding up speech, and which is particularly good at
low distortion for speeds of 2X and up. It's basically
<a href="http://keizai.yokkaichi-u.ac.jp/~ikeda/research/picola.html">PICOLA</a>, but with
a new algorithm that kicks in at 2X and above. Such an algorithm is needed for
improving existing text-to-speech engines to provide very high speed speech for
blind speed listeners. After trying various FFT and TD-PSOLA based methods, I
found that PICOLA produces far less distortion in sped up speech, even compared
to the popular WSOLA algorithm, and so I investigated why that is so. The
answer seems to be that the pitch synchronous overlap-add step produces no
spectral distortion of harmonics, and little distortion of everything else. So,
I felt it might work well as a pre-process to an FFT, especially if the FFT
frames are single pitch periods. I was amazed with the results.</p>
<p>DSP algorithms developers often use <a href="http://en.wikipedia.org/wiki/Window_function">window
functions</a> such as the popular Hamming
window to reduce spectral leakage in their FFTs.</p>
<p>So far as I know, none of this is new, with the possible exception of applying
Time-Aliased-Hann pitch synchronously to speech. A response on comp.dsp was so
informative, I think its worth reposting as-is here:</p>
<blockquote>
<p>It's always nice to see someone new rediscover the advantages of the
independence of window size from DFT size. The approach is not new. It
can be found in a number of guises.</p>
<p>It has long been used as one form of FFT based polyphase filter. For
examples: "polyphase DFT filterbank",
"PolyDFT" and "PFT" as used in places such as:
http://www.rfel.com/download/W03006-Comparison_of_FFT_and_PolyDFT_Transient=
_Response.pdf</p>
<p>Fred Harris presents the concept in the 'Time Domain Signal Processing
with the DFT' chapter in Doug Elliot=92s 1987 book Handbook of Digital
Signal Processing. He considers the name "data-wrapping" but considers
that too close to the context of "wrapping" in "phase unwrapping" and
suggests "data folding" instead.</p>
<p>A couple more terms approaching yours are "weighted overlap-add
structure" or "windowed-presum FFT" from "Understanding Digital Signal
Processing, Second Edition" by Richard G. Lyons as explained in:
http://www.eetimes.com/design/embedded/4007611/DSP-Tricks-Building-a-practi=
cal-spectrum-analyzer</p>
<p>The most complete exposition on it that I have found comes in a 300+
page opus:
TIME ALIASING METHODS OF SPECTRUM ESTIMATION
by Jason F Dahl
A dissertation submitted to the faculty of Brigham Young University,
Dept. of Mechanical Engineering, April 2003. 305pp
Available at:
http://contentdm.lib.byu.edu/ETD/image/etd157.pdf</p>
<p>I personally prefer Dahl's "time aliasing" as having the least
conflict with other uses of the component words.</p>
<p>This literature provides comparisons to other windows and window
design methods.</p>
<p>Dale B. Dalrymple</p>
</blockquote>
<p>Having now read these papers, and Jason Dahl's dissertation, I feel I have a much better understanding of time-aliased techniques and their applications. The pitch synchronous time-aliased FFT with a low leakage window like a Hanning window is excellent for speech analysis.</p>
<h1>Definition of Time-Aliased-Hann</h1>
<p>Applying a Time-Aliased-Hann window is done by first applying a Hann window to two
adjacent FFT input frames, and then adding the first frame to the second. This
second step is described in various "time aliasing" techniques for DFTs, and in
general is not restricted to two frames, but can be any number of input frames.
However, for pitch synchronous speech processing, exactly two pitch periods
works quite well. More frames make the time resolution too poor. Given two
frames worth of input samples, x(n), n = 0 .. 2*N -
1, we compute the windowed samples x'(n), n = 0 .. N - 1:</p>
<pre><code>w(n) = (1 - cos(pi*n/N))/2, n = 0 .. 2*N - 1.
x'(n) = w(n)*x(n) + w(n + N)*x(n + N), n = 0 .. N - 1
</code></pre>
<p>Here is a plot of worst-case spectral noise for Hamming windows vs Time-Aliased-Hann
windows, at about 1KHz:</p>
<p><img alt="Hamming vs Time-Aliased-Hann" src="time_aliased_hann_vs_hamming.png" /></p>
<p>This plot was created using <a href="time_aliased_hann.py">time_aliased_hann.py</a> and
<a href="hamming.py">hamming_py</a>. This plot basically shows that we should not use
Hamming windows for speech spectrograms, as is commonly done. The spectral
noise is too high for high dynamic range spectrograms like these. Hann
windows work better. The Time-Aliased-Hann window is exactly the same as a
normal FFT response of a Hann-windowed sample of 2 pitch periods, but we drop
every other frequency bin, keeping only harmonics of the fundamental pitch.</p>
<h1>What it Looks Like</h1>
<p>Let's see an example. In this case, we're using a frame size of 500.
The input signal is a worst case for Time-Aliased-Hann: 5.75
sine wave cycles per frame, neither harmonic, or anti-harmonic, but exactly in between.
Here's two frames worth of input data:</p>
<p><img alt="Input signal" src="signal.jpg" /></p>
<p>We apply a Hann window function to two frames, or 1000 samples. Here's what a
Hann function looks like:</p>
<p><img alt="Hann window" src="hann_window.jpg" /></p>
<p>We multiply the Hann function onto the input signal to get:</p>
<p><img alt="Hann window applied to input signal" src="hann_applied.jpg" /></p>
<p>Finally, we take the first 500 samples and add them to the second 500 samples to
get our 500 sample Time-Aliased-Hann result:</p>
<p><img alt="Time-Aliased-Hann applied to input signal" src="time_aliased_hann_applied.jpg" /></p>
<h1>Pitch Synchronous Time-Aliased-Hann FFTs</h1>
<p>Highly harmonic signals like voiced speech have repeating wave forms that slowly
evolve over time. By detecting two similar adjacent pitch periods, with an
algorithm like AMDF, we can significantly reduce noise in the FFT. One property
of Time-Aliased-Hann FFTs is that 100% of all harmonic energy goes to the correct FFT
bin, with no leakage. This makes it especially good for analyzing speech, since
voiced speech is highly harmonic.</p>
<p>Here is a spectrogram of the phrase <a href="voxin_golfer.wav">With the pro golfer</a>,
generated with the voxin TTS engine:</p>
<p><img alt="With the pro golfer spectrogram" src="voxin_golfer.png" /></p>
<p>Here is the same sound analyzed using Praat, with a short-time FFT using Hamming
windows.</p>
<p><img alt="Praat spectrogram of same" src="praat_golfer.png" /></p>
<p>An important benefit of the pitch synchronous Time-Aliased-Hann technique is
computational efficiency. The Praat spectrogram was made using 1000 500-sample
FFTs. The Time-Aliased-Hann version was done with only 163 FFTs, of an average of 98
points each. Since frame size vary, and are short, result frames were scaled to
200 points using linear interpolation. This is roughly a 40X speed improvement,
assuming FFTs are O(N*log2(N)). Also, the artifacts created by pitch periods
entering and leaving the Hamming window are gone. Notice the vertical and
horizontal lines in the spectrogram above. These are essentially noise that
make it harder to match spectrograms for speech recognition. The better spectral
resolution and low noise makes matching spectrograms a reasonable approach to speech
recognition.</p>
<h1>Alternative Time-Aliased Window Functions</h1>
<p>The Time-Aliased technique can be applied with any window function, not just Hann.
However, I find window functions with the following property give better results:</p>
<pre><code>w(n) + w(n + N) = constant, n = 0 .. N - 1
</code></pre>
<p>This is a bit more restrictive than the "weak COLA" constraint. This property
insures that all pure harmonics of the fundamental pitch are exactly represented
in the correct frequency bin with no leakage. Other window functions that have
this property are Triangle and Blackman windows. Time-Aliased-Triangle has
considerably more spectral noise, but still far less than traditional Triangle
windows. Time-Aliased-Blackman windows have lower spectral leakage than
Time-Aliased-Hann, with just a bit more complexity.</p>
<p>The same voxin sample above generates this spectrogram with Time-Aliased-Blackman. It
seems about the same to me.</p>
<p><img alt="With the pro golfer spectrogram, using Time-Aliased-Blackman window" src="voxin_golfer_blackman.png" /></p>
<p>These three spectrograms are of a time-varying sine wave, showing spectral
leakage for Time-Aliased-Triangle, Time-Aliased-Hann, and Time-Aliased-Blackman.
They are generated with 100 point Time-Aliased-FFTs, and plotted with 70 DB
dynamic range (0 is 70 DB below the peak value). As above, results are scaled
to 200 points with linear interpolation. The frequency varies from 100 Hz to 4
KHz over a 2 second time frame.</p>
<p><img alt="Time-Aliased-Triangle" src="sine_triangle.png" title="Time-Aliased-Triangle" /></p>
<p>Time-Aliased-Triangle</p>
<p><img alt="Time-Aliased-Hann" src="sine_hann.png" title="Time-Aliased-Hann" /></p>
<p>Time-Aliased-Hann</p>
<p><img alt="Time-Aliased-Blackman" src="sine_blackman.png" title="Time-Aliased-Blackman" /></p>
<p>Time-Aliased-Blackman</p>
<p>Note that these signals are not harmonics of the frame rate. If they had been, there would be no leakage at all.</p>
<p>For comparison, here's the same signal analyzed the same way, but with a
traditional rectangle window in the first image, a traditional Hann window
in the second, and a traditional Hamming window in the third:</p>
<p><img alt="Rectangle window" src="rectangle.png" title="Rectangle window" /></p>
<p>Traditional rectangle window</p>
<p><img alt="Hann window" src="hann.png" title="Hann window" /></p>
<p>Traditional Hann window</p>
<p><img alt="Hamming window" src="hamming.png" title="Hamming window" /></p>
<p>Traditional Hamming window</p>
<h1>Applications in Speech Synthesis and Recognition</h1>
<p>For both speech synthesis and recognition, common practice is to use LPC (Linear
Predictive Coding) based analysis rather than directly matching FFTs. LPC is
essentially a model order reduction method, and is lossy. Popular TTS engines
based on the MBROLA algorithm family all sound "tinny", though I have come to
think of this distortion as "LPC-ish". Speech recognition algorithms often
reduce a spectrogram to 25 "Mel scale" frequency bins, losing much of the
clarity of the signal. In both cases, computational efficiency is a key driver.
With the improved clarity and computational efficiency of Time-Aliased-Hann FFTs, it
should be possible to significantly reduce distortion in TTS engines, while
improving accuracy in speech recognition engines.</p>
<h1>Proof of Zero Leakage of Harmonics</h1>
<p>Let the input signal x be a sine wave defined as:</p>
<pre><code>x(n) = cos(2*pi*f*n/fs + p), n = 0 .. 2*N - 1,
</code></pre>
<p>where f the frequency, fs is the sample rate, p is the phase, and and N is
the window length. We're interested in harmonics, which occur at frequencies:</p>
<pre><code>f = m*fs/N, m an integer >= 1
</code></pre>
<p>Rewriting x(n):</p>
<pre><code>x(n) = cos(2*pi*(m*fs/N)*n/fs + p)
= cos(2*pi*m*n/N + p)
</code></pre>
<p>The windowed frame, x'(n), is:</p>
<pre><code>w(n) = (1 - cos(pi*n/N))/2, n = 0 .. 2*N - 1.
x'(n) = (1 - cos(pi*n/N))*x(n)/2 + (1 - cos(pi*(n + N)/N))*x(n + N)/2
= (1 - cos(pi*n/N))*cos(2*pi*m*n/N + p)/2 +
(1 - cos(pi*(n + N)/N))*cos(2*pi*m*(n + N)/N + p)/2
= (cos(2*pi*m*n/N + p) + cos(2*pi*m*(n + N)/N + p))/2
- (cos(pi*n/N)*cos(2*pi*m*n/N + p) + cos(pi*(n + N)/N)*cos(2*pi*m*(n + N)/N + p))/2
= (cos(2*pi*m*n/N + p) + cos(2*pi*m*n/N + p + 2*pi*m))/2
- (cos(pi*n/N)*cos(2*pi*m*n/N + p) + cos(pi*(n + N)/N)*cos(2*pi*m*(n + N)/N + p))/2
</code></pre>
<p>Since cos(a)*cos(b) = cos(a + b)/2 + cos(a - b)/2,</p>
<pre><code>x'(n) = (cos(2*pi*m*n/N + p) + cos(2*pi*m*n/N + p + 2*pi*m))/2
- (cos(2*pi*m*n/N + p + pi*n/N) + cos(2*pi*m*n/N + p - pi*n/N)
+ cos(2*pi*m*(n + N)/N + p + pi*(n + N)/N)
+ cos(2*pi*m*(n + N)/N + p - pi*(n + N)/N))/4
x'(n) = (cos(2*pi*m*n/N + p) + cos(2*pi*m*n/N + p + 2*pi*m))/2
- (cos((n/N)*(2*pi*m + pi) + p) + cos((n/N)*(2*pi*m - pi) + p)
+ cos((n/N)*(2*pi*m + pi) + p + 2*pi*m + pi)
+ cos((n/N)*(2*pi*m - pi) + p + 2*pi*m - pi))/4
</code></pre>
<p>Using cos(a +/- pi) = -cos(a):</p>
<pre><code>x'(n) = (cos(2*pi*m*n/N + p) + cos(2*pi*m*n/N + p + 2*pi*m))/2
- (cos((n/N)*(2*pi*m + pi) + p) + cos((n/N)*(2*pi*m - pi) + p)
- cos((n/N)*(2*pi*m + pi) + p + 2*pi*m)
- cos((n/N)*(2*pi*m - pi) + p + 2*pi*m))/4
</code></pre>
<p>Now, assuming m is an integer >=1, then cos(a + 2<em>pi</em>m) = cos(a):</p>
<pre><code>x'(n) = (cos(2*pi*m*n/N + p) + cos(2*pi*m*n/N + p))/2
- (cos((n/N)*(2*pi*m + pi) + p) + cos((n/N)*(2*pi*m - pi) + p)
- cos((n/N)*(2*pi*m + pi) + p)
- cos((n/N)*(2*pi*m - pi) + p))/4
= cos(2*pi*m*n/N + p)
= x(n)
</code></pre>
<p>Thus, x'(n) = x(n), and as with a rectangle window, the FFT will have only one
non-zero value, at m. So, harmonic energy does not leak at all.</p>
<p>For anti-harmonics, at frequencies where m is a positive integer + 1/2:</p>
<pre><code>x'(n) = (cos(2*pi*m*n/N + p) + cos(2*pi*m*n/N + p + pi))/2
- (cos((n/N)*(2*pi*m + pi) + p) + cos((n/N)*(2*pi*m - pi) + p)
- cos((n/N)*(2*pi*m + pi) + p + pi)
- cos((n/N)*(2*pi*m - pi) + p + pi))/4
x'(n) = (cos(2*pi*m*n/N + p) - cos(2*pi*m*n/N + p))/2
- (cos((n/N)*(2*pi*m + pi) + p) + cos((n/N)*(2*pi*m - pi) + p)
+ cos((n/N)*(2*pi*m + pi) + p)
+ cos((n/N)*(2*pi*m - pi) + p))/4
x'(n) = - (cos((n/N)*(2*pi*m + pi) + p) + cos((n/N)*(2*pi*m - pi) + p)/2
</code></pre>
<p>This is 1/2 times a sine wave in the bin before f, plus 1/2 times a sine wave in
the bin after f. Thus, anti-harmonics also have no leakage.</p>