66 lines
1.7 KiB
Matlab
66 lines
1.7 KiB
Matlab
function [evm_total,evm_lvl] = calc_evm(test_signal,reference_signal,options)
|
|
|
|
arguments(Input)
|
|
test_signal;
|
|
reference_signal;
|
|
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);
|
|
|
|
assert((options.skip_end+options.skip_front)<length(test_signal),"You can not skip more bits than overall length of data! Set skip_front or skip_end to lower value or check data_in");
|
|
|
|
if isa(reference_signal,'Signal')
|
|
reference_signal = reference_signal.signal;
|
|
end
|
|
|
|
if isa(test_signal,'Signal')
|
|
test_signal = test_signal.signal;
|
|
end
|
|
|
|
% TRIM
|
|
[test_signal,reference_signal]=trimseq(test_signal,reference_signal,options.skip_front,options.skip_end);
|
|
|
|
% CALC EVM
|
|
[evm_total,evm_lvl] = calc_evm_(test_signal,reference_signal);
|
|
|
|
|
|
function [evm_total,evm_lvl] = calc_evm_(test_signal,reference_signal)
|
|
|
|
assert(length(test_signal) == length(reference_signal),"Sequence length does not match");
|
|
|
|
error_vector = (test_signal-reference_signal);
|
|
|
|
%%% Overall EVM
|
|
evm_total = rms(error_vector);
|
|
|
|
try
|
|
%%% Per Level EVM
|
|
k = unique(reference_signal);
|
|
for lvl = 1:length(k)
|
|
lvl_errors = error_vector(reference_signal==k(lvl));
|
|
evm_lvl(lvl) = rms(lvl_errors);
|
|
end
|
|
catch
|
|
evm_lvl = NaN;
|
|
warning('No EVM per level calculated')
|
|
end
|
|
|
|
end
|
|
|
|
function [data_,reference_]=trimseq(data,reference,skipstart,skip_end)
|
|
|
|
data_ = data(skipstart+1:end-skip_end,:);
|
|
|
|
delta_bits = length(reference) - length(data);
|
|
|
|
skip_end = delta_bits + skip_end;
|
|
|
|
reference_ = reference(skipstart+1:end-skip_end,:);
|
|
|
|
end
|
|
|
|
end |