System Object Variable Size Tuneable Properties
Ältere Kommentare anzeigen
I am new to system objects, but need to develop one to do some stream processing of incoming data. Part of the algorithm I am developing depends on buffering blocks of data for processing. I need these blocks to be overlapping for the processing. For this reason, I am trying to build a property of my system object that holds a buffer of data, from which I can cleave and process when there are a sufficient number of samples in the buffer.
The trouble I am having is deailing with variable sizes in my tuneable properties list. My object seems to run fine in Matlab, but when I try to deploy it in simulink I get size mismatch errors. The example below tries to create a u_hold proprty used to hold data sent to the step method. The object definition is at the end of this question. I try to initialize it as an empty matrix because and then add to that matrix as data comes in. I would obviously add code later to clear out u_hold when it reached a certain size, but I am not there yet.
Here is how I would call this function in Matlab - it seems to work - u_hold get concatinated.
>> blah = detection
blah =
detection with properties:
u_hold: [0×1 double]
>> out = blah([1 2 3 4]')
out =
1
2
3
4
>> out = blah([1 2 3 4]')
out =
1
2
3
4
>> blah.u_hold
ans =
1
2
3
4
1
2
3
4
If I try to throw this in Simulink and feed it audio data like this:

I get the following Simulink errors:
% An error occurred in the block 'detect_play/MATLAB System' during compile.
% Caused by:
% Simulink detected an error
% 'Size mismatch (size [1 x 1] ~= size [0 x 1]).
% The size to the left is the size of the left-hand side of the assignment.'.
%
% The error occurred for MATLAB System block 'detect_play/MATLAB System'. See line 26, column 13 in file '/Users/mshafer/Dropbox (NAU)/UAV-RT Team/CODE/SYSTEM OBJECT EXPLORATION/detection.m'. The error was detected during code generation phase.
% Start code generation report.
%
% To prevent this error, use one of the following:
% * Modify the System object to avoid code that does not support code generation.
% * Implement propagation methods in the System object code.
% Component:Simulink | Category:Block error
If anyone could help my figure out how to allow for the u_hold propery to expand in size during each call to the system object step while in Simulink, I would appreciate it!
classdef detection < matlab.System
% Public, tunable properties
properties
u_hold(:,1){mustBeNumeric}=[];
end
properties(DiscreteState)
end
% Pre-computed constants
properties(Access = private)
end
methods(Access = protected)
function setupImpl(obj)
% Perform one-time calculations, such as computing constants
end
function [y] = stepImpl(obj,u)
% Implement algorithm. Calculate y as a function of input u and
% discrete states.
obj.u_hold = [obj.u_hold;u];
y = u;
end
function resetImpl(obj)
% Initialize / reset discrete-state properties
obj.u_hold=[];
end
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Create System Objects finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!