Вы находитесь на странице: 1из 4

02/09/20 12:44 C:\Users\Amro\Desktop\SUST\F...\SCFDMA3.

m 1 of 4

clc;
clear;
close all;
no_scr=512;
no_sym =128;
cp=20;
M=16;

Nfft = 128;
Nps=4;
Np=Nfft/Nps; % Number of pilots

for k=1:Np
Xp((k-1)*Nps+1)= exp(j*pi*(k-1)^2/Np).'; % Pilot boosting with an even Np
%xp((k-1)*Nps+1)= exp(j*pi*(k-1)*k/Np); % Pilot boosting with an odd Np
end

nb_s=log2(M);%number of bits per symbol

% channel type
ch_type = 'awgn';
EbNo = 1:32;
SNR = EbNo+10*log10(nb_s);

% Channels based on 3GPP TS 25.104.???!!!


pedAchannel = [1 10^(-9.7/20) 10^(-22.8/20)];
pedAchannel = pedAchannel/sqrt(sum(pedAchannel.^2));
channel = pedAchannel;
idenChannel = 1; % This is identity channel for AWGN simulation.
H_channel= fft(channel,no_scr);% frequency domain channel response
%generat random data
data=randi([0 1],no_sym*nb_s,1);

x1=bi2de(reshape(data,nb_s,numel(data)/nb_s).','left-msb');
%test = reshape(data,nb_s,numel(data)/nb_s)
%test2 = test.'
% modulate data

x=qammod(x1,M,'gray');
%draw scatterplot(x)
Nfft = 128;
Nps=4;
xp= add_pilot(x,Nfft,Nps);
%xp==x

% freq domain of data


x_fft=fft(xp,no_sym);
%%fix to xx=fft(x); returns fft vector%%
%%testing xx==x_fft; copmarison is valid%%

%%%how to include the sampling freq.%%%

% Fs = 6000000; % Sampling frequency T = 1/Fs; %


02/09/20 12:44 C:\Users\Amro\Desktop\SUST\F...\SCFDMA3.m 2 of 4

% Sampling period L = 150; % Length of signal t = (0:L-1)*T; %


% Time vector
%
% P2 = abs(x_fft/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); f =
% Fs*(0:(L/2))/L; plot(f,P1) title('Single-Sided Amplitude Spectrum of
% S(t)') xlabel('f (Hz)') ylabel('|P1(f)|')

% Localized sub-mapp
x_lfdma=zeros(no_scr,1);
for i=1:no_sym
x_lfdma(i)=x_fft(i);
end
% time domain of data
x_ifft=ifft(x_lfdma,no_scr).';

% add cyclic perfix


Tx_cp=[x_ifft(:,end-cp+1:end), x_ifft];
% Propagate through multi-path channel.
Rx_lfdma = filter(channel, 1,Tx_cp);
% Generate AWGN with appropriate noise power.
for ii=1:length(EbNo)
variance=1;
mu=0;
noise=sqrt(variance/2)*(randn(1,no_scr+cp)+1i*randn(1,no_scr+cp))+mu;
noisePower = 10^(-SNR(ii)/10);
end
% Add AWGN to the transmitted signal.
Rx_lfdma = Rx_lfdma +noisePower*noise;
% Remove CP
Rx_rcp = Rx_lfdma(cp+1:no_scr+cp);
% Convert the received signal in to frequency domain.
Y_lfdma = fft(Rx_rcp);
% Subcarrier de-mapping.
Y_lfdmade = Y_lfdma([1:no_sym]);
% Find the channel response for the localized subcarriers.
H_eff = H_channel([1:no_sym]);

pilot_loc = [];
[H_MMSE] = MMSE_CE(Y_lfdmade,Xp,pilot_loc,Nfft,Nps,H_eff);
channel_new= H_eff-H_MMSE;
% Perform channel equalization in the frequencydomain.
C = conj(channel_new)./(conj(channel_new).*channel_new+ 10^(-SNR(ii)/10));
Y= Y_lfdmade.*C;
% Convert the signal back to time domain.
y_ifft = ifft(Y,no_sym);

%qamdemodulation
y=qamdemod(y_ifft,M,'gray');
y_rev1=de2bi(y,'left-msb').';
y_rev2=reshape(y_rev1,numel(y_rev1),1);

%%%TESTING%%%
y_rev2==data;
%% matching data:
ABC=find(ans);
02/09/20 12:44 C:\Users\Amro\Desktop\SUST\F...\SCFDMA3.m 3 of 4

function xp=add_pilot(x,Nfft,Nps)

%CAZAC (Constant Amplitude Zero AutoCorrelation) sequence --> pilot


%CAZAC(ºã¶¨·ù¶ÈÁã×ÔÏà¹Ø)ÐòÁÐ --> µ¼Æµ
%Nps : Pilot spacing|µ¼Æµ¼ä¸ô
%MIMO-OFDM Wireless Communications with MATLAB¢ç Yong Soo Cho, Jaekwon Kim, Won
Young Yang and Chung G. Kang
%2010 John Wiley & Sons (Asia) Pte Ltd

% number of subcarriers(M)
% number of ofdm symbols(N)

% http://www.wiley.com//legacy/wileychi/cho/

if nargin<3,
Nps=4;
end
Np=Nfft/Nps; % Number of pilots
xp=x; % an OFDM signal including pilot signal
for k=1:Np
xp((k-1)*Nps+1)= exp(j*pi*(k-1)^2/Np); % Pilot boosting with an even Np
%xp((k-1)*Nps+1)= exp(j*pi*(k-1)*k/Np); % Pilot boosting with an odd Np
end
end
% CAZAC (Constant Amplitude Zero AutoCorrelation) sequence --> pilot

function [H_MMSE] = MMSE_CE(Y,Xp,pilot_loc,Nfft,Nps,h)


% MMSE channel estimation function
% Inputs:
% Y = Frequency-domain received signal
% Xp = Pilot signal
% pilot_loc = Pilot location
% Nfft = FFT size
% Nps = Pilot spacing
% h = Channel impulse response
% SNR = Signal-to-Noise Ratio[dB]
% output:
% H_MMSE = MMSE channel estimate

Np=Nfft/Nps;
%snr = 10.^(SNR*0.1);

%k=1:Np;
L=1:4:128;
H_tilde = Y(1,L)./Xp(L); % LS estimate Eq.(6.12) or (6.8)
%testing o=Y(1,125)./Xp(125)

k=0:length(h)-1; %k_ts = k*ts;


hh = h*h';
tmp = h.*conj(h).*k; %tmp = h.*conj(h).*k_ts;
r = sum(tmp)/hh;
r2 = tmp*k.'/hh; %r2 = tmp*k_ts.’/hh;
tau_rms = sqrt(r2-r^2); % rms delay
df = 1/Nfft; %1/(ts*Nfft);
02/09/20 12:44 C:\Users\Amro\Desktop\SUST\F...\SCFDMA3.m 4 of 4

j2pi_tau_df = j*2*pi*tau_rms*df;
K1 = repmat([0:Nfft-1].',1,Np); K2 = repmat([0:Np-1],Nfft,1);
rf = 1./(1+j2pi_tau_df*Nps*(K1-K2)); % Eq.(6.17a) frequency-domain correlation
K3 = repmat([0:Np-1].',1,Np); K4 = repmat([0:Np-1],Np,1);
rf2 = 1./(1+j2pi_tau_df*Nps*(K3-K4)); % Eq.(6.17a)
Rhp = rf;
Rpp = rf2 + eye(length(H_tilde),length(H_tilde)); % Eq.(6.14)
H_MMSE = transpose(Rhp*inv(Rpp)*H_tilde.'); % MMSE estimate Eq.(6.15)
end

Вам также может понравиться