ITC Lab Mannual Using MATLAB Programs
ITC Lab Mannual Using MATLAB Programs
% Calculate entropy
H = -sum(p .* log2(p));
% Define the channel transition matrix (probabilities of each output symbol given
an input symbol)
channel_matrix = [0.7, 0.1, 0.1, 0.1; % Probability of output given input A
0.2, 0.6, 0.1, 0.1; % Probability of output given input B
0.1, 0.1, 0.8, 0.0; % Probability of output given input C
0.1, 0.1, 0.1, 0.7]; % Probability of output given input D
disp(' ');
#This program calculates the entropy and mutual information for both an error-free
channel and a binary symmetric channel. You can adjust the probabilities and the
crossover probability for the binary symmetric channel according to your specific
scenario.
# Program3.
#Write a MATLAB program to implement algorithm for generation
and evaluation of Shannan Fano coding and decoding. compute
entropy, average length and coding efficiency.
% Define the probabilities of each symbol in the input message
p = [0.2, 0.3, 0.15, 0.15, 0.1, 0.1]; % Example probabilities, you can change them
as needed
% Calculate entropy
H = -sum(p .* log2(p));
% Display results
disp(['Entropy (H): ', num2str(H)]);
disp(['Average Code Length (L_avg): ', num2str(L_avg)]);
disp(['Coding Efficiency: ', num2str(efficiency)]);
This program generates the Shannon-Fano codes for a given set of probabilities,
computes entropy, average code length, and coding efficiency.
#Program 4
#Write a matlab program to implement algorithm for generation and
evaluation of Huffman coding and decoding. Compute entropy
average length and coding efficiency.
% Define the probabilities of each symbol in the input message
p = [0.2, 0.3, 0.15, 0.15, 0.1, 0.1]; % Example probabilities, you can change them
as needed
% Update codes
symbols{1}.code = strcat(symbols{1}.code, '0');
symbols{2}.code = strcat(symbols{2}.code, '1');
end
% Calculate entropy
H = -sum(p .* log2(p));
% Display results
disp(['Entropy (H): ', num2str(H)]);
disp(['Average Code Length (L_avg): ', num2str(L_avg)]);
disp(['Coding Efficiency: ', num2str(efficiency)]);
This program generates the Huffman codes for a given set of probabilities,
computes entropy, average code length, and coding efficiency.
#Program5
#Write a MATLAB program to implement algorithm for generation
and evaluation of Lempel Ziv dictionary method. Compute entropy
average length and coding efficiency.
% Define the input data
input_data = 'abcbabcbabaaaa';
% Display results
disp(['Entropy of Input Data: ', num2str(entropy_input)]);
disp(['Entropy of Compressed Data: ', num2str(compressed_entropy)]);
disp(['Average Length of Compressed Data: ', num2str(average_length)]);
disp(['Coding Efficiency: ', num2str(coding_efficiency)]);
This program performs LZ77 compression on the input data, calculates its
entropy, average length, and coding efficiency.
#Program6
#Write a MATLAB program to implement algorithm for encoding and
decoding of linear block code.
#Implementing a linear block code encoder and decoder involves
defining a generator matrix for encoding and a parity check matrix for
decoding. Here's a MATLAB program that implements a simple (7, 4)
Hamming code, which encodes 4-bit messages into 7-bit codewords
and decodes them back:
% Define generator matrix for (7, 4) Hamming code
G=[
1 0 0 0 1 1 1;
0 1 0 0 1 0 1;
0 0 1 0 0 1 1;
0001110
];
% Example usage:
message = [1 0 1 1]; % Example 4-bit message
codeword = encode(message, G); % Encode the message
disp(['Encoded Codeword: ', num2str(codeword)]);
received_codeword = codeword;
% Introduce an error in the received codeword
received_codeword(3) = mod(received_codeword(3) + 1, 2);
decoded_message = decode(received_codeword, H); % Decode the received
codeword
disp(['Decoded Message: ', num2str(decoded_message)]);
This program defines the generator matrix G and parity check matrix H for a (7, 4)
Hamming code. It includes functions to encode a 4-bit message into a 7-bit
codeword using matrix multiplication and to decode a received codeword using
syndrome decoding.
#Program7
#Write a MATLAB program to implement algorithm for encoding and
decoding of cyclic block code.
#Implementing a cyclic block code encoder and decoder involves defining a
generator polynomial for encoding and a syndrome polynomial for decoding.
Here's a MATLAB program that implements a simple (7, 4) cyclic code, which
encodes 4-bit messages into 7-bit codewords and decodes them back:
% Define generator polynomial for (7, 4) cyclic code (example: x^3 + x^2 + 1)
gen_poly = [1 1 0 1];
% Example usage:
message = [1 0 1 1]; % Example 4-bit message
codeword = encode(message, gen_poly); % Encode the message
disp(['Encoded Codeword: ', num2str(codeword)]);
received_codeword = codeword;
% Introduce an error in the received codeword
received_codeword(3) = mod(received_codeword(3) + 1, 2);
decoded_message = decode(received_codeword, gen_poly); % Decode the
received codeword
disp(['Decoded Message: ', num2str(decoded_message)]);
This program defines the generator polynomial for a (7, 4) cyclic code and
includes functions to encode a 4-bit message into a 7-bit codeword using
polynomial division and to decode a received codeword using syndrome
decoding. Finally, it demonstrates an example of encoding, introducing an error,
and decoding a message. You can adjust the generator polynomial and the
message accordingly.
#Program8
#Write a MATLAB program to implement algorithm for generating
convolutional code by code tree.
#Generating a convolutional code using a code tree involves defining
the code tree structure and traversing it to generate the code
sequences. Here's a MATLAB program to generate a convolutional
code using a code tree:
% Define the generator polynomials for the convolutional code
g1 = [1 1 1]; % Example generator polynomial 1
g2 = [1 0 1]; % Example generator polynomial 2
% Display results
disp('Original Message:');
disp(msg);
disp('Encoded Codeword:');
disp(codeword);
disp('Received Codeword with Errors:');
disp(received_codeword);
disp('Decoded Message:');
disp(decoded_msg);
This program demonstrates how to encode a random message using a BCH code,
introduce errors into the codeword, and then decode the received codeword to
recover the original message. Adjust the parameters n, k, and t according to your
specific requirements.