I want to generate HDL from a System Object that contains several dsp.FIRFilter objects, the number of which is determined by a Nontunable property

38 views (last 30 days)
I'm trying to develop a generic System Object that utilizes dsp.FIRFilter objects. I want my class to determine and construct the number of dsp.FIRFilter objects required and compute their corresponding coefficient sets from a fixed, NonTunable property value.
My first thought was to allocate a cell array of dsp.FIRFIlter objects in setupImpl(), but this is not supported for HDL generation, as described in the documentation, here. The examples linked there all create properties for each individual object, which doesn't help for this use case, where the number is not known a priori, but is fixed during initiialization.
Is there a recommended way to accomplish what I'm trying to do without cell arrays?
Thanks!
Paul

Answers (1)

Kiran Kintali
Kiran Kintali on 19 Dec 2025 at 1:52
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.

Categories

Find more on Code Generation in Help Center and File Exchange

Products


Release

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!