📄 ofdm_cfo1.m
字号:
%% generate the OFDM data using for blind timing estimation;
clear all;
close all;
clc;
%% 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=20;
%% the oversampling factor;
J2=2;
%% the oversampling period;
Tss=Ts/J2;
%% the length of one OFDM symbol;
sym_l=128;
%% the length of the prefix;
pre_l=12;
%% 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=10;
%% exploit M-ary modulation style;
M=4;
%% the number of the array elements;
arr_l=4;
%% exploit half-wavelength spacing;
sidelength=0.5;
%% 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=[];
% break;
for i2=1:b_n
x_s=[x_s;xs_pre(:,i2)];
x_i=[x_i;xi_pre(:,i2)];
end
% break;
f_cfo=0.3*SBW;%% the frequency offset;
ph_r=exp(j*2*pi*f_cfo*[1:length(x_s)].'*Ts/J1);
x_s=x_s.*ph_r;
% 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,:);
% break;
% 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=10;
%% the interference to noise ratio of the first ray;
INR=5;
%% 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;-29.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=[0;58;91;120];
%% 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;
b_mm=5;
iik=[1:sym_l/2 sym_l*3/2+1:sym_l*J2];
% iik=[-sym_l+1:-sym_l/2 sym_l/2+1:sym_l];
% %
% % Wp=[];
% %
% % for k=1:sym_l
% %
% % Wp=[Wp exp(j*2*pi*(iik(k)-1)*SBW*[1:sym_l*J2].'*Tss)];
% %
% % end
% %
Wp = exp(j*2*pi*[1:256]'*(iik-1)/256);
b_m=40;
f=zeros(1*b_m+1,1);
index=0;
% break;
for ii=0:40
ii
index=index+1;
fre_e=ii*0.1*SBW;
% fre_e = 2.3*SBW;
Z=diag(exp(j*2*pi*fre_e*Tss*[0:sym_l*J2-1].'));
R=zeros(arr_l,arr_l);
for k=1:b_mm
Y=arr_X(:,(sym_l+pre_l)*(k-1)*J2+1:(sym_l+pre_l)*(k-1)*J2+sym_l*J2).';
R=R+Y'*Z*(eye(sym_l*J2,sym_l*J2)-Wp*Wp'./(sym_l*J2))*conj(Z)*Y;
end
% clear Y Z;
[V_R,d_R]=eig(R);
% [min_v,min_ind]=min(real(diag(d_R)));
Wopt=V_R(:,1);
f(index)=Wopt'*R*Wopt;
% clear R;
end
plot([0:b_m],abs(f),'r');
grid;
%% 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 + -