Eb=1;
k=5;
M=2^k;
Es=k*Eb;
c=0;
dr1=0.01;
for EbN0dB=0:12
    c=c+1;
    EbN0=10^(EbN0dB/10);
    N0=Eb/EbN0;
    r1=0:dr1:sqrt(Es)+10*sqrt(N0/2);
    Pr1=1/sqrt(2*pi*N0/2)*exp(-(r1-sqrt(Es)).^2/(2*N0/2));
    Pc(c)=sum([1-2*qfunc(r1/sqrt(N0/2))].^(M/2-1).*Pr1)*dr1;
    Pe(c)=1-Pc(c);
end 
EbN0dB=0:12;
hold on;
semilogy(EbN0dB,Pe,'k--o')