Sie sind auf Seite 1von 4

%% NOMA-OFDM

% SIC receiver for downlink NOMA based on OFDM scheme


% 2016/06/28
% Copyright
% By z.s.yin
%--------------------------------------------------------------------------
clc;
clear all

Fc = 2*1e9; % the Carrier Frequency of 4G system :2G


Bw = 8.192*1e6; % the Bandwidth of 4G system :4M
T = 62.5 *1e-6; % the useful symbol duration 62.5us
Tg = 1.953*1e-6; % the guard interval duration
detF = 16*1e3; % the interval of subcarriers
Tsymbol = T+Tg; % the total symbol duration
nFFT = 512; % fft size
nDSC = 512; % number of data subcarriers
nBitPerSym = nDSC ; % number of bits per OFDM symbol
nSym = 1000; % number of symbols
detT = T/nFFT; % the sampling interval of simulation programe

Ng = 16; % the number of sample point of the cyclic prefix:16


nTotal = nFFT+Ng; % add cp
M = 2; % BPSK
ML = log2(M);
SNR_dB = [0:5:45];
nPow = zeros(1,length(SNR_dB));
for ii = 1:length(SNR_dB)

%-----------------------------------------------------------------------
% 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 = reshape(st1.',1,nSym*nTotal); %??????,649000?


xt2 = reshape(st2.',1,nSym*nTotal); %??????,649000?
ps1 = (xt1*xt1')/length(xt1);
ps2 = (xt2*xt2')/length(xt2);

%xt1 = 1/sqrt(2)*xt1/sqrt(ps1)
p1 = 0.6;
p2 = 0.4;

trans_signal = sqrt(p1)*xt1/sqrt(ps1) + sqrt(p2)*xt2/sqrt(ps2);


xt = reshape(trans_signal,nTotal,nSym).';
%-----------------------------------------------------------------------
% multipath channel
%-----------------------------------------------------------------------
nTap = 10;
% % gains10 = sqrt([0.08 0.02 0.03 0.09 0.15 0.11 0.3 0.02 0.05 0.15]);
% gains8 = sqrt([0.25 0.2 0.18 0.12 0.1 0.08 0.05 0.02]);
ht1 = 1/sqrt(2)*1/sqrt(nTap)*(randn(nSym,nTap) + 1j*randn(nSym,nTap)); % UE#1
receive channel.
% ht = 1/sqrt(2)*(randn(nSym,nTap) + 1j*randn(nSym,nTap));
% gains = repmat(gains8,nSym,1);
% ht1 = 1/sqrt(2)*(randn(nSym,nTap) + 1j*randn(nSym,nTap));
% ht = gains.*ht1;
ht2 = 1/sqrt(2)*1/sqrt(nTap)*(randn(nSym,nTap) + 1j*randn(nSym,nTap)); % UE#2
receive channel.

%-----------------------------------------------------------------------
% 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,:)); % ????????????

% UE#2 received signal


%xht2(jj,:) = conv(ht2(jj,:),xt(jj,:)); % ????????????
end
%xt = xht;
for jj = 1:nSym
%-------------------------------------------------------------------
% convolution operation //
% UE#1 received signal
%xht1(jj,:) = conv(ht1(jj,:),xt(jj,:)); % ????????????

% UE#2 received signal


xht2(jj,:) = conv(ht2(jj,:),xt(jj,:)); % ????????????
end

%-----------------------------------------------------------------------
% 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

yt2 = reshape(yt2.',nTotal+nTap-1,nSym).'; % formatting the received vector into


symbols
yt2 = yt2(:,[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).';

yF2_det = yF2 - sqrt(p1)*hF2.*S1;


ModHat2 = reshape(yF2_det.',1,[]); % Converting the Matrix to sequence
S2 = demodulate(ModHat2,M);

error2 = size(find(round(S2 - ipMod2)),2);

nErr(ii) = error1 + error2;

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')

Das könnte Ihnen auch gefallen