Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Ch. 6 BiQuad filter equation questions
January 22, 2016 - 7:57 am
Member Since: November 19, 2015
Forum Posts: 46
sp_UserOfflineSmall Offline

Hi all,

I've gone through and implemented most of the filters in chapter 6 but cannot get the 2nd order all pass filter working. The phase response is pretty much a straight line. I've contacted Will and he says the equations are correct, so has anyone else gotten the 2nd order APF working? (BTW, changing the tan function to tan(pi * fc / (Q * fs)) gives a phase response that looks like it should: -180 at fc -360 at nyquist. Not saying that's right but at least the freq and phase response graphs look correct)

Also, through searching for APFs on the web I came across the Audio EQ cookbook http://www.musicdsp.org/files/.....okbook.txt It has 2nd order equations for most of the filters in ch 6, but the coefficient equations are different from the book (except the LPF & HPF). The equations seems simple enough using the substitutions at the bottom of that page but again produce different coeffs from the book.

So my questions are
1) Did anyone get the 2nd order APF working?
2) Where did Will get the equations in the book? (I'd love to see a complete math work through for the BSF, BPF, or APF)
3) Why are the coefficient equations different from the Audio EQ cookbook?


edit:: btw, I'm referring to the BiQuad filters.

January 22, 2016 - 3:23 pm
Member Since: April 3, 2014
Forum Posts: 74
sp_UserOfflineSmall Offline

remember that you only have so many pixels on a screen Wink Try to change the value of Q and see what happens. I have been at the same point...but the equations are correct indeed.

W Pirkle
January 22, 2016 - 7:40 pm
Member Since: January 29, 2017
Forum Posts: 573
sp_UserOfflineSmall Offline


1) the APFs work fine. I just coded both filters for a new/updated module that I was working on. In fact, these are the identical equations as the APF in the Modules menu item in RAFX. Choose Modules -> Allpass Filters and that is the same algorithm. If you open the block diagram window you can see the coefficient calculations which change as you move the sliders. You can compare those coefficients to your own to see if your calculations are off (this is one of the reasons that I included these Modules with block diagrams populated). Use the analyzer and hit the Phase button (with no audio streaming) to see the phase response.

