Gaussian Filter - Digital Implementation

Digital Implementation

The Gaussian function is non-zero for and would theoretically require an infinite window length. However, since it decays rapidly, it is often reasonable to truncate the filter window and implement the filter directly for narrow windows, in effect by using a simple rectangular window function. In other cases, the truncation may introduce significant errors. Better results can be achieved by instead using a different window function; see scale space implementation for details.

Filtering involves convolution. The filter function is said to be the kernel of an integral transform. The Gaussian kernel is continuous. Most commonly, the discrete equivalent is the sampled Gaussian kernel that is produced by sampling points from the continuous Gaussian. An alternate method is to use the discrete Gaussian kernel which has superior characteristics for some purposes. Unlike the sampled Gaussian kernel, the discrete Gaussian kernel is the solution to the discrete diffusion equation.

Since the Fourier transform of the Gaussian function yields a Gaussian function, the signal (preferably after being divided into overlapping windowed blocks) can be transformed with a Fast Fourier transform, multiplied with a Gaussian function and transformed back. This is the standard procedure of applying an arbitrary finite impulse response filter, with the only difference that the Fourier transform of the filter window is explicitly known.

Due to the central limit theorem, the Gaussian can be approximated by several runs of a very simple filter such as the moving average. The simple moving average corresponds to convolution with the constant B-spline, and, for example, four iterations of a moving average yields a cubic B-spline as filter window which approximates the Gaussian quite well.

In the discrete case the standard deviations are related by

,

where the standard deviations are expressed in number of samples and N is the total number of samples. Borrowing the terms from statistics, the standard deviation of a filter can be interpreted as a measure of its size. The cut-off frequency of a Gaussian filter might be defined by the standard deviation in the frequency domain yielding

,

where all quantities are expressed in their physical units. If is measured in samples the cut-off frequency (in physical units) can be calculated with

,

where is the sample rate. The response value of the Gaussian filter at this cut-off frequency equals exp(-0.5)≈0.607.

However, it is more common to define the cut-off frequency at the point where the filter response is reduced to 0.5 in power spectra (the -3 dB point) or 1/√2 ≈ 0.707 in amplitude spectra (see e.g. Butterworth filter). For an arbitrary cut-off value 1/c for the response of the filter the cut-off frequency is given by

For c=2 the constant before the standard deviation in the frequency domain in the last equation equals approximately 1.1774, which is half the Full Width at Half Maximum (FWHM) (see Gaussian_function). For c=√2 this constant equals approximately 0.8326. These values are quite close to 1.

A simple moving average corresponds to a uniform probability distribution and thus its filter width of size has standard deviation . Thus the application of successive moving averages with sizes yield a standard deviation of

.

(Note that standard deviations do not sum up, but variances do.)

A gaussian kernel requires values, e.g. for a of 3 it needs a kernel of length 17. A running mean filter of 5 points will have a sigma of . Running it three times will give a of 2.42. It remains to be seen where the advantage is over using a gaussian rather than a poor approximation.

When applied in two dimensions, this formula produces a Gaussian surface that has a maximum at the origin, whose contours are concentric circles with the origin as center. A two dimensional convolution matrix is precomputed from the formula and convolved with two dimensional data. Each element in the resultant matrix new value is set to a weighted average of that elements neighborhood. The focal element receives the heaviest weight (having the highest Gaussian value) and neighboring elements receive smaller weights as their distance to the focal element increases. In Image processing, each element in the matrix represents a pixel attribute such as brightness or a color intensity, and the overall effect is called Gaussian blur.

The Gaussian filter is non-causal which means the filter window is symmetric about the origin in the time-domain. This makes the Gaussian filter physically unrealizable. This is usually of no consequence for applications where the filter bandwidth is much larger than the signal. In real-time systems, a delay is incurred because incoming samples need to fill the filter window before the filter can be applied to the signal. However, no amount of delay can make a Gaussian filter causal, because the Gaussian function is never zero.

Read more about this topic:  Gaussian Filter