0% found this document useful (0 votes)
9 views30 pages

Lab 4 Part 2

Uploaded by

saisiva3002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views30 pages

Lab 4 Part 2

Uploaded by

saisiva3002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2

S Bhargava Siva Sai(SC21B121)

% This program Transmits the Bits through a channel and receives it using QPSK
scheme.

clear;
fc = 25; % Carrier Frequency
Ts = 1; % Symbol Time
N = 10000; % Number of Bits
fs = 100; % Sampling Frequency
norm_factor = fs/2; % Normalization factor
var = 10; % AWGN Noise Variance

% This function is used to create an input wave


[~, inp_bits, temp] = plus_one_and_minus_one_seq(fs, Ts, N);

% This function is used to create another array of ODD and EVEN bits
[odd_bit_wave, even_bit_wave, ~, ~, ~] = bit_split_by_2(inp_bits, temp, Ts, N,
fs);

% Modulation of ODD and EVEN binary wave


odd_bit_modulate = am_modulation(odd_bit_wave,Ts,N/2,fc,fs,"cos");
even_bit_modulate = am_modulation(even_bit_wave,Ts,N/2,fc,fs,"sin");

% QPSK transmitted signal


% Here imaginary part is used show phase difference between EVEN and ODD bit
wave
qpsk_signal = odd_bit_modulate + 1i*even_bit_modulate;

% Signal Received from channel & Band Pass Receive filter


y = qpsk_signal;

% Adding AWGN to Channel's Impulse response


Noise = sqrt(var)*(randn([1,length(y)]) + 1i*randn(1,length(y))); % AWGN
y = y + Noise;

% Correlating Receiver for odd_bits & even_bits


corr_odd_wave = imag(y*1i);
corr_even_wave = real(y*-1i);

% Creating Local Oscillators


variable = 0:1/fs:Ts*N*0.5-1/fs;
local_oscillator_cos = cos(2*pi*fc*variable);
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
local_oscillator_sin = sin(2*pi*fc*variable);

% Demodulating the wave received from Band Pass Receive Filter


demodulated_wave_even = corr_even_wave.*local_oscillator_sin;
demodulated_wave_odd = corr_odd_wave.*local_oscillator_cos;

% Demodulator Low Pass Filter Specifications


fpass_LPF = 5;
fstop_LPF = 10;
fpass_LPF_norm = fpass_LPF/norm_factor;
fstop_LPF_norm = fstop_LPF/norm_factor;

% Creating a Low Pass Filter to Filter the Unfiltered Demodulated Wave


[imp, ~, ~] = Low_pass_Filter(fs, [0 fpass_LPF_norm, fstop_LPF_norm, 1], [1 1
0 0]);

% Convolving Low Pass Filter with Unfiltered Demodulated Wave (EVEN & ODD)
Cont_Demodulated_Wave_Even = conv(imp,demodulated_wave_even);
Cont_Demodulated_Wave_Odd = conv(imp,demodulated_wave_odd);

% Taking 5 samples for a particular Bit


% If 100 bits are input, then 500 samples are taken
sample_even = [];
for i = fs/2:(fs*Ts)/5:length(Cont_Demodulated_Wave_Even)-fs/2
sample_even = [sample_even Cont_Demodulated_Wave_Even(i)];
end

% Decision maker which converts a sample of 5 values into single bit (For
Channel)
sample_bits_even = decision_maker(sample_even);

% Taking 5 samples for a particular Bit


% If 100 bits are input, then 500 samples are taken
sample_odd = [];
for i = fs/2:fs*Ts/5:length(Cont_Demodulated_Wave_Odd)-fs/2
sample_odd= [sample_odd Cont_Demodulated_Wave_Odd(i)];
end

% Decision maker which converts a sample of 5 values into single bit (For
Channel)
sample_bits_odd = decision_maker(sample_odd);

% Creating an array of receievd even and odd bits


COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
received_bits = [];
for i = 1:N/2
received_bits = [received_bits sample_bits_odd(i) sample_bits_even(i)];
end

% Calculating Bit Error Rate


BER = Bit_Error_Rate(inp_bits, received_bits, N);
Bit_Error_Rate = sprintf("Bit Error rate = %d percent", BER);
disp(Bit_Error_Rate);
Bit Error rate = 2.392000e+01 percent

Q2.

% This program Transmits the Bits through a channel and receives it using 16-
QAM scheme.

clear;
fc = 25; % Carrier Frequency
Ts = 1; % Symbol Time
N = 20000; % Number of Bits
fs = 100; % Sampling Frequency
norm_factor = fs/2; % Normalization factor
var = 10; % AWGN Noise Variance

% This function is used to create an input wave


[~, inp_bits, temp] = plus_one_and_minus_one_seq(fs, Ts, N);

% This function is used to create another array of ODD and EVEN bits
[~, ~, ~, ~, temp_half_bits] = bit_split_by_2(inp_bits, temp, Ts, N, fs);

% To create Time Axis for 16-QAM modulated signal


temp_quarter_bits = temp_half_bits(1:length(temp_half_bits)/2);

QAM_16_signal = []; % 16-QAM transmitted signal


