function [evm,stdev] = calc_evm(vector_received,vector_ideal)

    error_vector = (vector_received-vector_ideal);
    
    k = unique(vector_ideal);

    error = repmat(zeros(size(vector_ideal)),1,length(k));

    for lvl = 1:length(k)
        error(vector_ideal==k(lvl),lvl)          = error_vector(vector_ideal==k(lvl));
    end

    error(error==0) = NaN;

    stdev = std(error,"omitnan");
    
    error = sqrt(error.^2);
    evm =  sqrt( 1/length(error) .* sum(error.^2,1,'omitnan') ) ;
end