Avatar

Please consider registering
Guest

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 sp_TopicIcon
Ch. 6 BiQuad filter equation questions
No permission to create posts
January 22, 2016
7:57 am
Avatar
Derek
Member
Members
Forum Posts: 41
Member Since:
November 19, 2015
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?

thanks!
Derek

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

January 22, 2016
3:23 pm
Avatar
Tom
Admin
Forum Posts: 65
Member Since:
April 3, 2014
sp_UserOfflineSmall Offline

Hi,
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.

January 22, 2016
7:40 pm
Avatar
W Pirkle
Admin
Forum Posts: 140
Member Since:
January 28, 2017
sp_UserOnlineSmall Online

Hello

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)

http://www.ece.rochester.edu/~.....ric_EQ.pdf

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;

FOR APF1:
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
Avatar
Derek
Member
Members
Forum Posts: 41
Member Since:
November 19, 2015
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
Avatar
cristofergr
Member
Members
Forum Posts: 5
Member Since:
January 26, 2016
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 )
V0=10^(G/20);
H0=V0-1;
H01=H0/2;
if G >=0
c=(tan(pi*Wc/2)-1)/(tan(pi*Wc/2)+1); %b
else
c=(tan(pi*Wc/2)-V0)/(tan(pi*Wc/2)+V0); %c
end;
xh=0;
for n=1:length(x)
xh_new=x(n)-c*xh;
ap_y=c*xh_new+xh;
xh=xh_new;
y(n)=0.5*H0*(x(n)+ap_y)+x(n);
end;
b0=1+(1+c)*H01
b1=c+(1+c)*H01
a0=1
a1=c
b = [ b0,b1]
a = [ a0,a1]
[sos,g]=tf2sos(b,a);
Hd=dfilt.df2sos(sos,g);

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

please will can you help me

January 27, 2016
2:19 am
Avatar
W Pirkle
Admin
Forum Posts: 140
Member Since:
January 28, 2017
sp_UserOnlineSmall Online

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: 36

Currently Online: W Pirkle
3 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Skyler: 47

Derek: 41

Peter: 41

clau_ste: 39

Frodson: 38

Gwen: 32

EZB: 24

lppier: 23

Msaldaña: 18

Jorge: 17

Member Stats:

Guest Posters: 1

Members: 478

Moderators: 1

Admins: 4

Forum Stats:

Groups: 11

Forums: 29

Topics: 479

Posts: 1870

Newest Members:

certvalue111, sobhana s, sam, annaharris, Marie Weaver, kev, Steven, Mr Anderson, mguy, omelc

Moderators: W Pirkle: 140

Administrators: Tom: 65, JD Young: 80, Will Pirkle: 0, W Pirkle: 140