chnages from silas pc again
This commit is contained in:
68
Functions/Metrics/calc_std.m
Normal file
68
Functions/Metrics/calc_std.m
Normal file
@@ -0,0 +1,68 @@
|
||||
function [std_total,std_lvl] = calc_std(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
|
||||
[std_total,std_lvl] = calc_std_(test_signal,reference_signal);
|
||||
|
||||
|
||||
function [std_total,std_lvl] = calc_std_(test_signal,reference_signal)
|
||||
|
||||
assert(length(test_signal) == length(reference_signal),"Sequence length does not match");
|
||||
|
||||
error_vector = (test_signal-reference_signal);
|
||||
|
||||
%%% Overall EVM
|
||||
std_total = std(test_signal);
|
||||
|
||||
test_signal = test_signal ./ rms(test_signal);
|
||||
|
||||
try
|
||||
%%% Per Level EVM
|
||||
k = unique(reference_signal);
|
||||
for lvl = 1:length(k)
|
||||
% lvl_errors = error_vector(reference_signal==k(lvl));
|
||||
std_lvl(lvl) = std(test_signal(reference_signal==k(lvl)));
|
||||
end
|
||||
catch
|
||||
std_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
|
||||
Reference in New Issue
Block a user