37 lines
867 B
Matlab
37 lines
867 B
Matlab
function [bits,errors,ber,errorLocation] = calc_ber(data_in,data_ref,options)
|
|
|
|
arguments(Input)
|
|
data_in;
|
|
data_ref;
|
|
options.skip = 0;
|
|
options.returnErrorLocation = 0;
|
|
end
|
|
|
|
bits = 0;
|
|
errors= 0;
|
|
ber= 0;
|
|
errorLocation= [];
|
|
|
|
data_ref = logical(data_ref)';
|
|
data_in = logical(data_in)';
|
|
|
|
bits = 0;
|
|
bits = bits+numel(data_in(:,options.skip+1:end));
|
|
|
|
try
|
|
if options.returnErrorLocation == 0
|
|
errors = sum( data_in(:,options.skip+1:end) ~= data_ref(:,options.skip+1:end),"all" );
|
|
else
|
|
errorLocation = sum(data_in(:,options.skip+1:end) ~= data_ref(:,options.skip+1:end),1);
|
|
errors = sum(errorLocation ,"all" );
|
|
end
|
|
|
|
catch
|
|
%warning('BER calculation not optimal: Arrays have incompatible sizes for this operation.')
|
|
errors = NaN;
|
|
end
|
|
|
|
% Determine BER
|
|
ber = sum(errors)/sum(bits);
|
|
|
|
end |