MATLAB Question.. Add noise to two codes below: clear all %% transmitter % -----
ID: 662617 • Letter: M
Question
MATLAB Question.. Add noise to two codes below:
clear all
%% transmitter
% ------>Digitizing
[y, Fs, nbits] = wavread('road.wav', 'double');
% Source Coding ---->Huffman Encoding:
% Channel Coding ----> Hamming Encoding:
%add noise
%% receiver
% Channel DeCoding ----> Hamming Decoding:
% Source DeCoding ----> Huffman Decoding:
% Mapping
------------------------------------------------------------------
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
if (meas == 1) %Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.