1、%pskclc;clear all;close all;nsymbol = 1e6;%每种信噪比下符号数的发送符号数data = randint(1,nsymbol,0,1);%产生1行,nsymbol列均匀分布的随机数0,1bpsk_mod = 2*data-1;%调制,0转化为-1;1转化为1spow = norm(bpsk_mod).2/nsymbol;%求每个符号的平均值,其中norm是求向量2范数函数SNR_dB = 1:10;%信噪比dB形式SNR = 10.(SNR_dB/10);%信噪比转化为线性值for loop= 1:length(SNR) sigma = sqrt(spo
2、w/(2*SNR(loop);%根据符号功率求噪声功率 s_receive = bpsk_mod+sigma*(randn(1,length(bpsk_mod)+j*randn(1,length(bpsk_mod);%添加复高斯白噪声 bpsk_demod = (real(s_receive)0);%解调 data_receive=double(bpsk_demod);%接收数据,转化为 err,ser(loop) = symerr(data,data_receive);%误码率endser_theory = qfunc(sqrt(2*SNR);%理论误码率,注意Q函数和误差函数的对应关系semilogy(SNR_dB,ser,-k*,SNR_dB,ser_theory,-bo);title(BPSK信号在AWGN信道下的性能);xlabel(信噪比/dB);ylabel(误码率);legend(误码率,理论误码率);grid on;