-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathzeropadding.html
211 lines (186 loc) · 7.28 KB
/
zeropadding.html
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
<html>
<head>
<title>Circles Sines and Signals - Zero Padding</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="third_party/d3/d3.min.js"></script>
<script type="text/javascript" src="third_party/jsfft/lib/complex_array.js"></script>
<script type="text/javascript" src="third_party/jsfft/lib/fft.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
jax: ["input/TeX","input/MathML","output/SVG"],
extensions: ["tex2jax.js","mml2jax.js","MathMenu.js","MathZoom.js"],
TeX: {
extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
}
});
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ TeX: { extensions: ["color.js"] }});
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config(
{
SVG: {linebreaks: { automatic:true }},
displayAlign: "center"
}
);
</script>
<script type="text/javascript"
src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_SVG">
</script>
<link href='//fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Vollkorn:400italic,400' rel='stylesheet' type='text/css'>
<style>
@import url("fontello-b1d57784/css/fontello.css");
@import url("style.css");
</style>
<link rel="icon" type="" href="favicon.ico"></head>
<body>
<div class="title">
<table width="900">
<tr>
<td width="90%">
<div class="bigheader" id="titleinfo">
</div>
</td>
</tr>
<tr>
<td width="70%">
<br/>
<div id="menu" class="menu" style="margin-left: 45; ">
<table> <tr id="menurow"> </tr> </table>
</div>
<!-- -->
</td>
</tr>
</table>
</div>
<div class="littleheader"> ZERO-PADDING
<div class="subheader" style="font-size: 14px"> INCREASING DFT RESOLUTION </div>
</div>
<script>
var FFT_SIZE = 8;
function updateSize(value) {
if (value == 1)
{
FFT_SIZE = 8;
}
else if (value == 2)
{
FFT_SIZE = 16;
}
else if (value == 3)
{
FFT_SIZE = 32;
}
else if (value == 4)
{
FFT_SIZE = 64;
}
else if (value == 5)
{
FFT_SIZE = 128;
}
}
</script>
<table class="figureTable">
<tr>
<td style="vertical-align: top;">
<div class="text" style="margin-left: 0px">
<p>
There’s a classic technique you need to be aware of when working with the Discrete Fourier Transform, and it’s called <i>Zero-Padding</i>.<sup>1</sup> As it turns out, it’s possible to interpolate or “fill-in” the output of the DFT by simply appending zeroes to the end of your input signal. Appending zeroes to the end of your signal doesn’t alter the frequency content of your signal in any undue way, it merely interpolates the output spectrum. You can experiment with zero-padding in <i>Figure 1</i>. Drag the slider at the bottom of the figure to the right to append more zeroes to the end of the input signal.
</p>
<br/>
<table>
<tr class="figureCaption">
<td width="100%">
<b>Figure 1.</b> Zero Padding the Input Interpolates the Output Spectrum
</td>
</tr>
<tr>
<td>
<svg id="zeropadding" class="svgWithText" width="740" height="400" style="margin-left: 0px; margin-right: 0px; padding-top: 0px; padding-left: 20px;"></svg>
<script type="text/javascript" src="js/zeropadding.js"></script>
<div class="controls" style="margin-top: 5px">
<label for=size>Zero Padding</label><br/>
<input type=range min=1 max=5 value=1 id=size step=1 oninput="updateSize(value);"
onMouseDown="" onMouseUp="" style="width: 150px"><br/>
</div>
</td>
</tr>
</table>
<br/>
<p>
You might be surprised to see little mountains and valleys appear in the DFT output as you begin to zero-pad the signal. We’ll devote the entire <a href="dft_leakage.html">next section</a> to understanding this phenomenon. For now, let’s move onto a subtle point about zero-padding which can confuse and confound.
</p>
</td>
<td class="figureExplanation" style="">
<b>1.</b>
You’ll often need to perform this sort of zero-padding to ensure that the input you provide to a FFT (Fast Fourier Transform) routine has a length which is equal to a power of two.
</td>
</tr>
</table><br/>
<div class="littleheader"> ZERO PADDING AND DFT RESOLUTION
<div class="subheader" style="font-size: 14px"> IT'S NOT ALCHEMY </div>
</div>
<script>
var FFT_SIZE2 = 8;
function updateSize2(value) {
if (value == 1)
{
FFT_SIZE2 = 8;
}
else if (value == 2)
{
FFT_SIZE2 = 16;
}
else if (value == 3)
{
FFT_SIZE2 = 32;
}
else if (value == 4)
{
FFT_SIZE2 = 64;
}
else if (value == 5)
{
FFT_SIZE2 = 128;
}
}
</script>
<table class="figureTable">
<tr>
<td style="vertical-align: top;">
<div class="text" style="margin-left: 0px">
<p>
It’s really important to understand that zero-padding does <i>not</i> actually increase the output resolution of the Discrete Fourier Transform. Zero-padding does not <i>add</i> any useful information to our signal. Let’s recall the example from the <a href="dft_frequency.html">previous section</a> where we attempted to distinguish between two sinusoidal components which were close in frequency. We were able to accomplish this feat by simply increasing the number of input samples which were fed into the DFT. You might be tempted to think that we can do the same thing using zero-padding. After all, zero-padding <i>does</i> increase the number of input samples, which in turn increases the number of bins in our DFT output.
</p>
<p>
<i>Figure 2</i> allows you to apply zero-padding to eight samples of our input signal from the last section. You’ll notice that the zero-padding process does not actually increase the resolution of our DFT output. It doesn’t help us pinpoint, identify, or distinguish between the two sinusoids hidden within the signal. In some sense, this shouldn’t be too terribly surprising. Always remember that you’re not actually adding any additional information to the signal by appending zeroes at the end.
</p>
<br/><br/>
<table>
<tr class="figureCaption">
<td width="100%">
<b>Figure 2.</b> Zero Padding Does <i>Not</i> Improve DFT Resolution!
</td>
</tr>
<tr>
<td>
<svg id="dftresolution" class="svgWithText" width="740" height="400" style="margin-left: 0px; margin-right: 0px; padding-top: 0px; padding-left: 20px;"></svg>
<script type="text/javascript" src="js/dft_resolution2.js"></script>
<div class="controls" style="margin-top: 5px">
<label for=size>Zero Padding</label><br/>
<input type=range min=1 max=5 value=1 id=size step=1 oninput="updateSize2(value);"
onMouseDown="" onMouseUp="" style="width: 150px"><br/>
</div>
</td>
</tr>
</table>
</td>
<td class="figureExplanation" style="">
</td>
</tr>
</table><br/>
<div class="title" id="footer"></div><script type="text/javascript" src="menu.js"></script></body>
</html>