Tuesday, November 11, 2008

Simulating OFDM systems

The popular LabVIEW simulation package from National Instruments can be used to develop
virtual instruments (VI’s) that implement OFDM in a graphical user interface. See also [1].
Other communication system building blocks and multicarrier modulation tools are available in
the National Instruments Modulation Toolkit.
OFDM functions can also be developed in Matlab.6 Here, we provide Matlab code for a
baseband OFDM transmitter and receiver for QPSK symbols. These functions can be modified
to transmit and receive M-QAM symbols or passband—complex baseband—signals.
function x=OFDMTx(N, bits, num, nu)

%==========================================================
% x=OFDMTx( N, bits, num, nu,zero_tones)
%
% APSK transmitter for OFDM
%
% N is the FFT size
% bits is a {1,-1} stream of length (N/2-1)*2*num (baseband, zero DC)
% num is the number of OFDM symbols to produce
% nu is the cyclic prefix length

%==========================================================
if length(bits) ~= (N/2-1)*2*num
error('bits vector of improper length -- Aborting');
end x=[];
real_index = -1; %initial values
imag_index = 0;
for a=1:num
real_index = max(real_index)+2:2:max(real_index)+N-1;
imag_index = max(imag_index)+2:2:max(imag_index)+N-1;
X = (bits(real_index) + j*bits(imag_index))/2;
X=[0 X 0]; % zero nyquist and DC
x_hold=sqrt(N)*ifft([X,conj(fliplr(X(2:length(X)-1)))]); %Baseband so symmeteic
x_hold=[x_hold(length(x_hold)-nu+1:length(x_hold)),x_hold]; %Add CP
x=[x,x_hold];
end
x=real(x);

function bits_out = OFDMRx(N,y,h,num_symbols,nu)
%=========================================================
% bits_out = OFDMRx(M,N,y,num_symbols,nu,zero_tones)
%
% N is the FFT size
% y is received channel output for all symbols (excess delay spread removed)
% h is the (estimated) channel impulse response
% num_symbols is the # of symbols (each of N*sqrt(M) bits and N+nu samples)
% nu is the cyclic prefix length

%=========================================================
if length(y) ~= (N + nu)*num_symbols
error('received vector of improper length -- Aborting');
end bits_out=[]; bits_out_cur = zeros(1,N-2);
for a=1:num_symbols
y_cur = y((a-1)*(N+nu)+1+nu:a*(N+nu)); % Get current OFDM symbol, strip CP
X_hat = 1/sqrt(N)*fft(y_cur)./fft(h,N); %FEQ
X_hat = X_hat(1:N/2);
real_index = 1:2:N-2-1; % Don’t inc. X_hat (1) because is DC, zeroed
imag_index = 2:2:N-2;
bits_out_cur(real_index) = sign(real(X_hat(2:length(X_hat))));
bits_out_cur(imag_index) = sign(imag(X_hat(2:length(X_hat))));
bits_out=[bits_out,bits_out_cur];
end

No comments: