[go: up one dir, main page]

0% found this document useful (0 votes)
10 views10 pages

DC Lab Manual Part B

The document outlines various experiments involving signal processing and coding techniques, including Gram-Schmidt orthogonalization, binary baseband signal simulation, 16-QAM modulation, Huffman coding, Hamming code, and convolutional coding. Each experiment includes MATLAB code for implementation, demonstrating concepts such as orthogonal basis vectors, bit error rate estimation, modulation techniques, and error correction methods. The experiments provide practical applications of theoretical concepts in digital communications and coding theory.
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)
10 views10 pages

DC Lab Manual Part B

The document outlines various experiments involving signal processing and coding techniques, including Gram-Schmidt orthogonalization, binary baseband signal simulation, 16-QAM modulation, Huffman coding, Hamming code, and convolutional coding. Each experiment includes MATLAB code for implementation, demonstrating concepts such as orthogonal basis vectors, bit error rate estimation, modulation techniques, and error correction methods. The experiments provide practical applications of theoretical concepts in digital communications and coding theory.
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/ 10

Experiment No.

5 Date: __ /__ / _____


Gram-Schmidt Orthogonalization: To find orthogonal basis vectors for the
given set of vectors and plot the orthonormal vectors
% Given set of vectors as columns
V = [1 1 0; 1 0 1; 0 1 1]';
% Number of vectors
num_vectors = size(V, 2);
% Initialize orthogonal and orthonormal matrices
U = zeros(size(V));
E = zeros(size(V));
% Gram-Schmidt Process
U(:,1) = V(:,1); % First orthogonal vector is the first input vector
E(:,1) = U(:,1) / norm(U(:,1)); % First orthonormal vector
for i = 2:num_vectors
U(:,i) = V(:,i);
for j = 1:i-1
U(:,i) = U(:,i) - (dot(V(:,i), E(:,j)) * E(:,j)); % Subtract projection onto previous
orthonormal vectors
end
E(:,i) = U(:,i) / norm(U(:,i)); % Normalize to get orthonormal vector
end
% Display the orthonormal vectors
disp('Orthonormal basis vectors:');
disp(E);
% Plot the original and orthonormal vectors
figure;
hold on;
grid on;
axis equal;
% Plot original vectors
quiver3(0, 0, 0, V(1,1), V(2,1), V(3,1), 'r', 'LineWidth', 2);
quiver3(0, 0, 0, V(1,2), V(2,2), V(3,2), 'g', 'LineWidth', 2);
quiver3(0, 0, 0, V(1,3), V(2,3), V(3,3), 'b', 'LineWidth', 2);
% Plot orthonormal vectors
quiver3(0, 0, 0, E(1,1), E(2,1), E(3,1), 'r--', 'LineWidth', 2);
quiver3(0, 0, 0, E(1,2), E(2,2), E(3,2), 'g--', 'LineWidth', 2);
quiver3(0, 0, 0, E(1,3), E(2,3), E(3,3), 'b--', 'LineWidth', 2);
xlabel('X');
ylabel('Y');
zlabel('Z');
legend('Original V1', 'Original V2', 'Original V3', 'Orthonormal E1', 'Orthonormal E2',
'Orthonormal E3');
title('Original and Orthonormal Vectors');
hold off;
Experiment No. 6 Date: __ /__ / _____
Simulation of binary baseband signals using a rectangular pulse and estimate
the BER for AWGN channel using matched filter receiver
% Simplified Parameters
N = 1e4;
SNR_dB = 0:5:20;
pulse_width = 1;
% Number of bits
% SNR values in dB
% Pulse width for rectangular pulse
% Generate random binary data
data = randi([0 1], N, 1);
% Define the rectangular pulse
t = 0:0.01:pulse_width;
rect_pulse = ones(size(t));
% Initialize BER vector
BER = zeros(length(SNR_dB), 1);
for snr_idx = 1:length(SNR_dB)
% Modulate binary data
tx_signal = [];
for i = 1:N
if data(i) == 1
tx_signal = [tx_signal; rect_pulse'];
else
tx_signal = [tx_signal; zeros(size(rect_pulse'))];
end
end
% Add AWGN
SNR = 10^(SNR_dB(snr_idx) / 10);
noise_power = 1 / (2 * SNR);
noise = sqrt(noise_power) * randn(length(tx_signal), 1);
rx_signal = tx_signal + noise;
% Matched Filter
matched_filter = rect_pulse;
filtered_signal = conv(rx_signal, matched_filter, 'same');
% Sample the output of the matched filter
sample_interval = round(length(filtered_signal) / N);
sampled_signal = filtered_signal(1:sample_interval:end);
% Decision (Threshold = 0.5)
estimated_bits = sampled_signal > 0.5;
% Compute BER
num_errors = sum(estimated_bits ~= data);
BER(snr_idx) = num_errors / N;
end
% Plot BER vs. SNR
figure;
semilogy(SNR_dB, BER, 'b-o');
grid on;
xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)');
title('BER vs. SNR for Rectangular Pulse Modulated Binary Data');
Experiment No. 8 Date: __ /__ / _____
Generate 16-QAM Modulation and obtain the QAM constellation
close all
m=16
k=log2(m);
n=9e3;
nsamp=1;
x=randint(n,1);
stem(x(1:20),'filled');
title('bit sequence');
xlabel('bit index');
ylabel('bit amplitude');
xsym=bi2de(reshape(x,k,length(x)/k).','left-msb');
figure;
stem(xsym(1:10));
title('symbol plot');
xlabel('symbol index');
ylabel('symbol amplitude');
y=modulate(modem.qammod(m),xsym);
ytx=y;
ebno=10
snr=ebno+10*log(k)-10*log10(nsamp);
yn=awgn(ytx,snr);
yrx=yn;
scatterplot(y);
scatterplot(yrx,30);
Experiment No. 9 Date: __ /__ / _____
Encoding and Decoding of Huffman code
x = input('Enter the number of symbols:');
N = 1:x;
disp('The number of symbols are N:');
disp(N);
P = input('Enter the probabilities = ');
disp(P);
S = sort(P, 'descend');
disp('The sorted probabilities are:');
disp(S);
[dict,avglen] = huffmandict(N,S);
disp('The average length of the code is:');
disp(avglen);
H = 0;
for i = 1:x
H = H + (P(i) * log2(1/P(i)));
end
disp('Entropy is:');
disp(H);
disp('bits/msg');
%Encoding and Decoding of Huffman code.
E = (H/avglen) * 100;
disp('Efficiency is:');
disp(E);
codeword = huffmanenco(N,dict);
disp('The codewords are:');
disp(codeword);
decode = huffmandeco(codeword,dict);
disp('Decoded output is:');
disp(decode);
Experiment No. 10 Date: __ /__
/ _____ Encoding and Decoding of binary data using a Hamming code

% Hamming Code Encoding and Decoding Example


% Parameters of the Hamming Code
n = 15; % Codeword length
k = 11; % Message length
% Generate random binary data of length k (message length)
data = randi([0 1], k, 1); % Random message of k bits
disp('Original Message:');
disp('data');
% Encode the data using Hamming code (binary)
encData = encode(data, n, k, 'hamming/binary');
disp('Encoded Message:');
disp('encData');
% Introduce an error in the encoded message
errLoc = randerr(1, n); % Generate random error positions (1-bit error)
encData_corrupted = mod(encData + errLoc', 2); % Corrupt the encoded message
disp('Corrupted Encoded Message:');
disp('encData_corrupted');
% Decode the corrupted message using Hamming decoding
decData = decode(encData_corrupted, n, k, 'hamming/binary');
disp('Decoded Message (after error correction):');
disp('decData');
% Compare original data and decoded data
numerr = biterr(data, decData); % Count number of bit errors between original and
decoded data
disp(['Number of bit errors between original and decoded message: ',
num2str(numerr)]);

Experiment No. 10 Date: __ /__


/ _____
Encoding and Decoding of Convolution code

% Complete Example of Convolutional Code Encoding and Decoding


% Input message to be encoded
msg = [1 0 1 1 0 1 0 0];
% Define constraint length and generator polynomial
constraint_length = 3;
generator_polynomials = [7 5];
% Create trellis
trellis = poly2trellis(constraint_length, generator_polynomials);
% Encode the message
encoded_msg = convenc(msg, trellis);
% Introduce some noise (optional)
% Example: Flip a bit in the encoded message to simulate noise
encoded_msg_noisy = encoded_msg;
encoded_msg_noisy(4) = ~encoded_msg_noisy(4); % Flip the 4th bit
% Decode the noisy message using Viterbi decoder
%Encoding and Decoding of Convolution code
traceback_length = 5;
decoded_msg = vitdec(encoded_msg_noisy, trellis, traceback_length, 'trunc', 'hard');
% Display results
disp('Original Message:');
disp(msg);
disp('Encoded Message:');
disp(encoded_msg);
disp('Noisy Encoded Message:');
disp(encoded_msg_noisy);
disp('Decoded Message:');
disp(decoded_msg);

You might also like