JayBeams  0.1
Another project to have fun coding.
ut_time_delay_estimator.cpp
Go to the documentation of this file.
4 
5 #include <boost/test/unit_test.hpp>
6 #include <chrono>
7 
8 /**
9  * @test Verify that we can create and use a simple time delay estimator.
10  */
11 BOOST_AUTO_TEST_CASE(fftw_time_delay_estimator_simple) {
12  int const nsamples = 1 << 15;
13  int const delay = 1250;
14  typedef jb::fftw::aligned_vector<float> timeseries_type;
16 
17  timeseries_type a(nsamples);
18  timeseries_type b(nsamples);
19  tested estimator(a, b);
20 
23  a, std::chrono::microseconds(delay), std::chrono::microseconds(1));
24 
25  auto e = estimator.estimate_delay(a, b);
26  BOOST_CHECK_EQUAL(e.first, true);
27  BOOST_CHECK_CLOSE(e.second, double(delay), 0.01);
28 }
29 
30 /**
31  * @test Verify that jb::fftw::time_delay_estimator can handle edge conditions.
32  */
33 BOOST_AUTO_TEST_CASE(fftw_time_delay_estimator_error) {
34  int const nsamples = 1 << 15;
35  typedef jb::fftw::aligned_vector<float> timeseries_type;
37 
38  timeseries_type a = {0};
39  timeseries_type b = a;
40 
41  tested estimator(a, b);
42  auto e = estimator.estimate_delay(a, b);
43  BOOST_CHECK_EQUAL(e.first, false);
44 
45  b.resize(nsamples / 2);
46  BOOST_CHECK_THROW(estimator.estimate_delay(a, b), std::exception);
47 
48  BOOST_CHECK_THROW(tested tmp(a, b), std::exception);
49 }
timeseries_t delay_timeseries_periodic(timeseries_t const &ts, duration_t delay, duration_t sampling_period)
Delay a timeseries using a periodic extension for early values.
std::vector< T, jb::fftw::allocator< T > > aligned_vector
Alias std::vector with properly allocated storage for FFTW3.
A simple time delay estimator based on cross-correlation.
void create_square_timeseries(int nsamples, timeseries &ts)
Create a simple timeseries where the values look like a square.
std::size_t nsamples(container_type const &a)
Count the elements in the last dimension of a vector-like container.
BOOST_AUTO_TEST_CASE(fftw_time_delay_estimator_simple)