Re: Filter algorithims
Re: Filter algorithims
- Subject: Re: Filter algorithims
- From: paul Fultz <email@hidden>
- Date: Sat, 20 Oct 2007 18:26:46 -0700 (PDT)
yea most common filters that are used are biquads
which can be written in this form:
y[n]=b0*x[n] + b1*x[n-1] + b2*x[n-2] - a1*y[n-1] -
a2*y[n-2];
there are a couple of different ways to implement it.
You can convert filters from analog to digital using
bilinear transform you can read about that here:
http://en.wikipedia.org/wiki/Bilinear_transform
Common analog filters to model from are butterworth,
there are some other types also but it depends on the
their use:
http://en.wikipedia.org/wiki/Butterworth_filter
and here is a piece of c++ code that i use to
calculate the coeffecients, it is a little different
then the cookbook eq:
//HS is high shelf
//And LS is low shelf filter
//Peak is a peak/notch
//also getSampleInterval() = 1/getSampleRate()
void eqfilter::setHP(double freq)
{
double omega = tan( pi * freq * getSampleInterval()
);
double omegasquared = omega * omega;
HP_Freq=freq;
double phi = sqrt(2);
a0 = 1 + phi*omega + omegasquared;
a1 = (2*omegasquared - 2) / a0;
a2 = (1 - phi*omega + omegasquared) / a0;
b0 = 1/a0;
b1 = (-2) * b0;
b2 = b0;
}
void eqfilter::setLP(double freq)
{
double omega = tan( pi * freq * getSampleInterval()
);
double omegasquared = omega * omega;
LP_Freq=freq;
double phi = sqrt(2);
a0 = 1 + phi*omega + omegasquared;
a1 = (2*omegasquared - 2) / a0;
a2 = (1 - phi*omega + omegasquared) /a0;
b0 = omegasquared/a0;
b1 = (2) * b0;
b2 = b0;
}
void eqfilter::setHS(double freq,double gain)
{
double omega = tan( pi * freq * getSampleInterval()
);
double omegasquared = omega * omega;
if ( gain == 0 ) gain = 1;
else gain = pow(10,(gain/20));
double phi = sqrt(2);
double gainsqrt = sqrt(gain);
a0 = 1 + phi*omega + omegasquared;
a1 = (2*omegasquared - 2) / a0;
a2 = (1 - phi*omega + omegasquared) / a0;
b0 = (gain + phi*omega*gainsqrt + omegasquared)/a0;
b1 = (2*omegasquared - 2*gain) / a0;
b2 = (gain - phi*omega*gainsqrt + omegasquared)/a0;
}
void eqfilter::setLS(double freq,double gain)
{
double omega = tan( pi * freq * getSampleInterval()
);
double omegasquared = omega * omega;
if ( gain == 0 ) gain = 1;
else gain = pow(10,(gain/20));
double phi = sqrt(2);
double gainsqrt = sqrt(gain);
a0 = 1 + phi*omega + omegasquared;
a1 = (2*omegasquared - 2) / a0;
a2 = (1 - phi*omega + omegasquared) / a0;
b0 = (1 + phi*omega*gainsqrt +
gain*omegasquared)/a0;
b1 = (2*omegasquared*gain - 2) / a0;
b2 = (1 - phi*omega*gainsqrt +
gain*omegasquared)/a0;
}
void eqfilter::setPeak(double freq,double gain,double
q0)
{
double omega = tan( pi * freq * getSampleInterval()
);
double omegasquared = omega * omega;
if ( gain == 0 ) gain = 1;
else gain = pow(10,(gain/20));
double phi = 1/q0;
a0 = 1 + (phi*omega) + omegasquared;
a1 = (2*(omegasquared) - 2) / a0;
a2 = (1 - (phi*omega) + omegasquared) / a0;
b0 = (1 + phi*omega*gain + omegasquared)/a0;
b1 = a1;
b2 = (1 - (phi*omega*gain) + omegasquared) / a0;
}
i hope this helps,
paul
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden