commit 56f4aea6c6fb2716543f806193e19e883e34e914
parent dc1f7e4e50d56d4ce4c5fd5bfaf68d80178ffc2e
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date: Fri, 19 Aug 2016 22:10:40 +0300
Add documentation for biquad filter functions
Diffstat:
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/include/kfr/dsp/biquad.hpp b/include/kfr/dsp/biquad.hpp
@@ -44,6 +44,9 @@ enum class biquad_type
highshelf
};
+/**
+ * @brief Structure for holding biquad filter coefficients.
+ */
template <typename T>
struct biquad_params
{
@@ -162,12 +165,24 @@ struct expression_biquads : public expression<E1>
};
}
+/**
+ * @brief Returns template expressions that applies biquad filter to the input.
+ * @param bq Biquad coefficients
+ * @param e1 Input expression
+ */
template <typename T, typename E1>
CMT_INLINE internal::expression_biquads<1, T, internal::arg<E1>> biquad(const biquad_params<T>& bq, E1&& e1)
{
const biquad_params<T> bqs[1] = { bq };
return internal::expression_biquads<1, T, internal::arg<E1>>(bqs, std::forward<E1>(e1));
}
+
+/**
+ * @brief Returns template expressions that applies cascade of biquad filters to the input.
+ * @param bq Array of biquad coefficients
+ * @param e1 Input expression
+ * @note The current implementation introduces delay of N - 1 samples, where N is the filter count.
+ */
template <size_t filters, typename T, typename E1>
CMT_INLINE internal::expression_biquads<filters, T, internal::arg<E1>> biquad(
const biquad_params<T> (&bq)[filters], E1&& e1)
diff --git a/include/kfr/dsp/biquad_design.hpp b/include/kfr/dsp/biquad_design.hpp
@@ -31,6 +31,12 @@
namespace kfr
{
+/**
+ * @brief Calculates coefficients for the all-pass biquad filter
+ * @param frequency Normalized frequency (frequency_Hz / samplerate_Hz)
+ * @param Q Q factor
+ * @return Biquad filter coefficients
+ */
template <typename T = fbase>
CMT_INLINE biquad_params<T> biquad_allpass(identity<T> frequency, identity<T> Q)
{
@@ -46,6 +52,12 @@ CMT_INLINE biquad_params<T> biquad_allpass(identity<T> frequency, identity<T> Q)
return { b0, b1, b2, a0, a1, a2 };
}
+/**
+ * @brief Calculates coefficients for the low-pass biquad filter
+ * @param frequency Normalized frequency (frequency_Hz / samplerate_Hz)
+ * @param Q Q factor
+ * @return Biquad filter coefficients
+ */
template <typename T = fbase>
CMT_INLINE biquad_params<T> biquad_lowpass(identity<T> frequency, identity<T> Q)
{
@@ -60,6 +72,12 @@ CMT_INLINE biquad_params<T> biquad_lowpass(identity<T> frequency, identity<T> Q)
return { 1.0, b1, b2, a0, a1, a2 };
}
+/**
+ * @brief Calculates coefficients for the high-pass biquad filter
+ * @param frequency Normalized frequency (frequency_Hz / samplerate_Hz)
+ * @param Q Q factor
+ * @return Biquad filter coefficients
+ */
template <typename T = fbase>
CMT_INLINE biquad_params<T> biquad_highpass(identity<T> frequency, identity<T> Q)
{
@@ -74,6 +92,12 @@ CMT_INLINE biquad_params<T> biquad_highpass(identity<T> frequency, identity<T> Q
return { 1.0, b1, b2, a0, a1, a2 };
}
+/**
+ * @brief Calculates coefficients for the band-pass biquad filter
+ * @param frequency Normalized frequency (frequency_Hz / samplerate_Hz)
+ * @param Q Q factor
+ * @return Biquad filter coefficients
+ */
template <typename T = fbase>
CMT_INLINE biquad_params<T> biquad_bandpass(identity<T> frequency, identity<T> Q)
{
@@ -88,6 +112,12 @@ CMT_INLINE biquad_params<T> biquad_bandpass(identity<T> frequency, identity<T> Q
return { 1.0, b1, b2, a0, a1, a2 };
}
+/**
+ * @brief Calculates coefficients for the notch biquad filter
+ * @param frequency Normalized frequency (frequency_Hz / samplerate_Hz)
+ * @param Q Q factor
+ * @return Biquad filter coefficients
+ */
template <typename T = fbase>
CMT_INLINE biquad_params<T> biquad_notch(identity<T> frequency, identity<T> Q)
{
@@ -102,6 +132,13 @@ CMT_INLINE biquad_params<T> biquad_notch(identity<T> frequency, identity<T> Q)
return { 1.0, b1, b2, a0, a1, a2 };
}
+/**
+ * @brief Calculates coefficients for the peak biquad filter
+ * @param frequency Normalized frequency (frequency_Hz / samplerate_Hz)
+ * @param Q Q factor
+ * @param gain Gain in dB
+ * @return Biquad filter coefficients
+ */
template <typename T = fbase>
CMT_INLINE biquad_params<T> biquad_peak(identity<T> frequency, identity<T> Q, identity<T> gain)
{
@@ -133,6 +170,12 @@ CMT_INLINE biquad_params<T> biquad_peak(identity<T> frequency, identity<T> Q, id
return result;
}
+/**
+ * @brief Calculates coefficients for the low-shelf biquad filter
+ * @param frequency Normalized frequency (frequency_Hz / samplerate_Hz)
+ * @param gain Gain in dB
+ * @return Biquad filter coefficients
+ */
template <typename T = fbase>
CMT_INLINE biquad_params<T> biquad_lowshelf(identity<T> frequency, identity<T> gain)
{
@@ -164,6 +207,12 @@ CMT_INLINE biquad_params<T> biquad_lowshelf(identity<T> frequency, identity<T> g
return result;
}
+/**
+ * @brief Calculates coefficients for the high-shelf biquad filter
+ * @param frequency Normalized frequency (frequency_Hz / samplerate_Hz)
+ * @param gain Gain in dB
+ * @return Biquad filter coefficients
+ */
template <typename T = fbase>
CMT_INLINE biquad_params<T> biquad_highshelf(identity<T> frequency, identity<T> gain)
{