📄 bpsk.m
字号:
close all;
clear all;
N = 10^6; % number of bits
sr_br=1; % for bpsk, br=sr. where br: bit rate sr: symbol rate
PowS=1;
Eb_N0_dB = [-3:35]; % multiple Eb/N0 values
EbN0Lin = 10.^(Eb_N0_dB/10); % multiple Eb/N0 values in linear
% Transmitter
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0
for ii = 1:length(Eb_N0_dB)
PowN=sr_br*PowS/EbN0Lin(ii); % power of noise
n = sqrt(PowN/2)*[randn(1,N) + j*randn(1,N)]; % white gaussian noise
h = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % Rayleigh channel
y = h.*s + n; % Channel and noise Noise addition
yHat = y./h; % equalization
ipHat = real(yHat)>0; % receiver - hard decision decoding
nErr(ii) = size(find([ip- ipHat]),2); % counting the errors
end
simBer = nErr/N; % simulated ber
theoryBerAWGN = 0.5*erfc(sqrt(EbN0Lin)); % theoretical ber on AWGN
theoryBerRayleigh = 0.5.*(1-sqrt(EbN0Lin./(EbN0Lin+1))); % theoretical ber on Rayleighchannel
% plot
figure
semilogy(Eb_N0_dB,theoryBerAWGN,'cd-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,theoryBerRayleigh,'bp-','LineWidth',2);
semilogy(Eb_N0_dB,simBer,'mx-','LineWidth',2);
axis([-3 35 10^-5 0.5])
grid on
legend('AWGN-Theory','Rayleigh-Theory', 'Rayleigh-Simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation in Rayleigh channel');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -