Update April
This commit is contained in:
@@ -1,37 +1,58 @@
|
||||
function [bits,errors,ber,errorLocation] = calc_ber(data_in,data_ref,options)
|
||||
function [bits,errors,ber,errorIndice] = calc_ber(data_in,data_ref,options)
|
||||
|
||||
arguments(Input)
|
||||
data_in;
|
||||
data_ref;
|
||||
options.skip = 0;
|
||||
options.skip_front = 0;
|
||||
options.skip_end = 0;
|
||||
options.returnErrorLocation = 0;
|
||||
end
|
||||
options.skip_end = abs(options.skip_end);
|
||||
options.skip_front = abs(options.skip_front);
|
||||
|
||||
bits = 0;
|
||||
errors= 0;
|
||||
ber= 0;
|
||||
errorLocation= [];
|
||||
errorIndice= [];
|
||||
|
||||
data_ref = logical(data_ref)';
|
||||
data_in = logical(data_in)';
|
||||
% trim sequence to given start; stop. trim reference if signal is shorter
|
||||
[data_in,data_ref]=trimseq(data_in,data_ref,options.skip_front,options.skip_end);
|
||||
|
||||
bits = 0;
|
||||
bits = bits+numel(data_in(:,options.skip+1:end));
|
||||
if length(data_ref) == length(data_in)
|
||||
|
||||
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" );
|
||||
bits = 0;
|
||||
bits = bits+numel(data_in(:,options.skip_front+1:end));
|
||||
|
||||
try
|
||||
if options.returnErrorLocation == 0
|
||||
errors = sum( data_in ~= data_ref,"all" );
|
||||
else
|
||||
errorIndice = sum(data_in ~= data_ref,1);
|
||||
errors = sum(errorIndice ,"all" );
|
||||
[~,errorIndice] = find(errorIndice==1);
|
||||
end
|
||||
|
||||
catch
|
||||
warning('BER calculation not optimal: Arrays have incompatible sizes for this operation.')
|
||||
errors = NaN;
|
||||
end
|
||||
|
||||
catch
|
||||
%warning('BER calculation not optimal: Arrays have incompatible sizes for this operation.')
|
||||
errors = NaN;
|
||||
% Determine BER
|
||||
ber = sum(errors)/sum(bits);
|
||||
|
||||
else
|
||||
errormsg('Sequence length does not match');
|
||||
end
|
||||
|
||||
% Determine BER
|
||||
ber = sum(errors)/sum(bits);
|
||||
function [data_,reference_]=trimseq(data,reference,skipstart,skip_end)
|
||||
|
||||
data_ = logical(data(skipstart+1:end-skip_end,:))';
|
||||
|
||||
delta_bits = length(reference) - length(data_);
|
||||
|
||||
skip_end = max(skip_end,delta_bits);
|
||||
reference_ = logical(reference(skipstart+1:end-skip_end,:))';
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user