NAAN MUDHALVAN
ASSIGNMENT-1
BY,
PALANIKUMAR S
B.E.ECE(YEAR 3)
THANGAVELU ENGINEERING COLLEGE
QAM MODULATION
QAM Modulation;
% Clear the command window and any variables in the workspace
clear
clc
% Define the number of data points
N = 1000; % number of data
% Define the size of the signal constellation
mlevel = 4; % size of signal constellation
% Calculate the number of bits per symbol
k = log2(mlevel); % number of bits per symbol
% Generate random binary bit stream of length N
x = randi([0 1], N, 1); % signal generation in bit stream
% Convert the bit stream into symbols using binary to decimal conversion
% Reshape the binary stream into a matrix with each column representing a symbol
% and each row representing a set of bits for each symbol
% 'left-msb' indicates that the most significant bit (MSB) is on the left side
xsym = bi2de(reshape(x, k, length(x)/k).', 'left-msb'); % convert the bit stream into symbol stream
% Modulate the symbols using Quadrature Amplitude Modulation (QAM)
xmod = qammod(xsym, mlevel); % modulation
% Store the modulated symbols in a variable for transmission
Tx_x = xmod;
% Define the Signal-to-Noise Ratio (SNR) in decibels
SNR = 5;
% Add Additive White Gaussian Noise (AWGN) to the transmitted signal
Tx_awgn = awgn(Tx_x, SNR, 'measured'); % adding AWGN
% Store the received signal after noise addition
Rx_x = Tx_awgn; % Received signal
% Demodulate the received signal to recover the symbols
Rx_x_demod = qamdemod(Rx_x, mlevel); % demodulation
% Convert the demodulated symbols back to binary bits
z = de2bi(Rx_x_demod, 'left-msb'); % Convert integers to bits.
% Convert the matrix of bits back to a vector
Rx_x_BitStream = reshape(z.', prod(size(z)), 1); % Convert z from a matrix to a vector.
% Calculate the Bit Error Rate (BER) by comparing the transmitted and received bits
[number_of_errors, bit_error_rate] = biterr(x, Rx_x_BitStream); % Calculate BER
% Plot each step of the process
subplot(5,2,[1 2]); stem(x(1:200),'filled'); title('Transmitted Bit Stream');
subplot(5,2,[3 4]); stem(xsym(1:50),'filled'); title('Transmitted Symbol');
subplot(5,2,5); plot(real(Tx_x), imag(Tx_x), 'go', 'MarkerFaceColor', [0, 1, 0]);
axis([-mlevel/2 mlevel/2 -mlevel/2 mlevel/2]);
subplot(5,2,6); plot(real(Rx_x), imag(Rx_x), 'go', 'MarkerFaceColor', [0, 1, 0]);
axis([-mlevel/2 mlevel/2 -mlevel/2 mlevel/2]);
subplot(5,2,[7 8]); stem(Rx_x_demod(1:50),'filled'); title('Received Symbol');
subplot(5,2,[9 10]); stem(Rx_x_BitStream(1:200),'filled'); title('Received BitStream');
OUTPUT;
1.Explore the multiple in QAM.
Program;
% Clear the command window and any variables in the workspace
clear
clc
% Define the number of data points
N = 1000; % number of data
% Define the size of the signal constellation
mlevel = 8; % size of signal constellation
% Calculate the number of bits per symbol
k = log2(mlevel); % number of bits per symbol
% Generate random binary bit stream of length N
x = randi([0 1], N, 1); % signal generation in bit stream
% Convert the bit stream into symbols using binary to decimal conversion
% Reshape the binary stream into a matrix with each column representing a symbol
% and each row representing a set of bits for each symbol
% 'left-msb' indicates that the most significant bit (MSB) is on the left side
xsym = bi2de(reshape(x, k, length(x)/k).', 'left-msb'); % convert the bit stream into symbol stream
% Modulate the symbols using Quadrature Amplitude Modulation (QAM)
xmod = qammod(xsym, mlevel); % modulation
% Store the modulated symbols in a variable for transmission
Tx_x = xmod;
% Define the Signal-to-Noise Ratio (SNR) in decibels
SNR = 5;
% Add Additive White Gaussian Noise (AWGN) to the transmitted signal
Tx_awgn = awgn(Tx_x, SNR, 'measured'); % adding AWGN
% Store the received signal after noise addition
Rx_x = Tx_awgn; % Received signal
% Demodulate the received signal to recover the symbols
Rx_x_demod = qamdemod(Rx_x, mlevel); % demodulation
% Convert the demodulated symbols back to binary bits
z = de2bi(Rx_x_demod, 'left-msb'); % Convert integers to bits.
% Convert the matrix of bits back to a vector
Rx_x_BitStream = reshape(z.', prod(size(z)), 1); % Convert z from a matrix to a vector.
% Calculate the Bit Error Rate (BER) by comparing the transmitted and received bits
[number_of_errors, bit_error_rate] = biterr(x, Rx_x_BitStream); % Calculate BER
% Plot each step of the process
subplot(5,2,[1 2]); stem(x(1:200),'filled'); title('Transmitted Bit Stream');
subplot(5,2,[3 4]); stem(xsym(1:50),'filled'); title('Transmitted Symbol');
subplot(5,2,5); plot(real(Tx_x), imag(Tx_x), 'go', 'MarkerFaceColor', [0, 1, 0]);
axis([-mlevel/2 mlevel/2 -mlevel/2 mlevel/2]);
subplot(5,2,6); plot(real(Rx_x), imag(Rx_x), 'go', 'MarkerFaceColor', [0, 1, 0]);
axis([-mlevel/2 mlevel/2 -mlevel/2 mlevel/2]);
subplot(5,2,[7 8]); stem(Rx_x_demod(1:50),'filled'); title('Received Symbol');
subplot(5,2,[9 10]); stem(Rx_x_BitStream(1:200),'filled'); title('Received BitStream');
OUTPUT;
2.Explore the impact of mlevel on BER.
Program;
% Clear the command window and any variables in the workspace
clear
clc
% Define the number of data points
N = 1000; % number of data
% Define the size of the signal constellation
mlevel = 4; % size of signal constellation
% Calculate the number of bits per symbol
k = log2(mlevel); % number of bits per symbol
% Generate random binary bit stream of length N
x = randi([0 1], N, 1); % signal generation in bit stream
% Convert the bit stream into symbols using binary to decimal conversion
% Reshape the binary stream into a matrix with each column representing a symbol
% and each row representing a set of bits for each symbol
% 'left-msb' indicates that the most significant bit (MSB) is on the left side
xsym = bi2de(reshape(x, k, length(x)/k).', 'left-msb'); % convert the bit stream into symbol stream
% Modulate the symbols using Quadrature Amplitude Modulation (QAM)
xmod = qammod(xsym, mlevel); % modulation
% Store the modulated symbols in a variable for transmission
Tx_x = xmod;
% Define the Signal-to-Noise Ratio (SNR) in decibels
SNR = 5;
% Add Additive White Gaussian Noise (AWGN) to the transmitted signal
Tx_awgn = awgn(Tx_x, SNR, 'measured'); % adding AWGN
% Store the received signal after noise addition
Rx_x = Tx_awgn; % Received signal
% Demodulate the received signal to recover the symbols
Rx_x_demod = qamdemod(Rx_x, mlevel); % demodulation
% Convert the demodulated symbols back to binary bits
z = de2bi(Rx_x_demod, 'left-msb'); % Convert integers to bits.
% Convert the matrix of bits back to a vector
Rx_x_BitStream = reshape(z.', prod(size(z)), 1); % Convert z from a matrix to a vector.
% Plot each step of the process
subplot(5,2,[1 2]); stem(x(1:200),'filled'); title('Transmitted Bit Stream');
subplot(5,2,[3 4]); stem(xsym(1:50),'filled'); title('Transmitted Symbol');
subplot(5,2,5); plot(real(Tx_x), imag(Tx_x), 'go', 'MarkerFaceColor', [0, 1, 0]);
axis([-mlevel/2 mlevel/2 -mlevel/2 mlevel/2]);
subplot(5,2,6); plot(real(Rx_x), imag(Rx_x), 'go', 'MarkerFaceColor', [0, 1, 0]);
axis([-mlevel/2 mlevel/2 -mlevel/2 mlevel/2]);
subplot(5,2,[7 8]); stem(Rx_x_demod(1:50),'filled'); title('Received Symbol');
subplot(5,2,[9 10]); stem(Rx_x_BitStream(1:200),'filled'); title('Received BitStream');
OUTPUT;
3. Explore how Noise immunity differs with different mlevel values
Program;
% Clear the command window and any variables in the workspace
clear
clc
% Define the number of data points
N = 1000; % number of data
% Define the size of the signal constellation
mlevel = 4; % size of signal constellation
% Calculate the number of bits per symbol
k = log2(mlevel); % number of bits per symbol
% Generate random binary bit stream of length N
x = randi([0 1], N, 1); % signal generation in bit stream
% Convert the bit stream into symbols using binary to decimal conversion
% Reshape the binary stream into a matrix with each column representing a symbol
% and each row representing a set of bits for each symbol
% 'left-msb' indicates that the most significant bit (MSB) is on the left side
xsym = bi2de(reshape(x, k, length(x)/k).', 'left-msb'); % convert the bit stream into symbol stream
% Modulate the symbols using Quadrature Amplitude Modulation (QAM)
xmod = qammod(xsym, mlevel); % modulation
% Store the modulated symbols in a variable for transmission
Tx_x = xmod;
% Define the Signal-to-Noise Ratio (SNR) in decibels
SNR = 3;
% Add Additive White Gaussian Noise (AWGN) to the transmitted signal
Tx_awgn = awgn(Tx_x, SNR, 'measured'); % adding AWGN
% Store the received signal after noise addition
Rx_x = Tx_awgn; % Received signal
% Demodulate the received signal to recover the symbols
Rx_x_demod = qamdemod(Rx_x, mlevel); % demodulation
% Convert the demodulated symbols back to binary bits
z = de2bi(Rx_x_demod, 'left-msb'); % Convert integers to bits.
% Convert the matrix of bits back to a vector
Rx_x_BitStream = reshape(z.', prod(size(z)), 1); % Convert z from a matrix to a vector.
% Calculate the Bit Error Rate (BER) by comparing the transmitted and received bits
[number_of_errors, bit_error_rate] = biterr(x, Rx_x_BitStream); % Calculate BER
% Plot each step of the process
subplot(5,2,[1 2]); stem(x(1:200),'filled'); title('Transmitted Bit Stream');
subplot(5,2,[3 4]); stem(xsym(1:50),'filled'); title('Transmitted Symbol');
subplot(5,2,5); plot(real(Tx_x), imag(Tx_x), 'go', 'MarkerFaceColor', [0, 1, 0]);
axis([-mlevel/2 mlevel/2 -mlevel/2 mlevel/2]);
subplot(5,2,6); plot(real(Rx_x), imag(Rx_x), 'go', 'MarkerFaceColor', [0, 1, 0]);
axis([-mlevel/2 mlevel/2 -mlevel/2 mlevel/2]);
subplot(5,2,[7 8]); stem(Rx_x_demod(1:50),'filled'); title('Received Symbol');
subplot(5,2,[9 10]); stem(Rx_x_BitStream(1:200),'filled'); title('Received BitStream');
OUTPUT;