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

📄 bpsk_flat_fading_ber.m

📁 BPSK with flat fading effects
💻 M
字号:
Guys, help me understand why in my matlab code below the
BER I get is better than it should be (for coherent BPSK). Maybe I add noise not
to the proper sognal or maybe parameter B in raylrnd is improper.

%MATLAB code
N=10000;%number of bits
s1 = zeros(N*100,1)';%1st path
s2 = zeros(N*100,1)';%2ndpath
EbNo=20;% Eb/No in dB
scar=zeros(2,100*N);
a=(sign(rand(1,N)-0.5)+1)/2;%generating random sequence of bits
T=1%bit interval
t=0:0.01*T:N*T-0.01*T;
%time

BB=1.2; % parameter in the Rayleigh envelope function raylrnd

f=2% carrier frequency
scar(1,:)=sin(2*pi*f*t);% the 2 reference signals at the receiver
scar(2,:)=-sin(2*pi*f*t);

randn('state',123)
ab = raylrnd(BB,1,N*100); %Raylegh envelope
rand('state',234)
phi=unifrnd(0,2*pi,1,N*100); %uniform phase

for k=1:size(a,2)
    i=1;
    for j=(k-1)*100+1:k*100
        if (a(k)+1)==1
        s1(j)=ab(i).*sin(2*pi*f*t(i)+phi(i)); 
        end;                              
        if (a(k)+1)==2
        s1(j)=-ab(i).*sin(2*pi*f*t(i)+phi(i)); 
        end;  
        i=i+1;
    end;
end;


randn('state',1230)
ab = raylrnd(BB,1,N*100); 
rand('state',1234)
phi=unifrnd(0,2*pi,1,N*100);

for k=1:size(a,2)
    i=1;
    for j=(k-1)*100+1:k*100
        if (a(k)+1)==1
        s2(j)=ab(i).*sin(2*pi*f*t(i)+phi(i)); 
        end;                          
        if (a(k)+1)==2
        s2(j)=-ab(i).*sin(2*pi*f*t(i)+phi(i)); 
        end;  
        i=i+1;
    end;
end;


     





s = zeros(1,N*100);

for k=1:size(a,2)
    i=1;
    for j=(k-1)*100+1:k*100
        s(j)=scar(a(k)+1,i);         %bpsk signal
        i=i+1;
    end;
end;
sorig=s;% save bpsk signal for future purpose of noise addition

gmsksig=zeros(N*100,1)';
bpsksig=sorig;

SNR=-20+EbNo+3;% SNR in dB, +3dB is because adding noise to a real signal,
%not complex 

snoise = zeros(N*100,1)';
noise = zeros(N*100,1)';
snoise=awgn(bpsksig,SNR,'measured',123,'dB');
snoise1 = zeros(N*100,1)';
noise1 = zeros(N*100,1)';
noise=snoise-sorig;

snoise1=awgn(bpsksig,SNR,'measured',1234,'dB');
noise1=snoise1-sorig;

snoise2=awgn(bpsksig,SNR,'measured',234,'dB');
noise2=snoise2-sorig;


s=s1+s2+noise+noise1;  %2 paths faded

%correlator detector coherent

tt=0:0.01*T:T-0.01*T;
sinerom = zeros(100,2)';
cosintegral=zeros(N,2,100);
cossum=zeros(N,2);
sinerom(1,:)=sin(2*pi*f*tt);%signal copy of sine representing '1'
sinerom(2,:)=-sin(2*pi*f*tt);%signal copy of sine representing '-1' with inverted phase
for k=1:size(a,2)
    for i=1:2
        for jj=1:100
            cosintegral(k,i,jj)=s((k-1)*100+jj).*sinerom(i,jj);  % here correlation-type detector
        end;                                % is realized ;  first multiplying the received signal
                               %with  signal copies in the 2 branches of
                                %correlator
    end;
end;
j=0;
for k=1:size(a,2)
    for i=1:2
         cossum(k,i)=sum(cosintegral(k,i,:));   % here is integration or just sum of th samples
    end;
maxcossum(k)=max(cossum(k,:));          % here max value of the correlator branches is determined
end;
for k=1:size(a,2)
    for i=1:2
        if cossum(k,i)==maxcossum(k)
        indexcossum(k)=i;                       %here the number of the branch where maximum
                            % is achieved (1 or 2)
        end;
    end;
end;
atrsec=[0 1];
for k=1:size(a,2)
adetsec(k)=atrsec(indexcossum(k));        % the 1st branch means '1' has been transmitted
end;                                      % the 2nd branch means '-1' has been transmitted  

for j=1:size(a,2)
res(j)=adetsec(j)-a(j);
end;
max(res)
min(res)
kjk=0;
for j=1:size(a,2)
if res(j)==0
    kjk=kjk+1;
end;
end;
errornum=size(a,2)-kjk                       %number of errors
format short e;
bercalc=errornum/size(a,2)    %BER
format;

⌨️ 快捷键说明

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