DIGITAL_FILTER Function
Standard Library function that constructs finite impulse response digital filters for signal processing.
Usage
result = DIGITAL_FILTER(flow, fhigh, gibbs, nterm)
Input Parameters
flow — The value of the lower frequency of the filter, expressed as a fraction of the Nyquist frequency. Must be between 0 and 1.
fhigh — The value of the upper frequency of the filter, expressed as a fraction of the Nyquist frequency. Must be between 0 and 1.
gibbs — The size of the Gibbs Phenomenon variations. Expressed in units of –db (decibels).
nterm — The number of terms in the filter formula used. Determines the order of the filter.
Returned Value
result — The coefficients of a convolution mask to be used in the filtering of digital signals.
Keywords
None.
Discussion
The coefficients returned by DIGITAL_FILTER form the convolution mask or kernel that can be used with the CONVOL function to apply the filter to a signal. The size of this vector is equal to:
(2 * nterm) – 1
Highpass, lowpass, bandpass, and bandstop filters can be constructed with DIGITAL_FILTER. Use the values listed in
Table 5-9: Filtering Types for
fhigh and
flow to specify the type of filter you want to obtain:
These non-recursive filters require evenly spaced data points. Frequencies are expressed in terms of the Nyquist frequency, 1/2T, where T is the time elapsed between data samples.
The Gibbs Phenomenon variations are oscillations which result from the abrupt truncation of the infinite FFT series. Setting the gibbs parameter either too high or too low may yield unacceptable results.
note | A value of 50 for gibbs is a good choice for most filters. |
Sample Usage
DIGITAL_FILTER is used extensively in image and signal processing applications to build image or signal filters. It provides a convenient way of creating convolution kernels (containing the filter coefficients) — all you need do is specify the desired filter with respect to the high and low cutoff frequencies, the Gibb’s variations, and the number of terms. You can then use the constructed kernels with the CONVOL function to perform the actual filtering operation upon a signal or image.
To evaluate the coefficients of a digital filter and then apply them to a signal, use the following sequence of equations:
Coeff = DIGITAL_FILTER(flow, fhigh, gibbs, nterm)
Filtered_Signal = CONVOL(input_signal, coeff)
The end result is an image or signal that has certain frequencies or bands of frequencies filtered out of it. For example, an electrical engineer may want to filter out high frequency harmonics or low frequency flutter from a signal. This can easily be achieved by using the high and low pass filters constructed with DIGITAL_FILTER as the coefficients in the CONVOL function.
note | Two or more filters created by DIGITAL_FILTER can be combined by addition, subtraction, or averaging to create multiple filtering effects with one filter. |
Example 1
A digital signal processing example follows:
; Read average temperature field from air quality test dataset.
av_temp = FLTARR(140)
OPENR, unit, !Data_dir + 'example_air_q.dat', /Get_lun
READF, unit, av_temp, Format='(5X,F9.4)'
FREE_LUN, unit
; Display the original data.
PLOT, av_temp
; Create the convolution kernel for a lowpass filter.
filter = DIGITAL_FILTER(0.0, 0.1, 50, 10)
; Filter the data by convolving it with the kernel.
filt_temp = CONVOL(av_temp, filter)
; Display the filtered data using a dashed line.
OPLOT, filt_temp, Linestyle=2
Example 2
An image processing example follows:
; Read the mandril demo image.
mandril = BYTARR(512,512)
OPENR, unit, !Data_dir + 'mandril.img', /Get_lun
READU, unit, mandril
FREE_LUN, unit
; Display the original image.
WINDOW, XSize=512, YSize=512
TV, mandril
; Convert the byte data to floating-point for filtering.
mandril = FLOAT(mandril)
; Create the convolution kernel for a lowpass filter.
filter = DIGITAL_FILTER(0.0, 0.1, 50, 10)
; Filter the image by convolving it with the kernel.
filt_image = CONVOL(mandril, filter)
; Display the filtered image.
TV, filt_image
See Also
DIGITAL_FILTER is adapted from the article “Digital Filters,” by Robert Walraven, in Proceedings of the Digital Equipment User’s Society, Fall 1984, Department of Applied Science, University of California, Davis, CA 95616.