tttapa / Arduino-Filters

Arduino Finite Impulse Response and Infinite Impulse Response filter implementations.
GNU General Public License v3.0
115 stars 15 forks source link

List of Filters #1

Closed zachbellay closed 3 years ago

zachbellay commented 3 years ago

Hello,

Thank you for this wonderful library, I was hoping to use an array of butterworth filters, but my C++ skills aren't up to par to debug this issue. What I want is very simple:

auto filters[7]={butter<10>(f_n),butter<10>(f_n),butter<10>(f_n),butter<10>(f_n),butter<10>(f_n),butter<10>(f_n),butter<10>(f_n)};

and here is the resulting compilation error:

unable to deduce 'std::initializer_list<_Tp> [7]' from '{butter<10u, float, BiQuadFilterDF1<float> >(1.0e+0, 1), butter<10u, float, BiQuadFilterDF1<float> >(1.0e+0, 1), butter<10u, float, BiQuadFilterDF1<float> >(1.0e+0, 1), butter<10u, float, BiQuadFilterDF1<float> >(1.0e+0, 1), butter<10u, float, BiQuadFilterDF1<float> >(1.0e+0, 1), butter<10u, float, BiQuadFilterDF1<float> >(1.0e+0, 1), butter<10u, float, BiQuadFilterDF1<float> >(1.0e+0, 1)}'

Any help would be appreciated, thanks.

tttapa commented 3 years ago

AFAIK, you cannot use auto for array declarations. You could use something like this:

using filter_t = decltype(butter<10>(f_n));
filter_t filters[] = {
  butter<10>(f_n), butter<10>(f_n), butter<10>(f_n), butter<10>(f_n),
  butter<10>(f_n), butter<10>(f_n), butter<10>(f_n),
};
zachbellay commented 3 years ago

Awesome! Thank you for the quick reply, this solved the issue. Thank you so much!