Пример #1
0
void IIRFilter::makeHighPass (const double sampleRate,
                              const double frequency) noexcept
{
    const double n = tan (double_Pi * frequency / sampleRate);
    const double nSquared = n * n;
    const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared);

    setCoefficients (c1,
                     c1 * -2.0f,
                     c1,
                     1.0,
                     c1 * 2.0 * (nSquared - 1.0),
                     c1 * (1.0 - std::sqrt (2.0) * n + nSquared));
}
Пример #2
0
void BiquadBase::setTwoPole (complex_t pole1, complex_t zero1,
                             complex_t pole2, complex_t zero2)
{
#if 0
  pole1 = adjust_imag (pole1);
  pole2 = adjust_imag (pole2);
  zero1 = adjust_imag (zero1);
  zero2 = adjust_imag (zero2);
#endif

  const double a0 = 1;
  double a1;
  double a2;

  if (pole1.imag() != 0)
  {
    assert (pole2 == std::conj (pole1));

    a1 = -2 * pole1.real();
    a2 = std::norm (pole1);
  }
  else
  {
    assert (pole2.imag() == 0);

    a1 = -(pole1.real() + pole2.real());
    a2 =   pole1.real() * pole2.real();
  }

  const double b0 = 1;
  double b1;
  double b2;

  if (zero1.imag() != 0)
  {
    assert (zero2 == std::conj (zero1));

    b1 = -2 * zero1.real();
    b2 = std::norm (zero1);
  }
  else
  {
    assert (zero2.imag() == 0);

    b1 = -(zero1.real() + zero2.real());
    b2 =   zero1.real() * zero2.real();
  }

  setCoefficients (a0, a1, a2, b0, b1, b2);
}
Пример #3
0
void Biquad4proc::setPeaking(double center_frequency, double sampling_frequency, double gainDb, double slope)
{
    double w0 = 2 * M_PI * center_frequency / sampling_frequency;
    double A = pow(10, gainDb/40);
    double alpha = sin(w0)/2 * sqrt( (A + 1/A)*(1/slope - 1) + 2 );

    double b0 =   1 + alpha*A;
    double b1 =  -2*cos(w0);
    double b2 =   1 - alpha*A;
    double a0 =   1 + alpha/A;
    double a1 =  -2*cos(w0);
    double a2 =   1 - alpha/A;

    setCoefficients(a0, a1, a2, b0, b1, b2);
}
Пример #4
0
inline void OnePoleFilter::setPolePosition(float pos, bool normalize) {
	float b0, a1;
	a1 = -pos;
	b0 = 1.0f;
	/**Reasoning time:
	The maximum gain of the filter is at dc or nyquist, introducing either a term of -1 or a term of 1.
	The maximum gain of the filter occurs when the denominator is minimized. The denominator is minimized when a1 is negative. So:
	max = 1/(1-|a1|)
	We wish to normalize the filter with b0. This means we wish to set b0 = 1/max.
	By the rules of fractions:
	b0 = 1-|a1|.
	*/
	if(normalize) b0 = (float)(1.0-fabs(a1));
	setCoefficients(b0, a1);
}
Пример #5
0
void Biquad4proc::setHighShelf(double center_frequency, double sampling_frequency, double gainDb, double slope)
{
    double w0 = 2 * M_PI * center_frequency / sampling_frequency;
    double A = pow(10, gainDb/40);
    double alpha = sin(w0)/2 * sqrt( (A + 1/A)*(1/slope - 1) + 2 );

    double b0 =    A*( (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha );
    double b1 = -2*A*( (A-1) + (A+1)*cos(w0)                   );
    double b2 =    A*( (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha );
    double a0 =        (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha  ;
    double a1 =    2*( (A-1) - (A+1)*cos(w0)                   );
    double a2 =        (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha  ;

    setCoefficients(a0, a1, a2, b0, b1, b2);
}
Пример #6
0
//==============================================================================
void IIRFilter::makeLowPass (const double sampleRate,
                             const double frequency) noexcept
{
    jassert (sampleRate > 0);

    const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
    const double nSquared = n * n;
    const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared);

    setCoefficients (c1,
                     c1 * 2.0f,
                     c1,
                     1.0,
                     c1 * 2.0 * (1.0 - nSquared),
                     c1 * (1.0 - std::sqrt (2.0) * n + nSquared));
}
Пример #7
0
void AllPass::setup (double sampleRate,
                     double phaseFrequency,
                     double q)
{
  double w0 = 2 * doublePi * phaseFrequency / sampleRate;
  double cs = cos (w0);
  double sn = sin (w0);
  double AL = sn / ( 2 * q );
  double b0 =  1 - AL;
  double b1 = -2 * cs;
  double b2 =  1 + AL;
  double a0 =  1 + AL;
  double a1 = -2 * cs;
  double a2 =  1 - AL;
  setCoefficients (a0, a1, a2, b0, b1, b2);
}
Пример #8
0
void HighPass::setup (double sampleRate,
                      double cutoffFrequency,
                      double q)
{
  double w0 = 2 * doublePi * cutoffFrequency / sampleRate;
  double cs = cos (w0);
  double sn = sin (w0);
  double AL = sn / ( 2 * q );
  double b0 =  (1 + cs) / 2;
  double b1 = -(1 + cs);
  double b2 =  (1 + cs) / 2;
  double a0 =  1 + AL;
  double a1 = -2 * cs;
  double a2 =  1 - AL;
  setCoefficients (a0, a1, a2, b0, b1, b2);
}
Пример #9
0
void BandPass2::setup (double sampleRate,
                       double centerFrequency,
                       double bandWidth)
{
  double w0 = 2 * doublePi * centerFrequency / sampleRate;
  double cs = cos (w0);
  double sn = sin (w0);
  double AL = sn / ( 2 * bandWidth );
  double b0 =  AL;
  double b1 =  0;
  double b2 = -AL;
  double a0 =  1 + AL;
  double a1 = -2 * cs;
  double a2 =  1 - AL;
  setCoefficients (a0, a1, a2, b0, b1, b2);
}
Пример #10
0
void BiquadFilter::makeHighPass (const double sampleRate,
                                 const double frequency,
                                 const double Q) noexcept
{
	const double oneOverCurrentSampleRate = 1.0 / sampleRate;
	float w0 = (float) (2.0f * float_Pi * frequency * oneOverCurrentSampleRate);
	float cos_w0 = cos (w0);
	float sin_w0 = sin (w0);
	float alpha = sin_w0 / (2.0f * (float) Q);
    
	setCoefficients ((1.0f + cos_w0) * 0.5f, 
                     -(1.0f + cos_w0), 
                     (1.0f + cos_w0) * 0.5f, 
                     (1.0f + alpha), 
                     -2.0f * cos_w0, 
                     (1.0f - alpha));	
}
Пример #11
0
void HighShelf::setup (double sampleRate,
                       double cutoffFrequency,
                       double gainDb,
                       double shelfSlope)
{
  double A  = pow (10, gainDb/40);
  double w0 = 2 * doublePi * cutoffFrequency / sampleRate;
  double cs = cos (w0);
  double sn = sin (w0);
  double AL = sn / 2 * ::std::sqrt ((A + 1/A) * (1/shelfSlope - 1) + 2);
  double sq = 2 * sqrt(A) * AL;
  double b0 =    A*( (A+1) - (A-1)*cs + sq );
  double b1 = -2*A*( (A-1) - (A+1)*cs );
  double b2 =    A*( (A+1) - (A-1)*cs - sq );
  double a0 =        (A+1) + (A-1)*cs + sq;
  double a1 =    2*( (A-1) + (A+1)*cs );
  double a2 =        (A+1) + (A-1)*cs - sq;
  setCoefficients (a0, a1, a2, b0, b1, b2);
}
Пример #12
0
void BandShelf::setup (double sampleRate,
                       double centerFrequency,
                       double gainDb,
                       double bandWidth)
{
  double A  = pow (10, gainDb/40);
  double w0 = 2 * doublePi * centerFrequency / sampleRate;
  double cs = cos(w0);
  double sn = sin(w0);
  double AL = sn * sinh( doubleLn2/2 * bandWidth * w0/sn );
  assert (!Dsp::is_nan (AL));
  double b0 =  1 + AL * A;
  double b1 = -2 * cs;
  double b2 =  1 - AL * A;
  double a0 =  1 + AL / A;
  double a1 = -2 * cs;
  double a2 =  1 - AL / A;
  setCoefficients (a0, a1, a2, b0, b1, b2);
}
Пример #13
0
void BiquadBase::setOnePole (complex_t pole, complex_t zero)
{
#if 0
  pole = adjust_imag (pole);
  zero = adjust_imag (zero);
#else
  assert (pole.imag() == 0); 
  assert (zero.imag() == 0);
#endif
  
  const double a0 = 1;
  const double a1 = -pole.real();
  const double a2 = 0;
  const double b0 = -zero.real();
  const double b1 = 1;
  const double b2 = 0;

  setCoefficients (a0, a1, a2, b0, b1, b2);
}
Пример #14
0
void Biquad::setHighShelf(int32_t steps, float center_frequency, float sampling_frequency, float gainDb, float slope, float overallGainDb)
{
    float w0 = 2 * (float) M_PI * center_frequency / sampling_frequency;
    float A = powf(10, gainDb/40);
    float alpha = sinf(w0)/2 * sqrtf( (A + 1/A)*(1/slope - 1) + 2 );

    float b0 =    A*( (A+1) + (A-1)*cosf(w0) + 2*sqrtf(A)*alpha );
    float b1 = -2*A*( (A-1) + (A+1)*cosf(w0)                   );
    float b2 =    A*( (A+1) + (A-1)*cosf(w0) - 2*sqrtf(A)*alpha );
    float a0 =        (A+1) - (A-1)*cosf(w0) + 2*sqrtf(A)*alpha  ;
    float a1 =    2*( (A-1) - (A+1)*cosf(w0)                   );
    float a2 =        (A+1) - (A-1)*cosf(w0) - 2*sqrtf(A)*alpha  ;

    float overallGain = powf(10, overallGainDb / 20);
    b0 *= overallGain;
    b1 *= overallGain;
    b2 *= overallGain;

    setCoefficients(steps, a0, a1, a2, b0, b1, b2);
}
Пример #15
0
void BiquadFilter::makeBandPass(const double sampleRate,
                                const double frequency,
                                const double Q) noexcept
{
	const double qFactor = jlimit (0.00001, 1000.0, Q);
	const double oneOverCurrentSampleRate = 1.0 / sampleRate;
	
	float w0 = (float) (2.0f * float_Pi * frequency * oneOverCurrentSampleRate);
	float cos_w0 = cos (w0);
	float sin_w0 = sin (w0);
	float alpha = sin_w0 / (2.0f * (float) qFactor);
    //	float alpha = sin_w0 * sinh( (log(2.0)/2.0) * bandwidth * w0/sin_w0 );
	
	setCoefficients (alpha, 
					 0.0f, 
					 -alpha, 
                     1.0f + alpha, 
                     -2.0f * cos_w0, 
                     1.0f - alpha);
}
Пример #16
0
void BiquadFilter::makeAllpass (const double sampleRate,
                                const double frequency,
                                const double Q) noexcept
{
	const double qFactor = jlimit(0.00001, 1000.0, Q);
	const double oneOverCurrentSampleRate = 1.0 / sampleRate;
	
	
	float w0 = (float) (2.0f * float_Pi * frequency * oneOverCurrentSampleRate);
	float cos_w0 = cos(w0);
	float sin_w0 = sin(w0);
	float alpha = (float) (sin_w0 / (2 * qFactor));
	
	setCoefficients (1.0f - alpha,
                     -2 * cos_w0,
                     1.0f + alpha,
                     1.0f + alpha,
                     -2.0f * cos_w0,
                     1.0f - alpha);
}
Пример #17
0
void Biquad::setHighShelf(int32_t steps, double center_frequency, double sampling_frequency, double gainDb, double slope, double overallGainDb)
{
    double w0 = 2 * M_PI * center_frequency / sampling_frequency;
    double A = pow(10, gainDb/40);
    double alpha = sin(w0)/2 * sqrt( (A + 1/A)*(1/slope - 1) + 2 );

    double b0 =    A*( (A+1) + (A-1)*cos(w0) + 2*sqrt(A)*alpha );
    double b1 = -2*A*( (A-1) + (A+1)*cos(w0)                   );
    double b2 =    A*( (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha );
    double a0 =        (A+1) - (A-1)*cos(w0) + 2*sqrt(A)*alpha  ;
    double a1 =    2*( (A-1) - (A+1)*cos(w0)                   );
    double a2 =        (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha  ;

    double overallGain = pow(10, overallGainDb / 20);
    b0 *= overallGain;
    b1 *= overallGain;
    b2 *= overallGain;

    setCoefficients(steps, a0, a1, a2, b0, b1, b2);
}
Пример #18
0
    void ParametersInterpreter<NMSmodelT>::setSubjectParameters(const std::vector<double>& x) {


        unsigned count = 0;
        for (typename ParametersMap::const_iterator it(parameters_.begin()); it != parameters_.end(); ++it) {

            unsigned noCoefficients = it->second.size;
            std::vector<double>::const_iterator startIt(x.begin() + count);
            std::vector<double>::const_iterator endIt(x.begin() + count + noCoefficients);
            std::vector<double> groupedCoefficients(startIt, endIt);
            std::vector<double> coefficients;

            getCoefficients(it->first, coefficients);
            distributeValues(it->second.muscleGroups, coefficients, groupedCoefficients);
            setCoefficients(it->first, coefficients);

            count += noCoefficients;

        }

    }
Пример #19
0
void IIRFilter::makeBandPass (const double sampleRate,
                              const double centreFrequency,
                              const double Q,
                              const float gainFactor) noexcept
{
    jassert (sampleRate > 0);
    jassert (Q > 0);

    const double A = jmax (0.0f, gainFactor);
    const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
    const double alpha = 0.5 * std::sin (omega) / Q;
    const double c2 = -2.0 * std::cos (omega);
    const double alphaTimesA = alpha * A;
    const double alphaOverA = alpha / A;

    setCoefficients (1.0 + alphaTimesA,
                     c2,
                     1.0 - alphaTimesA,
                     1.0 + alphaOverA,
                     c2,
                     1.0 - alphaOverA);
}
Пример #20
0
void IIRFilter::makeHighShelf (const double sampleRate,
                               const double cutOffFrequency,
                               const double Q,
                               const float gainFactor) noexcept
{
    jassert (sampleRate > 0);
    jassert (Q > 0);

    const double A = jmax (0.0f, gainFactor);
    const double aminus1 = A - 1.0;
    const double aplus1 = A + 1.0;
    const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
    const double coso = std::cos (omega);
    const double beta = std::sin (omega) * std::sqrt (A) / Q;
    const double aminus1TimesCoso = aminus1 * coso;

    setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
                     A * -2.0 * (aminus1 + aplus1 * coso),
                     A * (aplus1 + aminus1TimesCoso - beta),
                     aplus1 - aminus1TimesCoso + beta,
                     2.0 * (aminus1 - aplus1 * coso),
                     aplus1 - aminus1TimesCoso - beta);
}
Пример #21
0
void BiquadBase::setIdentity ()
{
  setCoefficients (1, 0, 0, 1, 0, 0);
}
Пример #22
0
void BiquadBase::applyScale (double scale)
{
    setCoefficients(m_a0, m_a1, m_a2, m_b0 * scale, m_b1 * scale, m_b2 * scale);
}
Пример #23
0
HarmonicFunction::HarmonicFunction( const RVector & coeff, double xmin, double xmax )
: xMin_( xmin ), xMax_( xmax ){
    setCoefficients( coeff );
}
Пример #24
0
 void Linear::set(const std::vector<scalar>& coeffs, const Engine* engine) {
     setCoefficients(coeffs);
     setEngine(engine);
 }
Пример #25
0
void ProcessorBiquad::setHighpass(float Q, float frequency) {
    float angularFreq = M_2PI * (frequency / LANTERN_AUDIO_SAMPLE_RATE);
    float alpha = sin(angularFreq) / (2.0f * Q);
    float incCos = 1.0f + cos(angularFreq);
    setCoefficients(1.0f + alpha, -2.0f * cos(angularFreq), 1.0f - alpha, incCos * 0.5f, -incCos, incCos * 0.5f);
}
Пример #26
0
void ProcessorBiquad::setBandpass(float Q, float frequency) {
    float angularFreq = M_2PI * (frequency / LANTERN_AUDIO_SAMPLE_RATE);
    float alpha = sin(angularFreq) / (2.0f * Q);
    setCoefficients(1.0f + alpha, -2.0f * cos(angularFreq), 1.0f - alpha, Q * alpha, 0, -Q * alpha);
}
Пример #27
0
void Polynomial::deleteData()
{
   setCoefficients(nullptr, 0);
}
Пример #28
0
void Biquad4proc::setSOS(double a0, double a1, double a2, double b0, double b1, double b2)
{
	setCoefficients(a0, a1, a2, b0, b1, b2);
}
Пример #29
0
Biquad::Biquad()
{
    reset();
    setCoefficients(0, 1, 0, 0, 1, 0, 0);
}
Пример #30
0
Biquad4proc::Biquad4proc()
{
    reset();
    setCoefficients(1, 0, 0, 1, 0, 0);
}