# Normalizing Negative filter coefficients for Digital filter design

I am designing a High pass Digital filter. I calculated the filter coefficients using fdatool and got some negative filter values.

Now, I need to convert them into values from 0 to 255.

In case of low pass filter , I used

value = value*255/sum(value)


I have heard that same needs to be done for negative coefficients as well by taking absolute values of all the coefficients, but that seems a little odd to me.

Can anyone please tell me how to convert my filter coefficients to values ranging from 0 to 255

Thanks

• For 8-bit representation, I think you filter values should go from -128 to 127. This covers both positive and negative values. – Phonon Feb 12 '12 at 19:49
• Could you please be more explicit about why you need to convert the values into the 0..255 range? Is this because the software framework you will use to apply the filter to the image only uses 8-bit filter coefficients? Do you have any documentation explaining how the software implements the filter computation and how those 8-bit coefficients are interpreted? – pichenettes Feb 12 '12 at 20:06
• Hmm..I think converting it in range -128 to 127 will work... – Prashant Singh Feb 12 '12 at 20:41
• On which architecture? Does your architecture support signed/unsigned multiplications? You'll probably have to normalize the numbers to the -128..127 range, store them as signed char (int8_t) and use signed x unsigned multiplication. Your inner filter loop will be something like result += pixel[x + i][y + j] * coefficient[i][j] >> 7 where acc is a 16 bit unsigned int, and where clipping is applied to acc once all points of the filter have been accumulated. – pichenettes Feb 12 '12 at 20:45
• If the input is an 8-bit grayscale image your grayscale values will be in 0-255 and should be represented as uint8_t ; while your filter coefficients (which can be negative) will be int8_t. Your accumulator in the core filter loop will need to be int16_t to prevent overflows, and you'll need to apply clipping to the result to constraint it to the 0..255 grayscale range. – pichenettes Feb 12 '12 at 20:49