Help with Biquad Filter

Algorithm development and general DSP issues

Moderator: frank

Post Reply
Admiral_dk
Posts: 13
Joined: Wed Sep 27, 2017 8:31 am

Help with Biquad Filter

Post by Admiral_dk »

Hi All.

I have a problem, where I need a moveable LowPass filter, where it is f0 that is moved between 500Hz. and as close as possible to the full 15KHz. bandwith (32.768Hz. Clock). I tried a simple BiQuad filter I partly pinched from SpinCAD (thanks Larry). :

equ Frequency REG4 ; Tone (Low Pass) Frequency (f0)
equ LowPass REG5 ;
equ BandPass REG6 ;
equ DelayOut REG7

; ------ biquad filter ------------------------------------------------------------------------------

RDAX POT0 ,1 ; Read Tone Pot
SOF 0.22 , -0.35 ; Shift Value : -.13 - -.35 => 100Hz. - 6.3KHz.
EXP 1 , 0 ; Expand to Range : 0.7046 ~ 100Hz. , 1 ~ 15KHz.
; 0.7046 ~ 100Hz. , 0.8783 ~ 6350Hz. - MAX OK value
WRAX Frequency , 0 ; Store as Frequency Factor

; ------ Filter Rutine starts here ---------------

RDAX BandPass , 1 ; Read old BandPass Register / Integrator Value
MULX Frequency ; Multiply with Frequency Gain Value
RDAX LowPass , 1 ; Read LowPass Register / Integrator Value
WRAX LowPass , 0 ; and ADD them for later

RDAX BandPass , -1 ; Read BandPass and Invert (-Q=1)
RDAX LowPass , -1 ; ADD LowPass Inverted

RDAX ADCL , 1
; ACC = High Pass Output here if needed.
MULX Frequency
RDAX BandPass , 1 ; Read BandPass Register / Integrator Value
WRAX BandPass , 0 ; and ADD them for later

; -------------------------------------------------------------------------------------------------------

LDAX LowPass
WRAX DACL , 0

EOP:

I have limited the max f0 as the Output "wobles when viewed on a scope" if f0 is higher than 6350 Hz. - any quick replies as to why ?
I read in some other posts here that this filter has problems below 500Hz. but I haven't seen any ….
The Digital representation is extremely similar to the Analog counterpart, and the Analog version can have the Input anywhere in the "chain" as this only moves where the Outputs are - this is sometimes useful in the Analog version - does it make sense in the Digital version too ?

I can live with a Q that is a bit higher or lower if this helps. Another filter type that solves my problem is fine too - thanks.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Help with Biquad Filter

Post by frank »

This is the same filter as found here http://www.spinsemi.com/knowledge_base/ ... ng_filters with -Kq = -1 but there is an important note as well that says:

If peaking (or cutoff) frequencies higher than about Fs/4 are required, they will be difficult to do without oversampling the filter. Oversampling simply means that the algorithm is written twice within the program, so to have the effect of being executed twice as often on the data samples. This technique allows the above filter to be swept over the entire DC to Fs/2 bandwidth.

So you have to really do the filter routine twice to get the full bandwidth.
Frank Thomson
Experimental Noize
Admiral_dk
Posts: 13
Joined: Wed Sep 27, 2017 8:31 am

Re: Help with Biquad Filter

Post by Admiral_dk »

Thank you Frank and happy New Year.

I added the following to the code :

Code: Select all

; ------	UpSample Routine --------------------

	RDAX 	ADCL , 1				; Get New Sample
	WRA	UpSample , 0.5				; Save for later and Multply with 0.5
	RDA	UpSample + 1 , 0.5			; Add 0.5* Previous Sample
	WRA	UpSample + 2 , 0			; Save the Interpolated Sample back for later
And used it for the input to the first run of the previous shown code and it works fine up to the full samplerate - BUT only at about half the max possible undistorted input - at higher levels the same happens as if it is in slewrate limitations …?

Should I expect this ?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Help with Biquad Filter

Post by frank »

Why are you interpolating? Run twice with the same input.
Frank Thomson
Experimental Noize
Admiral_dk
Posts: 13
Joined: Wed Sep 27, 2017 8:31 am

Re: Help with Biquad Filter

Post by Admiral_dk »

Thank you for your reply Frank.

I posted a reply yesterday that apparently disappeared into thin air … :( …. oh well I try again.

You are right - I forgot that interpolating is used in down and not up sampling :oops:

As far as I remember (I was taught DSP programming in 96 and didn't use it for 19 years) you need to run a low pass filter in both cases (up & down) - is the Biquad filter ok to use in this capacity, or does the high/band pass part of the filter wreck havoc here ?

I'm surprised that the current version works perfect up to full sample frequency as long as I keep the max signal level at 1/2 the max possible undistorted into the ADC (fine), but when I go between 1/2 and max, I can only go to max 6350 Hz (@32.768) before I run into trouble :evil: and I simply do not understand why.
Do I have a problem in the code (with the filter run twice) or is it a hardware limitation I haven't thought of ?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Help with Biquad Filter

Post by frank »

This biquad is an IIR structure and you always risk overflow/saturation in an IIR (look at the un. What I typically do is read the input, cut it in half so there is extra head room for the registers, do the filtering then multiply by 2 after the filter. I've even had times that I need to divide/multiply by 4 to make things work. It sounds like the filter is fine and it is just register saturation which happens. Look at the feedback at the LP and BP taps, no attenuation so possible for overflow to happen.
Frank Thomson
Experimental Noize
Admiral_dk
Posts: 13
Joined: Wed Sep 27, 2017 8:31 am

Re: Help with Biquad Filter

Post by Admiral_dk »

Once again - thank you very much Frank.

We where taught over and over again that we would need to scale the level up and down and even how to calculate if a routine needs it - use it or loose it - so it was your comment that brought it back :D

Halv the inputs ( * -0.5 ) and multiplying back up ( * -2 ) completely cured the problem (along with running it twice) :mrgreen:
Post Reply