Circular Buffer: A Critical Element of Digital Signal Processors
- Nov 17, 2017
- 3 min read
This article discusses circular buffering, which allows us to significantly accelerate the data transfer in a real-time system.
A digital signal processor is a specialized microprocessor for the kind of algorithms employed in digital signal processing (DSP). The main goal is to accelerate the calculations while keeping the power consumption as low as possible. In this article, we review a basic addressing capability of DSP processors, i.e. circular buffering, which allows us to significantly accelerate the data transfer in a real-time system.
Please note that since the acronym “DSP” stands for both “digital signal processing” and “digital signal processor," we will use the term “DSP processor” when referring to the hardware rather than the algorithm.
Since the finite-impulse-response (FIR) filtering is a common operation in DSP, we will continue our discussion based on examining the difference equation of an FIR filter. This simple example will show the typical properties of many DSP algorithms. After reviewing the problem of handling the incoming samples, we will discuss the circular buffering as an efficient solution to the problem.
Performing FIR Filtering on a Real-Time Input
Assume that we have a four-tap filter with the following difference equation:
y(n)=b0x(n)+b1x(n−1)+b2x(n−2)+b3x(n−3)y(n)=b0x(n)+b1x(n−1)+b2x(n−2)+b3x(n−3)
Equation 1
where
b0b0
,
b1b1
,
……
,
b3b3
are the filter coefficients and
x(n)x(n)
denotes the input samples. To calculate Equation 1, we need to store the last four samples of the input in a memory. Assume that we have a real-time system, such as a hearing aid. In this case, there is an infinite number of input samples which become available to us over time. As a result, we may take one input sample, calculate Equation 1, move the result to an output device, and then, repeat this procedure for the next input sample. Hence, this example requires the following steps for each input sample:
Acquire an input sample from the analog world and find its digital representation using an analog-to-digital converter (ADC).
Inform the system that the new sample is available.
Store the new sample in the memory (in the example of Equation 1, we will need this new sample to produce four output samples, so we have to store the acquired samples for some time).
Use the new sample and the last three samples to calculate Equation 1.
Move the result to an output device such as a digital-to-analog converter (DAC) or simply store it somewhere in the memory for later use.
Go back to step 1.
This example shows that a simple DSP algorithm involves data transfer, inequality evaluation, and a lot of math operations. For example, during steps 3 and 5, we have to transfer, respectively, the input and the result to a memory location. Step 4 involves a lot of math operations. In this step, the input samples are multiplied by their corresponding filter coefficients and the products are added together. This is generally achieved by a dedicated multiply-and-accumulate (MAC) unit which is shown in Figure 1.
Figure 1. The simplified model of a MAC.
Step 4 requires some inequality evaluations to keep track of the intermediate results and control the loops.
The math operations in step 4 seem to be the most time-consuming part of the algorithm and the DSP processors attempt to accelerate these calculations using various techniques. However, it is interesting to note that, without a careful design, operations such as transferring the data and controlling the loops can be time-consuming too. In the rest of this article will review a well-known technique, i.e. circular buffering, to facilitate the data transfer in a real-time system.










Comments