资源简介
基于Matlab/Simulink建模的算法:Trigger. Trigger使用移动平均和匹配滤波器对原始信号进行噪声处理和信号峰值提取,并验证原始信号的正确性。Trigger使用M-code实现,并且使用S-function封装到Simulink中。
代码片段和文件信息
function trigger_constant(block)
% Level-2 MATLAB file S-Function for unit delay demo.
% Copyright 1990-2009 The MathWorks Inc.
% $Revision: 1.1.6.2 $
setup(block);
%endfunction
function setup(block)
block.NumDialogPrms = 0;
%% Register number of input and output ports
block.NumInputPorts = 2;
block.NumOutputPorts = 2;
%% Setup functional port properties to dynamically
%% inherited.
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
block.InputPort(1).Dimensions = 85;
block.InputPort(1).DatatypeID = 0;
block.InputPort(1).DirectFeedthrough = 1;
block.InputPort(2).Dimensions = 1300;
block.InputPort(1).DatatypeID = 0;
block.InputPort(2).DirectFeedthrough = 1;
block.OutputPort(1).Dimensions = 1300;
block.OutputPort(1).DatatypeID = 0;
block.OutputPort(2).Dimensions = 85;
block.OutputPort(2).DatatypeID = 0;
%% Set block sample time to inherited
block.SampleTimes = [-1 0];
%% Set the block simStateCompliance to default (i.e. same as a built-in block)
block.SimStateCompliance = ‘DefaultSimState‘;
%% Register methods
block.RegBlockMethod(‘PostPropagationSetup‘ @DoPostPropSetup);
block.RegBlockMethod(‘InitializeConditions‘ @InitConditions);
block.RegBlockMethod(‘Outputs‘ @Output);
block.RegBlockMethod(‘Update‘ @Update);
block.RegBlockMethod(‘SetInputPortSamplingMode‘@SetInputPortSamplingMode);
block.RegBlockMethod(‘SetInputPortDimensions‘ @SetInpPortDims);
%endfunction
function DoPostPropSetup(block)
%% Setup Dwork
block.NumDworks = 1;
block.Dwork(1).Name = ‘x0‘;
block.Dwork(1).Dimensions = 1385;
block.Dwork(1).DatatypeID = 0;
block.Dwork(1).Complexity = ‘Real‘;
block.Dwork(1).UsedAsDiscState = true;
%endfunction
function InitConditions(block)
%% Initialize Dwork
%endfunction
function Output(block)
Nbuffer = 1300; %%total buffer size
LenMA = 85;%%lenth of MA buffer
Lbuffer = zeros(1LenMA);
MAbuffer = zeros(1Nbuffer);
Triggerdata2 = block.Dwork(1).Data;
Triggerdata2 = Triggerdata2‘;
for i= 1:Nbuffer
for j= 1:LenMA
Lbuffer(1j)= Triggerdata2(1i+j);
end
MAbuffer(1i) = mean(Lbuffer);
end
Pbuffer = Lbuffer;
Ma = 0;
Mc = 85;
Mb = 170;
Fbuffer = zeros(1Nbuffer-Mb);
for n = 1:(Nbuffer-Mb)
Fbuffer(1n) = 2*MAbuffer(1n+Mc)- MAbuffer(1n+Ma)- MAbuffer(1n+Mb);
end
block.OutputPort(1).Data = MAbuffer;
block.OutputPort(2).Data = Pbuffer;
%endfunction
function Update(block)
block.Dwork(1).Data = [block.InputPort(1).data;block.InputPort(2).data];
%endfunction
function SetInputPortSamplingMode(block idx fd)
block.InputPort(idx).SamplingMode = fd;
block.InputPort(idx).SamplingMode = fd;
block.OutputPort(idx).SamplingMode = fd;
block.OutputPort(idx).SamplingMode = fd;
function SetInpPortDims(block idx di)
block.InputPort(idx).Dimensions = di;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 27086 2012-08-11 11:18 Trigger Algorithm\msfcndemo_sfundsc2.mdl
文件 198 2012-08-09 17:42 Trigger Algorithm\Pbuffer.mat
文件 717888 2012-08-09 12:02 Trigger Algorithm\triggerdata_4KHZ_Constant.mat
文件 717965 2012-08-11 08:27 Trigger Algorithm\triggerdata_constant.mat
文件 2994 2012-08-11 11:17 Trigger Algorithm\trigger_constant.m
目录 0 2012-08-16 20:45 Trigger Algorithm
----------- --------- ---------- ----- ----
1466131 6
评论
共有 条评论