1
$\begingroup$

I'd like to output the frequency response of this filter.

Here's how the coefficients are calculated:

void StateVariableTPTFilter<SampleType>::update()
{
    g  = static_cast<SampleType> (std::tan (juce::MathConstants<double>::pi * cutoffFrequency / sampleRate));
    R2 = static_cast<SampleType> (1.0 / resonance);
    h  = static_cast<SampleType> (1.0 / (1.0 + R2 * g + g * g));
}

The method that I actually use to plot the freq response (of a biquad filter) is the one suggested by earlevel on one of his topic. Code I wrote is:

// zeros
std::complex<double> resZeros(0.0, 0.0);
resZeros += mCoefficients.mA0 * std::exp(std::complex<double>(0.0, -0 * freq * k2PI));
resZeros += mCoefficients.mA1 * std::exp(std::complex<double>(0.0, -1 * freq * k2PI));
resZeros += mCoefficients.mA2 * std::exp(std::complex<double>(0.0, -2 * freq * k2PI));

// poles
std::complex<double> resPoles(0.0, 0.0);
resPoles += 1.0 * std::exp(std::complex<double>(0.0, -0 * freq * k2PI));
resPoles += mCoefficients.mB1 * std::exp(std::complex<double>(0.0, -1 * freq * k2PI));
resPoles += mCoefficients.mB2 * std::exp(std::complex<double>(0.0, -2 * freq * k2PI));

std::complex<double> res = resZeros / resPoles;

// magnitude
float magnitude = (float)std::abs(res);
if (std::isnan(magnitude)) {
    magnitude = 0.0f;
}

// phase
float phase = (float)std::arg(res); // i.e. math.atan2(res.im, res.re)
if (std::isnan(phase)) {
    phase = 0.0f;
}

return std::polar(magnitude, phase);

Basically, now I need to match the g, R2 and h coefficients from the SVF filter to the ones earlevel provide as mA0, mA1, mA2, mB1 and mB2.

Tried some test, but it doesn't works at all, such as:

mCoefficients.mA0 = mG;
mCoefficients.mA1 = mR2;
mCoefficients.mA2 = mH;

Where am i wrong?

$\endgroup$

1 Answer 1

2
$\begingroup$

Not exactly what you're asking but the frequency (and phase) response of that SVF is identical to a biquad filter whose coefficients were calculated using the bilinear Z-transform.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.