Beruflich Dokumente
Kultur Dokumente
%-----------------------------------------------------------------------
% Transmitter ==> 2 Users
%-----------------------------------------------------------------------
ipBit1 = round(rand(1,nBitPerSym*ML*nSym)); % random 1's and 0's for User1
ipBit2 = round(rand(1,nBitPerSym*ML*nSym)); % random 1's and 0's for User2
%-----------------------------------------------------------------------
% BPSK modulator
%-----------------------------------------------------------------------
ipMod1 = Modulator(ipBit1,M); % BPSK modulation
ipMod2 = Modulator(ipBit2,M); % BPSK modulation
%tx_signals = reshape(ipMod,1,[]);
%-----------------------------------------------------------------------
% Grouping modulated symbols into multiple symbols of OFDM from
%-----------------------------------------------------------------------
xF1 = reshape(ipMod1,nBitPerSym,nSym).'; % grouping into multiple symbols
xF2 = reshape(ipMod2,nBitPerSym,nSym).'; % grouping into multiple symbols
%-----------------------------------------------------------------------
% Assigning OFDM symbols to subcarriers from [-256 to -1, +1 to +256]
%-----------------------------------------------------------------------
% Taking FFT, the term (nFFT/sqrt(nDSC)) is for normalizing the power of
transmit symbol to 1
st1 = (nFFT/sqrt(nDSC))*ifft(fftshift(xF1.')).';
st2 = (nFFT/sqrt(nDSC))*ifft(fftshift(xF2.')).';
%-----------------------------------------------------------------------
% Appending cylic prefix
%-----------------------------------------------------------------------
st1 = [st1(:,[nFFT-Ng+1:nFFT]) st1];
st2 = [st2(:,[nFFT-Ng+1:nFFT]) st2];
%xt1 = 1/sqrt(2)*xt1/sqrt(ps1)
p1 = 0.6;
p2 = 0.4;
%-----------------------------------------------------------------------
% computing and storing the frequency response of the channel, for use at
recevier
%-----------------------------------------------------------------------
hF1 = fftshift(fft(ht1,nFFT,2)); % ?????????,???????va
hF2 = fftshift(fft(ht2,nFFT,2)); % ?????????,???????va
%-----------------------------------------------------------------------
% convolution of each symbol with the random channel
%-----------------------------------------------------------------------
xht1 = zeros(1000,537);
xht2 = zeros(1000,537);
for jj = 1:nSym
%-------------------------------------------------------------------
% convolution operation //
% UE#1 received signal
xht1(jj,:) = conv(ht1(jj,:),xt(jj,:)); % ????????????
%-----------------------------------------------------------------------
% Concatenating multiple symbols to form a long vector
%-----------------------------------------------------------------------
xht1 = reshape(xht1.',1,nSym*(nTotal+nTap-1));
%ps = (xht*xht')/length(xht);
xht2 = reshape(xht2.',1,nSym*(nTotal+nTap-1));
%-----------------------------------------------------------------------
% Gaussian noise of unit variance, 0 mean
%-----------------------------------------------------------------------
nt1 = 1/sqrt(2)*[randn(1,nSym*(nTotal+nTap-1)) + 1j*randn(1,nSym*(nTotal+nTap-
1))];
nt2 = 1/sqrt(2)*[randn(1,nSym*(nTotal+nTap-1)) + 1j*randn(1,nSym*(nTotal+nTap-
1))];
pn = 1/10^(SNR_dB(ii)/10);
% n = 10^(-SNR_dB(ii)/20)*nt;
debug = 1;
n1 = sqrt(pn)*nt1*debug;
n2 = sqrt(pn)*nt2*debug;
%-----------------------------------------------------------------------
% Adding noise// 2 users time domain received signals
%-----------------------------------------------------------------------
yt1 = xht1 + n1; % UE#1
yt2 = xht2 + n2; % UE#2
%-----------------------------------------------------------------------
% Receiver
%-----------------------------------------------------------------------
yt1 = reshape(yt1.',nTotal+nTap-1,nSym).'; % formatting the received vector into
symbols
yt1 = yt1(:,[Ng+1:nTotal]); % removing cyclic prefix
%-----------------------------------------------------------------------
%----------------------------------------------------------------------
% converting to frequency domain
%----------------------------------------------------------------------
yF1 = (sqrt(nDSC)/nFFT)*fftshift(fft(yt1.')).';
yF2 = (sqrt(nDSC)/nFFT)*fftshift(fft(yt2.')).';
%----------------------------------------------------------------------
% equalization by the known channel frequency response
%----------------------------------------------------------------------
%yF1 = yF1./hF1; % Equalization using perfect CSI
%yF2 = yF2./hF2;
%----------------------------------------------------------------------
% extracting the required data subcarriers
%??????
%----------------------------------------------------------------------
%yMod = yF(:,[(nFFT-nDSC)/2+[1:nBitPerSym/2] (nFFT-nDSC)/2+
[nBitPerSym/2+1:nBitPerSym] ]);
%-----------------------------------------------------------------------
% SIC detecting
%-----------------------------------------------------------------------
ModHat1 = reshape(yF1.',1,[]); % Converting the Matrix to sequence
S1 = demodulate(ModHat1,M); % NoBN BPSK-Demodulator
error1 = size(find(round(S1 - ipMod1)),2);
S1 = reshape(S1,nFFT,nSym).';
end
%----------------------------------------------------------------------
%the SER of the simulation
%----------------------------------------------------------------------
simBer = nErr/(nSym*ML*nBitPerSym*2);
%----------------------------------------------------------------------
%the SER of theory-NoBN
%----------------------------------------------------------------------
SNR = 10.^(SNR_dB/10);
theoryBer = 0.5.*(1-sqrt(SNR./(SNR+1)));
%----------------------------------------------------------------------
%close all;
figure
semilogy(SNR_dB,theoryBer,'bo-','LineWidth',2);
hold on
semilogy(SNR_dB,simBer,'ro-','LineWidth',2);
% axis([0 35 10^-5 1])
grid on
% legend('no blanks-theory', 'BN blanks-theory','BN blanks-simulation');
xlabel('SNR(dB)')
ylabel('SER')