Reduce the sample rate of a signal, by specifying a decimation factor and applying a custom antialiasing filter.
vDSP provides functions for decimating a signal. A decimated signal has a lower sample rate compared to its original. Decimation can be advantageous when, for example, you are transmitting a signal, creating a visual representation of a large dataset, or reducing the memory overhead when processing data.
In the following pair of images, the original signal (at left) contains 1024 samples. After decimation by a factor of two, the result (at right) contains 512 samples.
This article walks you through the following steps to decimate a signal:
Create a composite sine wave to use as a signal.
Define an antialiasing filter to control how the signal is resampled.
Calculate the length of the destination array that receives the decimation result.
Apply the decimation operation.
Create the Input Signal
For this example, create an array and populate it with a composite sine wave:
The following image shows a visualization of the values in
Define the Antialiasing Filter
The vDSP decimation function accepts a filter that controls how adjacent samples combine. Each decimated value is the sum of the combined original values multiplied by the corresponding filter value.
In this example, use the following code to create a filter containing
The resulting filter averages pairs of adjacent values in the original signal.
For the most complete result, set the filter length to the same value as the decimation factor, which indicates how much the original signal is decimated. For example, consider an input signal containing 18 values:
The following images visualize the original and decimated signals, and illustrate the effects of different antialiasing filters. The original signal can be visualized as:
If you create a filter containing a single value
[1 and a decimation factor of
2, you will only sample the even values of the original signal and will get a result that misses the second
50 at position
13, as shown below.
However, you can create a filter with two values,
[0, and it will consider all values in the original signal, illustrated below.
Define the Output Length
The decimation result length is a function of the original signal length, the decimation factor, and the length of the filter. Use the following code to create a zero-filled array, suitable to receive the decimation result: