Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % number of bits, Signal to Noise Ratio in dB then Watts
- numbits = 1e6;
- SNR = 0 : 2 : 30;
- snr = 10.^(SNR/10);
- % Random array of bits (0 or 1)
- rand_bits = randi([0 1], 1, numbits);
- % case OOK
- % Initializing zero arrays to be manipulated later
- no_error1 = zeros(1, length(SNR));
- noise1 = zeros(size(rand_bits));
- BER1 = zeros(1, length(SNR));
- Rx_sequence1 = zeros(size(rand_bits));
- Tx_sequence1 = zeros(size(rand_bits));
- % Calculating Power to be used in noise equation
- power1 = mean(abs(rand_bits.^2));
- % Adding noise, then deciding which bits are ones and which are zeroes.
- % Afterwards, the results are compared to the original array of bits
- % rand_bits and the number of error bits and their ratio are stored
- for i = 1 : length(snr)
- noise1 = (sqrt(power1/(snr(i)))) * (1/sqrt(2)) * (randn(1,length(rand_bits)) + 1j * randn(1, length(rand_bits)));
- Rx_sequence1 = rand_bits + noise1;
- Tx_sequence1 = real(Rx_sequence1) > 1/2;
- [no_error1(i), BER1(i)] = biterr(Tx_sequence1, rand_bits);
- end
- figure
- semilogy(SNR, BER1, 'ro-');
- title('Modulation Types (Coding) Comparison')
- % case PRK %
- no_error2 = zeros(1, length(SNR));
- noise2 = zeros(size(rand_bits));
- BER2 = zeros(1, length(SNR));
- Rx_sequence2 = zeros(size(rand_bits));
- Tx_sequence2 = zeros(size(rand_bits));
- % PRK formula that returns 1 if 1 is entered, -1 if 0 is entered
- PRK = 2 * rand_bits - 1;
- % Calculating Power to be used in noise equation
- power2 = mean(abs(PRK.^2));
- % Adding noise, then deciding which bits are ones and which are zeroes.
- % Afterwards, the results are compared to the original array of bits
- % rand_bits and the number of error bits and their ratio are stored
- for i = 1: length(snr)
- noise2 = (sqrt(power2/snr(i))) * (1/sqrt(2)) * (randn(1, length(PRK)) + 1j * randn(1, length(rand_bits))) ;
- Rx_sequence2 = PRK + noise2;
- Tx_sequence2 = real(Rx_sequence2) > 0;
- [no_error2(i), BER2(i)] = biterr(Tx_sequence2, rand_bits);
- end
- hold on
- semilogy(SNR, BER2, 'gx-')
- % case FSK %
- no_error3 = zeros(1, length(SNR));
- noise3 = zeros(size(rand_bits));
- BER3 = zeros(1, length(SNR));
- Rx_sequence3 = zeros(size(rand_bits));
- Tx_sequence3 = zeros(size(rand_bits));
- fsk = zeros(size(rand_bits));
- % FSK formula: returns 1 if 0 is entered, 1i if 1 is entered
- for i = 1:length(fsk)
- if rand_bits(i) == 0
- fsk(i) = 1;
- else
- fsk(i) = 1i;
- end
- end
- % Calculating Power to be used in noise equation
- power3 = mean(abs(fsk.^2));
- % Adding noise, then deciding which bits are ones and which are zeroes.
- % Afterwards, the results are compared to the original array of bits
- % rand_bits and the number of error bits and their ratio are stored
- for i = 1: length(snr)
- noise3 = (sqrt(power3/snr(i))) * (1/sqrt(2)) * (randn(1, length(fsk)) + 1i * randn(1, length(fsk)));
- Rx_sequence3 = fsk + noise3;
- Tx_sequence3 = imag(Rx_sequence3) > real(Rx_sequence3);
- [no_error3(i), BER3(i)] = biterr(Tx_sequence3, rand_bits);
- end
- hold on
- semilogy(SNR, BER3, 'b*-')
- legend('OOK','PRK','FSK');
- % The results of all Biterrors from all 3 modulation techniques are
- % compared on semilogy and it is deduced that PRK is the most efficient
Advertisement
Add Comment
Please, Sign In to add comment