if sum(qdata2((n-1)/delta_T+1:n/delta_T))>=0 qdata3(n)=1; else qdata3(n)=0; end end
% 为了显示星座图,将信号进行处理 idata4=zeros(1,nb/2); qdata4=zeros(1,nb/2); for n=1:nb/2
Awgn_ichsum(n)=sum(idata2((n-1)/delta_T+1:n/delta_T))*delta_T; if Awgn_ichsum(n)>=0 idata4(n)=1; else idata4(n)=0; end
Awgn_qchsum(n)=sum(qdata2((n-1)/delta_T+1:n/delta_T))*delta_T; if Awgn_qchsum(n)>=0 qdata4(n)=1; else qdata4(n)=0; end end
% 将判决之后的数据存放进数组 demodata=zeros(1,nb);
demodata(1:ml:(nb-1))=idata3; demodata(2:ml:nb)=qdata3;
%为了显示,将它变成波形信号(即传输一个1代表单位宽度的高电平) demodata1=zeros(1,nb/delta_T); for q=1:nb
demodata1((q-1)/delta_T+1:q/delta_T)=demodata(q); end
% 累计误码数
% abs(demodata-data)求接收端和发射端 % 数据差的绝对值,累计之后就是误码个数 Awgn_num_BER=sum(abs(demodata-data))
% 解调部分(瑞利+高斯)
Ray_idata2=Ray_s.*a; Ray_qdata2=Ray_s.*b;
% 为了显示星座图,将信号进行处理 Ray_idata4=zeros(1,nb/2); Ray_qdata4=zeros(1,nb/2); for n=1:nb/2
Ray_ichsum(n)=sum(idata2((n-1)/delta_T+1:n/delta_T))*delta_T;
16
if Ray_ichsum(n)>=0 Ray_idata4(n)=1; else Ray_idata4(n)=0; end
Ray_qchsum(n)=sum(qdata2((n-1)/delta_T+1:n/delta_T))*delta_T; if Ray_qchsum(n)>=0 Ray_qdata4(n)=1; else Ray_qdata4(n)=0; end end
% 将判决之后的数据存放进数组 Ray_demodata=zeros(1,nb);
Ray_demodata(1:ml:(nb-1))=Ray_idata4; Ray_demodata(2:ml:nb)=Ray_qdata4;
%为了显示,将它变成波形信号(即传输一个1代表单位宽度的高电平) Ray_demodata1=zeros(1,nb/delta_T); for q=1:nb
Ray_demodata1((q-1)/delta_T+1:q/delta_T)=Ray_demodata(q); end
% 累计误码数
% abs(demodata-data)求接收端和发射端 % 数据差的绝对值,累计之后就是误码个数 Ray_num_BER=sum(abs(Ray_demodata-data))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 误码率计算
%% 调用了cm_sm32();和cm_sm33()函数 %%声明: 函数声明在另外俩个M文件中
%%作用: cm_sm32()用于瑞利信道误码率的计算 %% cm_sm33()用于高斯信道误码率的计算 %% ecoh on/off 作用在于决定是否显示指令内容
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SNRindB1=0:1:6; SNRindB2=0:0.1:6; % 瑞利衰落信道
for i=1:length(SNRindB1),
[pb,ps]=cm_sm32(SNRindB1(i)); % 比特误码率 smld_bit_ray_err_prb(i)=pb; smld_symbol_ray_err_prb(i)=ps; disp([ps,pb]); echo off; end;
% 高斯信道 echo on;
for i=1:length(SNRindB1),
17
[pb1,ps1]=cm_sm33(SNRindB1(i)); smld_bit_awgn_err_prb(i)=pb1; smld_symbol_awgn_err_prb(i)=ps1; disp([ps1,pb1]); echo off; end;
% 理论曲线 echo on;
for i=1:length(SNRindB2),
SNR=exp(SNRindB2(i)*log(10)/10); theo_err_awgn_prb(i)=0.5*erfc(sqrt(SNR)); theo_err_ray_prb(i)=0.5*(1-1/sqrt(1+1/SNR)); echo off; end;
h = spectrum.welch;
%---------------------------- 输出显示部分
% 第一部分(理想) figure(1)
subplot(3,2,1);
plot(data0),title('基带信号'); axis([0 20000 -2 2]); subplot(3,2,2);
psd(h,data1,'fs',fs),title('基带信号功率谱密度'); subplot(3,2,3);
plot(s),title('调制信号'); axis([0 500 -3 3]); subplot(3,2,4);
psd(h,s,'fs',fs),title('调制信号功率谱密度'); subplot(3,2,5);
plot(demodata1),title('解调输出'); axis([0 20000 -2 2]); subplot(3,2,6);
psd(h,demodata1,'fs',fs),title('解调输出功率谱密度');
% 通过高斯信道 figure(2)
subplot(2,2,1);
plot(s1),title('调制信号(Awgn)'); axis([0 500 -5 5]); subplot(2,2,2);
psd(h,s1,'fs',fs),title('调制信号功率谱密度(Awgn)'); subplot(2,2,3);
plot(s111),title('高斯噪声曲线');
18
axis([0 2000 -5 5]); figure(3) for i=1:nb/2
plot(idata(i),qdata(i),'r+'),title('QPSK信号星座图(Awgn)');hold on; axis([-2 2 -2 2]);
plot(Awgn_ichsum(i),Awgn_qchsum(i),'*');hold on; legend('理论值(发射端)','实际值(接收端)'); end
%通过高斯信道再通过瑞利衰落信道 figure(4) subplot(2,2,1)
plot(Ray_s),title('调制信号(Ray+Awgn)'); axis([0 500 -5 5]); subplot(2,2,2);
psd(h,Ray_s,'fs',fs),title('调制信号功率谱密度(Ray)'); figure(5) for i=1:nb/2
plot(idata(i),qdata(i),'r+'),title('QPSK信号星座图(Awgn+Ray)');hold on; axis([-2 2 -2 2]);
plot(Ray_ichsum(i),Ray_qchsum(i),'*');hold on; legend('理论值(发射端)','实际值(接收端)'); end
figure(6)
semilogy(SNRindB2,theo_err_awgn_prb,'r'),title('误码率曲线');hold on; semilogy(SNRindB1,smld_bit_awgn_err_prb,'r*');hold on; semilogy(SNRindB2,theo_err_ray_prb);hold on; semilogy(SNRindB1,smld_bit_ray_err_prb,'+'); xlabel('Eb/No');ylabel('BER');
legend('理论AWGN','仿真AWGN','理论Rayleigh','仿真Rayleigh');
cm_sm32()用于瑞利信道误码率的计算: function [pb,ps]=cm_sm32(snr_in_dB) % [pb,ps]=cm_sm32(snr_in_dB)
% CM_SM3 finds the probability of bit error and symbol error for % the given value of snr_in_dB, signal to noise ratio in dB.
N=100;
E=1; % energy per symbol numofsymbolerror=0; numofbiterror=0; counter=0;
snr=10^(snr_in_dB/10); % signal to noise ratio sgma=sqrt(E/snr)/2; % noise variance
19
s00=[1 0]; s01=[0 1]; s11=[-1 0]; s10=[0 -1]; % signal mapping % generation of the data source while(numofbiterror<100) for i=1:N,
temp=rand; % a uniform random variable between 0 and 1
if (temp<0.25), % with probability 1/4, source output is \ dsource1(i)=0; dsource2(i)=0;
elseif (temp<0.5), % with probability 1/4, source output is \ dsource1(i)=0; dsource2(i)=1;
elseif (temp<0.75), % with probability 1/4, source output is \ dsource1(i)=1; dsource2(i)=0;
else % with probability 1/4, source output is \
dsource1(i)=1; dsource2(i)=1; end; end;
% detection and the probability of error calculation
for i=1:N,
ray=raylrnd(0.8);
n=sgma*randn(1,2); % 2 normal distributed r.v with 0, variance sgma
if ((dsource1(i)==0) & (dsource2(i)==0)), r=ray*s00+n;
elseif ((dsource1(i)==0) & (dsource2(i)==1)), r=ray*s01+n;
elseif ((dsource1(i)==1) & (dsource2(i)==0)), r=s10*ray+n; else
r=s11*ray+n; end;
% The correlation metrics are computed below
c00=dot(r,s00); c01=dot(r,s01); c10=dot(r,s10); c11=dot(r,s11); % The decision on the ith symbol is made next c_max=max([c00,c01,c10,c11]);
if (c00==c_max), decis1=0; decis2=0; elseif (c01==c_max), decis1=0; decis2=1; elseif (c10==c_max), decis1=1; decis2=0; else decis1=1; decis2=1; end;
% Increment the error counter, if the decision is not correct symbolerror=0;
if (decis1~=dsource1(i)), numofbiterror=numofbiterror+1; symbolerror=1; end;
if (decis2~=dsource2(i)), numofbiterror=numofbiterror+1; symbolerror=1;
20
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库基于matlab的QPSK仿真(4)在线全文阅读。
相关推荐: