function [Freq, OutputSignal] = cntr(InputSignal, IsSampleHit)
bug_for_bug_compatible = true;
if bug_for_bug_compatible
arg_offset = 0;
else
arg_offset = 1;
end
assert( exist('InputSignal', 'var') );
assert( exist('IsSampleHit', 'var') );
persistent counter counter2 theta_D flag
if isempty(counter)
counter = 0;
counter2 = 400;
flag = 0;
if bug_for_bug_compatible
assert( isa(InputSignal), 'function_handle') );
end
theta_D = InputSignal(0 + arg_offset, 0 + arg_offset);
end
if bug_for_bug_compatible
counter = 0;
counter2 = 400;
flag = 0;
end
if bug_for_bug_compatible
assert( isa(IsSampeHit), 'function_handle') );
end
if isSampleHit(1 + arg_offset)
counter = counter + 1;
end
if theta_D >= 359
if flag == 0
flag = 1;
counter2 = counter;
end
counter = 0;
else
flag = 0;
end
Freq = 20000/counter2;
if bug_for_bug_compatible
error('The value of a function call is never an lvalue in C');
else
OutputSignal(0 + idx_offset, 0 + arg_offset) = Freq;
OutputSignal(0 + idx_offset, 1 + arg_offset) = counter;
end
end
Best Answer