Matlab2020bAWGN信道下2PSK和2DPSK的误码率曲线代码
时间: 2023-08-24 13:04:05 浏览: 128
这是一个基于 Matlab 2020b 的 AWGN 信道下 2PSK 和 2DPSK 的误码率曲线代码示例:
```matlab
%% 2PSK and 2DPSK Bit Error Rate (BER) simulation in AWGN channel
% Define modulation parameters
M = 2; % Modulation order (2 for 2PSK and 4 for 2DPSK)
k = log2(M); % Number of bits per symbol
EbNoVec = 0:10; % Eb/No values to simulate (in dB)
% Define simulation parameters
numBits = 1e6; % Number of bits to simulate
numErrs = zeros(length(EbNoVec),1); % Number of errors for each Eb/No value
numBitsVec = k*numBits*ones(length(EbNoVec),1); % Total number of bits transmitted for each Eb/No value
% Loop over each Eb/No value and simulate transmission and reception
for i = 1:length(EbNoVec)
% Generate random bit stream
txBits = randi([0 1], numBits, k);
% Map bits to symbols
txSym = pskmod(txBits, M);
% Add AWGN noise to signal
noiseVar = 10^(-EbNoVec(i)/10); % Noise variance
noise = sqrt(noiseVar) * randn(size(txSym)); % Gaussian noise
rxSym = txSym + noise;
% Demodulate symbols to bits
rxBits = pskdemod(rxSym, M);
% Count number of bit errors
numErrs(i) = biterr(txBits, rxBits);
end
% Calculate simulated BER values
simBer = numErrs./numBitsVec;
% Calculate theoretical BER values (for comparison)
theoryBer = berawgn(EbNoVec, 'psk', M, 'nondiff');
% Plot results
semilogy(EbNoVec, simBer, 'o-', 'LineWidth', 2);
hold on;
semilogy(EbNoVec, theoryBer, 'r--', 'LineWidth', 2);
hold off;
grid on;
xlabel('Eb/No (dB)');
ylabel('Bit Error Rate (BER)');
title(['2PSK and 2DPSK BER in AWGN channel with ' num2str(k) ' bits per symbol']);
legend('Simulated BER', 'Theoretical BER');
```
这段代码可以生成 AWGN 信道下 2PSK 和 2DPSK 的误码率曲线,并将其与理论值进行比较。您可以根据需要进行修改和调整。
阅读全文