: OFDM Simulator (outer function)
clear allmodulate;
A = [1 1/exp(1) 1/exp(2)]; % power delay profile
N = 64; % number of symbols in a single OFDM symbol
GI = 16; % guard interval
Mt = 1; % number of Tx antennas
Mr = 1; % number of Rx antennas
sig2 = 1e-3; % noise variance
M = 8; % max constellation bit number
Mgap = 10.^(1:(1.7/10):2.7); % gap
Btot = 100*Mt; % total # bits per OFDM symbol
TransmitIter = 50; % # iterations of symbol transmissions for each channel instance
ChannelIter = 100; % # iterations of independent identically distributed channel instances
GapIter = length(Mgap);
load
load
load
load
load
TotEbNo = [];
Errors =[];
EbNo = [];
for lGap = 1:GapIter
lGap
gap = Mgap(lGap);
totalErrors = 0;
for lChan = 1:ChannelIter
% create channel
[H h_f]=create_channel(Mt, Mr, A, N+GI);
% decompose each subchannel in the frequency domain
[U S V] = svd_decompose_channel(Mt, Mr, h_f, N);
% bitloading
[bits_alloc,energy_alloc] = BitLoad(S,Btot,Mt*N,gap,sig2,M);
%energy_alloc=energy_alloc/(mean(energy_alloc));
%energy_alloc=ones(1,128);
for lTrans = 1:TransmitIter
% bits to transmit
x = (randn(1,Btot)>0);
% modulate
x_mod = modulate(x,bits_alloc,energy_alloc, s2,s4,s16,s64,s256);
% precode modulated signal
x_pre = precode(Mt, x_mod, V, N);
% ifft, with cyclic prefix for each antenna
ofdm_symbol =[];
for i=1:Mt
ofdm_symbol = [ofdm_symbol; ifft_cp_tx_blk(x_pre(i:Mt:Mt*(N-1)+i),N,GI)];
end
ofdm_symbol2 = reshape(ofdm_symbol,Mt*(N+GI),1);
% channel
y = transpose(channel(sig2, Mt, Mr, ofdm_symbol2, H, N+GI));
% fft
rec_symbol =[];
for i=1:Mt
rec_symbol = [rec_symbol; fft_cp_rx_blk(y(i:Mt:Mt*(N+GI-1)+i),N,GI)];
end
rec_symbol2 = reshape(rec_symbol,1,Mt*N);
% shape received signal
shaped_vals = shape(rec_symbol2, Mr, U, N);
% demodulate
y_demod = demodulate(shaped_vals, bits_alloc, energy_alloc, S, s2,s4,s16,s64,s256, c2,c4,c16,c64,c256);
% comparison
totalErrors = totalErrors + sum(xor(y_demod,x));
end
EbNo = [EbNo sum(energy_alloc)/Btot/sig2];
end
Errors = [Errors totalErrors/Btot/ChannelIter/TransmitIter]
TotEbNo = [TotEbNo mean(EbNo)]
EbNo = [];
end
semilogx(TotEbNo, Errors);
xlabel('Eb/No');
ylabel('BER');
title('SISO link, adaptive rate and power')
save Errors EbNo
: Generates a Rayleigh fading frequency-selective channel, parametrized by the antenna configuration, the OFDM configuration, and the power-delay profile.
function [H, H_f]=create_channel(Mt, Mr, A, N);
% function [H, H_f]=create_channel(Mt, Mr, A, N);
%
% A - vector containing the power-delay profile (real values)
% Mt - number of Tx antennas
% Mr - number of Rx antennas
% N - number of vector symbols to be sent in a single OFDM symbol Tx
% ie: N MIMO transmissions in one OFDM symbol
% This is for Rayleigh frequency-selective fading, which assumes complex
% Gaussian matrix elements with in-phase and quadrature components independent.
% Assume iid matrix channel elements, and further, independent channel taps
% define the channel taps
H_int = 1/sqrt(2)*(randn(Mr*length(A),Mt) + j*randn(Mr*length(A),Mt));
H_int2=[];
for i = 1:length(A)
H_int2 = [H_int2;sqrt(A(i))*H_int((i-1)*Mr+1:i*Mr,:)];
end
%h_f = fft(H_int2',64);
%%H = H_int2';
H_int2 = [H_int2;zeros((N-length(A))*Mr,Mt)];
H_f = zeros(Mr,Mt*(N-16));
for i = 1:Mt
for j = 1:Mr
h_f = fft(H_int2(j:Mr:(N-16-1)*Mr+j,i));
for k = 1:(N-16)
H_f(j,i+(k-1)*Mt) = h_f(k);
end
end
end
H=[H_int2];
for i = 1:N-1
H=[H,[zeros(Mr*i,Mt);H_int2(1:(N-i)*Mr,:)]];
end
: Since full channel knowledge is assumed, transmission is across parallel singular value modes. This function decomposes the channel into these modes.
function [U, S, V] = svd_decompose_channel(Mt, Mr, h_f, N);
% [U S V] = svd_decompose_channel(Mt, Mr, h_f, N);
%
% Function decomposes the channel at each subcarrier into its SVD components
%
% Mt - # Tx antennas
% Mr - # Rx antennas
% h_f - MIMO impulse response - Mr rows, Mt*L columns, where L is the number of
% channel taps
% N - # subcarriers
U = [];
S = [];
V = [];
for i = 1:N
[Utmp Stmp Vtmp] = svd(h_f(:,(i-1)*Mt+1:i*Mt));
U=[U Utmp];
V=[V Vtmp];
S=[S Stmp];
end
S = sum(S,1);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论