Você está na página 1de 10

5.

MATLAB: BPSK over Rayleigh Channel- Simulate the performance of BPSK detection over a Rayleigh faing wireless channel and plot the BER from both the simulation and the analytical expression derived in class. For comparison, on the same figure, plot the BER performance of BPSK transmission across the AWGN channel from the previous assignment. clc close all clear all %% %%%%%%% generate BPSK signal %%%%%% %% number_of_bits=input('enter the number of input bits'); a=0; b=1; A=a+(b-a)*rand(1,number_of_bits); BIN=1*(A>=0.5); BPSK=2*BIN-1; %% %%%%%%% SNR vs BER %%%%%%%%% %% snr_db=-5:10; snr=10.^(snr_db/10); index=1; for i=1:length(snr_db) n1=sqrt(1/2)*randn(1,number_of_bits); n2=sqrt(1/2)*randn(1,number_of_bits); a=sqrt((n1.^2)+(n2.^2)); phi=0; h=a*exp(j*phi); no=1/snr(i); awgnnoise=sqrt(no)*randn(1,number_of_bits); %% BER calculation over rayleigh fading channel %% noisy_signal=(h.*BPSK)+awgnnoise; DBPSK=1*(noisy_signal>=0); temp=xor(DBPSK,BIN); number_of_error=length(find(temp==1)); BER(index)=number_of_error/number_of_bits; %% BER calculation over AWGN channel %% noisy_signal1=BPSK+awgnnoise; DBPSK1=1*(noisy_signal1>=0); temp1=xor(DBPSK1,BIN); number_of_error1=length(find(temp1==1)); BER1(index)=number_of_error1/number_of_bits; index=index+1; end BER_THEORTICAL=0.5.*(1-sqrt(snr./(2+snr))); semilogy(snr_db,BER_THEORTICAL,'-+'); hold on semilogy(snr_db,BER,'r-o'); BER_THEORTICAL1=0.5*erfc(sqrt(snr/2)) semilogy(snr_db,BER_THEORTICAL1,'m'); semilogy(snr_db,BER1,'k-*'); grid on legend('BPSK over rayleigh fading channel(Theoritical)', 'BPSK over rayleigh fading channel(Simulated)','BPSK over AWGN channel(Theoretical)','BPSK over AWGN channel(simulated)'); xlabel('SNR, db'); ylabel('Bit Error Rate');

Simulation results: enter the number of input bits 10^5 %% Simulated and Theoretical BER for Rayleigh fading channel BER = 0.3157 0.2958 0.2746 0.2537 0.2343 0.2132 0.1885 0.1673 0.1470 0.1267 0.1073 0.0933 0.0770 0.0646 0.0526 0.0435 BER_THEORTICAL = 0.3153 0.2963 0.2762 0.2551 0.2334 0.2113 0.1892 0.1675 0.1467 0.1269 0.1087 0.0921 0.0773 0.0643 0.0531 0.0436 %% Simulated and Theoretical BER for AWGN channel BER1 = 0.2871 0.2645 0.2376 0.2120 0.1888 0.1588 0.1296 0.1035 0.0784 0.0560 0.0373 0.0230 0.0127 0.0065 0.0024 0.0009 BER_THEORTICAL1 = 0.2869 0.2640 0.2395 0.2135 0.1864 0.1587 0.1309 0.1040 0.0789 0.0565 0.0377 0.0230 0.0126 0.0060 0.0024 0.0008

Fig.1 BER performance of BPSK modulation over AWGN and Rayleigh fading channel

Qustion6 WITHOUT INTERLEAVING Note: In this case we consider that affected by same fading coefficient. each symbol in repetition block is

%Repetition code over Rayleigh Channel, symbol-wise and block-wise detection without interleaving clc clear all %% Generate input bits number_of_bits=input('enter the number of input bits'); n=input('enter codeword length n for repetition code(n,1)'); a=0; b=1; A=a+(b-a)*rand(1,number_of_bits); BIN=1*(A>=0.5); %% Repetition coding (n,1) codedbits=[]; for j=1:length(BIN) codedbit=BIN(j).*ones(1,n); codedbits=[codedbits codedbit]; end %% BPSK Modulation BPSK=2*codedbits-1; %% Simulated BER vs SNR snr_db=-5:10; snr=10.^(snr_db/10); ub=1.*ones(1,n); ua=-1.*ones(1,n); index=1; for i=1:length(snr_db) i n1=sqrt(1/2)*randn(1,length(BIN)); n2=sqrt(1/2)*randn(1,length(BIN)); raynoise=sqrt((n1.^2)+(n2.^2)); raynoise1=[]; for j1=1:length(raynoise) raynoise2=raynoise(j1).*ones(1,n); raynoise1=[raynoise1 raynoise2]; end no=1/snr(i); awgnnoise=sqrt(no)*randn(1,length(BPSK)); %% BER calculation over rayleigh fading channel %% noisy_signal=(raynoise1.*BPSK)+awgnnoise; %% Symbolwise detection scheme l=[]; for i1 =1:n:length(noisy_signal) l1 = length(find(noisy_signal(i1:i1+n-1)<0)); l = [l l1]; end DBPSK = 1*(l<=(n/2)); number_of_error = length(find(xor(DBPSK,BIN)==1)); BER(index) = number_of_error/number_of_bits; %% Blockwise detection scheme

DBPSK2=[]; for i4 = 1:n:length(noisy_signal) d1 = norm(noisy_signal(i4:i4+n-1)-ua); d2 = norm(noisy_signal(i4:i4+n-1)-ub); DBPSK3 = 1*(d1>=d2); DBPSK2 = [DBPSK2 DBPSK3]; end number_of_error1 = length(find(xor(DBPSK2,BIN)==1)); BER1(index) = number_of_error1/number_of_bits; index = index+1; end %% Theoretical block detection BER_T_block = 0.5*(1- sqrt(n*snr./(2+n*snr))); %% plot BER vs SNR semilogy(snr_db,BER); hold on semilogy(snr_db,BER1,'m'); semilogy(snr_db, BER_T_block,'k'); P=0.5*(1-sqrt(snr./(2+snr))); semilogy(snr_db,P,'g') grid on legend('symbol detection(simulated)','block detection(simulated)','block detection(theoretical)','BPSK with rayleigh fading'); xlabel('SNR, db'); ylabel('Bit Error Rate');

Fig.2 Repetition code over Rayleigh Channel, symbol-wise and block-wise detection without interleaving where fading coefficients is same for each symbol in repetition block

Note: In this case we consider that each affected by different fading coefficient.

symbol

in

repetition

block

is

%Repetition code over Rayleigh Channel,symbolwise and block detection without %interleaving clc clear all %% Generate input bits number_of_bits=input('enter the number of input bits'); n=input('enter codeword length n for repetition code(n,1)'); a=0; b=1; A=a+(b-a)*rand(1,number_of_bits); BIN=1*(A>=0.5); %% Repetition coding (n,1) codedbits=[]; for j=1:length(BIN) codedbit=BIN(j).*ones(1,n); codedbits=[codedbits codedbit]; end %% BPSK Modulation BPSK=2*codedbits-1; %% Simulated BER vs SNR snr_db=-5:10; snr=10.^(snr_db/10); ub=1.*ones(1,n); ua=-1.*ones(1,n); index=1; for i=1:length(snr_db) i n1=sqrt(1/2)*randn(1,length(BPSK)); n2=sqrt(1/2)*randn(1,length(BPSK)); raynoise=sqrt((n1.^2)+(n2.^2)); no=1/snr(i); awgnnoise=sqrt(no)*randn(1,length(BPSK)); %% BER calculation over rayleigh fading channel %% noisy_signal=(raynoise.*BPSK)+awgnnoise; %% Symbolwise detection scheme l=[]; for i1 =1:n:length(noisy_signal) l1 = length(find(noisy_signal(i1:i1+n-1)<0)); l = [l l1]; end DBPSK = 1*(l<=(n/2)); number_of_error = length(find(xor(DBPSK,BIN)==1)); BER(index) = number_of_error/number_of_bits; %% Blockwise detection scheme DBPSK2=[]; for i4 = 1:n:length(noisy_signal) d1 = norm(noisy_signal(i4:i4+n-1)-ua); d2 = norm(noisy_signal(i4:i4+n-1)-ub); DBPSK3 = 1*(d1>=d2); DBPSK2 = [DBPSK2 DBPSK3]; end number_of_error1 = length(find(xor(DBPSK2,BIN)==1));

