⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ofdm_timing_cfo1_mon_b1.m

📁 OFDM信号的时间偏差校正程序
💻 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=6;
%% the number of used C
c_number=3;

%% exploit M-ary modulation style;
M=4;

%% the number of the array elements;
arr_l=2;

%% exploit half-wavelength spacing;
sidelength=0.5;

ff_0=10e3;
a=0;
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=5;
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].'*Ts/40);%% 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-4;

%% 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);
 
%  arr_X=arr_s;
l_s=sym_l*J2;

l_p=pre_l*J2;

l_sp=(sym_l+pre_l)*J2;

% W=[];

f_a1=zeros(l_sp,1);

w_k1=zeros(arr_l,4);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  coarse search   %%%%%%%%%%%%%
 f_max1=zeros(4,1);
 ind_maxa1=zeros(4,1);
 c=0;

for f1=(pi/4):(pi/2):(pi/4+3*pi/2)
    c=c+1;


 for k=1:l_sp
  
    C1=[];
    
    C2=[];
    
   for l=0:(c_number-1)
         
   C1=[C1 arr_X(:,k+l*l_sp:k+l*l_sp+l_p-1)];
       
   C2=[C2 arr_X(:,k+l*l_sp+l_s:k+l*l_sp+l_sp-1)];
       
   end
   
  
      R1=exp(j*f1)*conj(C1)*C2.';
   
      R2=R1';
      Rc=R1+R2;

    
   [V_eig D_eig]=eig(Rc);
   
   [v_max,ind_max]=max(diag(D_eig));
 
%     w_k1=V_eig(:,ind_max);
    
      w_k1(:,c)=V_eig(:,ind_max);
    
    f_a1(k)=w_k1(:,c)'*Rc*w_k1(:,c);
  
    
%    clear V_eig D_eig v_max ind_max w_k1 Rc;
       
    
   end


   [f_max1(c,1),ind_maxa1(c,1)]=max(abs(f_a1));
end

[maxf1,ind_maxf1]=max(f_max1);
w_opt=w_k1(:,ind_maxf1);
f_coarse=(ind_maxf1-1)*(pi/2)+(pi/4);

  t_p1=ind_maxa1(ind_maxf1,1);

    C1=[];
    
    C2=[];
    
   for l=0:(c_number-1)
         
   C1=[C1 arr_X(:,t_p1+l*l_sp:t_p1+l*l_sp+l_p-1)];
       
   C2=[C2 arr_X(:,t_p1+l*l_sp+l_s:t_p1+l*l_sp+l_sp-1)];
       
   end
   
A=w_opt'*conj(C1)*C2.'*w_opt;
B=w_opt'*conj(C2)*C1.'*w_opt;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  coarse seaerch %%%%%%%%%%%%%%%%%%%%%%%




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% die dai  %%%%%%%%%%%%%%%%%%%%%

f_a=[];
d_f1=[];
f_a2=zeros(l_sp,1);
 f2=f_coarse;

f_e=0;
f=0;
d_f=5;
while d_f>0.001
% while abs(d_f)>0.001
%     if abs(f_e-f2)<0.05,break,end
%     if f>10,break,end
    
    f=f+1;
   
    f_a=[f_a f_a2];
    
d_f=2*real(j*exp(j*f2)*A);
% d_f=j*exp(j*f2)*A-j*exp(-j*f2)*B;
% d_f=j*exp(j*f2)*w_opt'*conj(C1)*C2.'*w_opt-j*exp(-j*f2)*w_opt'*conj(C2)*C1.'*w_opt;
d_f2=2*real(-exp(j*f2)*A);
d_f1=[d_f1 d_f];
f_e=f2;
f2=f2 + (d_f/d_f2);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  die dai %%%%%%%%%%%%%%%%%%

% break;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  fine %%%%%%%%%%%%%%%%%%%%%%%%

f_a3=zeros(l_sp,1);

w_k3=zeros(arr_l,5);

%  ind_maxf1=zeros(arr_l,4);
 f_max3=zeros(5,1);
 ind_maxa3=zeros(5,1);

%  f_fine1=f2;
f_fine1=f_e;



d=0;
for f3=f_fine1-(pi/4):(pi/8):f_fine1+(pi/4)

    d=d+1;
   


 for k=1:l_sp
  
   C1=[];
    
    C2=[];
    
   for l=0:(c_number-1)
         
   C1=[C1 arr_X(:,k+l*l_sp:k+l*l_sp+l_p-1)];
       
   C2=[C2 arr_X(:,k+l*l_sp+l_s:k+l*l_sp+l_sp-1)];
       
   end
   
      R1_3=exp(-j*f3)*conj(C1)*C2.';
   
      R2_3=R1_3';
      Rc_3=R1_3+R2_3;

    
   [V_eig D_eig]=eig(Rc_3);
   
   [v_max,ind_max]=max(diag(D_eig));
 
%     w_k1=V_eig(:,ind_max);
    
      w_k3(:,d)=V_eig(:,ind_max);
    
    f_a3(k)=w_k3(:,d)'*Rc_3*w_k3(:,d);
  
    
%    clear V_eig D_eig v_max ind_max w_k1 Rc;
       
    
   end


   [f_max3(d,1),ind_maxa3(d,1)]=max(abs(f_a3));
end


[maxf3,ind_maxf3]=max(f_max3);



%  [f_max1,ind_maxa1]=max(abs(f_a1));

% t_p=ind_maxa3(ind_maxf3,1)
%    
   t_p(mon,a)=ind_maxa3(ind_maxf3,1);
   err(mon,a)=(abs(t_p(mon,a)-1025))^2;
   sum(1,a)=sum(1,a)+err(mon,a);
    clear arr_X;
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 + -