📄 ofdm_tinming_max_e.m
字号:
%% The programme is used to generate the OFDM data;
%% 2005-4-18;
clear all;
clc;
close all;
%% load the original state of random squence;
load randn_set_file_y5
%% the original state of uniform distribution;
randn('state',sn_set_y2);
%% the original state of Gaussian distribution;
rand('state',s_set_y2);
%% the bandwidth of OFDM systems;
BW=20e6;
%% the original sampling period, which is also the reciprocal of bandwidth;
Ts=1/BW;
%% the oversampling factor;
J1=40;
%% the downsampling factor;
os=10;
%% the oversampling factor;
J2=4;
%% the oversampling period;
Tss=Ts/J2;
%% the length of one OFDM symbol;
sym_l=256;
%% the length of the prefix;
pre_l=25;
%% the sub-carrier interval;
SBW=BW/sym_l;
%% the transmitted rate of input data;
Fd=1;
%% the transmitted rate of output data;
Fs=1;
%% the number of overall OFDM blocks;
b_n=13;
%% the number of used cp
c_number=10;
%% exploit M-ary modulation style;
M=4;
%% the number of the array elements;
arr_l=8;
%% exploit half-wavelength spacing;
sidelength=0.5;
a=0;
ff_0=10e3;
m_number=300;
S_number=7;
err=zeros(m_number,S_number);
t_p=zeros(m_number,S_number);
E=zeros(1,S_number);
sum=zeros(1,S_number);
for snr=-6:4:18
a=a+1
m=0;
for mon=1:m_number
m=m+1
%% generate M-ary random sequence as modulated information;
xs=randint(sym_l*b_n,1,M);
%% modulate the user information;
xs_mod0=modmap(xs,Fd,Fs,'qam',M);
%% the modulated data by combining the real part with image part;
xs_mod=xs_mod0(:,1)+j*xs_mod0(:,2);
%% generate four M-ary random sequences as interference data;
xi=randint(sym_l*b_n,1,M);
%% modulate the interference data;
xi_mod0=modmap(xi,Fd,Fs,'qam',M);
%% the modulated interference data by combining the real part with image part;
xi_mod=xi_mod0(:,1)+j*xi_mod0(:,2);
clear xs xs_mod0 xi xi_mod0;
%% save the signal data;
x_s=[];
%% save the interference data;
x_i=[];
%% assign each OFDM block to each column of the matrix;
for i1=1:b_n
x_s=[x_s xs_mod((i1-1)*sym_l+1:i1*sym_l,:)];
x_i=[x_i xi_mod((i1-1)*sym_l+1:i1*sym_l,:)];
end
%% normlize the signal mean power;
x_s=sym_l^0.5/2^0.5*J1.*x_s;
%% normlize the interference mean power;
x_i=sym_l^0.5/2^0.5*J1.*x_i;
%% padding zeros in the middle of the modulated signal;
xs_ifft=ifft([x_s(1:sym_l/2,:);zeros(sym_l*(J1-1),b_n);x_s(sym_l/2+1:sym_l,:)],sym_l*J1,1);
%% padding zeros in the middle of the modulated interference;
xi_ifft=ifft([x_i(1:sym_l/2,:);zeros(sym_l*(J1-1),b_n);x_i(sym_l/2+1:sym_l,:)],sym_l*J1,1);
clear xs_mod xi_mod x_s x_i;
%% insert perfix to form OFDM blocks of signal;
xs_pre=[xs_ifft((sym_l-pre_l)*J1+1:sym_l*J1,:);xs_ifft];
%% insert perfix to form OFDM blocks of interference;
xi_pre=[xi_ifft((sym_l-pre_l)*J1+1:sym_l*J1,:);xi_ifft];
%% save the series data stream of signal;
x_s=[];
%% save the series data stream of interference;
x_i=[];
for i2=1:b_n
x_s=[x_s;xs_pre(:,i2)];
x_i=[x_i;xi_pre(:,i2)];
end
%yy=length(x_s);%% the length of the transmitted data passing by filter;
%ph_r=exp(j*2*pi*ff_0*[1:yy].'*Tss);%% the phase rotation resulted by the CFO;
%x_s=x_s.*ph_r;%% multiply the phase rotation component;
clear xs_ifft xi_ifft xs_pre xi_pre;
%% the length of the series data stream;
yl=length(x_s);
%% raised cosine filter;
f_t0=rcosflt(1,1,40,'norm',0.05,3);
%% cut the front 241 points;
ft=f_t0(1:241,:);
%% filter the OFDM signal by raised cosine filter;
x_fs=filter(ft,1,x_s);
%% cut the front 121 points;
xs=x_fs(121:yl,:);
clear x_s x_fs;
%% the length of the received data;
yyl=length(xs);
%% the OFDM signal mean power;
s_mp=norm(xs)^2/yyl;
%% the received interference passing by raised cosine filter;
x_fi=filter(ft,1,x_i);
%% cut the front 241 points;
xi=x_fi(121:yl,:);
clear x_i x_fi;
%% the interference signal mean power;
i_mp=norm(xi)^2/length(xi);
%% the addtive white gaussian noise;
G_noise_0=1/2^0.5*(randn(yl,arr_l)+j*randn(yl,arr_l));
%% filter the noise using raised cosine filter;
G_noise_1=filter(ft,1,G_noise_0);
clear G_noise_0;
%% cut the front 121 points of the filtered noise ;
G_noise=G_noise_1(121:yl,:);
clear G_noise_1;
%% the recieved noise of the first antenna;
noise1=G_noise(:,1);
%% the mean power of the noise;
g_mp=norm(noise1)^2/yyl;
clear noise1;
%% normlized SNR equals zero;
xss=(1/(s_mp/g_mp)^0.5).*xs;
%% normlized INR equals zero;
xii=(1/(i_mp/g_mp)^0.5).*xi;
clear xs xi;
% the signal to noise ratio of the first ray;
SNR=snr;
%% the interference to noise ratio of the first ray;
INR=snr-3;
%% the amplified signal amplitude;
sig_a=10^(SNR/20);
%% the amplified interference amplitude;
inf_a=10^(INR/20);
% after adjusting the SNR, the signal vector;
xss=sig_a.*xss;
%% after adjusting the INR, the interference signal vector;
xii=inf_a.*xii;
%% the original sampling position;
Lorig=(sym_l+2*pre_l)*J1;
%%the sampling starting position;
L1=Lorig+1;
%% the terminal sampling position;
lr=yyl;
%% the number of multipath rays;
L_rays=4;
%% the arrival angle of multipath OFDM signals;
ths=[52.4;47.8;57.5;63.4];;
%% the arrival angle of multipath interference signals;
thi=[-35.5;-28.6;-39.6;-43.5];
%% the time delay of multipath OFDM signals;
ds_soi = [0;24;58;98];
%% the time delay of multipath interference signals;
di_soi=[600;658;691;720];
%% the propogation loss of multipath OFDM signals;
Ksis = [0.98+0.21j;0.69+0.16j;0.34+0.19j;0.09-0.08j];
%% the propogation loss of multipath interference signals;
Ksii=[-0.17+0.98j;0.31-0.46j;-0.43+0.11j;-0.06-0.16j];
for i3=1:L_rays
%% save the multipath rays of OFDM signals;
s_soi(:,i3)=xss(L1-ds_soi(i3):os:lr-ds_soi(i3),:);
%% save the multipath rays of interference signals;
i_soi(:,i3)=xii(L1-di_soi(i3):os:lr-di_soi(i3),:);
end
clear xss xii;
for i4=1:L_rays
%% the array manifold of the OFDM signals;
bs_soi(:,i4)=Ksis(i4)*steering(ths(i4),arr_l,sidelength);
%% the array manifold of the interference signals;
bi_soi(:,i4)=Ksii(i4)*steering(thi(i4),arr_l,sidelength);
end
%% the received user signal of a single ray of the antenna array;
% arr_s=bs_soi(:,[1])*s_soi(:,[1]).';
%% the received user signal of multipath rays of the antenna array;
arr_s=bs_soi*s_soi.';
%% the received interference signal of a single ray of the antenna array;
% arr_i=bi_soi(:,[1])*i_soi(:,[1]).';
%% the received interference signal of multipath rays of the antenna array;
arr_i=bi_soi*i_soi.';
%% the received noise of the antenna array;
arr_n=G_noise(L1:os:lr,:).';
clear s_soi i_soi G_noise;
% the array output data with interference signal;
arr_X=(arr_s+arr_i+arr_n);
%% the array output data without interference signal;
% arr_X=(arr_s+arr_n);
l_s=sym_l*J2;
l_p=pre_l*J2;
l_sp=(sym_l+pre_l)*J2;
W=[];
f_a=zeros(l_sp,1);
for k=1:l_sp
C1=[];
C2=[];
for j=0:(c_number-1)
C1=[C1 arr_X(:,k+j*l_sp:k+j*l_sp+l_p-1)];
C2=[C2 arr_X(:,k+j*l_sp+l_s:k+j*l_sp+l_sp-1)];
end
R1=conj(C1)*C2.';
R2=R1';
Rc=R1+R2;
%[V_eig D_eig]=eig(R1);
%[v_max,ind_max]=max(diag(D_eig));
%w_k=V_eig(:,ind_max);
%f_h(k)=w_k'*R1*w_k;
%clear V_eig D_eig v_max ind_max w_k R1;
[V_eig D_eig]=eig(Rc);
[v_max,ind_max]=max(diag(D_eig));
w_k=V_eig(:,ind_max);
f_a(k)=w_k'*Rc*w_k;
%clear V_eig D_eig v_max ind_max w_k Rc;
end
clear arr_X;
%[f_max,ind_maxh]=max(abs(f_h));
%t_p=ind_maxh
[f_max,ind_maxa]=max(abs(f_a));
t_p(mon,a)=ind_maxa;
err(mon,a)=(abs(t_p(mon,a)-1025))^2;
sum(1,a)=sum(1,a)+err(mon,a);
end
E(1,a)=(sum(1,a)/m_number)^0.5;
end
plot([-6:4:18],E,'r-*')
%% save the state information of random sequences;
sn_set_y2=randn('state');
s_set_y2=rand('state');
save randn_set_file_y5 sn_set_y2 s_set_y2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -