You are correct. HDL Coder (and hardware modeling in general) does not support dynamic behavior in MATLAB code. All structural aspects such as the number of filters must be determined at compile time using non-tunable constants. For example, define MAX_Filters and other parameters that cannot be dynamic (like sizes of the arrays etc.,) as compile-time constants so the hardware can be synthesized correctly. You can use one of these two recommended patterns:
Pattern A – Parallel Filters with a Fixed Upper Bound
- Think of this as a filter bank where all filters run simultaneously.
- Decide on a maximum number of filters (e.g., 4) and create that many filter objects upfront.
- Every input sample passes through all filters in parallel, producing a vector of outputs (one per filter).
- Pros: Full throughput; all channels processed at once.
- Cons: Higher hardware resource usage.
Pattern B – One Filter, Time-Multiplexed
- Use a single filter object and store all coefficient sets.
- Switch coefficients after each sample or frame, cycling through channels in a round-robin fashion.
- Pros: Saves hardware resources (only one filter).
- Cons: Lower throughput because channels share the same filter over time.
- You also output a tag indicating which channel was processed.
Based on your input, where the number of filters is fixed after initialization but unknown beforehand, Pattern B might be your best choice. You can define a MAX_Filters constant and use up to that maximum based on an input variable. Additional control logic (e.g., valid and ready signals) can track which filter bank is being processed and manage data flow accordingly.
If you need help authoring this MATLAB code please do not hesitate to reach out to technical support team.