32template <
typename FloatType>
35 double sampleRate,
size_t order,
39 jassert (sampleRate > 0);
40 jassert (frequency > 0 && frequency <= sampleRate * 0.5);
44 auto*
c = result->getRawCoefficients();
47 for (
size_t i = 0; i <= order; ++i)
61 theWindow.multiplyWithWindowingTable (
c, order + 1);
66template <
typename FloatType>
72 jassert (sampleRate > 0);
73 jassert (frequency > 0 && frequency <= sampleRate * 0.5);
89 return designFIRLowpassWindowMethod (frequency, sampleRate,
static_cast<size_t> (order),
94template <
typename FloatType>
99 jassert (sampleRate > 0);
100 jassert (frequency > 0 && frequency <= sampleRate * 0.5);
107 auto*
c = result->getRawCoefficients();
109 for (
size_t i = 0; i <= order; ++i)
111 if (i == order / 2 && order % 2 == 0)
127template <
typename FloatType>
130 double sampleRate,
size_t order,
134 jassert (sampleRate > 0);
135 jassert (frequency > 0 && frequency <= sampleRate * 0.5);
147 auto*
c = result->getRawCoefficients();
152 auto M = (
N - 1) / 2;
163 for (
size_t i = 0; i <=
M; ++i)
168 for (
size_t i = 1; i <= 2 *
M; ++i)
178 c[
M] =
static_cast<FloatType
> (
b (0, 0));
180 for (
size_t i = 1; i <=
M; ++i)
182 c[
M - i] =
static_cast<FloatType
> (
b (i, 0) * 0.5);
183 c[
M + i] =
static_cast<FloatType
> (
b (i, 0) * 0.5);
201 for (
size_t i = 0; i <
M; ++i)
204 for (
size_t i = 0; i < 2 *
M; ++i)
227 for (
size_t i = 0; i <
M; ++i)
229 c[
M - i - 1] =
static_cast<FloatType
> (
b (i, 0) * 0.25);
230 c[
M + i] =
static_cast<FloatType
> (
b (i, 0) * 0.25);
237template <
typename FloatType>
247 auto n = roundToInt (std::ceil ((
amplitudedB - 18.18840664 *
wpT + 33.64775300) / (18.54155181 *
wpT - 29.13196871)));
248 auto kp = (n *
wpT - 1.57111377 * n + 0.00665857) / (-1.01927560 * n + 0.37221484);
249 auto A = (0.01525753 * n + 0.03682344 + 9.24760314 / (
double) n) *
kp + 1.01701407 + 0.73512298 / (
double) n;
250 auto B = (0.00233667 * n - 1.35418408 + 5.75145813 / (
double) n) *
kp + 1.02999650 - 0.72759508 / (
double) n;
257 for (
int i = 0; i <
diff; ++i)
265 for (
int i = 0; i <
hn.
size(); ++i)
269 auto*
c = result->getRawCoefficients();
271 for (
int i = 0; i <
hh.
size(); ++i)
272 c[i] = (
float)
hh[i];
278 NN = 2.0 * result->getMagnitudeForFrequency (0.5, 1.0);
288 for (
int i = 0; i <
hh.
size(); ++i)
289 c[i] =
static_cast<FloatType
> ((A *
hn[i] + B *
hnm[i]) /
NN);
291 c[2 * n + 1] =
static_cast<FloatType
> (0.5);
296template <
typename FloatType>
308 alpha.
setUnchecked (2 * n - 4, -(4 * n + 1 + (n - 1) * (2 * n - 1) *
kp *
kp) / (2.0 * n) * alpha[2 * n - 2]
309 - (2 * n + 1) * ((n + 1) *
kp *
kp + 1) / (2.0 * n) * alpha[2 * n]);
311 for (
int k = n;
k >= 3; --
k)
313 auto c1 = (3 * (n*(n + 2) -
k * (
k - 2)) + 2 *
k - 3 + 2 * (
k - 2)*(2 *
k - 3) *
kp *
kp) * alpha[2 *
k - 4];
314 auto c2 = (3 * (n*(n + 2) - (
k - 1) * (
k + 1)) + 2 * (2 *
k - 1) + 2 *
k*(2 *
k - 1) *
kp *
kp) * alpha[2 *
k - 2];
315 auto c3 = (n * (n + 2) - (
k - 1) * (
k + 1)) * alpha[2 *
k];
316 auto c4 = (n * (n + 2) - (
k - 3) * (
k - 1));
324 for (
int k = 0;
k <= n; ++
k)
328 hn.
resize (2 * n + 1 + 2 * n + 1 + 1);
330 for (
int k = 0;
k <= n; ++
k)
339template <
typename FloatType>
340ReferenceCountedArray<IIR::Coefficients<FloatType>>
350template <
typename FloatType>
361template <
typename FloatType>
372template <
typename FloatType>
383template <
typename FloatType>
390 jassert (sampleRate > 0);
391 jassert (frequency > 0 && frequency <= sampleRate * 0.5);
405 auto epsp = std::sqrt (1.0 / (
Gp *
Gp) - 1.0);
406 auto epss = std::sqrt (1.0 / (
Gs *
Gs) - 1.0);
419 N = roundToInt (std::ceil (std::log (1.0 /
k1) / std::log (1.0 /
k)));
421 else if (type == 1 || type == 2)
423 N = roundToInt (std::ceil (std::acosh (1.0 /
k1) / std::acosh (1.0 /
k)));
427 double K, Kp, K1, K1p;
432 N = roundToInt (std::ceil ((K1p * K) / (K1 * Kp)));
436 const int L = (N - r) / 2;
437 const double H0 = (type == 1 || type == 3) ? std::pow (Gp, 1.0 - r) : 1.0;
439 Array<Complex<double>> pa, za;
440 Complex<double> j (0, 1);
445 pa.add (-omegap * std::pow (epsp, -1.0 / (
double) N));
447 for (
int i = 1; i <= L; ++i)
449 auto ui = (2 * i - 1.0) / (
double) N;
450 pa.add (omegap * std::pow (epsp, -1.0 / (
double) N) * j * exp (ui * halfPi * j));
455 auto v0 = std::asinh (1.0 / epsp) / (N * halfPi);
458 pa.add (-omegap * std::sinh (v0 * halfPi));
460 for (
int i = 1; i <= L; ++i)
462 auto ui = (2 * i - 1.0) / (
double) N;
463 pa.add (omegap * j * std::cos ((ui - j * v0) * halfPi));
468 auto v0 = std::asinh (epss) / (N * halfPi);
471 pa.add(-1.0 / (k / omegap * std::sinh (v0 * halfPi)));
473 for (
int i = 1; i <= L; ++i)
475 auto ui = (2 * i - 1.0) / (
double) N;
477 pa.add (1.0 / (k / omegap * j * std::cos ((ui - j * v0) * halfPi)));
478 za.add (1.0 / (k / omegap * j * std::cos (ui * halfPi)));
488 for (
int i = 1; i <= L; ++i)
490 auto ui = (2 * i - 1.0) / (
double) N;
494 za.add (omegap * j / (k * zetai));
498 Array<Complex<double>> p, z, g;
502 p.add ((1.0 + pa[0]) / (1.0 - pa[0]));
503 g.add (0.5 * (1.0 - p[0]));
506 for (
int i = 0; i < L; ++i)
508 p.add ((1.0 + pa[i + r]) / (1.0 - pa[i + r]));
509 z.add (za.size() == 0 ? -1.0 : (1.0 + za[i]) / (1.0 - za[i]));
510 g.add ((1.0 - p[i + r]) / (1.0 - z[i]));
513 ReferenceCountedArray<IIR::Coefficients<FloatType>> cascadedCoefficients;
517 auto b0 =
static_cast<FloatType
> (H0 * std::real (g[0]));
519 auto a1 =
static_cast<FloatType
> (-std::real (p[0]));
521 cascadedCoefficients.add (
new IIR::Coefficients<FloatType> (b0, b1, 1.0f, a1));
524 for (
int i = 0; i < L; ++i)
526 auto gain = std::pow (std::abs (g[i + r]), 2.0);
528 auto b0 =
static_cast<FloatType
> (gain);
529 auto b1 =
static_cast<FloatType
> (std::real (-z[i] - std::conj (z[i])) * gain);
530 auto b2 =
static_cast<FloatType
> (std::real ( z[i] * std::conj (z[i])) * gain);
532 auto a1 =
static_cast<FloatType
> (std::real (-p[i+r] - std::conj (p[i + r])));
533 auto a2 =
static_cast<FloatType
> (std::real ( p[i+r] * std::conj (p[i + r])));
535 cascadedCoefficients.add (
new IIR::Coefficients<FloatType> (b0, b1, b2, 1, a1, a2));
538 return cascadedCoefficients;
541template <
typename FloatType>
542ReferenceCountedArray<IIR::Coefficients<FloatType>>
544 double sampleRate,
int order)
546 jassert (sampleRate > 0);
547 jassert (frequency > 0 && frequency <= sampleRate * 0.5);
556 for (
auto i = 0; i < order / 2; ++i)
560 static_cast<FloatType
> (
Q)));
565 for (
auto i = 0; i < order / 2; ++i)
569 static_cast<FloatType
> (
Q)));
576template <
typename FloatType>
579 double sampleRate,
int order)
581 jassert (sampleRate > 0);
582 jassert (frequency > 0 && frequency <= sampleRate * 0.5);
591 for (
auto i = 0; i < order / 2; ++i)
595 static_cast<FloatType
> (
Q)));
600 for (
auto i = 0; i < order / 2; ++i)
604 static_cast<FloatType
> (
Q)));
611template <
typename FloatType>
623 auto kp = std::sqrt (1.0 -
k *
k);
624 auto e = (1 - std::sqrt (
kp)) / (1 + std::sqrt (
kp)) * 0.5;
625 auto q =
e + 2 * std::pow (
e, 5.0) + 15 * std::pow (
e, 9.0) + 150 * std::pow (
e, 13.0);
628 int n = roundToInt (std::ceil (std::log (
k1 *
k1 / 16) / std::log (
q)));
636 auto q1 = std::pow (
q, (
double) n);
637 k1 = 4 * std::sqrt (
q1);
639 const int N = (n - 1) / 2;
642 for (
int i = 1; i <=
N; ++i)
648 while (std::abs (
delta) > 1
e-100)
650 delta = std::pow (-1, m) * std::pow (
q, m * (m + 1))
656 num *= 2 * std::pow (
q, 0.25);
662 while (std::abs (
delta) > 1
e-100)
664 delta = std::pow (-1, m) * std::pow (
q, m * m)
680 for (
int i = 0; i <
N; i += 2)
682 0, 1, 1, 0,
static_cast<FloatType
> (
ai[i])));
686 for (
int i = 1; i <
N; i += 2)
688 0, 1, 1, 0,
static_cast<FloatType
> (
ai[i])));
void setUnchecked(int indexToChange, ParameterType newValue)
void addArray(const Type *elementsToAdd, int numElementsToAdd)
int size() const noexcept
void insert(int indexToInsertAt, ParameterType newElement)
void add(const ElementType &newElement)
void resize(int targetNumItems)
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
static Matrix hankel(const Matrix &vector, size_t size, size_t offset=0)
static Matrix identity(size_t size)
static Matrix toeplitz(const Matrix &vector, size_t size)
ReferenceCountedObjectPtr< Coefficients > Ptr
static ReferenceCountedArray< IIRCoefficients > designIIRLowpassHighOrderButterworthMethod(FloatType frequency, double sampleRate, FloatType normalisedTransitionWidth, FloatType passbandAmplitudedB, FloatType stopbandAmplitudedB)
static FIRCoefficientsPtr designFIRLowpassLeastSquaresMethod(FloatType frequency, double sampleRate, size_t order, FloatType normalisedTransitionWidth, FloatType stopBandWeight)
static FIRCoefficientsPtr designFIRLowpassKaiserMethod(FloatType frequency, double sampleRate, FloatType normalisedTransitionWidth, FloatType amplitudedB)
static IIRPolyphaseAllpassStructure designIIRLowpassHalfBandPolyphaseAllpassMethod(FloatType normalisedTransitionWidth, FloatType stopbandAmplitudedB)
static ReferenceCountedArray< IIRCoefficients > designIIRLowpassHighOrderChebyshev1Method(FloatType frequency, double sampleRate, FloatType normalisedTransitionWidth, FloatType passbandAmplitudedB, FloatType stopbandAmplitudedB)
static ReferenceCountedArray< IIRCoefficients > designIIRHighpassHighOrderButterworthMethod(FloatType frequency, double sampleRate, int order)
static FIRCoefficientsPtr designFIRLowpassTransitionMethod(FloatType frequency, double sampleRate, size_t order, FloatType normalisedTransitionWidth, FloatType spline)
static ReferenceCountedArray< IIRCoefficients > designIIRLowpassHighOrderChebyshev2Method(FloatType frequency, double sampleRate, FloatType normalisedTransitionWidth, FloatType passbandAmplitudedB, FloatType stopbandAmplitudedB)
static ReferenceCountedArray< IIRCoefficients > designIIRLowpassHighOrderEllipticMethod(FloatType frequency, double sampleRate, FloatType normalisedTransitionWidth, FloatType passbandAmplitudedB, FloatType stopbandAmplitudedB)
static FIRCoefficientsPtr designFIRLowpassHalfBandEquirippleMethod(FloatType normalisedTransitionWidth, FloatType amplitudedB)
static FIRCoefficientsPtr designFIRLowpassWindowMethod(FloatType frequency, double sampleRate, size_t order, WindowingMethod type, FloatType beta=static_cast< FloatType >(2))
static Complex< double > sne(Complex< double > u, double k) noexcept
static Complex< double > cde(Complex< double > u, double k) noexcept
static Complex< double > asne(Complex< double > w, double k) noexcept
static void ellipticIntegralK(double k, double &K, double &Kp) noexcept