Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Question.. please add noise to codes below clear all %% transmitter fid =

ID: 662577 • Letter: M

Question

MATLAB Question.. please add noise to codes below

clear all

%% transmitter

fid = fopen('sample.txt','r');

data = fread(fid);

data=reshape(data,1,87);

original_text= char(data);

chars = unique(data);%number of unique characters:

number_of_chars = length(chars);

% Source Coding ---->Huffman Encoding:

% Probability of characters are calculated with using formula:

% probability= usage of char / number of chars in text

probabilities = zeros(1,number_of_chars);

for k = 1:number_of_chars

probabilities(k) = numel(find(data==chars(k)))/length(data);

end

chars_list=double(chars);

[dict,avglen] = huffmandict(chars_list,probabilities);% huffman dict is ready.

coded_data= huffmanenco(data,dict);% data is coded with huffman coding.

disp(length(coded_data))

% Channel Coding ----> Hamming Encoding:

[h,g,n,k] = hammgen(4);

add_zeros = horzcat(coded_data, [0 0]);

row = length(add_zeros)/11;

res_code=reshape(add_zeros, [row, 11]);

a = res_code*g;

coding = mod(a,2);

disp(coding)

size(coding)

x = reshape(coding,1,36*15)%with interleave

%frame

y = [0;1;1;0;1;0;1;0;1;0;0;1]'

if y in x

disp('k')

else

disp('l')

end

%synrome matrix

syndrome_matrix = [];

for i = 1:15;

error_matrix = zeros(15,1);

error_matrix(i)=1;

errors = h*error_matrix;

syndrome_matrix = horzcat(syndrome_matrix, errors);

end

%add noise

%% receiver

% Channel DeCoding ----> Hamming Decoding:

% Source DeCoding ----> Huffman Decoding:

decoded_data = huffmandeco(coded_data,dict);

%Received data is reshaped in order to get original data.

received_text= char(decoded_data);

disp('Decoded Text:')

disp(text)

fclose(fid);

Explanation / Answer

Generally noise means...not making error .....just adding some junk to data so that it gives incorrect results which may misleads one's from their original output.

I highlithed inside code,.as bold one..please have a look

If data is image ..noise added in terms of spots on the diagram...if it is in form of data., some random data will add to original data.

----------------------------------------------------------------------------------------------

clear all
%% transmitter

fid = fopen('sample.txt','r');
data = fread(fid);
data=reshape(data,1,87);
original_text= char(data);

chars = unique(data);%number of unique characters:
number_of_chars = length(chars);

% Source Coding ---->Huffman Encoding:
% Probability of characters are calculated with using formula:
% probability= usage of char / number of chars in text
probabilities = zeros(1,number_of_chars);
for k = 1:number_of_chars
probabilities(k) = numel(find(data==chars(k)))/length(data);
end

chars_list=double(chars);
[dict,avglen] = huffmandict(chars_list,probabilities);% huffman dict is ready.
coded_data= huffmanenco(data,dict);% data is coded with huffman coding.
disp(length(coded_data))

% Channel Coding ----> Hamming Encoding:

[h,g,n,k] = hammgen(4);
add_zeros = horzcat(coded_data, [0 0]);
row = length(add_zeros)/11;
res_code=reshape(add_zeros, [row, 11]);
a = res_code*g;
coding = mod(a,2);
disp(coding)


size(coding)
x = reshape(coding,1,36*15)%with interleave

%frame

y = [0;1;1;0;1;0;1;0;1;0;0;1]'

if y in x
disp('k')
else
disp('l')
end











%synrome matrix
syndrome_matrix = [];
for i = 1:15;
error_matrix = zeros(15,1);
error_matrix(i)=1;
errors = h*error_matrix;
syndrome_matrix = horzcat(syndrome_matrix, errors);
end


%add noise

for i = 1:15;
yd=syndrome_matrix[i]+rand(1,numel(10)).*syndrome_matrix[i]/100 % added noise here
end


%% receiver

% Channel DeCoding ----> Hamming Decoding:







% Source DeCoding ----> Huffman Decoding:
decoded_data = huffmandeco(coded_data,dict);

%Received data is reshaped in order to get original data.
received_text= char(decoded_data);
disp('Decoded Text:')
disp(text)
fclose(fid);