前言
此示例创建了一个【频率平坦的瑞利衰落信道】对象,并使用该对象来对DBPSK信号进行衰落处理,衰落之后增加了不同信噪比的AWGN,计算出不同的信噪比值计算误码率,并和理论误码率进行了对比。
一、MATLAB仿真代码
代码如下:
% Create Rayleigh fading channel objects
chan = comm.RayleighChannel('SampleRate',1e4,'MaximumDopplerShift',100);
M = 2; % DBPSK modulation order
tx = randi([0 M-1],50000,1); % Generate a random bit stream
% Create modulator, and demodulator objects
mod = comm.DBPSKModulator;
demod = comm.DBPSKDemodulator;
dpskSig = mod(tx); % dpskSig=±1序列
% Apply the channel effects
sig_test = 1j*ones(50000,1);
fadedTestSig = chan(sig_test); % 衰落
fadedSig = dpskSig.*fadedTestSig; % 衰落作用与发射信号,得到衰落信号
figure()
plot(20*log10(abs(fadedSig)))
hold on
grid on
xlim([0,10000])
title('DBPSK衰落信号的功率')
xlabel('samples');
ylabel('Signal power(dB)');
% Create an AWGN channel object.
awgnChan = comm.AWGNChannel('NoiseMethod', 'Signal to noise ratio (SNR)');
% Create an error rate calculator object.
errorCalc = comm.ErrorRate;
% Compute error rate for different values of SNR.
SNR = 0:2:20; % Range of SNR values, in dB.
numSNR = length(SNR);
berVec = zeros(3, numSNR); % Preallocate a vector for BER results
for n = 1:numSNR
awgnChan.SNR = SNR(n);
rxSig = awgnChan(fadedSig); % Add Gaussian noise
rx = demod(rxSig); % Demodulate
reset(errorCalc)
berVec(:,n) = errorCalc(tx,rx); % Compute error rate.
end
BER = berVec(1,:);
% Compute theoretical performance results, for comparison.
BERtheory = berfading(SNR,'dpsk',M,1);
% Plot BER results.
figure()
semilogy(SNR,BERtheory,'b-',SNR,BER,'r*','LineWidth',1);
grid on;
xlabel('SNR (dB)');
ylabel('BER');
title('Binary DPSK over Rayleigh Fading Channel');
legend('Theoretical BER','Empirical BER');
二、仿真结果画图
衰落信号功率:
BER性能曲线: