NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

clc;
clear;
close all;

%% PARAMETERS
N = 8; % Subcarriers
cp_len = 2; % Cyclic Prefix length
numSymbols = 5000;
M = 16;
bits_per_sym = log2(M);

SNR_dB_range = 0:2:20;

BER_cp = zeros(size(SNR_dB_range));
BER_no_cp = zeros(size(SNR_dB_range));

%% CHANNEL
h = [0.9 0.4 0.2];
H = fft(h, N);

%% LOOP OVER SNR
for snr_idx = 1:length(SNR_dB_range)

SNR_dB = SNR_dB_range(snr_idx);

%% BIT GENERATION
numBits = N * numSymbols * bits_per_sym;
bits = randi([0 1], 1, numBits);

%% 16-QAM MODULATION (MANUAL)
symbols = zeros(1, numBits/4);
k = 1;

for i = 1:4:numBits
b = bits(i:i+3);

% I mapping
if isequal(b(1:2), [0 0])
I = -3;
elseif isequal(b(1:2), [0 1])
I = -1;
elseif isequal(b(1:2), [1 1])
I = 1;
else
I = 3;
end

% Q mapping
if isequal(b(3:4), [0 0])
Q = -3;
elseif isequal(b(3:4), [0 1])
Q = -1;
elseif isequal(b(3:4), [1 1])
Q = 1;
else
Q = 3;
end

symbols(k) = (I + 1j*Q) / sqrt(10);
k = k + 1;
end

%% SERIAL TO PARALLEL
symbols_parallel = reshape(symbols, N, numSymbols);

%% MANUAL IFFT
ofdm_time = zeros(N, numSymbols);

for sym = 1:numSymbols
for n = 1:N
sum_val = 0;
for kk = 1:N
sum_val = sum_val + symbols_parallel(kk, sym) * ...
exp(1j*2*pi*(n-1)*(kk-1)/N);
end
ofdm_time(n, sym) = sum_val / N;
end
end

%% ================= WITH CP =================
ofdm_cp = [ofdm_time(end-cp_len+1:end, :); ofdm_time];
tx_cp = reshape(ofdm_cp, 1, []);

rx_cp = conv(tx_cp, h);

% AWGN
signal_power = mean(abs(rx_cp).^2);
noise_power = signal_power / (10^(SNR_dB/10));

noise = sqrt(noise_power/2)*(randn(size(rx_cp)) + 1j*randn(size(rx_cp)));
rx_cp = rx_cp + noise;

% Trim
rx_cp = rx_cp(1:(N+cp_len)*numSymbols);

% Remove CP
rx_parallel = reshape(rx_cp, N+cp_len, numSymbols);
rx_no_cp = rx_parallel(cp_len+1:end, :);

%% FFT
rx_freq = zeros(N, numSymbols);

for sym = 1:numSymbols
for k = 1:N
sum_val = 0;
for n = 1:N
sum_val = sum_val + rx_no_cp(n, sym) * ...
exp(-1j*2*pi*(n-1)*(k-1)/N);
end
rx_freq(k, sym) = sum_val;
end
end

%% EQUALIZATION
for sym = 1:numSymbols
rx_freq(:,sym) = rx_freq(:,sym) ./ H.';
end

%% SERIAL
rx_symbols = reshape(rx_freq, 1, []);

%% DEMODULATION
rx_bits = zeros(1, numBits);

for i = 1:length(rx_symbols)
I = real(rx_symbols(i)) * sqrt(10);
Q = imag(rx_symbols(i)) * sqrt(10);

idx = (i-1)*4 + 1;

% I bits
if I < -2
rx_bits(idx:idx+1) = [0 0];
elseif I < 0
rx_bits(idx:idx+1) = [0 1];
elseif I < 2
rx_bits(idx:idx+1) = [1 1];
else
rx_bits(idx:idx+1) = [1 0];
end

% Q bits
if Q < -2
rx_bits(idx+2:idx+3) = [0 0];
elseif Q < 0
rx_bits(idx+2:idx+3) = [0 1];
elseif Q < 2
rx_bits(idx+2:idx+3) = [1 1];
else
rx_bits(idx+2:idx+3) = [1 0];
end
end

%% BER WITH CP
BER_cp(snr_idx) = sum(bits ~= rx_bits) / numBits;

%% ================= WITHOUT CP =================
tx_no_cp = reshape(ofdm_time, 1, []);
rx_no_cp2 = conv(tx_no_cp, h);

% AWGN
signal_power = mean(abs(rx_no_cp2).^2);
noise_power = signal_power / (10^(SNR_dB/10));

noise = sqrt(noise_power/2)*(randn(size(rx_no_cp2)) + 1j*randn(size(rx_no_cp2)));
rx_no_cp2 = rx_no_cp2 + noise;

rx_no_cp2 = rx_no_cp2(1:N*numSymbols);

rx_parallel2 = reshape(rx_no_cp2, N, numSymbols);

%% FFT
rx_freq2 = zeros(N, numSymbols);

for sym = 1:numSymbols
for k = 1:N
sum_val = 0;
for n = 1:N
sum_val = sum_val + rx_parallel2(n, sym) * ...
exp(-1j*2*pi*(n-1)*(k-1)/N);
end
rx_freq2(k, sym) = sum_val;
end
end

%% Equalization (imperfect due to ISI)
for sym = 1:numSymbols
rx_freq2(:,sym) = rx_freq2(:,sym) ./ H.';
end

rx_symbols2 = reshape(rx_freq2, 1, []);

%% DEMODULATION
rx_bits2 = zeros(1, numBits);

for i = 1:length(rx_symbols2)
I = real(rx_symbols2(i)) * sqrt(10);
Q = imag(rx_symbols2(i)) * sqrt(10);

idx = (i-1)*4 + 1;

if I < -2
rx_bits2(idx:idx+1) = [0 0];
elseif I < 0
rx_bits2(idx:idx+1) = [0 1];
elseif I < 2
rx_bits2(idx:idx+1) = [1 1];
else
rx_bits2(idx:idx+1) = [1 0];
end

if Q < -2
rx_bits2(idx+2:idx+3) = [0 0];
elseif Q < 0
rx_bits2(idx+2:idx+3) = [0 1];
elseif Q < 2
rx_bits2(idx+2:idx+3) = [1 1];
else
rx_bits2(idx+2:idx+3) = [1 0];
end
end

%% BER WITHOUT CP
BER_no_cp(snr_idx) = sum(bits ~= rx_bits2) / numBits;

end

%% PLOT
figure;
semilogy(SNR_dB_range, BER_cp, '-o', 'LineWidth', 2); hold on;
semilogy(SNR_dB_range, BER_no_cp, '-s', 'LineWidth', 2);
grid on;

xlabel('SNR (dB)');
ylabel('BER');
title('OFDM BER Performance');

legend('With CP','Without CP');


     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.