kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 0aa56368555fb72807418253a4d9bd1bebbd75a7
parent c3217b1775632eb80da59c5923c9b9114d69c54b
Author: [email protected] <[email protected]>
Date:   Tue, 20 Nov 2018 09:11:13 +0300

More tests for FIR filters

Diffstat:
Mtests/dsp_test.cpp | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+), 0 deletions(-)

diff --git a/tests/dsp_test.cpp b/tests/dsp_test.cpp @@ -10,6 +10,7 @@ #include <kfr/dsp.hpp> #include <kfr/io.hpp> +#include <complex> #include <numeric> using namespace kfr; @@ -306,6 +307,59 @@ TEST(fir) }); } +TEST(fir_different) +{ + const univector<float, 100> data = counter() + sequence(1, 2, -10, 100) + sequence(0, -7, 0.5f); + const univector<double, 6> taps{ 1, 2, -2, 0.5, 0.0625, 4 }; + + CHECK_EXPRESSION(fir(data, taps), 100, [&](size_t index) -> float { + double result = 0.0; + for (size_t i = 0; i < taps.size(); i++) + result += data.get(index - i, 0.0) * taps[i]; + return float(result); + }); + + CHECK_EXPRESSION(short_fir(data, taps), 100, [&](size_t index) -> float { + double result = 0.0; + for (size_t i = 0; i < taps.size(); i++) + result += data.get(index - i, 0.0) * taps[i]; + return float(result); + }); +} + +template <typename T> +inline std::complex<T> to_std(const kfr::complex<T>& c) +{ + return { c.re, c.im }; +} + +template <typename T> +inline kfr::complex<T> from_std(const std::complex<T>& c) +{ + return { c.real(), c.imag() }; +} + +TEST(fir_complex) +{ + const univector<complex<float>, 100> data = + counter() * complex<float>{ 0.f, 1.f } + sequence(1, 2, -10, 100) + sequence(0, -7, 0.5f); + const univector<float, 6> taps{ 1, 2, -2, 0.5, 0.0625, 4 }; + + CHECK_EXPRESSION(fir(data, taps), 100, [&](size_t index) -> complex<float> { + std::complex<float> result = 0.0; + for (size_t i = 0; i < taps.size(); i++) + result = result + to_std(data.get(index - i, 0.0)) * taps[i]; + return from_std(result); + }); + + CHECK_EXPRESSION(short_fir(data, taps), 100, [&](size_t index) -> complex<float> { + std::complex<float> result = 0.0; + for (size_t i = 0; i < taps.size(); i++) + result = result + to_std(data.get(index - i, 0.0)) * taps[i]; + return from_std(result); + }); +} + #ifndef KFR_NO_MAIN int main() {