
5.1 Components for Embedded Programs 213
change, we can use a fixed-size buffer to hold the current data. To avoid constantly
copying data within the buffer, we will move the head of the buffer in time. The
buffer points to the location at which the next sample will be placed;every time we
add a sample, we automatically overwrite the oldest sample, which is the one that
needs to be thrown out. When the pointer gets to the end of the buffer, it wraps
around to the top. Programming Example 5.2 provides an ef ficient implementation
of a circular buffer.
Programming Example 5.2
A circular buffer implementation of an FIR filter
Appearing below are the declarations ...