Half-Band Filter Module Output Clipping?

Hi

I’ve been looking at the USRP2 filter characteristics, to see if it will
work for me. After going through the
half-band filter code (hb_dec.v from gnu-radio 3.2) I understand what
the filter coefficients are, but I have
a question about the output from this module.

Near the end of the module the filtered data is clipped and rounded in
lines 152-153:

143 wire [ACCWIDTH:0] final_sum_unrounded;

149 add2_reg /* add2_and_round_reg */ #(.WIDTH(ACCWIDTH+1))
150 final_adder (.clk(clk), .in1({acc_out,1’b0}),
.in2({data_even_signext,1’b0}), .sum(final_sum_unrounded));
151
152 round_reg #(.bits_in(ACCWIDTH-4),.bits_out(OWIDTH))
153 final_round
(.clk(clk),.in(final_sum_unrounded[ACCWIDTH-5:0]),.out(final_sum));

where ACCWIDTH = 24
and OWIDTH = 18

and the module round_reg just calls round and puts the result in a
register, and round.v is
module round
#(parameter bits_in=0, // for this instantiation,
bits_in = ACCWIDTH-4 = 20
parameter bits_out=0) // for this instantiation,
bits_out = OWIDTH = 18
(input [bits_in-1:0] in,
output [bits_out-1:0] out);

    assign out = in[bits_in-1:bits_in-bits_out] + (in[bits_in-1] &

|in[bits_in-bits_out-1:0]);

 endmodule // round

It looks to me like final_sum_unrounded is 25-bits long, so the input to
final_round is the
20 LSBs of final_sum_unrounded (final_sum_unrounded[19:0]), and the
output final_sum is those 20
bits rounded to 18 bits in the usual way. But this data is two’s
complement, so clipping the 5 MSBs from
final_sum_unrounded can drasticaly change the data value, for example
changing both the sign and
magnitude, even when the magnitude of final_sum_unrounded < 2^17.

What am I missing here?

Thanks
Bruce

Matt E. wrote:

Near the end of the module the filtered data is clipped and rounded in
lines 152-153:

What am I missing here?

Based on the coefficients, we can guarantee that the final sum will have
a magnitude which fits in 20 bits, including the sign bit. We can just
drop those extra sign bits, since they’ll all be the same.

Matt

So I’m curious. If the final sum fit into 20 bits, why were the
accumulation and
following sum carried out with 24 or 25 bits?

Bruce

Bruce McGuffin wrote:

Bruce

If we changed the coefficients we might need more bits.

Matt