请写出完成BPSK和QPSK调制在AWGN信道下的SNR-BER误码率性能评估的matlab代码
时间: 2024-03-16 17:43:35 浏览: 176
AWGN信道BPSK调制技术误码率性能分析matlab代码.zip
以下是BPSK和QPSK调制在AWGN信道下的SNR-BER误码率性能评估的MATLAB代码:
```matlab
clear all;
close all;
% Modulation type
mod_type = 'BPSK'; % 'BPSK' or 'QPSK'
% Channel parameters
SNR_dB = 0:1:15; % SNR in dB
SNR = 10.^(SNR_dB/10); % SNR in linear scale
nbits = 1e5; % number of bits
nerr = zeros(size(SNR)); % number of errors
nframes = 10; % number of frames
% Modulation
if strcmp(mod_type,'BPSK')
bits = randi([0 1],1,nbits); % generate random bits
x = 2*bits - 1; % BPSK modulation
else
bits = randi([0 1],1,2*nbits); % generate random bits
x = 1/sqrt(2)*(2*bits(1:2:end)-1 + 1i*(2*bits(2:2:end)-1)); % QPSK modulation
end
% AWGN channel
for i=1:length(SNR)
for j=1:nframes
% Add noise
n = sqrt(1/2/SNR(i))*(randn(size(x))+1i*randn(size(x)));
% Received signal
y = x + n;
% Demodulation
if strcmp(mod_type,'BPSK')
bits_hat = y>0;
else
bits_hat = zeros(1,2*nbits);
bits_hat(1:2:end) = real(y)>0;
bits_hat(2:2:end) = imag(y)>0;
end
% Count errors
nerr(i) = nerr(i) + sum(bits~=bits_hat);
end
end
% BER calculation
BER = nerr/nbits/nframes;
% Plot results
figure;
semilogy(SNR_dB,BER,'o-');
grid on;
xlabel('SNR (dB)');
ylabel('BER');
if strcmp(mod_type,'BPSK')
title('BPSK modulation in AWGN channel');
else
title('QPSK modulation in AWGN channel');
end
```
阅读全文