フィルターのクリア

Composite System Object for Code Generation or use in Simulink

2 ビュー (過去 30 日間)
Constantin Runge
Constantin Runge 2018 年 11 月 27 日
コメント済み: Honglei Chen 2018 年 11 月 27 日
I've built a composite System Object with the goal, to provide a 'parallel' FIR filter with a parameterizable number of parallel channels to my Simulink model:
classdef ParallelFIR < matlab.System
% parallel_fir takes a matrix of taps and applies them to matrices of
% inputs, where each matrix column is a channel
% Public, tunable properties
properties
Taps = [0.5 0.5; 0.5 0.5];
end
properties(Access = private)
fir_channel
end
methods
function obj = ParallelFIR(varargin)
if nargin == 1
setProperties(obj, 2, 'Taps', varargin{1});
else
setProperties(obj, nargin, varargin{:});
end
end
end
methods(Access = protected)
function setupImpl(obj)
c = size(obj.Taps, 1);
obj.fir_channel = cell(c, 1);
for i = 1:c
obj.fir_channel{i} = dsp.FIRFilter(obj.Taps(i,:));
end
end
function validateInputsImpl(obj, in)
assert(size(in, 1) == size(obj.Taps, 1), "taps and input are required to have the same number of channels");
end
function y = stepImpl(obj,u)
y = zeros(size(u));
for i = 1:size(obj.Taps, 1)
y(i,:) = step(obj.fir_channel{i}, u(i,:));
end
end
function resetImpl(obj)
for i = 1:size(obj.Taps, 1)
reset(obj.fir_channel{i});
end
end
end
end
Whenever I try to use the system object in a Simulink MATLAB System Block or to generate C++ code for a script using the system object, I get the following error:
Cannot compute constant value for argument #1 for this System object constructor. All arguments to the constructor of this System object must be constants for code generation. One way to supply a constant value is to pass it to the main function using Simulink non-tunable parameters (for MATLAB Function block) or coder.newtype('constant',...) (for MATLAB Coder). The error occurred for MATLAB System block 'Subsystem/MATLAB System'. See line 29, column 38 in file 'ParallelFIR.m'.
Line 29 is the one with
obj.fir_channel{i} = dsp.FIRFilter(obj.Taps(i,:));
How can I implement the parallel FIR to be usable for Simulink System Blocks?

採用された回答

Honglei Chen
Honglei Chen 2018 年 11 月 27 日
編集済み: Honglei Chen 2018 年 11 月 27 日
If you don't intend to change your Taps during the simulation, you may want to consider setting it as Nontunable, like
properties (Nontunable)
Taps = [0.5 0.5; 0.5 0.5];
end
Also it may be helpful to share your code generation script as well as your code generation command.
HTH
  4 件のコメント
Constantin Runge
Constantin Runge 2018 年 11 月 27 日
Thank you very much. Where can I find the objects implementation?
Yes, the Discrete FIR Filter Block does support multiple filters. But only for sample-based processing. I am working in a frame-based domain. Thus I believe I have to implement my own multi-channel FIR.
Honglei Chen
Honglei Chen 2018 年 11 月 27 日
Oh, sorry, I mean the doc
See where they talked about NumeratorSource.
HTH

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with DSP System Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by