% This loop is to process 4-bits at a time
for i = 1:N/4
temp_stor = inp_bits(4*i-3:4*i);
encoded = encode_16_QAM(temp_stor); % This encodes the 4-bits of 16-QAM
every time the loop runs

% This creates an array of ones


one_arr = ones(1,fs*Ts);

% This modulates the wave created for ODD and EVEN bits
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
odd_bit_modulate = encoded(1)*am_modulation(one_arr,Ts,1,fc,fs,"cos");
even_bit_modulate = encoded(2)*am_modulation(one_arr,Ts,1,fc,fs,"sin");

% This is 16-QAM modulated signal (wave) processed with the encoded


function
QAM_16_signal = [QAM_16_signal odd_bit_modulate+1i*even_bit_modulate];
end

% Signal Received from channel & Band Pass Receive filter


y = QAM_16_signal;

% Adding AWGN to Channel's Impulse response


Noise = sqrt(var)*(randn([1,length(y)]) + 1i*randn([1,length(y)])); % AWGN
y = y + Noise;

% Correlation Receiver for odd & even part


corr_even = imag(y);
corr_odd = real(y);

% Creating Local Oscillators


variable = 0:1/fs:Ts*N*0.25-1/fs;
local_oscillator_cos = cos(2*pi*fc*variable);
local_oscillator_sin = sin(2*pi*fc*variable);

% Demodulating the wave received from Band Pass Receive Filter


demodulated_wave_odd = corr_odd.*local_oscillator_cos;
demodulated_wave_even = corr_even.*local_oscillator_sin;

% Demodulator Low Pass Filter Specifications


fpass_LPF = 5;
fstop_LPF = 10;
fpass_LPF_norm = fpass_LPF/norm_factor;
fstop_LPF_norm = fstop_LPF/norm_factor;

% Creating a Low Pass Filter to Filter the Unfiltered Demodulated Wave


[imp, ~, ~] = Low_pass_Filter(fs, [0 fpass_LPF_norm, fstop_LPF_norm, 1], [1 1
0 0]);

% Convolving Low Pass Filter with Unfiltered Demodulated Wave (EVEN & ODD)
Cont_Demodulated_Wave_Even = conv(demodulated_wave_even,imp);
Cont_Demodulated_Wave_Odd = conv(demodulated_wave_odd,imp);

% If 100 bits are input, then 100 samples are taken


COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
sample_even = [];
for i = fs:(fs*Ts):length(Cont_Demodulated_Wave_Even)-fs/2
sample_even = [sample_even Cont_Demodulated_Wave_Even(i)];
end

sample_odd = [];
for i = fs:fs*Ts:length(Cont_Demodulated_Wave_Odd)-fs/2
sample_odd= [sample_odd Cont_Demodulated_Wave_Odd(i)];
end

% Decision maker which gives received bits


received_bits = decode_16_QAM_single_sample(sample_odd, sample_even, Ts, N);

subplot(2,1,1);
stem (inp_bits);
title("Transmitted Bits");
xlabel("Bits");
ylabel("Amplitude (0 or 1)");

subplot(2,1,2);
stem(received_bits);
title("Received Bits");
xlabel("Bits");
ylabel("Amplitude (0 or 1)");
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

% Calculating Bit Error Rate


BER = Bit_Error_Rate(inp_bits, received_bits, N);
Bit_Error_Rate = sprintf("Bit Error rate = %d percent", BER);
disp(Bit_Error_Rate);
Bit Error rate = 2.953000e+01 percent

Q3.

% This program provides with the demodulation scheme of 8-PSK

clear;
fc = 25; % Carrier Frequency
Ts = 1; % Bit Time
N = 15000; % Number of Bits
fs = 100; % Sampling Frequency
norm_factor = fs/2; % Normalization factor
var = 1; % AWGN Noise Variance

% This function is used to create an input wave


[~, inp_bits, ~] = plus_one_and_minus_one_seq(fs, Ts, N);

% Creating Time axis


temp_psk_wave = 0:1/fs:Ts*N/3 - 1/fs;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
psk_wave = []; % Creating a 8-PSK wave
% This loop extracts 3 bits at a time and phase-mapper function modulates its
phase accordingly
for i = 1:N/3
temp_stor = inp_bits(3*i-2:3*i); % This extracts 3 bits at a time and
stores it

% This creates an outwave and phase according to the bits received


[outwave, phase] = phase_mapper_8_PSK(temp_stor, Ts, fs, fc);

psk_wave = [psk_wave outwave]; % This is to append the outwave according


to the bit sequence processed
end

% Signal Received from channel & Band Pass Receive filter


y = psk_wave;

% Adding AWGN to Channel's Impulse response


Noise = sqrt(var)*(randn([1,length(y)])+1i*randn([1, length(y)])); % AWGN
y = y + Noise;

% Creating Local Oscillators


variable = 0:1/fs:1-1/fs;
local_oscillator_cos = cos(2*pi*fc*variable);
local_oscillator_sin = sin(2*pi*fc*variable);

% Demodulating the wave received from Band Pass Receive Filter


demod_cos = [];
demod_sin = [];
for i = 1:N/3
temp_stor = y((i-1)*fs*Ts+1:fs*Ts*i);
temp_demod_cos = local_oscillator_cos.*temp_stor;
temp_demod_sin = local_oscillator_sin.*temp_stor;
demod_cos = [demod_cos temp_demod_cos];
demod_sin = [demod_sin temp_demod_sin];
end

% Demodulator Low Pass Filter Specifications


fpass_LPF = 5;
fstop_LPF = 10;
fpass_LPF_norm = fpass_LPF/norm_factor;
fstop_LPF_norm = fstop_LPF/norm_factor;

% Creating a Low Pass Filter to Filter the Unfiltered Demodulated Wave


COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
[imp, ~, ~] = Low_pass_Filter(fs, [0 fpass_LPF_norm, fstop_LPF_norm, 1], [1 1
0 0]);

% Convolving Low Pass Filter with Unfiltered Demodulated Wave (EVEN & ODD)
demodulated_wave_cos = conv(demod_cos,imp);
demodulated_wave_sin = conv(demod_sin,imp);

% Taking 5 samples for a particular Bit (for sine and cosine wave)
% If 100 bits are input, then 500 samples are taken
sample_cos = [];
for i = fs:(fs*Ts):length(demodulated_wave_cos)-fs/2
sample_cos = [sample_cos demodulated_wave_cos(i)];
end

sample_sin = [];
for i = fs:(fs*Ts):length(demodulated_wave_sin)-fs/2
sample_sin = [sample_sin demodulated_wave_sin(i)];
end

% Decision maker for Received bits


received_bits = decode_phase_single_sample(sample_cos, sample_sin, Ts, N);

subplot(2,1,1);
stem(inp_bits);
title("Transmitted Bits");
xlabel("Bits");
ylabel("Amplitude (0 or 1)");

subplot(2,1,2);
stem(received_bits);
title("Received Bits");
xlabel("Bits");
ylabel("Amplitude (0 or 1)");
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

% Calculating Bit Error Rate


BER = Bit_Error_Rate(inp_bits, received_bits, N);
Bit_Error_Rate = sprintf("Bit Error rate = %d percent", BER);
disp(Bit_Error_Rate);
Bit Error rate = 3.395333e+01 percent

Q4.

% This program provides with the demodulation scheme of 8-PSK

clear;
Ts = 1; % Symbol Time
N = 10000; % Number of Bits
fs = 100; % Sampling Frequency
norm_factor = fs/2; % Normalized Frequency
var = 10; % AWGN Noise Variance

% This function is used to create an input wave


[x, inp_bits, ~] = plus_one_and_minus_one_seq(fs, Ts, N);

fsk_4 = []; % 4-FSK Transmitted signal


% This loop checks 2 bits at a Time and modulates accordingly
for i = 1:N/2
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
if inp_bits(2*i-1) == 0 && inp_bits(2*i) == 0
fc = 22; % Carrier frequency if 00 transmitted
fsk_4_modulate = am_modulation(x(2*(i-
1)*fs*Ts+1:2*i*fs*Ts),Ts,2,fc,fs,"cos"); % modulated wave
elseif inp_bits(2*i-1) == 0 && inp_bits(2*i) == 1
fc = 24; % Carrier frequency if 01 transmitted
fsk_4_modulate = am_modulation(x(2*(i-
1)*fs*Ts+1:2*i*fs*Ts),Ts,2,fc,fs,"cos"); % modulated wave
elseif inp_bits(2*i-1) == 1 && inp_bits(2*i) == 0
fc = 26; % Carrier frequency if 10 transmitted
fsk_4_modulate = am_modulation(x(2*(i-
1)*fs*Ts+1:2*i*fs*Ts),Ts,2,fc,fs,"cos"); % modulated wave
elseif inp_bits(2*i-1) == 1 && inp_bits(2*i) == 1
fc = 28; % Carrier frequency if 11 transmitted
fsk_4_modulate = am_modulation(x(2*(i-
1)*fs*Ts+1:2*i*fs*Ts),Ts,2,fc,fs,"cos"); % modulated wave
end
fsk_4 = [fsk_4 fsk_4_modulate]; % 4-FSK Transmitted Signal
end

% Signal Received from channel & Band Pass Receive filter


y = fsk_4;

% Adding AWGN to Channel's Impulse response


Noise = sqrt(var)*(randn([1,length(y)])+1i*randn([1, length(y)])); % AWGN
y = y + Noise;

% Different Carrier Frequencies for Local_Oscillator


fc1 = 22;
fc2 = 24;
fc3 = 26;
fc4 = 28;

% Creating the Local Oscillator for different carrier frequencies


variable = 0:1/fs:Ts*N-1/fs;
LO_cos_1 = cos(2*pi*fc1*variable);
LO_cos_2 = cos(2*pi*fc2*variable);
LO_cos_3 = cos(2*pi*fc3*variable);
LO_cos_4 = cos(2*pi*fc4*variable);

% Demodulator Low Pass Filter Specifications


fpass_LPF = 5;
fstop_LPF = 10;
fpass_LPF_norm = fpass_LPF/norm_factor;
fstop_LPF_norm = fstop_LPF/norm_factor;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
% Creating a Low Pass Filter to Filter the Unfiltered Demodulated Wave
[imp, ~, ~] = Low_pass_Filter(fs, [0 fpass_LPF_norm, fstop_LPF_norm, 1], [1 1
0 0]);

% Demodulating the 4_fsk wave


fsk_demod = y.*LO_cos_1 + y.*LO_cos_2 + y.*LO_cos_3 + y.*LO_cos_4;
% Filtering the Unfiltered Demodulated Wave
cont_fsk_demod = conv(imp,fsk_demod);

% Taking 5 samples for a particular Bit


% If 100 bits are input, then 500 samples are taken
sample = [];
for i = fs/2:fs*Ts/5:length(cont_fsk_demod)-fs/2
sample= [sample cont_fsk_demod(i)];
end

% Decision maker which converts a sample of 5 values into single bit (For
Channel)
received_bits = decision_maker(sample);

subplot(2,1,1);
stem (inp_bits);
title("Transmitted Bits");
xlabel("Bits");
ylabel("Amplitude (0 or 1)");

subplot(2,1,2);
stem(received_bits);
title("Received Bits");
xlabel("Bits");
ylabel("Amplitude (0 or 1)");
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

% Calculating Bit Error Rate


BER = Bit_Error_Rate(inp_bits, received_bits, N);
Bit_Error_Rate = sprintf("Bit Error rate = %d percent", BER);
disp(Bit_Error_Rate);
Bit Error rate = 4.012000e+01 percent

Q5.

% This program helps to transmit a data through QPSK modulation approach


% The constellation map of transmitted data is also shown
% The PSD of the transmitted signal is also shown
% Observation - 1 : The Bandwidth of QPSK signal is same as of BPSK signal due
to same Symbol Time
% Observation - 2 : Bit rate is twice the original as 2 bits are processed at
a time

clear;
fc = 20; % Carrier Frequency
Ts = 1; % Symbol Time
N = 10000; % Number of Bits
fs = 100; % Sampling Frequency
var = 0.01; % AWGN Noise Variance

% This function is used to create an input wave


COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
[x, inp_bits, temp] = plus_one_and_minus_one_seq(fs, Ts, N);

% This is BPSK modulated signal (This will be compared with QPSK)


bpsk_modulate = am_modulation(x,Ts,N,fc,fs,"cos");

% This function is used to create another array of ODD and EVEN bits
[odd_bit_wave, even_bit_wave, odd_bits, even_bits, ~] =
bit_split_by_2(inp_bits, temp, Ts, N, fs);

% Modulation of ODD and EVEN binary wave


odd_bit_modulate = am_modulation(odd_bit_wave,Ts,N/2,fc,fs,"cos");
even_bit_modulate = am_modulation(even_bit_wave,Ts,N/2,fc,fs,"sin");

% QPSK transmitted signal


% Here imaginary part is used show phase difference between EVEN and ODD bit
wave
% This is for Constellation map
qpsk_signal = odd_bit_modulate + 1i*even_bit_modulate;

% Actual QPSK transmitted signal


qpsk_real = real(qpsk_signal)+imag(qpsk_signal);

% To convert the ODD and EVEN bits into NRZ form


even_bits_NRZ = even_bits*2-1;
odd_bits_NRZ = odd_bits*2-1;

% This signal is to show Constellation map of QPSK


QPSK_const = sqrt(Ts/2)*(odd_bits_NRZ + 1i*even_bits_NRZ);

% Adding AWGN to Channel's Impulse response


Noise = sqrt(var)*(randn([1,length(QPSK_const)]) +
1i*randn(1,length(QPSK_const))); % AWGN
QPSK_const = QPSK_const + Noise;

scatterplot(QPSK_const);
title("Constellation diagram of QPSK");
grid on;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

Q6.

% This program helps to transmit a data through 16-QAM modulation approach


% The constellation map of transmitted data is also shown
% The PSD of the transmitted signal is also shown
% Observation - 1 : The Bandwidth of 16-QAM signal is same as BPSK signal due
to same Symbol Time
% Observation - 2 : Bit rate is four times the original as 2 symbols (pair of
ODD and EVEN) are processed at a time
% 1 symbol = 4 bits here

clear;
fc = 20; % Carrier Frequency
Ts = 1; % Bit Time
N = 20000; % Number of Bits
fs = 100; % Sampling Frequency
var = 0.1; % AWGN Noise Variance
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
% This function is used to create an input wave
[x, inp_bit, temp] = plus_one_and_minus_one_seq(fs, Ts, N);

% This is BPSK modulated signal (This will be compared with 16-QAM)


bpsk_modulate = am_modulation(x,Ts,N,fc,fs,"cos");

% This function is used to create another array of ODD and EVEN bits
[~, ~, ~, even_bits, temp_half_bits] = bit_split_by_2(inp_bit, temp, Ts, N,
fs);

% To create Time Axis for 16-QAM modulated signal


temp_quarter_bits = temp_half_bits(1:length(temp_half_bits)/2);

QAM_16_signal = []; % 16-QAM transmitted signal


QAM_16_const = []; % Constellation map for 16-QAM transmitted bits

% This loop is to process 4-bits at a time


for i = 1:N/4
temp_stor = inp_bit(4*i-3:4*i);
encoded = encode_16_QAM(temp_stor); % This encodes the 4-bits of 16-QAM
every time the loop runs
% This creates an array of ones
one_arr = ones(1,fs*Ts);

