JayBeams  0.1
Another project to have fun coding.
create_square_timeseries.hpp
Go to the documentation of this file.
1 #ifndef jb_testing_create_square_timeseries_hpp
2 #define jb_testing_create_square_timeseries_hpp
3 
5 
6 namespace jb {
7 namespace testing {
8 
9 /**
10  * Create a simple timeseries where the values look like a square.
11  */
12 template <typename timeseries>
13 void create_square_timeseries(int nsamples, timeseries& ts) {
14  resize_if_applicable(ts, nsamples);
15  typedef typename timeseries::value_type value_type;
16  for (int i = 0; i != nsamples; ++i) {
17  if (i < nsamples / 4) {
18  ts[i] = value_type(-100);
19  } else if (i < 3 * nsamples / 4) {
20  ts[i] = value_type(+100);
21  } else {
22  ts[i] = value_type(-100);
23  }
24  }
25 }
26 
27 } // namespace testing
28 } // namespace jb
29 
30 #endif // jb_testing_create_square_timeseries_hpp
void resize_if_applicable(timeseries &ts, std::size_t newsize, std::true_type)
Resize a timeseries to a newsize.
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.
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7