Adc Lab Report
Adc Lab Report
Adc Lab Report
“OPEN-ENDED EXPERIMENTS”
IN
TH
5 SEMESTER
ADVANCED COMMUNICATION LAB (22EC5PCACL)
(PLATFORM-MATLAB)
Submitted in partial fulfilment of the requirements for the Activity plan
BACHELOR OF ENGINEERING
IN
UTTAM (1BM21EC190)
Dr. Madhusudhan K N
(Assistant Professor, BMSCE)
Department of Electronics and Communication Engineering
2023-2024
1).Demonstrate sampling,quantization and reconstruction of any given signal.
clc;
close all;
clear all;
% Signal parameters
Fs = 1000; % Sampling frequency (Hz)
t = 0:1/Fs:1; % Time vector from 0 to 1 second with 1/Fs increment
f_original = 5; % Frequency of the original signal (Hz)
original_signal = sin(2*pi*f_original*t); % Original signal (sine wave)
% Sampling
Fs_sampled = 200; % Sampling frequency for the sampled signal (Hz)
t_sampled = 0:1/Fs_sampled:1; % Time vector for sampled signal
sampled_signal = sin(2*pi*f_original*t_sampled); % Sampled signal
% Quantization
bits = 4; % Number of quantization bits
quantized_signal = quantize(sampled_signal, bits);
% Reconstruction
reconstructed_signal = interp1(t_sampled, quantized_signal, t, 'linear', 'extrap');
OUTPUT:
% PCM Encoding
bits_per_sample = 8; % Number of bits per sample
speech_max = max(abs(speech_signal));
speech_quantized = speech_signal / speech_max * (2^(bits_per_sample-1) - 1);
speech_quantized = round(speech_quantized);
% μ-law companding
mu = 255; % μ value for μ-law companding
speech_companded = sign(speech_quantized) .* log(1 + mu * abs(speech_quantized) / (1 + mu)) / log(1 + mu);
% PCM Decoding
speech_decompanded = sign(speech_companded) .* ((1 + mu).^abs(speech_companded) - 1) / mu;
speech_reconstructed = speech_decompanded * speech_max;
OUTPUT:
3).Demonstarte digital communication system employing BASK,BPSK,QPSK,BFSK
modulation and demodulation scheme you have studied and show the constellation plot/
BER performance/ Plot waveforms.Assume AWGN channel and demodulation.
For BFSK:
clc;
close all;
clear all;
% BFSK Modulation and Demodulation with AWGN Channel
% Parameters
f_mark = 1000; % Frequency for binary 1
f_space = 500; % Frequency for binary 0
T = 1 / 1000; % Symbol duration (1 ms)
A = 1; % Amplitude
SNR_dB = 10; % Signal-to-Noise Ratio in dB
% Simulation parameters
num_bits = 1000; % Number of bits to transmit
% Modulation
t = 0:T:(num_bits * T - T);
modulated_signal = zeros(size(t));
for i = 1:num_bits
if data(i) == 1
modulated_signal((i-1)*length(T)+1:i*length(T)) = A * cos(2*pi*f_mark*t((i-1)*length(T)
+1:i*length(T)));
else
modulated_signal((i-1)*length(T)+1:i*length(T)) = A * cos(2*pi*f_space*t((i-1)*length(T)
+1:i*length(T)));
end
end
% Demodulation
demodulated_data = zeros(1, num_bits);
for i = 1:num_bits
mark_amplitude = sum(noisy_signal((i-1)*length(T)+1:i*length(T)) .* cos(2*pi*f_mark*t((i-1)*length(T)
+1:i*length(T))));
space_amplitude = sum(noisy_signal((i-1)*length(T)+1:i*length(T)) .* cos(2*pi*f_space*t((i-1)*length(T)
+1:i*length(T))));
subplot(2, 2, 1);
plot(t, modulated_signal);
title('BFSK Modulated Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(2, 2, 2);
plot(t, noisy_signal);
title('Noisy Signal (AWGN)');
xlabel('Time');
ylabel('Amplitude');
% Constellation Plot
subplot(2, 2, 3);
scatter(real(noisy_signal), imag(noisy_signal));
title('Constellation Plot');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
% BER Performance
subplot(2, 2, 4);
bar([0, 1], [num_bits - sum(data), sum(data)], 'r');
hold on;
bar([0, 1], [sum(demodulated_data == data), num_bits - sum(demodulated_data == data)], 'b');
title(['Bit Error Rate (BER): ' num2str(ber)]);
xlabel('Transmitted Bit');
ylabel('Number of Bits');
legend('Transmitted', 'Received', 'Location', 'NorthEast');
hold off;
Output:
For BASK:
clc;
close all;
clear all;
% BASK Modulation and Demodulation with AWGN Channel
% Parameters
A1 = 1; % Amplitude for binary 1
A0 = 0; % Amplitude for binary 0
T = 1 / 1000; % Symbol duration (1 ms)
SNR_dB = 10; % Signal-to-Noise Ratio in dB
% Simulation parameters
num_bits = 1000; % Number of bits to transmit
% Modulation
t = 0:T:(num_bits * T - T);
modulated_signal = zeros(size(t));
for i = 1:num_bits
if data(i) == 1
modulated_signal((i-1)*length(T)+1:i*length(T)) = A1 * square(2*pi*(1/T)*t((i-1)*length(T)
+1:i*length(T)));
else
modulated_signal((i-1)*length(T)+1:i*length(T)) = A0 * square(2*pi*(1/T)*t((i-1)*length(T)
+1:i*length(T)));
end
end
% Demodulation
demodulated_data = zeros(1, num_bits);
for i = 1:num_bits
demodulated_data(i) = (sum(noisy_signal((i-1)*length(T)+1:i*length(T))) > 0);
end
subplot(2, 2, 1);
plot(t, modulated_signal);
title('BASK Modulated Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(2, 2, 2);
plot(t, noisy_signal);
title('Noisy Signal (AWGN)');
xlabel('Time');
ylabel('Amplitude');
% Constellation Plot
subplot(2, 2, 3);
scatter(real(noisy_signal), imag(noisy_signal));
title('Constellation Plot');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
% BER Performance
subplot(2, 2, 4);
bar([0, 1], [num_bits - sum(data), sum(data)], 'r');
hold on;
bar([0, 1], [sum(demodulated_data == data), num_bits - sum(demodulated_data == data)], 'b');
title(['Bit Error Rate (BER): ' num2str(ber)]);
xlabel('Transmitted Bit');
ylabel('Number of Bits');
legend('Transmitted', 'Received', 'Location', 'NorthEast');
hold off;
OUTPUT:
For QPSK:
clc;
close all;
clear all;
% QPSK Modulation and Demodulation with AWGN Channel
% Parameters
A = 1; % Amplitude for each symbol
T = 1 / 1000; % Symbol duration (1 ms)
SNR_dB = 10; % Signal-to-Noise Ratio in dB
% Simulation parameters
num_bits = 1000; % Number of bits to transmit
% Modulation
t = 0:T:(num_bits/2 * T - T);
modulated_signal = A * symbols;
% Demodulation
demodulated_symbols = noisy_signal / A;
subplot(2, 2, 1);
plot(real(modulated_signal), imag(modulated_signal), 'o');
title('QPSK Modulated Signal');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
axis square;
subplot(2, 2, 2);
plot(real(noisy_signal), imag(noisy_signal), 'o');
title('Noisy Signal (AWGN)');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
axis square;
% Constellation Plot
subplot(2, 2, 3);
scatter(real(noisy_signal), imag(noisy_signal));
title('Constellation Plot');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
% BER Performance
subplot(2, 2, 4);
bar([0, 1], [num_bits - sum(data), sum(data)], 'r');
hold on;
bar([0, 1], [sum(demodulated_data == data), num_bits - sum(demodulated_data == data)], 'b');
title(['Bit Error Rate (BER): ' num2str(ber)]);
xlabel('Transmitted Bit');
ylabel('Number of Bits');
legend('Transmitted', 'Received', 'Location', 'NorthEast');
hold off;
OUTPUT:
For BPSK:
clc;
close all;
clear all;
% BPSK Modulation and Demodulation with AWGN Channel
% Parameters
A = 1; % Amplitude for both binary 0 and 1
T = 1 / 1000; % Symbol duration (1 ms)
SNR_dB = 10; % Signal-to-Noise Ratio in dB
% Simulation parameters
num_bits = 1000; % Number of bits to transmit
% Modulation
t = 0:T:(num_bits * T - T);
modulated_signal = A * cos(2*pi*(1/T)*t + pi*(data-0.5));
% Demodulation
demodulated_data = (noisy_signal > 0);
subplot(2, 2, 1);
plot(t, modulated_signal);
title('BPSK Modulated Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(2, 2, 2);
plot(t, noisy_signal);
title('Noisy Signal (AWGN)');
xlabel('Time');
ylabel('Amplitude');
% Constellation Plot
subplot(2, 2, 3);
scatter(real(noisy_signal), imag(noisy_signal));
title('Constellation Plot');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
% BER Performance
subplot(2, 2, 4);
bar([0, 1], [num_bits - sum(data), sum(data)], 'r');
hold on;
bar([0, 1], [sum(demodulated_data == data), num_bits - sum(demodulated_data == data)], 'b');
title(['Bit Error Rate (BER): ' num2str(ber)]);
xlabel('Transmitted Bit');
ylabel('Number of Bits');
legend('Transmitted', 'Received', 'Location', 'NorthEast');
hold off;
OUTPUT:
% Parameters
fs = 100; % Sampling frequency
T = 1; % Total time duration
fc = 50; % Carrier frequency
SNR_dB = 10; % Signal-to-Noise Ratio in dB
% Generate a binary signal
data = randi([0 1], 1, fs*T);
for i = 1:length(data)
fh_modulated_signal((i-1)*fs + 1:i*fs) = cos(2*pi*(fc+hop_indices(i))/fs*(1:fs));
end
% Plotting
figure;
subplot(3,2,1);
plot(data, 'LineWidth', 1.5);
title('Binary Data');
subplot(3,2,2);
plot(ds_modulated_signal, 'r', 'LineWidth', 1.5);
title('DS Modulated Signal');
subplot(3,2,3);
plot(data, 'LineWidth', 1.5);
title('Binary Data');
subplot(3,2,4);
plot(fh_modulated_signal, 'r', 'LineWidth', 1.5);
title('FH Modulated Signal');
subplot(3,2,5);
plot(ds_received_signal, 'g', 'LineWidth', 1.5);
title('DS Received Signal with Noise');
subplot(3,2,6);
plot(fh_received_signal, 'g', 'LineWidth', 1.5);
title('FH Received Signal with Noise');
OUTPUT:
Huffman coding:
clc;
clear all;
close all;
probabilities=[1/5 1/5 3/5 2/15 2/15];
probabilities=probabilities/sum(probabilities);
for index=1:length(probabilities)
codewords{index}=[];
set_contents{index}=index;
set_probabilities(index)=probabilities(index);
end
while length(set_contents)>1
[temp,sorted_indices]=sort(set_probabilities);
zero_set=set_contents{sorted_indices(1)};
zero_probability=set_probabilities(sorted_indices(1));
for codeword_index=1:length(zero_set)
codewords{zero_set(codeword_index)}=[codewords{zero_set(codeword_index)},1];
end
one_set=set_contents{sorted_indices(2)};
one_probability=set_probabilities(sorted_indices(2));
for codeword_index=1:length(one_set)
codewords{one_set(codeword_index)}=[codewords{one_set(codeword_index)},0];
end
set_contents(sorted_indices(1:2))=[];
set_contents{length(set_contents)+1}=[zero_set,one_set];
set_probabilities(sorted_indices(1:2))=[];
set_probabilities(length(set_probabilities)+1)=zero_probability+one_probability;
end
for index=1:length(codewords)
disp([num2str(index),' ',num2str(probabilities(index)),' ',num2str(codewords{index}
(length(codewords{index}):-1:1))])
end
entropy=sum(probabilities.*log2(1./probabilities))
av_length=0
for index=1:length(codewords)
av_length=av_length+probabilities(index)*length(codewords{index});
end
OUTPUT:
1 0.15789 0 0 1
2 0.15789 0 0 0
3 0.47368 1
4 0.10526 0 1 1
5 0.10526 0 1 0
entropy =
2.0353
av_length =
OUTPUT:
Alpha Matrix
a = 0 0.5000 1.0000 1.4000 1.7000
Code length matrix
n=1 1 2 2 3
Codeword 1
z=0
Codeword 2
z =1
Codeword 3
z =2 0
Codeword 4
z =2 1
Codeword 5
z =3 0 1
Avg. Code Length
l =3
Entropy
h =2.5142
Efficiency 83.8082
Redundancy 16.1918
clc;
close all;
clear all;
%% Parameters
N = 10^4; % Number of bits (reduced for demonstration)
EbN0dB = 0:1:10; % Eb/N0 range in dB
EbN0 = 10.^(EbN0dB/10); % Eb/N0 in linear scale
nBitsPerSymbol = 1; % For BPSK
codeRate = 1/2; % Coding rate (for repetition code)
%% Initialization
ber = zeros(size(EbN0));
%% Simulation
for idx = 1:length(EbN0)
% Generate random bits
txBits = randi([0,1], 1, N);
% BPSK modulation
txSymbols = 1 - 2*txBits; % Mapping 0 to 1 and 1 to -1
% Adding noise
noise = sqrt(1/(2*codeRate*EbN0(idx))) * randn(1, length(codedSymbols));
rxSymbols = codedSymbols + noise;
% Demodulation
rxBits = rxSymbols < 0; % Decision rule for BPSK
%% Plotting
semilogy(EbN0dB, ber, 'bo-');
grid on;
xlabel('Eb/N0 (dB)');
ylabel('Bit Error Rate (BER)');
title('BER Performance of BPSK with Repetition Coding (1/2)');
OUTPUT:
Length of decodedBits: 10000
Length of txBits: 10000
Convolution method:
clc;
close all;
clear all;
%% Parameters
N = 10^6; % Number of bits
EbN0dB = 0:1:10; % Eb/N0 range in dB
EbN0 = 10.^(EbN0dB/10); % Eb/N0 in linear scale
nBitsPerSymbol = 1; % For BPSK
constraintLength = 7; % Constraint length of the convolutional code
codeRate = 1/2; % Coding rate (for convolutional code)
%% Initialization
ber = zeros(size(EbN0));
%% Convolutional Encoder
trellis = poly2trellis(constraintLength, [171 133]); % Define the convolutional code
convEncoder = comm.ConvolutionalEncoder(trellis); % Create a convolutional encoder object
%% Viterbi Decoder
vitDecoder = comm.ViterbiDecoder(trellis, 'InputFormat', 'Hard'); % Create a Viterbi decoder object
%% Simulation
for idx = 1:length(EbN0)
% Generate random bits
txBits = randi([0,1], 1, N);
% Convolutional encoding
codedBits = convEncoder(txBits.');
% BPSK modulation
txSymbols = 1 - 2*codedBits; % Mapping 0 to 1 and 1 to -1
% Adding noise
noiseVar = 1 / (2*codeRate*EbN0(idx)); % Noise variance
noise = sqrt(noiseVar) * randn(size(txSymbols));
rxSymbols = txSymbols + noise;
% Demodulation
rxBits = rxSymbols < 0; % Decision rule for BPSK
% Viterbi decoding
decodedBits = [];
for i = 1:size(rxBits, 2)
decodedBits = [decodedBits; vitDecoder(rxBits(:, i)).']; % Decode each channel separately
end
% Calculating BER
ber(idx) = sum(decodedBits ~= txBits) / N;
end
%% Plotting
semilogy(EbN0dB, ber, 'bo-');
grid on;
xlabel('Eb/N0 (dB)');
ylabel('Bit Error Rate (BER)');
title('BER Performance of BPSK with Convolutional Coding');
OUTPUT:
7) Plot the radiation plot of microstrip antenna using antenna design tool box
Fig(2):Radiation Pattern