simulate and compare the performance of BPSK, QPSK, and QAM modulation schemes in MATLAB, including BER (Bit Error Rate) analysis
Here’s a step-by-step guide to simulate and compare the performance of BPSK, QPSK, and QAM modulation schemes in MATLAB, including BER (Bit Error Rate) analysis:
1. Key Parameters Setup
Define common parameters for all modulation schemes:
% Simulation parameters numBits = 1e6; % Number of bits per SNR point snr_dB = 0:2:20; % SNR range in dB modulationSchemes = {'BPSK', 'QPSK', '16QAM', '64QAM'};
2. Modulation and Demodulation Functions
BPSK
- Modulation:
0
→-1
,1
→+1
- Demodulation: Threshold at
0
QPSK
- Uses 4 phases (Gray-coded)
QAM
- Supports 16-QAM, 64-QAM, etc. (normalized average power)
% Initialize BER results storage berResults = zeros(length(snr_dB), length(modulationSchemes)); theoryBER = zeros(length(snr_dB), length(modulationSchemes)); for modIdx = 1:length(modulationSchemes) scheme = modulationSchemes{modIdx}; % Set modulation parameters switch scheme case 'BPSK' M = 2; % Modulation order k = 1; % Bits per symbol case 'QPSK' M = 4; k = 2; case '16QAM' M = 16; k = 4; case '64QAM' M = 64; k = 6; end % Generate random bits bits = randi([0 1], numBits, 1); % Modulate switch scheme case {'BPSK', 'QPSK'} modulated = pskmod(bits, M, InputType='bit', ... SymbolOrder='gray'); case {'16QAM', '64QAM'} modulated = qammod(bits, M, InputType='bit', ... UnitAveragePower=true); end % Loop over SNR values for snrIdx = 1:length(snr_dB) % Add AWGN rxSig = awgn(modulated, snr_dB(snrIdx), 'measured'); % Demodulate switch scheme case {'BPSK', 'QPSK'} rxBits = pskdemod(rxSig, M, OutputType='bit', ... SymbolOrder='gray'); case {'16QAM', '64QAM'} rxBits = qamdemod(rxSig, M, OutputType='bit', ... UnitAveragePower=true); end % Calculate BER berResults(snrIdx, modIdx) = sum(bits ~= rxBits) / numBits; end % Theoretical BER calculation snr_linear = 10.^(snr_dB/10); switch scheme case 'BPSK' theoryBER(:, modIdx) = 0.5*erfc(sqrt(snr_linear)); case 'QPSK' theoryBER(:, modIdx) = 0.5*erfc(sqrt(snr_linear)); case '16QAM' theoryBER(:, modIdx) = 3/8 * erfc(sqrt(0.4*snr_linear)); case '64QAM' theoryBER(:, modIdx) = 7/24 * erfc(sqrt(0.2857*snr_linear)); end end
3. BER Performance Plotting
Visualize simulated vs. theoretical BER:
figure; for modIdx = 1:length(modulationSchemes) semilogy(snr_dB, berResults(:, modIdx), 'o-', 'LineWidth', 1.5); hold on; semilogy(snr_dB, theoryBER(:, modIdx), '--', 'LineWidth', 1.5); end grid on; xlabel('SNR (dB)'); ylabel('Bit Error Rate (BER)'); title('BER vs SNR for Different Modulation Schemes'); legend([modulationSchemes, strcat(modulationSchemes, ' (Theory)')], ... 'Location', 'southwest');
4. Example Output
- BPSK/QPSK: Require lower SNR for the same BER compared to QAM.
- QAM: Higher spectral efficiency but needs higher SNR.
5. Key Concepts
- Gray Coding: Minimizes bit errors between adjacent symbols.
- Unit Average Power: Ensures fair comparison across modulation schemes.
- AWGN Channel:
awgn()
adds noise to simulate real-world channel effects.
6. Extensions
- Fading Channels:
% Rayleigh fading example channel = comm.RayleighChannel('SampleRate', 1e6); fadedSig = channel(modulated);
- Error-Correcting Codes:
% Convolutional coding example trellis = poly2trellis(7, [171 133]); codedBits = convenc(bits, trellis);
- Spectral Efficiency:
Calculate bits/sec/Hz for each scheme:spectralEfficiency = log2(M) / (1 + CP/N); % For OFDM systems
Full MATLAB Code
[Combine the code blocks above into a single script. Requires Communications Toolbox for pskmod
, qammod
, etc.]
This framework allows you to:
- Compare modulation schemes under AWGN
- Validate results against theoretical BER
- Extend to advanced scenarios (fading, coding, etc.)