BER1(index) = number_of_error1/number_of_bits; index = index+1; end %% theoretical symbol detection P=0.5*(1-sqrt(snr./(2+snr))); r=ceil(n/2); index1=1; for i2=1:length(snr) Pe=0; for i3=r:n nCr = prod((n-i3+1):n)/prod(1:i3); P1=nCr*(P(i2)^i3)*((1-P(i2))^(n-i3)); Pe=Pe+P1; end BER_T_sym(index1)=Pe; index1 = index1+1 end %% plot BER vs SNR semilogy(snr_db,BER); hold on semilogy(snr_db,BER_T_sym,'r'); semilogy(snr_db,BER1,'m'); semilogy(snr_db,P,'g'); grid on legend('symbol detection(simulated)','symbol detection(theoretical)','block detection(simulated)','BPSK with rayleigh fading channel'); xlabel('SNR, db'); ylabel('Bit Error Rate');

Fig.3 Repetition code over Rayleigh Channel, symbol-wise and block-wise detection without interleaving where fading coefficients is different for each symbol in repetition block.

Qustion6 WITH INTERLEAVING Note: In this case we consider that each affected by different fading coefficient. symbol in repetition block is

clc clear all %% Generate input bits number_of_bits= input('enter the number of input bits'); n= input('enter codeword length n for repetition code(n,1)'); a=0; b=1; A=a+(b-a)*rand(1,number_of_bits); BIN=1*(A>=0.5); %% Repetition coding (n,1) codedbits=[]; for j=1:length(BIN) codedbit=BIN(j).*ones(1,n); codedbits=[codedbits codedbit]; end interl=[]; for j1=1:n interl1=codedbits(j1:n:end); interl=[interl interl1]; end %% BPSK Modulation BPSK=2*interl-1; %% Simulated BER vs SNR snr_db=-5:10; snr=10.^(snr_db/10); ub=1.*ones(1,n); ua=-1.*ones(1,n); index=1; for i=1:length(snr_db) i n1=sqrt(1/2)*randn(1,length(BPSK)); n2=sqrt(1/2)*randn(1,length(BPSK)); h=sqrt((n1.^2)+(n2.^2)); no=1/snr(i); awgnnoise=sqrt(no)*randn(1,length(BPSK)); %% BER calculation over rayleigh fading channel %% noisy_signal=(h.*BPSK)+awgnnoise; deinterl=[]; DBPSK2=[]; for j2=1:length(interl)/n deinterl1=length(find(noisy_signal(j2:length(BIN):end)<0)); deinterl=[deinterl deinterl1]; d1 = norm(noisy_signal(j2:length(BIN):end)-ua); d2 = norm(noisy_signal(j2:length(BIN):end)-ub); DBPSK3 = 1*(d1>=d2); DBPSK2 = [DBPSK2 DBPSK3]; end DBPSK = 1*(deinterl<=(n/2)); number_of_error = length(find(xor(DBPSK,BIN)==1)); BER(index) = number_of_error/number_of_bits;