% This modulates the wave created for ODD and EVEN bits
odd_bit_modulate = encoded(1)*am_modulation(one_arr,Ts,1,fc,fs,"cos");
even_bit_modulate = encoded(2)*am_modulation(one_arr,Ts,1,fc,fs,"sin");

% This is 16-QAM modulated signal (wave) processed with the encoded


function (To show Constellation map)
QAM_16_signal = [QAM_16_signal odd_bit_modulate+1i*even_bit_modulate];

% This is actual processed 16-QAM wave


QAM_16_signal_real = real(QAM_16_signal)+imag(QAM_16_signal);

% This signal is used to show 16-QAM signal (bits)


QAM_16_const = [QAM_16_const encoded(2)+1i*encoded(1)];
end

% This is scaled with sqrt(Ts/2) in order to maintain Amplitude


QAM_16_const = sqrt(Ts/2)*QAM_16_const;

% Adding AWGN to Channel's Impulse response


COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
Noise = sqrt(var)*(randn([1,length(QAM_16_const)]) +
1i*randn(1,length(QAM_16_const))); % AWGN
QAM_16_const = QAM_16_const + Noise;

scatterplot(QAM_16_const);
title("Constellation Diagram of 16-QAM");
grid on;

Q7.
% This program helps to transmit a data through 8-PSK modulation approach
% The constellation map of transmitted data is also shown
% The PSD of the transmitted signal is also shown
% Observation - 1 : The Bandwidth of 8-PSK signal is same as of BPSK signal
due to same Symbol Time
% Observation - 2 : Bit rate is thrice the original as 3 bits are processed at
a time

clear;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
fc = 20; % Carrier Frequency
Ts = 1; % Bit Time
N = 15000; % Number of Bits
fs = 100; % Sampling Frequency
var = 0.001; % AWGN Noise Variance

% This function is used to create an input wave


[x, inp_bits, ~] = plus_one_and_minus_one_seq(fs, Ts, N);

% This is BPSK modulated signal (This will be compared with 8-PSK)


bpsk_modulate = am_modulation(x,Ts,N,fc,fs,"cos");

% Creating Time axis


temp_psk_wave = 0:1/fs:Ts*N/3 - 1/fs;

psk_wave = []; % Creating a 8-PSK wave


PSK_8_const_sig = []; % Creating a 8-PSK bit sequence for constellation
mapping

% This loop extracts 3 bits at a time and phase-mapper function modulates its
phase accordingly
for i = 1:N/3
temp_stor = inp_bits(3*i-2:3*i); % This extracts 3 bits at a time and
stores it

% This creates an outwave and phase according to the bits received


[outwave, phase] = phase_mapper_8_PSK(temp_stor, Ts, fs, fc);

psk_wave = [psk_wave outwave]; % This is to append the outwave according


to the bit sequence processed
PSK_8_const_sig = [PSK_8_const_sig (Ts/2)*exp(1i*phase)]; % This is for
Contellation map
end

% Adding AWGN to Channel's Impulse response


Noise = sqrt(var)*(randn([1,length(PSK_8_const_sig)])+1i*randn([1,
length(PSK_8_const_sig)])); % AWGN
PSK_8_const_sig = PSK_8_const_sig + Noise;

scatterplot(PSK_8_const_sig);
title("Constellation diagram of 8-PSK")
grid on;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

Q8

% This program provides with the demodulation scheme of 8-PSK

clear;
Ts = 1; % Symbol Time
N = 10000; % Number of Bits
fs = 100; % Sampling Frequency
norm_factor = fs/2; % Normalized Frequency
var = 0.1; % AWGN Noise Variance

% This function is used to create an input wave


[x, inp_bits, ~] = plus_one_and_minus_one_seq(fs, Ts, N);

fsk_4 = []; % 4-FSK Transmitted signal


% This loop checks 2 bits at a Time and modulates accordingly
for i = 1:N/2
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
if inp_bits(2*i-1) == 0 && inp_bits(2*i) == 0
fc = 22; % Carrier frequency if 00 transmitted
fsk_4_modulate = am_modulation(x(2*(i-
1)*fs*Ts+1:2*i*fs*Ts),Ts,2,fc,fs,"cos"); % modulated wave
elseif inp_bits(2*i-1) == 0 && inp_bits(2*i) == 1
fc = 24; % Carrier frequency if 01 transmitted
fsk_4_modulate = am_modulation(x(2*(i-
1)*fs*Ts+1:2*i*fs*Ts),Ts,2,fc,fs,"cos"); % modulated wave
elseif inp_bits(2*i-1) == 1 && inp_bits(2*i) == 0
fc = 26; % Carrier frequency if 10 transmitted
fsk_4_modulate = am_modulation(x(2*(i-
1)*fs*Ts+1:2*i*fs*Ts),Ts,2,fc,fs,"cos"); % modulated wave
elseif inp_bits(2*i-1) == 1 && inp_bits(2*i) == 1
fc = 28; % Carrier frequency if 11 transmitted
fsk_4_modulate = am_modulation(x(2*(i-
1)*fs*Ts+1:2*i*fs*Ts),Ts,2,fc,fs,"cos"); % modulated wave
end
fsk_4 = [fsk_4 fsk_4_modulate]; % 4-FSK Transmitted Signal
end

