0
$\begingroup$

I am currently working on a Simulink block designed to perform an online computation of the weighted kurtosis typical of a certain signal. This block is part of a larger control algorithm, which will then be compiled as a DLL and run in both simulations and lab tests.

So far the Simulink block diagram is as follows.

enter image description here The circular buffer performs the following

function y = fcn(u,bufferIC,bufferLength)
persistent buffer;
if isempty(buffer)
    if isequal(numel(bufferIC),bufferLength)
        buffer = bufferIC;
    elseif isscalar(bufferIC)
        buffer = bufferIC*ones(1,bufferLength);
    else
        error('IC must either be scalar or the same dimensions as buffer length')
    end
end
% Output
y = buffer;
% Update
buffer = [u buffer(1:end-1)];
end %fcn

and the weighted kurtosis will then be calculated according to the following algorithm:

function WKurt = fcn(BuffSig)
N = length(BuffSig);
y = (1.005.^(1:N));
weights = 2*(y/max(y));
WMean = sum((weights.*BuffSig))/sum(weights);
WStd = sqrt(sum(weights.*((BuffSig - WMean).^2))/sum(weights));
WKurt = squeeze(((sum(weights.*((((BuffSig - WMean)./WStd)).^4))/sum(weights))) - 3);
WKurt(WKurt<0) = 0.0;
WKurt(isnan(WKurt)) = 0.0;
WKurt(isinf(WKurt)) = 0.0;

If I run simulations, everything is alright and I do not happen to run into any CPU computation issue. That does not hold valid as soon as I move to lab tests, which will be terminated because the block requires too much CPU memory.

Therefore, I would very much appreciate whether a work-around exists so as to achieve the same kurtosis estimation, but in a more CPU-effcient way.

$\endgroup$
2
  • $\begingroup$ Did you run the MATLAB profiler? Which part of the code is the most expensive? Have you tried: replacing the multiple computation of the sum(weights) by a variable and compute it only once? Have you tried to get rid of squeeze()? Have you tried to replace exponentiation by multiple multiplication (a^4 = a*a*a*a, then with b = a*a, a^4 = b*b), etc. $\endgroup$
    – M529
    Commented Jun 30, 2016 at 7:05
  • $\begingroup$ You can also replace the max(y) by a direct call to the last index. y follows a simple formula where you know the position of the maximum beforehand (last entry). You should really check the MATLAB profiler to find the culprit that causes the CPU load. $\endgroup$
    – M529
    Commented Jun 30, 2016 at 7:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.