number_of_error1 = length(find(xor(DBPSK2,BIN)==1)); BER1(index) = number_of_error1/number_of_bits; index = index+1; end semilogy(snr_db,BER); hold on semilogy(snr_db,BER1,'r-o') %% Theoretical symbol detection P=0.5*(1-sqrt(snr./(2+snr))); semilogy(snr_db,P,'g-*'); r=ceil(n/2); index1=1; for i2=1:length(snr) Pe=0; for i3=r:n nCr = prod((n-i3+1):n)/prod(1:i3); P1=nCr*(P(i2)^i3)*((1-P(i2))^(n-i3)); Pe=Pe+P1; end BER_T(index1)=Pe; index1 = index1+1 end semilogy(snr_db,BER_T,'m-.'); legend('symbol detection(simulated)','block detection(simulated)','BPSK over rayleigh fading channel','symbol detection(theoretical)'); grid on xlabel('SNR, db'); ylabel('Bit Error Rate');

Fig.4 Repetition code over Rayleigh Channel, symbol-wise and block-wise detection with interleaving where fading coefficients is different for each symbol in repetition block.

Note: In this case we consider that each symbol in repetition affected by same fading coefficient. clc clear all %% Generate input bits number_of_bits= input('enter the number of input bits'); n= input('enter codeword length n for repetition code(n,1)'); a=0; b=1; A=a+(b-a)*rand(1,number_of_bits); BIN=1*(A>=0.5); %% Repetition coding (n,1) codedbits=[]; for j=1:length(BIN) codedbit=BIN(j).*ones(1,n); codedbits=[codedbits codedbit]; end interl=[]; for j1=1:n interl1=codedbits(j1:n:end); interl=[interl interl1]; end %% BPSK Modulation BPSK=2*interl-1; %% Simulated BER vs SNR snr_db=-5:10; snr=10.^(snr_db/10); ub=1.*ones(1,n); ua=-1.*ones(1,n); index=1; for i=1:length(snr_db) i n1=sqrt(1/2)*randn(1,length(BIN)); n2=sqrt(1/2)*randn(1,length(BIN)); raynoise=sqrt((n1.^2)+(n2.^2)); raynoise1=[]; for j1=1:length(raynoise) raynoise2=raynoise(j1).*ones(1,n); raynoise1=[raynoise1 raynoise2]; end no=1/snr(i); awgnnoise=sqrt(no)*randn(1,length(BPSK)); %% BER calculation over rayleigh fading channel %% noisy_signal=(raynoise1.*BPSK)+awgnnoise; deinterl=[]; DBPSK2=[]; for j2=1:length(interl)/n deinterl1=length(find(noisy_signal(j2:length(BIN):end)<0)); deinterl=[deinterl deinterl1]; d1 = norm(noisy_signal(j2:length(BIN):end)-ua); d2 = norm(noisy_signal(j2:length(BIN):end)-ub); DBPSK3 = 1*(d1>=d2); DBPSK2 = [DBPSK2 DBPSK3]; end DBPSK = 1*(deinterl<=(n/2)); number_of_error = length(find(xor(DBPSK,BIN)==1)); BER(index) = number_of_error/number_of_bits;

block

is

number_of_error1 = length(find(xor(DBPSK2,BIN)==1)); BER1(index) = number_of_error1/number_of_bits; index = index+1; end semilogy(snr_db,BER); hold on semilogy(snr_db,BER1,'r-o') P=0.5*(1-sqrt(snr./(2+snr))); semilogy(snr_db,P,'g-*'); r=ceil(n/2); index1=1; for i2=1:length(snr) Pe=0; for i3=r:n nCr = prod((n-i3+1):n)/prod(1:i3); P1=nCr*(P(i2)^i3)*((1-P(i2))^(n-i3)); Pe=Pe+P1; end BER_T(index1)=Pe; index1 = index1+1 end semilogy(snr_db,BER_T,'m-.'); legend('symbol detection(simulated)','block detection(simulated)','BPSK over rayleigh fading channel','symbol detection(theoretical)'); grid on xlabel('SNR, db'); ylabel('Bit Error Rate');

Fig.2 Repetition code over Rayleigh Channel, symbol-wise and block-wise detection without interleaving where fading coefficients is same for each symbol in repetition block

Você também pode gostar