Test Your EQ (Engineering Quotient)

EQ #34

The following pseudocode represents an implementation of a single-pole low-pass IIR filter, using 16-bit input and output values and a 24-bit internal accumulator and a filter coefficient of 1/256:

#The 32-bit accumulator holds 16 integer
# and 16 fractional bits
$acc = 0x00000000;

# The input value is a 16-bit integer.
$input = 0xFFFF;

# Offset used for rounding the accumulator
# to 24 bits.
$offset = 0x80;

while (1) {
# acc = (255*acc + input)/256
$acc -= ($acc >> 8);
$acc += ($input << 8) + $offset; # limit acc to 24 bits $acc &= 0xFFFFFF00; # output is integer part of acc $output = $acc >> 16;

An implementor of this filter complained that “the output never reaches 0xFFFF.” What was the flaw in his reasoning?

The accumulator in this filter eventually settles at the value 0xFFFE8100. If you simply take the upper 16 bits of this, then the output value appears to be 0xFFFE. But if you properly round the accumulator by adding 0x00008000 before dropping the LSBs, then the output value is the correct value of 0xFFFF.

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.

Note: We’ve made the Dec 2022 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Supporting Companies

Upcoming Events

Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2024 KCK Media Corp.

EQ #34

by Circuit Cellar Staff time to read: 1 min