clear; bits = 64; threshold = 0.5; %Generate 64 random values. Check help on rand() function. data = rand(1, bits); %Quantize the random values only between two levels; 0 and 1. for i=1:length(data) if data (i) > threshold data2(i) = 1; else data2(i) = 0; end end %Commands for plotting the data. subplot(2, 1, 1); stairs(data2) title('Original Digital Data'); ylabel('Amplitute'); axis([0 bits -0.2 1.2]); grid off; %%%%%%%%%%%%%%%Genrate Gaussian Noise%%%%%%%%%%%%%%%%%%%%%% %%Different values for standard deviation for noise sn = 1.2; %%Generare different noise vectors. noise1 = randn(1, bits)*sn; %%Add noise to original data; recv_x = data2+noise1; %%Quatize the received data back to 0's and 1's%% for i=1:length(recv_x) if recv_x(i) > threshold recv_data(i) = 1; else recv_data(i) = 0; end end %Note how the received data is different than the data sent. subplot(2, 1, 2); stairs(recv_data) title('Received Quantized Data'); ylabel('Amplitute'); axis([0 bits -0.2 1.2]); grid off; %Calculate the number of errors error = XOR(data2, recv_data); error_cnt = 0; for i=1:length(error) if (error(i) == 1) error_cnt = error_cnt+1; end end %Calculate the error probability%% error_prob = error_cnt/length(data2); %Calculate the Signal-to-Noise Ratio%% signal_strength = std(data2); noise_strength = std(noise1); SNR = 10*log10(signal_strength./noise_strength); %Find tuples of (error_prob, SNR) for different values %of noise and plot them for every encoding scheme.