Skip to main content

MATLAB Code for SER vs SNR for 4-QAM


MATLAB Script

% This code is written by SalimWirelss.Com
clc;
clear all;
close all;

M = 4; % Number of levels after quantization / size of signal constellation
k = log2(M); % Number of bits per symbol
rng(10) % Assaining the value of seed integer
N = 10000; % Number of bits to process

% Initialize SNR values and BER array
snr_dB = 0:1:20; % SNR values in dB
BER = zeros(size(snr_dB));

for snr_idx = 1:length(snr_dB)
snrdB = snr_dB(snr_idx);

InputBits = randi([0 1], 1, N); % Generating randon bits
InputSymbol_matrix = reshape(InputBits, length(InputBits)/k, k); % Reshape data into binary k-tuples, k = log2(M)
InputSymbols_decimal = bi2de(InputSymbol_matrix); % Convert binary to decimal

for n = 1:N/k
if InputSymbols_decimal(n) == 0
QAM(n) = complex(1,1);
elseif InputSymbols_decimal(n) == 1
QAM(n) = complex(-1,1);
elseif InputSymbols_decimal(n) == 2
QAM(n) = complex(1,-1);
else
QAM(n) = complex(-1,-1);
end
end

% Transmission of 4QAM data over AWGN channel
Y = awgn(QAM, snrdB); % Received signal

% Threshold Detection
for n = 1:N/k
if (real(Y(n)) > 0 && imag(Y(n)) > 0)
Z(n) = complex(1,1);
elseif (real(Y(n)) > 0 && imag(Y(n)) < 0)
Z(n) = complex(1,-1);
elseif (real(Y(n)) < 0 && imag(Y(n)) > 0)
Z(n) = complex(-1,1);
else
Z(n) = complex(-1,-1);
end
end

for n = 1:N/k
if Z(n) == complex(1,1)
output(n) = 0;
elseif Z(n) == complex(-1,1)
output(n) = 1;
elseif Z(n) == complex(1,-1)
output(n) = 2;
else
output(n) = 3;
end
end
% Compute BER
BER(snr_idx) = sum(InputSymbols_decimal ~= output') / N;
end

% Plot BER vs. SNR
figure;
semilogy(snr_dB, BER, 'o-');
grid on;
xlabel('SNR (dB)');
ylabel('Symbol Error Rate (SER)');
title('SER vs. SNR');

 

Output

 

 

 
Fig 1: SER vs SNR for 4-QAM
 
 

Copy the MATLAB Code from here

Contact Us

Name

Email *

Message *

Popular Posts

Rayleigh vs Rician Fading (with MATLAB + Simulator)

  In Rayleigh fading , the channel coefficients tend to have a Rayleigh distribution, which is characterized by a random phase and magnitude with an exponential distribution. This means the magnitude of the channel coefficient follows an exponential distribution with a mean of 1. In Rician fading , there is a dominant line-of-sight component in addition to the scattered components. The channel coefficients in Rician fading can indeed tend towards 1, especially when the line-of-sight component is strong. When the line-of-sight component dominates, the Rician fading channel behaves more deterministically, and the channel coefficients may tend towards the value of the line-of-sight component, which could be close to 1.   MATLAB Script clc; clear all; close all; % Define parameters numSamples = 1000; % Number of samples K_factor = 5; % K-factor for Rician fading SNR_dB = 20; % Signal-to-noise ratio (in dB) % Generate complex Gaussian random variable for Rayleigh fading channel h_r...

UGC-NET Electronic Science Question Paper With Answer Key and Full Explanation [Dec 2023]

    UGC-NET Electronic Science Question Paper With Answer Key Download Pdf [Dec 2023] Download Question Paper               See Answers   2025 | 2024 | 2023 | 2022 | 2021 | 2020 UGC-NET Electronic Science  2023 Answers with Explanations 51. (A): The stacking fault is the most common area defect found in silicon. These faults typically occur along the 111 plane. In the crystalline structure of silicon, atoms are arranged in a specific pattern known as a diamond lattice. A stacking fault refers to a disruption in the normal order of atomic layers within this lattice, which usually occurs in the 111 plane due to the geometric arrangement of the atoms. This type of defect can affect the electrical and mechanical properties of the material, such as the mobility of charge carriers and mechanical strength. 52. (C): The important figure of merit for the microwave application of a Schot...

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...(MATLAB Code + Simulator)

Bit Error Rate (BER) & SNR Guide Analyze communication system performance with our interactive simulators and MATLAB tools. 📘 Theory 🧮 Simulators 💻 MATLAB Code 📚 Resources BER Definition SNR Formula BER Calculator MATLAB Comparison 📂 Explore M-ary QAM, PSK, and QPSK Topics ▼ 🧮 Constellation Simulator: M-ary QAM 🧮 Constellation Simulator: M-ary PSK 🧮 BER calculation for ASK, FSK, and PSK 🧮 Approaches to BER vs SNR What is Bit Error Rate (BER)? The BER indicates how many corrupted bits are received compared to the total number of bits sent. It is the primary figure of merit for a...

UGC NET Electronic Science Previous Year Question Papers

Home / Engineering & Other Exams / UGC NET 2022 PYQ 📥 Download UGC NET Electronics PDFs Complete collection of previous year question papers, answer keys and explanations for Subject Code 88. Start Downloading UGC-NET (Electronics Science, Subject code: 88) Subject_Code : 88; Department : Electronic Science; 📂 View All Question Papers Q. UGC Net Electronic Science Question Paper [June 2025] A. UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2025] with full explanation Q. UGC Net Electronic Science Question Paper [December 2024] A. UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2024] Q. UGC Net Electronic Science Question Paper [Aug 2024] A. UGC Net Electronic Scien...

