Lab 4 Part 2
Lab 4 Part 2
% 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 another array of ODD and EVEN bits
[odd_bit_wave, even_bit_wave, ~, ~, ~] = bit_split_by_2(inp_bits, temp, Ts, N,
fs);
% 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);
% Decision maker which converts a sample of 5 values into single bit (For
Channel)
sample_bits_even = decision_maker(sample_even);
% Decision maker which converts a sample of 5 values into single bit (For
Channel)
sample_bits_odd = decision_maker(sample_odd);
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 another array of ODD and EVEN bits
[~, ~, ~, ~, temp_half_bits] = bit_split_by_2(inp_bits, temp, Ts, N, fs);
% 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");
% 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);
sample_odd = [];
for i = fs:fs*Ts:length(Cont_Demodulated_Wave_Odd)-fs/2
sample_odd= [sample_odd Cont_Demodulated_Wave_Odd(i)];
end
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)
Q3.
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
% 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
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)
Q4.
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
% 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)
Q5.
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 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);
scatterplot(QPSK_const);
title("Constellation diagram of QPSK");
grid on;
COMMUNICATION SYSTEM 2 LAB SHEET 4 PART :2
S Bhargava Siva Sai(SC21B121)
Q6.
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 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);
% 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");
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 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
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
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
% 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 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);
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;
% 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)
% Decision maker which converts a sample of 5 values into single bit (For
Channel)
sample_bits_even = decision_maker(sample_even);
% Decision maker which converts a sample of 5 values into single bit (For
Channel)
sample_bits_odd = decision_maker(sample_odd);
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 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);
% 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");
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;
% 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);
sample_odd = [];
for j = fs:fs*Ts:length(Cont_Demodulated_Wave_Odd)-fs/2
sample_odd= [sample_odd Cont_Demodulated_Wave_Odd(j)];
end
Q11.
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
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;
% 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