% Signal Received from channel & Band Pass Receive filter


y = fsk_4;

% Adding AWGN to Channel's Impulse response


Noise = sqrt(var)*(randn([1,length(y)])); % AWGN
y = y + Noise;

% Different Carrier Frequencies for Local_Oscillator


fc1 = 22;
fc2 = 24;
fc3 = 26;
fc4 = 28;

% Creating the Local Oscillator for different carrier frequencies


variable = 0:1/fs:Ts*N-1/fs;
LO_cos_1 = cos(2*pi*fc1*variable);
LO_cos_2 = cos(2*pi*fc2*variable);
LO_cos_3 = cos(2*pi*fc3*variable);
LO_cos_4 = cos(2*pi*fc4*variable);

% Demodulator Low Pass Filter Specifications


fpass_LPF = 5;
fstop_LPF = 10;
fpass_LPF_norm = fpass_LPF/norm_factor;
fstop_LPF_norm = fstop_LPF/norm_factor;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
% Creating a Low Pass Filter to Filter the Unfiltered Demodulated Wave
[imp, magni, freq] = Low_pass_Filter(fs, [0 fpass_LPF_norm, fstop_LPF_norm,
1], [1 1 0 0]);

% Demodulating the 4_fsk wave


fsk_demod = y.*LO_cos_1 + y.*LO_cos_2 + y.*LO_cos_3 + y.*LO_cos_4;
% Filtering the Unfiltered Demodulated Wave
cont_fsk_demod = conv(imp,fsk_demod);

% Taking 5 samples for a particular Bit


% If 100 bits are input, then 500 samples are taken
sample = [];
for i = fs/2:fs*Ts/5:length(cont_fsk_demod)-fs/2
sample= [sample cont_fsk_demod(i)];
end

% Decision maker which converts a sample of 5 values into single bit (For
Channel)
received_bits = decision_maker(sample);

subplot(2,1,1);
stem (inp_bits);
title("Transmitted Bits");
xlabel("Bits");
ylabel("Amplitude (0 or 1)");

subplot(2,1,2);
plot(cont_fsk_demod);
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

Q9.

% This program Transmits the Bits through a channel and receives it using QPSK
scheme.

clear;
fc = 25; % Carrier Frequency
Ts = 1; % Symbol Time
N = 10000; % Number of Bits
fs = 100; % Sampling Frequency
norm_factor = fs/2; % Normalization factor
var = 0.1:0.1:1; % AWGN Noise Variance

% This function is used to create an input wave


[~, inp_bits, temp] = plus_one_and_minus_one_seq(fs, Ts, N);

% This function is used to create another array of ODD and EVEN bits
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
[odd_bit_wave, even_bit_wave, ~, ~, ~] = bit_split_by_2(inp_bits, temp, Ts, N,
fs);

% Modulation of ODD and EVEN binary wave


odd_bit_modulate = am_modulation(odd_bit_wave,Ts,N/2,fc,fs,"cos");
even_bit_modulate = am_modulation(even_bit_wave,Ts,N/2,fc,fs,"sin");

% QPSK transmitted signal


% Here imaginary part is used show phase difference between EVEN and ODD bit
wave
qpsk_signal = odd_bit_modulate + 1i*even_bit_modulate;

% Signal Received from channel & Band Pass Receive filter


y = qpsk_signal;

BER_plot = [];
for i = 1:length(var)
% Adding AWGN to Channel's Impulse response
Noise = sqrt(var(i))*(randn([1,length(y)]) + 1i*randn(1,length(y))); %
AWGN
y = y + Noise;

% Correlating Receiver for odd_bits & even_bits


corr_odd_wave = imag(y*1i);
corr_even_wave = real(y*-1i);

% Creating Local Oscillators


variable = 0:1/fs:Ts*N*0.5-1/fs;
local_oscillator_cos = cos(2*pi*fc*variable);
local_oscillator_sin = sin(2*pi*fc*variable);

% Demodulating the wave received from Band Pass Receive Filter


demodulated_wave_even = corr_even_wave.*local_oscillator_sin;
demodulated_wave_odd = corr_odd_wave.*local_oscillator_cos;

% Demodulator Low Pass Filter Specifications


fpass_LPF = 5;
fstop_LPF = 10;
fpass_LPF_norm = fpass_LPF/norm_factor;
fstop_LPF_norm = fstop_LPF/norm_factor;

% Creating a Low Pass Filter to Filter the Unfiltered Demodulated Wave


[imp, magni, freq] = Low_pass_Filter(fs, [0 fpass_LPF_norm,
fstop_LPF_norm, 1], [1 1 0 0]);

% Convolving Low Pass Filter with Unfiltered Demodulated Wave (EVEN & ODD)
Cont_Demodulated_Wave_Even = conv(imp,demodulated_wave_even);
Cont_Demodulated_Wave_Odd = conv(imp,demodulated_wave_odd);
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

% Taking 5 samples for a particular Bit