OFDM Waveform with MATLAB Code (with Simulator)

  In OFDM (Orthogonal Frequency Division Multiplexing) , we transmit multiple orthogonal subcarriers simultaneously. Since the subcarriers are orthogonal , they do not interfere with each other, which is one of the main advantages of OFDM. Practically, OFDM converts a wideband signal into multiple narrowband orthogonal subcarriers. For typical wireless communication, if the signal bandwidth (or symbol duration) exceeds the coherence bandwidth of the channel, the signal experiences frequency-selective fading . Fading distorts the signal, making it difficult to recover the original information. By using OFDM, we transmit the same wideband signal across multiple orthogonal narrowband subcarriers, reducing the effect of fading. For example, if we want to transmit a signal of bandwidth 1024 kHz , we can divide it into N = 8 subcarriers . Each subcarrier is then spaced by: Δf = Total Bandwidth N = 1024 8 kHz...

Simulation of ASK, FSK, and PSK using MATLAB Simulink (with Online Simulator)

📘 Overview 🧮 How to use MATLAB Simulink 🧮 Simulation of ASK using MATLAB Simulink 🧮 Simulation of FSK using MATLAB Simulink 🧮 Simulation of PSK using MATLAB Simulink 🧮 Simulator for ASK, FSK, and PSK 🧮 Digital Signal Processing Simulator 📚 Further Reading ASK, FSK & PSK HomePage MATLAB Simulation Simulation of Amplitude Shift Keying (ASK) using MATLAB Simulink In Simulink, we pick different components/elements from MATLAB Simulink Library. Then we connect the components and perform a particular operation. Result A sine wave source, a pulse generator, a product block, a mux, and a scope are shown in the diagram above. The pulse generator generates the '1' and '0' bit sequences. Sine wave sources produce a specific amplitude and frequency. The scope displays the modulated signal as well as the original bit sequence created by the pulse generator. Mux i...

Constellation Diagrams of ASK, PSK, and FSK (with MATLAB Code + Simulator)

Constellation Diagrams: ASK, FSK, and PSK Comprehensive guide to signal space representation, including interactive simulators and MATLAB implementations. 📘 Overview 🧮 Simulator ⚖️ Theory 📚 Resources Definitions Constellation Tool Key Points MATLAB Code 📂 Other Topics: M-ary PSK & QAM Diagrams ▼ 🧮 Simulator for M-ary PSK Constellation 🧮 Simulator for M-ary QAM Constellation BASK (Binary ASK) Modulation Transmits one of two signals: 0 or -√Eb, where Eb​ is the energy per bit. These signals represent binary 0 and 1. BFSK (Binary FSK) Modulation Transmits one...

Theoretical BER vs SNR for m-ary PSK and QAM

📊 BER vs SNR 📡 Modulation 🧮 MATLAB 📘 Simulations Relationship Between Bit Error Rate (BER) and Signal-to-Noise Ratio (SNR) The relationship between Bit Error Rate (BER) and Signal-to-Noise Ratio (SNR) is a fundamental concept in digital communication systems. Here’s a detailed explanation: BER (Bit Error Rate): The ratio of the number of bits incorrectly received to the total number of bits transmitted. It measures the quality of the communication link. SNR (Signal-to-Noise Ratio): The ratio of the signal power to the noise power, indicating how much the signal is corrupted by noise. Relationship The BER typically decreases as the SNR increases. This relationship helps evaluate the performance of various modulation schemes. BPSK (Binary Phase Shift Keying) Simple and robust. BER in AWGN channel: BER = 0.5 × erfc(√SNR) Performs well at low SNR. Q-function / erfc (Click here) QPSK (Quadrature Phase Shift Keying) Transmits 2 bits per ...