## fixed point coeficcients to floating point

Started by 5 years ago●2 replies●latest reply 5 years ago●162 viewsHi,

I am trying to modify a Texas Instruments provided example to fit my needs.

Example filters like this one is provided in the code:

// Insert optional second filter here (@16 kHz). Some examples:

//1147,-1516, 522, -1699, 708, // +5dB peak filter (F0=500 Hz, BW=3 octaves)

; Each second order section is assumed to have normalized both numerator and denominator,

; i.e b0 and a0 are 1. The gain g is applied to the input. If unormalized, g can be b0/a0

; and each coefficient in the numerator must then be divided by b0 and each coefficient

; in the denominator divided by a0.

; After the last section a dummy section with gain 0 indicates the end of the IIR filter.

; All coefficients must be in the SI.FFFF_FFFF_FF format, i.e 21 sign bits, one integer bit

; and ten fractional bits. Thus the range of the coefficients are [-2, 2) and the resolution

; is 2^-10

Now I am trying to verify this by plotting the frequency response of the peaking filter in Python

g = 1147*(2**-10)

sos = np.array([1*(2**-10)*g, -1516*(2**-10)*g, 522*(2**-10)*g, 1, -1699*(2**-10), 708*(2**-10)])

w, h = signal.sosfreqz(sos)

plt.plot()

db = 20 * np.log10(np.abs(h))

plt.plot(w/np.pi, db)

plt.grid(True)

plt.show()

The plot does not look like a peaking filter at all. I assume my convertion from fixed to floating point is incorrect. Hints would be appreciated.

Regards, Erlend

I don't know what sosfreqz does, but if it does not evaluate biquad coefficients, it would be the wrong function.

your time formula for the filter should be:

y[k] = 1147/1024*x[k] + (-1516)/1024*x[k-1] + 522/1024*x[k-2] - (-1699)/1024*y[k-1] - 708/1024*y[k-2]

My mistake. b0=1 is after convertion to float. b0 was a factor of 1024 to large.