Uploaded by Optimistic Minds

matlab code gpt

advertisement
clear all;
close all;
% Generate a binary sequence
data = randi([0 1], 1, 1000);
% Modulate the sequence using BPSK
modulated_data = 2 * data - 1;
% Define the range of SNR values in dB
SNR_dB = 0:2:20;
% Convert SNR from dB to linear scale
SNR = 10.^(SNR_dB/10);
% Initialize the vector to store the BER values
BER = zeros(1, length(SNR));
% Loop over different SNR values
for i = 1:length(SNR)
% Add AWGN noise
received_data = modulated_data + sqrt(1/2) * randn(1, length(modulated_data)) /
sqrt(SNR(i));
% Demodulate the received data using BPSK
demodulated_data = received_data > 0;
% Compute the number of bit errors
errors = sum(abs(data - demodulated_data));
% Compute the BER for the current SNR value
BER(i) = errors / length(data);
end
% Plot the BER versus SNR graph
semilogy(SNR_dB, BER, '-o');
xlabel('SNR (dB)');
ylabel('BER');
title('BER vs. SNR for BPSK modulation in AWGN channel');
grid on;
Download