% If 100 bits are input, then 500 samples are taken
sample_even = [];
for i = fs/2:(fs*Ts)/5:length(Cont_Demodulated_Wave_Even)-fs/2
sample_even = [sample_even Cont_Demodulated_Wave_Even(i)];
end

% Decision maker which converts a sample of 5 values into single bit (For
Channel)
sample_bits_even = decision_maker(sample_even);

% Taking 5 samples for a particular Bit


% If 100 bits are input, then 500 samples are taken
sample_odd = [];
for i = fs/2:fs*Ts/5:length(Cont_Demodulated_Wave_Odd)-fs/2
sample_odd= [sample_odd Cont_Demodulated_Wave_Odd(i)];
end

% Decision maker which converts a sample of 5 values into single bit (For
Channel)
sample_bits_odd = decision_maker(sample_odd);

% Creating an array of receievd even and odd bits


received_bits = [];
for j = 1:N/2
received_bits = [received_bits sample_bits_odd(j)
sample_bits_even(j)];
end

% Calculating Bit Error Rate


BER = Bit_Error_Rate(inp_bits, received_bits, N);
Bit_error = sprintf("Bit Error rate = %d percent", BER);
disp(Bit_error);
BER_plot = [BER_plot BER];
end
Bit Error rate = 0 percent
Bit Error rate = 0 percent
Bit Error rate = 3.100000e-01 percent
Bit Error rate = 1.530000e+00 percent
Bit Error rate = 3.930000e+00 percent
Bit Error rate = 6.560000e+00 percent
Bit Error rate = 9.670000e+00 percent
Bit Error rate = 1.240000e+01 percent
Bit Error rate = 1.508000e+01 percent
Bit Error rate = 1.773000e+01 percent
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

Q10

% This program Transmits the Bits through a channel and receives it using 16-
QAM scheme.

clear;
fc = 25; % Carrier Frequency
Ts = 1; % Symbol Time
N = 20000; % Number of Bits
fs = 100; % Sampling Frequency
norm_factor = fs/2; % Normalization factor
var = 0.1:0.1:1; % AWGN Noise Variance

% This function is used to create an input wave


[~, inp_bits, temp] = plus_one_and_minus_one_seq(fs, Ts, N);

% This function is used to create another array of ODD and EVEN bits
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
[odd_bit_wave, even_bit_wave, odd_bits, even_bits, temp_half_bits] =
bit_split_by_2(inp_bits, temp, Ts, N, fs);

% To create Time Axis for 16-QAM modulated signal


temp_quarter_bits = temp_half_bits(1:length(temp_half_bits)/2);

QAM_16_signal = []; % 16-QAM transmitted signal


% This loop is to process 4-bits at a time
for i = 1:N/4
temp_stor = inp_bits(4*i-3:4*i);
encoded = encode_16_QAM(temp_stor); % This encodes the 4-bits of 16-QAM
every time the loop runs

% This creates an array of ones


one_arr = ones(1,fs*Ts);

% This modulates the wave created for ODD and EVEN bits
odd_bit_modulate = encoded(1)*am_modulation(one_arr,Ts,1,fc,fs,"cos");
even_bit_modulate = encoded(2)*am_modulation(one_arr,Ts,1,fc,fs,"sin");

% This is 16-QAM modulated signal (wave) processed with the encoded


function
QAM_16_signal = [QAM_16_signal odd_bit_modulate+1i*even_bit_modulate];
end

% Signal Received from channel & Band Pass Receive filter


y = QAM_16_signal;

BER_plot = [];
for i = 1:length(var)
% Adding AWGN to Channel's Impulse response
Noise = sqrt(var(i))*(randn([1,length(y)]) + 1i*randn([1,length(y)])); %
AWGN
y = y + Noise;

% Correlation Receiver for odd & even part


corr_even = imag(y);
corr_odd = real(y);

% Creating Local Oscillators


variable = 0:1/fs:Ts*N*0.25-1/fs;
local_oscillator_cos = cos(2*pi*fc*variable);
local_oscillator_sin = sin(2*pi*fc*variable);

% Demodulating the wave received from Band Pass Receive Filter


demodulated_wave_odd = corr_odd.*local_oscillator_cos;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
demodulated_wave_even = corr_even.*local_oscillator_sin;

% Demodulator Low Pass Filter Specifications


fpass_LPF = 5;
fstop_LPF = 10;
fpass_LPF_norm = fpass_LPF/norm_factor;
fstop_LPF_norm = fstop_LPF/norm_factor;

% Creating a Low Pass Filter to Filter the Unfiltered Demodulated Wave


[imp, magni, freq] = Low_pass_Filter(fs, [0 fpass_LPF_norm,
fstop_LPF_norm, 1], [1 1 0 0]);

% Convolving Low Pass Filter with Unfiltered Demodulated Wave (EVEN & ODD)
Cont_Demodulated_Wave_Even = conv(demodulated_wave_even,imp);
Cont_Demodulated_Wave_Odd = conv(demodulated_wave_odd,imp);

% If 100 bits are input, then 100 samples are taken


sample_even = [];
for j = fs:(fs*Ts):length(Cont_Demodulated_Wave_Even)-fs/2
sample_even = [sample_even Cont_Demodulated_Wave_Even(j)];
end

