1+ #pragma once
2+
3+ #include < dsplib/array.h>
4+
5+ #include < cassert>
6+ #include < memory>
7+
8+ namespace dsplib {
9+
10+ class ChannelizerImpl ;
11+
12+ // TODO: use decim factor in matlab style (M/D)
13+
14+ /* *
15+ * @brief Polyphase FFT analysis filter bank
16+ * @details Separates a broadband input signal into multiple narrow subbands
17+ * @see Matlab dsp.Channelizer
18+ * @todo Add `Range` parameter [OneSided, Twosided, Centered]
19+ */
20+ class Channelizer
21+ {
22+ public:
23+ Channelizer (const Channelizer&) = delete ;
24+
25+ /* *
26+ * @brief Construct Channelizer
27+ *
28+ * @param filter Multirate FIR coeffs [num_bands * ntaps]
29+ * @param num_bands Number of frequency bands
30+ * @param decim_factor Decimation factor [1 : M-1]
31+ */
32+ explicit Channelizer (const arr_real& filter, int num_bands, int decim_factor);
33+
34+ /* *
35+ * @brief Construct Channelizer
36+ * @details Use this function to save memory if multiple Channelizer/ChannelSynthesizer objects can exist at the same time
37+ * @param filter Pointer to multirate FIR coeffs
38+ * @param num_bands Number of frequency bands
39+ * @param decim_factor Decimation factor [1 : M-1]
40+ */
41+ explicit Channelizer (std::shared_ptr<const arr_real> filter, int num_bands, int decim_factor);
42+
43+ /* *
44+ * @brief Construct Channelizer
45+ * @details The filter will be calculated using the `design_multirate_fir(1, num_bands, ceil(num_taps / 2.0))`
46+ * @param num_bands Number of frequency bands
47+ * @param decim_factor Decimation factor [1 : M-1]
48+ * @param num_taps Number of filter coefficients per frequency band (expected to be even)
49+ */
50+ explicit Channelizer (int num_bands, int decim_factor, int num_taps);
51+
52+ /* *
53+ * @brief Filter bank processing (analysis)
54+ * @param x Input broadband signal [num_bands / decim_factor]
55+ * @return arr_cmplx Subband signal [num_bands]
56+ */
57+ [[nodiscard]] arr_cmplx process (const arr_real& x);
58+
59+ arr_cmplx operator ()(const arr_real& x) {
60+ return this ->process (x);
61+ }
62+
63+ /* *
64+ * @brief Processing frame size
65+ * @return int frame len
66+ */
67+ [[nodiscard]] int frame_len () const noexcept ;
68+
69+ private:
70+ std::shared_ptr<ChannelizerImpl> d_;
71+ };
72+
73+ class ChannelSynthesizerImpl ;
74+
75+ /* *
76+ * @brief Polyphase FFT synthesis filter bank
77+ * @details Ideally ChannelSynthesizer(Channelizer(x)) == x.
78+ * @see Matlab dsp.ChannelSynthesizer
79+ * @warning This implementation differs from matlab in the decimation parameter. For decim_factor=1, the results should be identical.
80+ * @todo remove num_taps if filter is calculated
81+ * @todo params order (bands, decim, ntaps/coeffs)
82+ */
83+ class ChannelSynthesizer
84+ {
85+ public:
86+ ChannelSynthesizer (const ChannelSynthesizer&) = delete ;
87+
88+ /* *
89+ * @brief Construct ChannelSynthesizer
90+ *
91+ * @param filter Multirate FIR coeffs [num_bands * ntaps]
92+ * @param num_bands Number of frequency bands
93+ * @param decim_factor Decimation factor [1 : M-1]
94+ */
95+ explicit ChannelSynthesizer (const arr_real& filter, int num_bands, int decim_factor);
96+
97+ /* *
98+ * @brief Construct ChannelSynthesizer
99+ * @details Use this function to save memory if multiple Channelizer/ChannelSynthesizer objects can exist at the same time
100+ * @param filter Pointer to multirate FIR coeffs
101+ * @param num_bands Number of frequency bands
102+ * @param decim_factor Decimation factor [1 : M-1]
103+ */
104+ explicit ChannelSynthesizer (std::shared_ptr<const arr_real> filter, int num_bands, int decim_factor);
105+
106+ /* *
107+ * @brief Construct ChannelSynthesizer
108+ * @details The filter will be calculated using the `design_multirate_fir(1, num_bands, ceil(num_taps / 2.0))`
109+ * @param num_bands Number of frequency bands
110+ * @param decim_factor Decimation factor [1 : M-1]
111+ * @param num_taps Number of filter coefficients per frequency band (expected to be even)
112+ */
113+ explicit ChannelSynthesizer (int num_bands, int decim_factor, int num_taps);
114+
115+ /* *
116+ * @brief Filter bank processing (synthesis)
117+ * @param x Input subband signal [num_bands]
118+ * @return arr_cmplx Restored broadband signal [num_bands / decim_factor]
119+ */
120+ [[nodiscard]] arr_real process (const arr_cmplx& x);
121+
122+ arr_real operator ()(const arr_cmplx& x) {
123+ return this ->process (x);
124+ }
125+
126+ /* *
127+ * @brief Processing frame size
128+ * @return int frame len
129+ */
130+ [[nodiscard]] int frame_len () const noexcept ;
131+
132+ private:
133+ std::shared_ptr<ChannelSynthesizerImpl> d_;
134+ };
135+
136+ } // namespace dsplib
0 commit comments