⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpsk_fading.m

📁 代码为QPSK半分析方法计算误码率
💻 M
字号:
function [pb,ps]=QPSK_fading(snr_in_dB)
N=10000;
E=1;                                            % energy per symbol
snr=10^(snr_in_dB/10);                          % signal to noise ratio
sgma=sqrt(E/snr)/2;                             % noise variance
s00=[1 0]; s01=[0 1]; s11=[-1 0]; s10=[0 -1];   % signal mapping
% generation of the data source
numofsymbolerror=0;
numofbiterror=0;
flag=0;
     %   R1=jakemodel(N);
      %  R2=jakemodel(N);
      %  R=[R1 R2];
while ( numofbiterror<100 )
        B=fir1(60,0.5 );% design LPF using ftype as Fcutoff/Fs 
        x=randn(N,1);	% make 2048 normally distributed random number for I and Q
        y=randn(N,1);        % z=sqrt(x.*x + y.*y);
        x1=filter(B,1,x);	% filter the I and Q signals 
        y1=filter(B,1,y);
        R1=sqrt(x1.*x1 + y1.*y1);
        
      %  x=randn(N,1);	% make 2048 normally distributed random number for I and Q
       % y=randn(N,1);        % z=sqrt(x.*x + y.*y);
      %  x1=filter(B,1,x);	% filter the I and Q signals 
       % y1=filter(B,1,y);
        %R2=sqrt(x1.*x1 + y1.*y1);
        %R=[R1 R2];
        R=R1;
        
        flag=flag+1;
        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 "00"
            dsource1(i)=0; dsource2(i)=0;
        elseif (temp<0.5),                          % with probability 1/4, source output is "01"
            dsource1(i)=0; dsource2(i)=1;
        elseif (temp<0.75),                         % with probability 1/4, source output is "10"
            dsource1(i)=1; dsource2(i)=0;
        else                                        % with probability 1/4, source output is "11"
            dsource1(i)=1; dsource2(i)=1;
        end;
        end;
        % detection and the probability of error calculation
        for i=1:N,            % the received signal at the detection, for the ith symbol,is:
            n=sgma*randn(1,2);                          % 2 normal distributed r.v with 0, variance sgma
            
            if ((dsource1(i)==0) & (dsource2(i)==0)), 
                r=s00.*R(i)+n;
            elseif ((dsource1(i)==0) & (dsource2(i)==1)), 
                r=s01.*R(i)+n;
            elseif ((dsource1(i)==1) & (dsource2(i)==0)), 
                r=s10.*R(i)+n;
            else
                r=s11.*R(i)+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; 
            end;
            if (symbolerror==1), numofsymbolerror=numofsymbolerror+1; 
            end;
        end;
end
ps=numofsymbolerror/(N*flag);                          % since there are totally N symbols
pb=numofbiterror/(2*N*flag);                         % since 2N bits are transmitted 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -