matlab s function
hi , I want to develope digital filter in simulink using s-function..I tried Level -2 M file but not getting the filtered output ..here is sfunction I have developed ...pls help me ,I am stuck with this code from many days ....
function filtsfcn(block)
%MSFUNTMPL_BASIC A template for a Leve-2 M-file S-function
% The M-file S-function is written as a MATLAB function with the
% same name as the S-function. Replace 'msfuntmpl_basic' with the
% name of your S-function.
%
% It should be noted that the M-file S-function is very similar
% to Level-2 C-Mex S-functions. You should be able to get more
% information for each of the block methods by referring to the
% documentation for C-Mex S-functions.
%
% Copyright 2003-2007 The MathWorks, Inc.
%%
%% The setup method is used to setup the basic attributes of the
%% S-function such as ports, parameters, etc. Do not add any other
%% calls to the main body of the function.
%%
setup(block);
%endfunction
%% Function: setup ===================================================
%% Abstract:
%% Set up the S-function block's basic characteristics such as:
%% - Input ports
%% - Output ports
%% - Dialog parameters
%% - Options
%%
%% Required : Yes
%% C-Mex counterpart: mdlInitializeSizes
%%
function setup(block)
% Register number of ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).DirectFeedthrough = false;
% Override output port properties
block.OutputPort(1).Dimensions = 1;
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
% Register parameters
block.NumDialogPrms = 0;
% Register sample times
% [0 offset] : Continuous sample time
% [positive_num offset] : Discrete sample time
%
% [-1, 0] : Inherited sample time
% [-2, 0] : Variable sample time
block.SampleTimes = [-1 0];
% Specify the block simStateComliance. The allowed values are:
% 'UnknownSimState', < The default setting; warn and assume DefaultSimState
% 'DefaultSimState', < Same sim state as a built-in block
% 'HasNoSimState', < No sim state
% 'CustomSimState', < Has GetSimState and SetSimState methods
% 'DisallowSimState' < Error out when saving or restoring the model sim state
block.SimStateCompliance = 'DefaultSimState';
%%
%% The M-file S-function uses an internal registry for all
%% block methods. You should register all relevant methods
%% (optional and required) as illustrated below. You may choose
%% any suitable name for the methods and implement these methods
%% as local functions within the same file. See comments
%% provided for each function for more information.
%%
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
%block.RegBlockMethod('InitializeConditions', @InitializeConditions);
%block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Update', @Update);
%block.RegBlockMethod('Derivatives', @Derivatives);
block.RegBlockMethod('Terminate', @Terminate); % Required
%end setup
%%
%% PostPropagationSetup:
%% Functionality : Setup work areas and state variables. Can
%% also register run-time methods here
%% Required : No
%% C-Mex counterpart: mdlSetWorkWidths
%%
function DoPostPropSetup(block)
block.NumDworks = 1;
block.Dwork(1).Name = 'x1';
block.Dwork(1).Dimensions = 1;
block.Dwork(1).DatatypeID = 0; % double
block.Dwork(1).Complexity = 'Real'; % real
block.Dwork(1).UsedAsDiscState = true;
%%
%% InitializeConditions:
%% Functionality : Called at the start of simulation and if it is
%% present in an enabled subsystem configured to reset
%% states, it will be called when the enabled subsystem
%% restarts execution to reset the states.
%% Required : No
%% C-MEX counterpart: mdlInitializeConditions
%%
%function InitializeConditions(block)
%end InitializeConditions
%%
%% Start:
%% Functionality : Called once at start of model execution. If you
%% have states that should be initialized once, this
%% is the place to do it.
%% Required : No
%% C-MEX counterpart: mdlStart
%%
%function Start(block)
%block.Dwork(1).Data =
%endfunction
%%
%% Outputs:
%% Functionality : Called to generate block outputs in
%% simulation step
%% Required : Yes
%% C-MEX counterpart: mdlOutputs
%%
function Outputs(block)
block.OutputPort(1).Data = filter( [7.93950335016002e-005 4.2068444340919e-006 -0.000192833379464789 -0.000639122448022129 -0.00139707444307587 -0.00245625245399633 -0.00370071518169793 -0.0049066202014346 -0.00578002124120443 -0.00603295917787244 -0.00547897231748479 -0.00411607679985946 -0.0021644268397023 -3.41151281310269e-005 0.00177669441966399 0.00282864008648444 0.00288532864900338 0.00200322543812317 0.00052791992197702 -0.00101045402113809 -0.00207327082028958 -0.00230087264141553 -0.00164250432166114 -0.000376548748319844 0.000992158389182175 0.00192389609569889 0.00205368715570095 0.00133692890809704 7.09123507658864e-005 -0.00122089543005666 -0.00199936988544874 -0.00193221462627573 -0.00103679310801218 0.000318922930572234 0.00156285350822139 0.00215635616405561 0.00182547026198189 0.00068711256245219 -0.000788041001845299 -0.00196661448017079 -0.00232160775370418 -0.00166615668621754 -0.000248956972605352 0.00133647515911177 0.00239740941345114 0.00244209603696065 0.00140539572248529 -0.000302806772506288 -0.00195632132004645 -0.00281867778410291 -0.00246866362264886 -0.00100249403036538 0.00098310577365351 0.00263056426311881 0.0031891567771482 0.00235421045051084 0.000425777060022136 -0.00179327945832978 -0.00332828637333227 -0.00345790226068029 -0.00204923287907303 0.000351178678769648 0.00272431905459656 0.00400772058787193 0.00356746061696794 0.00150506012483035 -0.00134686211083758 -0.00375566596981736 -0.0046172068904128 -0.00345699502532703 -0.000678639915161797 0.00256597670678413 0.00484868569361424 0.00508824668524873 0.00305516079615843 -0.000474560482744197 -0.00400637337637883 -0.00595320314692646 -0.00534118618373109 -0.00228451312765527 0.0019972819148517 0.00565594846286424 0.00700322556346544 0.00527892119682813 0.00105361092242717 -0.00393808271116019 -0.00749696389711814 -0.00791476478226187 -0.00477616650564779 0.000761723991922121 0.00637423242508511 0.00952674941087938 0.00859807134200253 0.00368051904917151 -0.00332472830390768 -0.00941442975531867 -0.0117411832315303 -0.0089073424723017 -0.00172250015567689 0.0069579319097193 0.0133222725798866 0.0142215884784255 0.00865167506326345 -0.00156895989264316 -0.0123030986545982 -0.0186808489252971 -0.0171895004967254 -0.0074140307817742 0.00736324912433382 0.0210944914523893 0.0272186347440778 0.0214530755204663 0.00404061000292739 -0.0195239439917389 -0.0397552390592479 -0.0461603078788305 -0.0309883180308153 0.00757800611716887 0.06400620904665 0.126418851837905 0.179824501208783 0.210574563887124 0.210574563887124 0.179824501208783 0.126418851837905 0.06400620904665 0.00757800611716887 -0.0309883180308153 -0.0461603078788305 -0.0397552390592479 -0.0195239439917389 0.00404061000292739 0.0214530755204663 0.0272186347440778 0.0210944914523893 0.00736324912433382 -0.0074140307817742 -0.0171895004967254 -0.0186808489252971 -0.0123030986545982 -0.00156895989264316 0.00865167506326345 0.0142215884784255 0.0133222725798866 0.0069579319097193 -0.00172250015567689 -0.0089073424723017 -0.0117411832315303 -0.00941442975531867 -0.00332472830390768 0.00368051904917151 0.00859807134200253 0.00952674941087938 0.00637423242508511 0.000761723991922121 -0.00477616650564779 -0.00791476478226187 -0.00749696389711814 -0.00393808271116019 0.00105361092242717 0.00527892119682813 0.00700322556346544 0.00565594846286424 0.0019972819148517 -0.00228451312765527 -0.00534118618373109 -0.00595320314692646 -0.00400637337637883 -0.000474560482744197 0.00305516079615843 0.00508824668524873 0.00484868569361424 0.00256597670678413 -0.000678639915161797 -0.00345699502532703 -0.0046172068904128 -0.00375566596981736 -0.00134686211083758 0.00150506012483035 0.00356746061696794 0.00400772058787193 0.00272431905459656 0.000351178678769648 -0.00204923287907303 -0.00345790226068029 -0.00332828637333227 -0.00179327945832978 0.000425777060022136 0.00235421045051084 0.0031891567771482 0.00263056426311881 0.00098310577365351 -0.00100249403036538 -0.00246866362264886 -0.00281867778410291 -0.00195632132004645 -0.000302806772506288 0.00140539572248529 0.00244209603696065 0.00239740941345114 0.00133647515911177 -0.000248956972605352 -0.00166615668621754 -0.00232160775370418 -0.00196661448017079 -0.000788041001845299 0.00068711256245219 0.00182547026198189 0.00215635616405561 0.00156285350822139 0.000318922930572234 -0.00103679310801218 -0.00193221462627573 -0.00199936988544874 -0.00122089543005666 7.09123507658864e-005 0.00133692890809704 0.00205368715570095 0.00192389609569889 0.000992158389182175 -0.000376548748319844 -0.00164250432166114 -0.00230087264141553 -0.00207327082028958 -0.00101045402113809 0.00052791992197702 0.00200322543812317 0.00288532864900338 0.00282864008648444 0.00177669441966399 -3.41151281310269e-005 -0.0021644268397023 -0.00411607679985946 -0.00547897231748479 -0.00603295917787244 -0.00578002124120443 -0.0049066202014346 -0.00370071518169793 -0.00245625245399633 -0.00139707444307587 -0.000639122448022129 -0.000192833379464789 4.2068444340919e-006 7.93950335016002e-005],1,block.InputPort(1).Data);
%end Outputs
%%
%% Update:
%% Functionality : Called to update discrete states
%% during simulation step
%% Required : No
%% C-MEX counterpart: mdlUpdate
%%
function Update(block)
block.Dwork(1).Data = block.InputPort(1).Data;
%end Update
%%
%% Derivatives:
%% Functionality : Called to update derivatives of
%% continuous states during simulation step
%% Required : No
%% C-MEX counterpart: mdlDerivatives
%%
%function Derivatives(block)
%end Derivatives
%%
%% Terminate:
%% Functionality : Called at the end of simulation for cleanup
%% Required : Yes
%% C-MEX counterpart: mdlTerminate
%%
function Terminate(block)
%end Terminate
function filtsfcn(block)
%MSFUNTMPL_BASIC A template for a Leve-2 M-file S-function
% The M-file S-function is written as a MATLAB function with the
% same name as the S-function. Replace 'msfuntmpl_basic' with the
% name of your S-function.
%
% It should be noted that the M-file S-function is very similar
% to Level-2 C-Mex S-functions. You should be able to get more
% information for each of the block methods by referring to the
% documentation for C-Mex S-functions.
%
% Copyright 2003-2007 The MathWorks, Inc.
%%
%% The setup method is used to setup the basic attributes of the
%% S-function such as ports, parameters, etc. Do not add any other
%% calls to the main body of the function.
%%
setup(block);
%endfunction
%% Function: setup ===================================================
%% Abstract:
%% Set up the S-function block's basic characteristics such as:
%% - Input ports
%% - Output ports
%% - Dialog parameters
%% - Options
%%
%% Required : Yes
%% C-Mex counterpart: mdlInitializeSizes
%%
function setup(block)
% Register number of ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
% Override input port properties
block.InputPort(1).Dimensions = 1;
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).DirectFeedthrough = false;
% Override output port properties
block.OutputPort(1).Dimensions = 1;
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
% Register parameters
block.NumDialogPrms = 0;
% Register sample times
% [0 offset] : Continuous sample time
% [positive_num offset] : Discrete sample time
%
% [-1, 0] : Inherited sample time
% [-2, 0] : Variable sample time
block.SampleTimes = [-1 0];
% Specify the block simStateComliance. The allowed values are:
% 'UnknownSimState', < The default setting; warn and assume DefaultSimState
% 'DefaultSimState', < Same sim state as a built-in block
% 'HasNoSimState', < No sim state
% 'CustomSimState', < Has GetSimState and SetSimState methods
% 'DisallowSimState' < Error out when saving or restoring the model sim state
block.SimStateCompliance = 'DefaultSimState';
%%
%% The M-file S-function uses an internal registry for all
%% block methods. You should register all relevant methods
%% (optional and required) as illustrated below. You may choose
%% any suitable name for the methods and implement these methods
%% as local functions within the same file. See comments
%% provided for each function for more information.
%%
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
%block.RegBlockMethod('InitializeConditions', @InitializeConditions);
%block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs); % Required
block.RegBlockMethod('Update', @Update);
%block.RegBlockMethod('Derivatives', @Derivatives);
block.RegBlockMethod('Terminate', @Terminate); % Required
%end setup
%%
%% PostPropagationSetup:
%% Functionality : Setup work areas and state variables. Can
%% also register run-time methods here
%% Required : No
%% C-Mex counterpart: mdlSetWorkWidths
%%
function DoPostPropSetup(block)
block.NumDworks = 1;
block.Dwork(1).Name = 'x1';
block.Dwork(1).Dimensions = 1;
block.Dwork(1).DatatypeID = 0; % double
block.Dwork(1).Complexity = 'Real'; % real
block.Dwork(1).UsedAsDiscState = true;
%%
%% InitializeConditions:
%% Functionality : Called at the start of simulation and if it is
%% present in an enabled subsystem configured to reset
%% states, it will be called when the enabled subsystem
%% restarts execution to reset the states.
%% Required : No
%% C-MEX counterpart: mdlInitializeConditions
%%
%function InitializeConditions(block)
%end InitializeConditions
%%
%% Start:
%% Functionality : Called once at start of model execution. If you
%% have states that should be initialized once, this
%% is the place to do it.
%% Required : No
%% C-MEX counterpart: mdlStart
%%
%function Start(block)
%block.Dwork(1).Data =
%endfunction
%%
%% Outputs:
%% Functionality : Called to generate block outputs in
%% simulation step
%% Required : Yes
%% C-MEX counterpart: mdlOutputs
%%
function Outputs(block)
block.OutputPort(1).Data = filter( [7.93950335016002e-005 4.2068444340919e-006 -0.000192833379464789 -0.000639122448022129 -0.00139707444307587 -0.00245625245399633 -0.00370071518169793 -0.0049066202014346 -0.00578002124120443 -0.00603295917787244 -0.00547897231748479 -0.00411607679985946 -0.0021644268397023 -3.41151281310269e-005 0.00177669441966399 0.00282864008648444 0.00288532864900338 0.00200322543812317 0.00052791992197702 -0.00101045402113809 -0.00207327082028958 -0.00230087264141553 -0.00164250432166114 -0.000376548748319844 0.000992158389182175 0.00192389609569889 0.00205368715570095 0.00133692890809704 7.09123507658864e-005 -0.00122089543005666 -0.00199936988544874 -0.00193221462627573 -0.00103679310801218 0.000318922930572234 0.00156285350822139 0.00215635616405561 0.00182547026198189 0.00068711256245219 -0.000788041001845299 -0.00196661448017079 -0.00232160775370418 -0.00166615668621754 -0.000248956972605352 0.00133647515911177 0.00239740941345114 0.00244209603696065 0.00140539572248529 -0.000302806772506288 -0.00195632132004645 -0.00281867778410291 -0.00246866362264886 -0.00100249403036538 0.00098310577365351 0.00263056426311881 0.0031891567771482 0.00235421045051084 0.000425777060022136 -0.00179327945832978 -0.00332828637333227 -0.00345790226068029 -0.00204923287907303 0.000351178678769648 0.00272431905459656 0.00400772058787193 0.00356746061696794 0.00150506012483035 -0.00134686211083758 -0.00375566596981736 -0.0046172068904128 -0.00345699502532703 -0.000678639915161797 0.00256597670678413 0.00484868569361424 0.00508824668524873 0.00305516079615843 -0.000474560482744197 -0.00400637337637883 -0.00595320314692646 -0.00534118618373109 -0.00228451312765527 0.0019972819148517 0.00565594846286424 0.00700322556346544 0.00527892119682813 0.00105361092242717 -0.00393808271116019 -0.00749696389711814 -0.00791476478226187 -0.00477616650564779 0.000761723991922121 0.00637423242508511 0.00952674941087938 0.00859807134200253 0.00368051904917151 -0.00332472830390768 -0.00941442975531867 -0.0117411832315303 -0.0089073424723017 -0.00172250015567689 0.0069579319097193 0.0133222725798866 0.0142215884784255 0.00865167506326345 -0.00156895989264316 -0.0123030986545982 -0.0186808489252971 -0.0171895004967254 -0.0074140307817742 0.00736324912433382 0.0210944914523893 0.0272186347440778 0.0214530755204663 0.00404061000292739 -0.0195239439917389 -0.0397552390592479 -0.0461603078788305 -0.0309883180308153 0.00757800611716887 0.06400620904665 0.126418851837905 0.179824501208783 0.210574563887124 0.210574563887124 0.179824501208783 0.126418851837905 0.06400620904665 0.00757800611716887 -0.0309883180308153 -0.0461603078788305 -0.0397552390592479 -0.0195239439917389 0.00404061000292739 0.0214530755204663 0.0272186347440778 0.0210944914523893 0.00736324912433382 -0.0074140307817742 -0.0171895004967254 -0.0186808489252971 -0.0123030986545982 -0.00156895989264316 0.00865167506326345 0.0142215884784255 0.0133222725798866 0.0069579319097193 -0.00172250015567689 -0.0089073424723017 -0.0117411832315303 -0.00941442975531867 -0.00332472830390768 0.00368051904917151 0.00859807134200253 0.00952674941087938 0.00637423242508511 0.000761723991922121 -0.00477616650564779 -0.00791476478226187 -0.00749696389711814 -0.00393808271116019 0.00105361092242717 0.00527892119682813 0.00700322556346544 0.00565594846286424 0.0019972819148517 -0.00228451312765527 -0.00534118618373109 -0.00595320314692646 -0.00400637337637883 -0.000474560482744197 0.00305516079615843 0.00508824668524873 0.00484868569361424 0.00256597670678413 -0.000678639915161797 -0.00345699502532703 -0.0046172068904128 -0.00375566596981736 -0.00134686211083758 0.00150506012483035 0.00356746061696794 0.00400772058787193 0.00272431905459656 0.000351178678769648 -0.00204923287907303 -0.00345790226068029 -0.00332828637333227 -0.00179327945832978 0.000425777060022136 0.00235421045051084 0.0031891567771482 0.00263056426311881 0.00098310577365351 -0.00100249403036538 -0.00246866362264886 -0.00281867778410291 -0.00195632132004645 -0.000302806772506288 0.00140539572248529 0.00244209603696065 0.00239740941345114 0.00133647515911177 -0.000248956972605352 -0.00166615668621754 -0.00232160775370418 -0.00196661448017079 -0.000788041001845299 0.00068711256245219 0.00182547026198189 0.00215635616405561 0.00156285350822139 0.000318922930572234 -0.00103679310801218 -0.00193221462627573 -0.00199936988544874 -0.00122089543005666 7.09123507658864e-005 0.00133692890809704 0.00205368715570095 0.00192389609569889 0.000992158389182175 -0.000376548748319844 -0.00164250432166114 -0.00230087264141553 -0.00207327082028958 -0.00101045402113809 0.00052791992197702 0.00200322543812317 0.00288532864900338 0.00282864008648444 0.00177669441966399 -3.41151281310269e-005 -0.0021644268397023 -0.00411607679985946 -0.00547897231748479 -0.00603295917787244 -0.00578002124120443 -0.0049066202014346 -0.00370071518169793 -0.00245625245399633 -0.00139707444307587 -0.000639122448022129 -0.000192833379464789 4.2068444340919e-006 7.93950335016002e-005],1,block.InputPort(1).Data);
%end Outputs
%%
%% Update:
%% Functionality : Called to update discrete states
%% during simulation step
%% Required : No
%% C-MEX counterpart: mdlUpdate
%%
function Update(block)
block.Dwork(1).Data = block.InputPort(1).Data;
%end Update
%%
%% Derivatives:
%% Functionality : Called to update derivatives of
%% continuous states during simulation step
%% Required : No
%% C-MEX counterpart: mdlDerivatives
%%
%function Derivatives(block)
%end Derivatives
%%
%% Terminate:
%% Functionality : Called at the end of simulation for cleanup
%% Required : Yes
%% C-MEX counterpart: mdlTerminate
%%
function Terminate(block)
%end Terminate
0