function resarr = PeMaryPSK(SNRdB,M)
clear global k SNR M
global k SNR M
SNRarr = 10.^(0.1*SNRdB);
alt = 0;resarr = [];tol = 1e-10;k = log2(M);
for iSNR = 1:length(SNRarr)
    SNR = SNRarr(iSNR);
res1 = exp(-k*SNR)*quade(@funPe,alt,inf,tol)/sqrt(pi);
resarr = [resarr res1];end;resarr = 1 - resarr;
function yt = funPe(x)
global k SNR M
yt = exp(-x.^2 + 2*x*sqrt(k*SNR)).*erf(tan(pi/M)*x);