commit 029ce5697b4d740f6170fe41b76fa2fd313ac767
parent d725d23ea9f6b1e33fce7fd017c41c1d65cf62c7
Author: Stephen Larew <stephen@slarew.net>
Date: Fri, 28 Feb 2020 18:04:58 -0800
add stateless short_fir expression
Diffstat:
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/include/kfr/dsp/fir.hpp b/include/kfr/dsp/fir.hpp
@@ -257,6 +257,22 @@ short_fir(E1&& e1, const univector<T, TapCount>& taps)
std::forward<E1>(e1), taps);
}
+/**
+ * @brief Returns template expression that applies FIR filter to the input (count of coefficients must be in
+ * range 2..32)
+ * @param state FIR filter state
+ * @param e1 an input expression
+ */
+template <size_t TapCount, typename T, typename U, typename E1>
+KFR_INTRINSIC internal::expression_short_fir<next_poweroftwo(TapCount - 1) + 1, T, value_type_of<E1>, E1,
+ true>
+ short_fir(short_fir_state<next_poweroftwo(TapCount - 1) + 1, T, U>& state, E1&& e1)
+{
+ static_assert(TapCount >= 2 && TapCount <= 33, "Use short_fir only for small FIR filters");
+ return internal::expression_short_fir<next_poweroftwo(TapCount - 1) + 1, T, value_type_of<E1>, E1, true>(
+ std::forward<E1>(e1), state);
+}
+
template <typename T, typename U = T>
class fir_filter : public filter<U>
{
diff --git a/tests/dsp_test.cpp b/tests/dsp_test.cpp
@@ -418,6 +418,15 @@ TEST(fir)
return result;
});
+ short_fir_state<9, T> state2(taps);
+
+ CHECK_EXPRESSION(short_fir<taps.size()>(state2, data), 100, [&](size_t index) -> T {
+ T result = 0;
+ for (size_t i = 0; i < taps.size(); i++)
+ result += data.get(index - i, 0) * taps[i];
+ return result;
+ });
+
CHECK_EXPRESSION(moving_sum<taps.size()>(data), 100, [&](size_t index) -> T {
T result = 0;
for (size_t i = 0; i < taps.size(); i++)