sample_odd = [];
for j = fs:fs*Ts:length(Cont_Demodulated_Wave_Odd)-fs/2
sample_odd= [sample_odd Cont_Demodulated_Wave_Odd(j)];
end

% Decision maker which gives received bits


received_bits = decode_16_QAM_single_sample(sample_odd, sample_even, Ts,
N);

% Calculating Bit Error Rate


BER = Bit_Error_Rate(inp_bits, received_bits, N);
Bit_Error = sprintf("Bit Error rate = %d percent", BER);
disp(Bit_Error);

BER_plot = [BER_plot BER];


Bit Error rate = 0 percent
Bit Error rate = 6.250000e-01 percent
Bit Error rate = 3.490000e+00 percent
Bit Error rate = 6.755000e+00 percent
Bit Error rate = 1.052000e+01 percent
Bit Error rate = 1.370000e+01 percent
Bit Error rate = 1.646000e+01 percent
Bit Error rate = 1.918500e+01 percent
Bit Error rate = 2.165000e+01 percent
Bit Error rate = 2.403000e+01 percent
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

Q11.

% This program provides with the demodulation scheme of 8-PSK

clear;
fc = 25; % Carrier Frequency
Ts = 1; % Bit Time
N = 15000; % Number of Bits
fs = 100; % Sampling Frequency
norm_factor = fs/2; % Normalization factor
var = 0.1:0.1:1; % AWGN Noise Variance

% This function is used to create an input wave


[x, inp_bits, temp] = plus_one_and_minus_one_seq(fs, Ts, N);

% Creating Time axis


temp_psk_wave = 0:1/fs:Ts*N/3 - 1/fs;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

psk_wave = []; % Creating a 8-PSK wave


% This loop extracts 3 bits at a time and phase-mapper function modulates its
phase accordingly
for i = 1:N/3
temp_stor = inp_bits(3*i-2:3*i); % This extracts 3 bits at a time and
stores it

% This creates an outwave and phase according to the bits received


[outwave, phase] = phase_mapper_8_PSK(temp_stor, Ts, fs, fc);

psk_wave = [psk_wave outwave]; % This is to append the outwave according


to the bit sequence processed
end

% Signal Received from channel & Band Pass Receive filter


y = psk_wave;

BER_plot = [];
for i = 1:length(var)
% Adding AWGN to Channel's Impulse response
Noise = sqrt(var(i))*(randn([1,length(y)])+1i*randn([1, length(y)])); %
AWGN
y = y + Noise;

% Creating Local Oscillators


variable = 0:1/fs:1-1/fs;
local_oscillator_cos = cos(2*pi*fc*variable);
local_oscillator_sin = sin(2*pi*fc*variable);

% Demodulating the wave received from Band Pass Receive Filter


demod_cos = [];
demod_sin = [];
for i = 1:N/3
temp_stor = y((i-1)*fs*Ts+1:fs*Ts*i);
temp_demod_cos = local_oscillator_cos.*temp_stor;
temp_demod_sin = local_oscillator_sin.*temp_stor;
demod_cos = [demod_cos temp_demod_cos];
demod_sin = [demod_sin temp_demod_sin];
end

% Demodulator Low Pass Filter Specifications


fpass_LPF = 5;
fstop_LPF = 10;
fpass_LPF_norm = fpass_LPF/norm_factor;
fstop_LPF_norm = fstop_LPF/norm_factor;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
% Creating a Low Pass Filter to Filter the Unfiltered Demodulated Wave
[imp, magni, freq] = Low_pass_Filter(fs, [0 fpass_LPF_norm,
fstop_LPF_norm, 1], [1 1 0 0]);

% Convolving Low Pass Filter with Unfiltered Demodulated Wave (EVEN & ODD)
demodulated_wave_cos = conv(demod_cos,imp);
demodulated_wave_sin = conv(demod_sin,imp);

% Taking 5 samples for a particular Bit (for sine and cosine wave)
% If 100 bits are input, then 500 samples are taken
sample_cos = [];
for i = fs:(fs*Ts):length(demodulated_wave_cos)-fs/2
sample_cos = [sample_cos demodulated_wave_cos(i)];
end

sample_sin = [];
for j = fs:(fs*Ts):length(demodulated_wave_sin)-fs/2
sample_sin = [sample_sin demodulated_wave_sin(j)];
end

% Decision maker for Received bits


received_bits = decode_phase_single_sample(sample_cos, sample_sin, Ts, N);

% Calculating Bit Error Rate


BER = Bit_Error_Rate(inp_bits, received_bits, N);
Bit_Error = sprintf("Bit Error rate = %d percent", BER);
disp(Bit_Error);

BER_plot = [BER_plot BER];


Bit Error rate = 1.578667e+01 percent
Bit Error rate = 2.508667e+01 percent
Bit Error rate = 3.020667e+01 percent
Bit Error rate = 3.397333e+01 percent
Bit Error rate = 3.726667e+01 percent
Bit Error rate = 3.938667e+01 percent
Bit Error rate = 4.091333e+01 percent
Bit Error rate = 4.222667e+01 percent
Bit Error rate = 4.298000e+01 percent
Bit Error rate = 4.432667e+01 percent
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)

You might also like