Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

OFDM Frame Generator

(MATLAB tutorial)

M.Sc. Vladimir Fadeev

Kazan, 2017


Hello, everyone!

The material presented below is primarily intended for students of GRIAT-CSP (KNRTU-KAI named after A.Tupolev). However, everyone can join the discussion, or write to me, if you know how to make this small tutorial more interesting and useful. You are welcome!

This tutorial aims to show the opportunities of modeling without different GUI (Graphical User Interface), such as MatLab Simulink, for example.

The author does not deny that for certain purposes it is more convenient to use the Simulink, however, he is deeply convinced that the solutions made with the help of programming languages are more manageable, faster (in terms of speed of processing) and elegant.

The way of modeling of the OFDM signal generator based on the MATLAB language features will be presented in this tutorial. This approach will rely entirely on MATLAB's matrices magic and if after that you will still consider Simulink as a simpler solution - well, nobody is perfect.

So, all the words are said, tune in to a serious mood, let's go!

M.Sc. Vladimir Fadeev

clear all; close all; clc
M = 4; % e.g. QPSK
N_inf = 16; % number of subcarriers (information symbols, actually) in the frame
fr_len = 32; % the length of our OFDM frame
N_pil = fr_len - N_inf - 5; % number of pilots in the frame
pilots = [1; j; -1; -j]; % pilots (BPSK, in fact)
nulls_idx = [1, 2, fr_len/2, fr_len-1, fr_len]; % indexes of nulls
idx_1_start = 4;
idx_1_end = fr_len/2 - 2;
idx_2_start = fr_len/2 + 2;
idx_2_end = fr_len - 3;
inf_idx_1 = (floor(linspace(idx_1_start, idx_1_end, N_inf/2))).';
inf_idx_2 = (floor(linspace(idx_2_start, idx_2_end, N_inf/2))).';
inf_ind = [inf_idx_1; inf_idx_2]; % simple concatenation
inf_and_nulls_idx = union(inf_ind, nulls_idx); %concatenation and ascending sorting
pilot_idx = setdiff(1:fr_len, inf_and_nulls_idx); %numbers in range from 1 to frame length
% that don't overlape with inf_and_nulls_idx vector
%% Pilots vector
% it should be very convinient to insert pilots if we prepare before "long-vector"
pilots_len_psudo = floor(N_pil/length(pilots)); % floor rounds value to lower integer
% - now we know how many full pilots vectors OFDM-frame consists
mat_1 = pilots*ones(1, pilots_len_psudo); % rank-one matrix - linear algebra trick
resh = reshape(mat_1, pilots_len_psudo*length(pilots),1); % vectorization - linear algebra trick
tail_len = fr_len - N_inf - length(nulls_idx) ...
- length(pilots)*pilots_len_psudo;
tail = pilots(1:tail_len); % "tail" of pilots vector
vec_pilots = [resh; tail]; % completed pilots vector that frame consists
message = randi([0 M-1], N_inf, 1); % decimal information symbols
if M >= 16
info_symbols = qammod(message, M, pi/4);
info_symbols = pskmod(message, M, pi/4);
%% Frame construction
frame = zeros(fr_len,1);
frame(pilot_idx) = vec_pilots;
frame(inf_ind) = info_symbols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.