2) almost all of the IIR filters came from: the Lane et al source, Lane& Hillman, or the original Motorola App Notes (all the authors of Lane et. al. were employees at Motorola in the 1980's and they did the derivations - two of them were classmates of mine in grad school, so I am somewhat "loyal" to the Motorola versions). The Constant Q Peaking filter is from Zöler. The Direct-Z-Plane designs are from F.R.Moore. The all-pole first order filters are from Dodge and Jerse. The APFs actually came from a really OLD Regalia-Mitra paper that is copied here (this reference is incorrectly missing from the References; I will need to add it to the 2nd Edition)


3) the equations don't match the RBJ book because I did not use the RBJ book when writing the FX book - in fact, I've not implemented any of the RBJ cookbook filters personally (nothing against them, I've just always had my own algorithms).

There are multiple ways to synthesize IIR Digital Filters. So, you might find slightly different algorithms that produce the same result, in a similar way that there are multiple analog filter realizations that produce the same frequency response. In some cases, after doing some algebra, you realize the algorithms are identical. For example, the Regalia-Mitra paper above shows how to synthesize low shelving and peaking filters in an entirely different way than either the Lane et. al, or other sources.

The APFs I just coded use the following coefficient calculations (m_LeftFilter is a CBiQuad filter) - you can verify that these match the book code.

float theta_c = 2.0*pi*m_fFc/fs;

float fAlphaNumerator = tan((pi*m_fFc)/fs) - 1.0;
float fAlphaDenominator = tan((pi*m_fFc)/fs) + 1.0;

float fAlpha = fAlphaNumerator/fAlphaDenominator;

m_LeftFilter.m_f_a0 = fAlpha;
m_LeftFilter.m_f_a1 = 1.0;
m_LeftFilter.m_f_a2 = 0.0;
m_LeftFilter.m_f_b1 = fAlpha;
m_LeftFilter.m_f_b2 = 0.0;

FOR APF2 Note: m_fBW is the same thing as Q - for the 2nd Order APF, Q really means BandWidth (the range of frequencies over which the phase is adjusted):
float fAlphaNumerator = tan((pi*m_fBW)/fs) - 1.0;
float fAlphaDenominator = tan((pi*m_fBW)/fs) + 1.0;

float fAlpha = fAlphaNumerator/fAlphaDenominator;
float fBeta = -1.0*cos(theta_c);

m_LeftFilter.m_f_a0 = -1.0*fAlpha;
m_LeftFilter.m_f_a1 = fBeta*(1.0 - fAlpha);
m_LeftFilter.m_f_a2 = 1.0;
m_LeftFilter.m_f_b1 = fBeta*(1.0 - fAlpha);
m_LeftFilter.m_f_b2 = -1.0*fAlpha;

- Will

January 22, 2016 - 11:30 pm
Member Since: November 19, 2015
Forum Posts: 46
sp_UserOfflineSmall Offline

Thanks Will!

I see the issue now. In the 2nd order APF you're using Q to mean BW (BW silder is in the APF module of RackAFX).
This requires an input range of some low number to several thousand for the BW, the module uses 0 to 10K.

I was using Q as the same range as the other filters, in a range of 0.1 to 20. In that case band width can still be calculated by Fc / Q.
(e.g. Fc of 1000 and Q of 0.25 gives a BW of 4000). The only difference with that implementation is the BW changes if you modulate Fc while keeping Q constant.
I'm clipping to just below pi / 2 so the BW never exceeds nyquist.

Please do add that distinction in the 2nd Edition. I think using the BW variable in the 2nd order APF tan equation (vs. Q) would keep the book more consistent.

I'll check out those references, thanks.

January 27, 2016 - 12:21 am
Member Since: January 26, 2016
Forum Posts: 5
sp_UserOfflineSmall Offline

Hallo everyone
thank you for accepting me as member of this forum i have a code which implements a 1 order lowshelving filter using a 1 order allpass filter
but i have some questions can i make some questions the code is thisone some parts of this code are from a book, some parts are my
Now can i ask some questions????????????????
function [ Hd] = lowshelving( x,Wc,G )
if G >=0
c=(tan(pi*Wc/2)-1)/(tan(pi*Wc/2)+1); %b
c=(tan(pi*Wc/2)-V0)/(tan(pi*Wc/2)+V0); %c
for n=1:length(x)
b = [ b0,b1]
a = [ a0,a1]

January 27, 2016 - 1:47 am
Member Since: January 26, 2016
Forum Posts: 5
sp_UserOfflineSmall Offline

please will can you help me

W Pirkle
January 27, 2016 - 2:19 am
Member Since: January 29, 2017
Forum Posts: 573
sp_UserOfflineSmall Offline

First, I don't know what your question is.

Secondly, I do not generally debug anyone's code or algorithms. That is your job. But perhaps someone else on the forum will do that.

- Will

Forum Timezone: America/New_York

Most Users Ever Online: 152

Currently Online:
4 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Chaes: 51

Skyler: 48

Derek: 46

Frodson: 45

Peter: 43

TheSmile: 43

clau_ste: 39

jim: 34

JimmyM: 33

Gwen: 32

Member Stats:

Guest Posters: 1

Members: 696

Moderators: 1

Admins: 5

Forum Stats:

Groups: 13

Forums: 41

Topics: 757

Posts: 2894

Newest Members:

Jas, Rowan, sojourn, fabhenr, rg1, Niklas, Wutru, Tim Campbell, Danny Jonel, Valentin

Moderators: W Pirkle: 573

Administrators: Tom: 74, JD Young: 80, Will Pirkle: 0, W Pirkle: 573, VariableCook: 3