MATLAB Question.. Please add noise to following two matlab codes. First one incl
ID: 662581 • Letter: M
Question
MATLAB Question.. Please add noise to following two matlab codes. First one include image and second include sound data type.
clear all
%% transmitter
img = imread('hand.jpg'); % converts to rgb codes.
%data is converted into one row data:
data=reshape(img,1,numel(img));
data = double(data);
colors=unique(data);%colors in image are selected.
%occurance of colors:
[occurances,symbols] = hist(data, colors);
% Source Coding ---->Huffman Encoding:
[dict,avglen] = huffmandict(symbols,occurances/numel(data));
% encode with Huffman coding
coded_data = huffmanenco(data, dict);
% Channel Coding ----> Hamming Encoding:
%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.
size_of_img = size(img);
received_img = reshape(uint8(decoded_data),size_of_img(1),size_of_img(2),size_of_img(3));
image(received_img); % display image
title('Decoded Image');
------------------------
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
Explanation / Answer
Add the following snippet to the first code:
noise_add = imnoise(img,'salt & pepper',0.02);
figure, imshow(img)
figure, imshow(noise_add)
Add the following code snippet to the second code:
x = sawtooth(y); % Create sawtooth signal.
z = awgn(y,10,'measured'); % Add white Gaussian noise.
plot(t,x,t,y) % Plot both signals.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.