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 BPSKQPSK, and QAM modulation schemes in MATLAB, including BER (Bit Error Rate) analysis:


1. Key Parameters Setup

Define common parameters for all modulation schemes:

matlab
Copy
% 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

  • Modulation0 → -11 → +1
  • Demodulation: Threshold at 0

QPSK

  • Uses 4 phases (Gray-coded)

QAM

  • Supports 16-QAM, 64-QAM, etc. (normalized average power)
matlab
Copy
% 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:

matlab
Copy
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

BER vs SNR for BPSK, QPSK, 16QAM, and 64QAM

  • BPSK/QPSK: Require lower SNR for the same BER compared to QAM.
  • QAM: Higher spectral efficiency but needs higher SNR.

5. Key Concepts

  1. Gray Coding: Minimizes bit errors between adjacent symbols.
  2. Unit Average Power: Ensures fair comparison across modulation schemes.
  3. AWGN Channelawgn() adds noise to simulate real-world channel effects.

6. Extensions

  1. Fading Channels:
    matlab
    Copy
    % Rayleigh fading example
    channel = comm.RayleighChannel('SampleRate', 1e6);
    fadedSig = channel(modulated);
  2. Error-Correcting Codes:
    matlab
    Copy
    % Convolutional coding example
    trellis = poly2trellis(7, [171 133]);
    codedBits = convenc(bits, trellis);
  3. Spectral Efficiency:
    Calculate bits/sec/Hz for each scheme:

    matlab
    Copy
    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 pskmodqammod, etc.]

This framework allows you to:

  • Compare modulation schemes under AWGN
  • Validate results against theoretical BER
  • Extend to advanced scenarios (fading, coding, etc.)