Hi, I'm trying to write a simple class which handles the short-time window signals…I've a strange problem which I can't find out the cause:
the field stws is not created in the instanciated object and cause strange problems. My question is why instanciating object with or without input signal cause to elimination of this crucial part for example if you consider this test code:
close all clear all clear classes close all clc
n = 1:100;x = sin(n);a = ShortTimeWinSig(x);
this goes without error but you don't have any field, the object is empty and hence this command lead to error!!!! a.stws
Error:
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)to change the limit. Be aware that exceeding your available stack space cancrash MATLAB and/or your computer.Error in ShortTimeWinSig/get.stws
The Code (ShortTimeWinSig.m):
classdef ShortTimeWinSig % this class handels short time windowed signal.
%%Properties
properties (GetAccess = public, SetAccess = public) stws % the short-time windowed signal
winType = @hamming % window type
winLen % window length
end properties (Dependent = true, SetAccess = private) len end %%Methods
methods % constructor
function obj = ShortTimeWinSig(x,windowHandle,windowLength) if nargin>0 obj.stws = x; if exist('windowHandle','var') obj.winType = windowHandle; else obj.winType = @hamming; end if exist('windowLength','var') obj.winLen = windowLength; else obj.winLen = floor(length(x)/8); end else obj.stws = sin(1:100); end end % designed such that the object is put on the output and
% automatically before this, the signal will be calculated again
% using the updated window parameter.
function y = get.stws(obj) numSeg = ceil(obj.len/obj.winLen); % number of segments
if size(obj.stws,1)>1 origSig = obj.stws.'; origSig = origSig.'; else origSig = obj.stws; end y = zeros(numSeg,obj.winLen); for i=1:numSeg y(i,:) = origSig((i-1)*obj.winLen+1:i*obj.winLen); end end % get.stws
function y = get.winType(obj) if ~isa(obj,'ShortTimeWinSig') error('the input argument should be "ShortTimeWinSig" object'); else y = obj.winType; end end % get.winType
function y = get.len(obj) if ~isa(obj,'ShortTimeWinSig') error('the input argument should be "ShortTimeWinSig" object'); else y = size(obj.stws,1)*size(obj.stws,2); end end % get.len
function y = get.winLen(obj) if ~isa(obj,'ShortTimeWinSig') error('the input argument should be "ShortTimeWinSig" object'); else y = size(obj.winLen,1)*size(obj.winLen,2); end end % get.len function obj = set.stws(obj,x) if isa(x,'ShortTimeWinSig') obj.stws = x.stws; else obj.stws = x; end end % set.stws
function obj = set.winType(obj,val) if ~isa(obj,'ShortTimeWinSig') error('the input argument should be "ShortTimeWinSig" object'); else if ~isa(val,'function_handle') error('the value assigned should be function hadle type') else obj.winType = val; end end end % set.winType
function obj = set.len(obj,~) fprintf( '%s%d\n' , 'signal length is: ',obj.len) error( 'You cannot set Modulus explicitly'); end function obj = set.winLen(obj,val) if ~isa(obj,'ShortTimeWinSig') error('the input argument should be "ShortTimeWinSig" object'); else obj.winLen = val; end end % set.winLen
end
end
Best Answer