fixed point coeficcients to floating point

Started by erlend 4 years ago2 replieslatest reply 4 years ago155 views


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)

db = 20 * np.log10(np.abs(h))
plt.plot(w/np.pi, db)

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

[ - ]
Reply by dudelsoundJanuary 15, 2020
I don't know much about numpy, but from the comments I figure this is about an IIR filter, namely a biquad. Since there are only 5 coefficients, they must be normalized and thus the first coefficient is already b0/a0 and so on.

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]

[ - ]
Reply by erlendJanuary 15, 2020

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