Filter in Maltab gives me a set of filter coefficients which I want to use in FPGA/VHDL design.
in Matlab I work with floating point, in FPGA I cant use it.
Will be it correct if I convert the coefficients as:
h_12 = floor(h_coeff/2^(-12))
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It only takes a minute to sign up.
Sign up to join this communityMost modern FPGAs have 18-bit multipliers, therefore I scale my coefficients to use all 18 bits. Assuming the absolute value of all the coefficients is smaller than 1, then you can use the following code snippet. I multiply by 2**17 since coefficients can also be negative so 1 sign bit is needed..
h_18 = round(h_coeff.*2^17))
Depending on the number of taps and the dynamic range of the coefficients, you might not gain much by switching from 12 bits to 18 bits, but like I said it's free. Furthermore, FIR filters are easily pipelineable, they're unlikely to prevent you from reaching timing closure.
Edit : As Dan Boschen mentionned, you should round the coefficients instead of truncating them (with the floor function).
The coefficients are scaled to the maximum allowed by the precision allowed for the coefficients, and ensuring no overflow in the extended precision accumulator. A good rule of thumb is to ensure the coefficient precision is at least two more than the datapath precision to ensure the dynamic range allows for full attenuation to the quantization noise floor.
If the coefficient quantization was 12 bits (for example), then scale the floating point coefficients by normalizing them to a range of +/-1 based on the magnitude of the largest coefficient, and then map that to 11 bits peak (as a signed number). Use rounding instead of truncation to select the closest quantization level.