Signal processing · window functions
Gaussian Window: Formula and Choice of σ
The Gaussian window multiplies a block of samples by a bell curve centered on the block. A single number, sigma, sets how narrow the bell is. A narrow bell drops to a small value at the ends, which suppresses spectral leakage well and widens the main peak, while a wide bell approaches a rectangular window and has the opposite trade. Among all windows, it has the special property that its Fourier transform is also a Gaussian. It is one of several window shapes used in signal processing.
Definition
For N points numbered n = 0 to N − 1, let c = (N − 1)/2 be the center. A common parametrization is
w(n) = exp( −½ · ( (n − c) / (σ·c) )² )
Here σ is a fraction of the half-length: at the edges, n − c = ±c, the argument is ±1/σ and the window value is exp(−1/(2σ²)). The center value is always 1. Other parametrizations use the number of standard deviations spanned by the whole window, or a factor α with σ = (N − 1)/(2α); be sure to check which one a given routine adopts before comparing numbers.
Worked values
Take N = 5 and σ = 0.5. Then c = 2, σ·c = 1, and the window is exp(−½(n − 2)²):
- n = 2: exp(0) = 1
- n = 1 and n = 3: exp(−0.5) = 0.6065
- n = 0 and n = 4: exp(−2) = 0.1353
The window is [0.1353, 0.6065, 1, 0.6065, 0.1353]. Compare the Blackman window for the same length, [0, 0.34, 1, 0.34, 0], which reaches zero at the ends. The Gaussian never quite does.
For N = 7 and σ = 0.5 the center is c = 3 and σ·c = 1.5. The argument at distance d from the center is −½(d/1.5)². So d = 1 gives exp(−0.2222) = 0.8007, d = 2 gives exp(−0.8889) = 0.4111 and d = 3 gives exp(−2) = 0.1353. The window is [0.1353, 0.4111, 0.8007, 1, 0.8007, 0.4111, 0.1353].
Truncation sets the real limit
A true Gaussian extends to infinity and its transform is a Gaussian with no sidelobes at all. A finite window cuts the tails, and the cut produces ripple in the spectrum. The jump at the edge is the window value there. For σ = 0.5 that is 0.1353, a hard step, and the sidelobes are correspondingly high. For σ = 0.25 the edge value is exp(−8) ≈ 0.0003, almost no step, and the leakage falls to a very low floor.
So the rule for choosing σ is mostly about the edge value. Pick it so the edge value is below the leakage level wanted, then accept the main lobe width that results. As σ shrinks, the effective length of the window shrinks too, since the outer samples are nearly zeroed, and resolution worsens.
Relation to other windows
Windows with a single smooth bell, such as the Gaussian, have no oscillating sidelobe pattern once the edge is small. That makes the leakage drop smoothly with frequency rather than in the ripple seen for a Blackman window. The price is a main lobe wider than that of a rectangular window and no sharp cutoff.
The Gaussian also reaches the smallest possible product of time spread and frequency spread. No window can be short in time and narrow in frequency at once beyond that limit, and the Gaussian sits exactly on it. That property is the reason the Gabor transform, a spectrogram built from Gaussian-windowed blocks, uses this shape.
Practical notes
When a Gaussian window is used to taper the truncated impulse response of an ideal filter, multiply it entry by entry with the sinc function samples. In smoothing, the same bell shape serves as a convolution kernel; the two-dimensional extension of that idea is described under two-dimensional convolution. For the random disturbance that often motivates windows and filters in the first place, see additive white Gaussian noise.
Pseudocode
function gaussian_window(N, sigma):
c = (N - 1) / 2
for n in 0 .. N-1:
w[n] = exp(-0.5 * ((n - c) / (sigma * c))^2)
return w
If the amplitude of a windowed tone matters, normalize by the sum of the window entries, which equals the coherent gain times N, so that a pure tone of height 1 gives a peak of height 1 in the spectrum.