## MATLAB Script for BER vs. SNR for M-QAM, M-PSK, QPSk, BPSK

## Output

If M>8, the distance between constellation points is short, and a higher Eb/No (SNR per Bit) ratio is required to reach the desired BER. Although the mapping from the data bits is arbitrary, some data bits are typically used. Every constellation point in the M-PSK constellation has two neighbors, each with an equal chance of making an error. As there are four bits per symbol, BER assumes a one-bit error for every mistake in a character. The demodulator in PSK must be able to calculate the received sinusoid's phase about some reference phase. While using the same bandwidths as ASK, PSK is less prone to errors than ASK. Also, using bandwidth with a significant data rate is more effective.

In the above figure, it is clear that PSK is more robust than QAM in the context of noise resilience. QAM modulations, including 16-QAM, are sensitive to both amplitude and phase errors. As you increase the number of constellation points (e.g., from 16-QAM to 8-PSK), the signal becomes more susceptible to amplitude and phase noise. In contrast, PSK modulations primarily rely on phase information and may be less sensitive to amplitude variations. This can make 8-PSK more robust in this scenario.

QAM schemes require a higher SNR to achieve the same error rates as PSK schemes with the same number of constellation points. This means that 16-QAM may require a higher SNR than 8-PSK to achieve a satisfactory bit error rate (BER) or symbol error rate (SER). In practical communication systems, achieving the necessary SNR can be challenging, especially in noisy or fading channels.

## MATLAB Code for BER vs SNR for m-ary QAM

clc;

clear all;

close all;

% Set parameters

snr_dB = -20:2:20; % SNR values in dB

qam_orders = [4, 16, 64, 256]; % QAM modulation orders

% Loop through each QAM order

for qam_order = qam_orders

% Calculate theoretical BER using berawgn

ber = berawgn(snr_dB, 'qam', qam_order);

% Plot the results

semilogy(snr_dB, ber, 'o-', 'DisplayName', sprintf('%d-QAM', qam_order));

hold on;

end

% Add labels and legend

title('BER vs SNR for Variable QAM');

xlabel('SNR (dB)');

ylabel('Bit Error Rate (BER)');

grid on;

legend('Location', 'best');

clear all;

close all;

% Set parameters

snr_dB = -20:2:20; % SNR values in dB

qam_orders = [4, 16, 64, 256]; % QAM modulation orders

% Loop through each QAM order

for qam_order = qam_orders

% Calculate theoretical BER using berawgn

ber = berawgn(snr_dB, 'qam', qam_order);

% Plot the results

semilogy(snr_dB, ber, 'o-', 'DisplayName', sprintf('%d-QAM', qam_order));

hold on;

end

% Add labels and legend

title('BER vs SNR for Variable QAM');

xlabel('SNR (dB)');

ylabel('Bit Error Rate (BER)');

grid on;

legend('Location', 'best');

## Output

**Fig: BER vs SNR graph for Various QAM**

## Copy the aforementioned MATLAB Code from Here

## MATLAB Code for BER vs SNR for m-ary PSK

clc;

clear all;

close all;

% Parameters

num_symbols = 1e5; % Number of symbols

snr_db = 0:2:20; % Range of SNR values in dB

% PSK orders to be tested

psk_orders = [2, 4, 8, 16, 32];

% Initialize BER arrays

ber_results = zeros(length(psk_orders), length(snr_db));

% BER calculation for each PSK order and SNR value

for i = 1:length(psk_orders)

psk_order = psk_orders(i);

for j = 1:length(snr_db)

% Generate random symbols

data_symbols = randi([0, psk_order-1], 1, num_symbols);

% Modulate symbols to generate signal

modulated_signal = pskmod(data_symbols, psk_order);

% Add AWGN to the signal

snr_linear = 10^(snr_db(j)/10);

received_signal = awgn(modulated_signal, snr_db(j), 'measured');

% Demodulate received signal

demodulated_symbols = pskdemod(received_signal, psk_order);

% Calculate BER

ber_results(i, j) = sum(data_symbols ~= demodulated_symbols) / num_symbols;

end

end

% Plot BER vs. SNR

figure;

semilogy(snr_db, ber_results(1, :), 'o-', 'DisplayName', 'BPSK');

hold on;

for i = 2:length(psk_orders)

semilogy(snr_db, ber_results(i, :), 'o-', 'DisplayName', sprintf('%d-PSK', psk_orders(i)));

end

title('BER vs. SNR for Various PSK Schemes');

xlabel('SNR (dB)');

ylabel('Bit Error Rate (BER)');

legend('Location', 'best');

grid on;

hold off;

clear all;

close all;

% Parameters

num_symbols = 1e5; % Number of symbols

snr_db = 0:2:20; % Range of SNR values in dB

% PSK orders to be tested

psk_orders = [2, 4, 8, 16, 32];

% Initialize BER arrays

ber_results = zeros(length(psk_orders), length(snr_db));

% BER calculation for each PSK order and SNR value

for i = 1:length(psk_orders)

psk_order = psk_orders(i);

for j = 1:length(snr_db)

% Generate random symbols

data_symbols = randi([0, psk_order-1], 1, num_symbols);

% Modulate symbols to generate signal

modulated_signal = pskmod(data_symbols, psk_order);

% Add AWGN to the signal

snr_linear = 10^(snr_db(j)/10);

received_signal = awgn(modulated_signal, snr_db(j), 'measured');

% Demodulate received signal

demodulated_symbols = pskdemod(received_signal, psk_order);

% Calculate BER

ber_results(i, j) = sum(data_symbols ~= demodulated_symbols) / num_symbols;

end

end

% Plot BER vs. SNR

figure;

semilogy(snr_db, ber_results(1, :), 'o-', 'DisplayName', 'BPSK');

hold on;

for i = 2:length(psk_orders)

semilogy(snr_db, ber_results(i, :), 'o-', 'DisplayName', sprintf('%d-PSK', psk_orders(i)));

end

title('BER vs. SNR for Various PSK Schemes');

xlabel('SNR (dB)');

ylabel('Bit Error Rate (BER)');

legend('Location', 'best');

grid on;

hold off;

## Output

**Fig: BER vs SNR graph for various PSK**

## Copy the above code from here

**Read more about**