3 #include "utilities/foldl.h" 4 #include "utilities/map.h" 19 constexpr
auto make_item_and_index(T item,
size_t index) {
23 template <
typename T,
size_t... Ix>
24 constexpr
auto zip_with_indices(
const std::array<T,
sizeof...(Ix)>& arr,
25 std::index_sequence<Ix...>) {
26 return std::array<item_and_index<T>,
sizeof...(Ix)>{
27 {make_item_and_index(std::get<Ix>(arr), Ix)...}};
30 template <
typename T,
size_t N>
31 constexpr
auto zip_with_indices(
const std::array<T, N>& arr) {
32 return zip_with_indices(arr, std::make_index_sequence<N>{});
38 auto freqz(
const std::array<double, N>& coeffs,
double frequency) {
40 [&](
const auto& accumulator,
const auto& item) {
41 using namespace std::complex_literals;
43 item.item * std::exp(-1i * frequency *
44 static_cast<double>(item.index));
47 zip_with_indices(coeffs));
50 template <
size_t B,
size_t A>
51 auto freqz(
const std::array<double, B>& b_coeffs,
52 const std::array<double, A>& a_coeffs,
54 return freqz(b_coeffs, frequency) / freqz(a_coeffs, frequency);
57 template <
size_t N,
size_t O>
58 auto freqz(
const std::array<double, N>& coeffs,
59 const std::array<double, O>& frequencies) {
60 return map([&](
const auto& f) {
return freqz(coeffs, f); }, frequencies);
63 template <
size_t B,
size_t A,
size_t O>
64 auto freqz(
const std::array<double, B>& b_coeffs,
65 const std::array<double, A>& a_coeffs,
66 const std::array<double, O>& frequencies) {
67 return map([&](
const auto& f) {
return freqz(b_coeffs, a_coeffs, f); },
Definition: capsule_base.h:9