📄 alamoutiofdm2x2.m
字号:
%************************************************************************
%Alamouti Coding for OFDM with 2x2 antenna configuration
%
%Num_RxAnt: the number of receive antenna
%M: M-ary digital modulation
%
%
%************************************************************************
clc;
clear all;
%repeat for different receive antennas
M = 4; %M-ary QAM Modulation Scheme
SNR_max = 10;
Bn = 200; %the number of OFDM symbol will being transmitted
randn('state',0); %Remove it if you want a random start of the randn generator
randn('state',0); %Remove it if you want a random start of the randn generator
z = 1;
%Creating Fl matrix for decoding Alamouti code
for n = 1:64
for l = 1:16
F(n,l) = exp(-(j*2*pi*(l-1)*(n-1))/64);
end
end
l = 0;
n = 0;
Fl = [F zeros(size(F));zeros(size(F)) F];
for k = 1:0.5:SNR_max
snr = 10.^(k/10);
sig = 0.5/snr;
Smv = floor(M*rand(2,64*Bn)); %transmitted alphabet
Sm = exp(j*2*pi/M*Smv)/sqrt(2); %transmitted symbols
%Sm = 2x(64*Bn) matrix, the block of input is going to be transmitted with constant SNR
%calculating y in time domain and change it to frequency domain then apply detection part
for p = 1:Bn
Sof = Sm(:,(1+(p-1)*64:p*64)); %transmitted OFDM block with constant SNR
Sofc = conj(Sof);
%Taking IFFT of the block
Sot = [ifft(Sof(1,:));ifft(Sof(2,:))];
Sotc = [ifft(Sofc(1,:));ifft(Sofc(2,:))];
%Creating channel matrix with l = 16 multipaths
for l = 0:15
sig2 = 0.395*exp(-0.5*l);
h(:,l+1) = (randn(4,1)+j*rand(4,1))/sqrt(2)*sqrt(sig2);
end
%Creating Toeplitz matrix for each of impulse response separately and calculation corresponding received signal y
ns = sqrt(sig).*(randn(80,4)+j*randn(80,4));
y011 = [toeplitz([h(1,:) zeros(1,64)],[h(1,1) zeros(1,79)])]*[Sot(1,:) Sot(1,1:16)].';
y012 = [toeplitz([h(2,:) zeros(1,64)],[h(2,1) zeros(1,79)])]*[Sot(2,:) Sot(2,1:16)].';
y0 = y011 + y012 + ns(:,1); %at time t1 for received antenna 1
y111 = [toeplitz([h(1,:) zeros(1,64)],[h(1,1) zeros(1,79)])]*-[Sotc(2,:) Sotc(2,1:16)].';
y112 = [toeplitz([h(2,:) zeros(1,64)],[h(2,1) zeros(1,79)])]*[Sotc(1,:) Sotc(1,1:16)].';
y1 = y111 + y112 + ns(:,2); %at time t2 for received antenna 1
y021 = [toeplitz([h(3,:) zeros(1,64)],[h(3,1) zeros(1,79)])]*[Sot(1,:) Sot(1,1:16)].';
y022 = [toeplitz([h(4,:) zeros(1,64)],[h(4,1) zeros(1,79)])]*[Sot(2,:) Sot(2,1:16)].';
y2 = y021 + y022 + ns(:,3); %at time t1 for received antenna 2
y121 = [toeplitz([h(3,:) zeros(1,64)],[h(3,1) zeros(1,79)])]*-[Sotc(2,:) Sotc(2,1:16)].';
y122 = [toeplitz([h(4,:) zeros(1,64)],[h(4,1) zeros(1,79)])]*[Sotc(1,:) Sotc(1,1:16)].';
y3 = y121 + y122 + ns(:,4); %at time t2 for received antenna 2
%Removing CP and transform the signals to frequency domain
ya0 = [y0(65:79,1);y0(16:64,1)];
YA0 = fft(ya0);
ya1 = [y1(65:79,1);y1(16:64,1)];
YA1 = fft(ya1);
ya2 = [y2(65:79,1);y2(16:64,1)];
YA2 = fft(ya2);
ya3 = [y3(65:79,1);y3(16:64,1)];
YA3 = fft(ya3);
Y = [YA0 conj(YA1) YA2 conj(YA3)];
%Creating subcarrier matrix in frequency domain
ht=[(h(1,:)).' (h(2,:)).';(h(3,:)).' (h(4,:)).'];
H = Fl*ht;
%Alamouti Decoding
for Kc = 1:64
YC = Y(Kc,:);
Yc = YC.';
Hc = [H(Kc,1) H(Kc,2);H(Kc,2)' -H(Kc,1)';H(Kc+64,1) H(Kc+64,2);H(Kc+64,2)' -H(Kc+64,1)'];
X_ = (Hc)'*Yc;
%Selecting 2 symbols from OFDM block, send it and retrive it until the end of the OFDM block as well as for Bn OFDM block
ang = angle(X_); %receive angles
S_ = mod(round(ang/(2*pi/M)),M); %received alphabet, its another
S_det_mat(:,(64*(p-1)+Kc)) = S_; %Output one OFDM transmission block
end
end
%Calculating bit error rate
BER = 0;
ERROR = 0;
for p = 1:2
for u = 1:64*Bn
if Smv(p,u) ~= S_det_mat(p,u)
ERROR = ERROR + 1;
end
end
end
ber(z) = ERROR/(2*64*Bn);
z = z + 1;
end
Snr = 1:0.5:SNR_max;
ber2 = ber;
%plot the bit error rate
semilogy(Snr,ber2,'bh-','LineWidth',2.0);
xlabel('SNR [dB]');
ylabel('BER');
title('Bit Error Rate Evaluation for OFDM system with Alamouti coding and perfect CSI, M-ary QAM Modulation');
grid on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -