📄 v06_03_dem_2up_arrange.m
字号:
% 一个OFDM符号128个有效符号,插入128个虚拟子载波
% 符号率(即有效数据率)fsymbol,而发送速率(需要包括虚拟子载波)2fsymbol
% 输入的数据需要2倍的发送数据率,以便进行内插,实现位定时跟踪,即4倍fsymbol采样率的调制信号
% OFDM symbol Nfft=128 points
% 一个OFDM符号数据点 Nfft*2 = 256 , Guard Interval点 =Ng*2=64
% ------------------------------------------------------------------------------------
close all;
clear;
initializing_now = ['please wait...']
% ------------------------------------------------------------------------------------
% 参数设置
% 系统参数设置
% FFT点数为256,子载波个数为128,虚拟子载波个数为128
Nfft = 128;
Ng = 32;
Ntotal = Nfft+Ng;
M_pilot = 8; % 每个OFDM符号加入的导频数目
Max_symbols = 50;
% 读取训练字
% 短训练字的内容
% 10重复的个短训练字,每个是一个Guard Interval的长度
% 可以看成2个重复的长训练字,每个长训练字是由5个重复的部分组成的
% 这里读入的是这样一个假设的长训练字的频域上的值
% I,Q两路分别读入
fid3=fopen('data_I_train_word_re_i0_256.txt','r');
I_train_word_re_temp=fscanf(fid3,'%f');
fclose(fid3);
I_train_word_re = (I_train_word_re_temp)';
fid3=fopen('data_Q_train_word_re_i0_256.txt','r');
Q_train_word_re_temp=fscanf(fid3,'%f');
fclose(fid3);
Q_train_word_re = (Q_train_word_re_temp)';
train_word_re = I_train_word_re + j*Q_train_word_re;
% 第一个训练字的内容
% 这里读入的是第一个长训练字的频域上的值
% I,Q两路分别读入
fid3=fopen('data_I_train_word_1_i0_256.txt','r');
I_train_word_1_temp=fscanf(fid3,'%f');
fclose(fid3);
I_train_word_1 = (I_train_word_1_temp)';
fid3=fopen('data_Q_train_word_1_i0_256.txt','r');
Q_train_word_1_temp=fscanf(fid3,'%f');
fclose(fid3);
Q_train_word_1 = (Q_train_word_1_temp)';
train_word_1 = I_train_word_1 + j*Q_train_word_1;
% 第二个训练字的内容
% 这里读入的是第二个长训练字的频域上的值
% I,Q两路分别读入
fid3=fopen('data_I_train_word_2_i0_256.txt','r');
I_train_word_2_temp=fscanf(fid3,'%f');
fclose(fid3);
I_train_word_2 = (I_train_word_2_temp)';
fid3=fopen('data_Q_train_word_2_i0_256.txt','r');
Q_train_word_2_temp=fscanf(fid3,'%f');
fclose(fid3);
Q_train_word_2 = (Q_train_word_2_temp)';
train_word_2 = I_train_word_2 + j*Q_train_word_2;
% 第二个长训练字与第一个长训练字对应子载波位置上的值的比值
% 用于整数倍频偏估计,具体算法参考Schmidl和Cox的文章
% "Robust Frequency and Timing Synchronization for OFDM"
for temp_i=1:1:Nfft/2
if(rem(temp_i,2)==1)
vv(temp_i)=sqrt(2)*train_word_2(temp_i)/train_word_1(temp_i);
end
end
% 缓冲区参数设置
% 采用两个缓冲区,当对一个缓冲区里的数据进行处理的时候,对另一个缓冲区进行数据写入
% 同一个缓冲区不同时进行读和写的操作
% 软件仿真这一个过程跟实际过程中的一个极端情况,可以应用于实际情况
MI_IN_1(1:Ntotal*2*8) = 0;
MQ_IN_1(1:Ntotal*2*8) = 0;
MI_IN_2(1:Ntotal*2*8) = 0;
MQ_IN_2(1:Ntotal*2*8) = 0; % 直接从已经准备好的文件里读出来的数据的存储空间
% 此时是完全理想的数据,没有加任何噪声以及偏移量
% I、Q是区分I、Q两路信号
% 1、2是区分两个交替使用的缓冲区
I_INnoised_1(1:Ntotal*2*8) = 0;
Q_INnoised_1(1:Ntotal*2*8) = 0;
I_INnoised_2(1:Ntotal*2*8) = 0;
Q_INnoised_2(1:Ntotal*2*8) = 0; % 加过高斯白噪声后的数据的存储空间
% I、Q是区分I、Q两路信号
% 1、2是区分两个交替使用的缓冲区
I_INnoised_error_f_1(1:Ntotal*2*8) = 0;
Q_INnoised_error_f_1(1:Ntotal*2*8) = 0;
I_INnoised_error_f_2(1:Ntotal*2*8) = 0;
Q_INnoised_error_f_2(1:Ntotal*2*8) = 0; % 加过载波频偏后的数据的存储空间
% I、Q是区分I、Q两路信号
% 1、2是区分两个交替使用的缓冲区
IDEMOD_1(1:Ntotal*2*8) = 0;
QDEMOD_1(1:Ntotal*2*8) = 0;
IDEMOD_2(1:Ntotal*2*8) = 0;
QDEMOD_2(1:Ntotal*2*8) = 0; % 最后实际进行处理的数据,已经仿真加入了噪声以及偏移量
% I、Q是区分I、Q两路信号
% 1、2是区分两个交替使用的缓冲区
% 内插滤波参数设置
% 具体算法参考Floyd M. Gardner关于内插器的两篇文章
% "Interpolation in Digital Modems - Part I: Fundamentals"
% "Interpolation in Digital Modems - Part II: Implementation and Performance"
reg=0.9;
wint=0.5000; % 内插器使输出信号为输入信号的1/2
Ix(1:4)=0;
Qx(1:4)=0; % 内插器参数设置
alpha=0.5;
B=[0,1,0,0;
-alpha,alpha-1,alpha+1,-alpha;
alpha,-alpha,-alpha,alpha]; % 内插器参数设置
IV(1:3)=0;
QV(1:3)=0; % 内插器参数设置
IInter(1:Ntotal*2)=0;
QInter(1:Ntotal*2)=0;
c(1:Ntotal*2)=0;
IInter_2(1:Ntotal*2*2)=0;
QInter_2(1:Ntotal*2*2)=0;
c_2(1:Ntotal*2*2)=0; % 经过内插后的数据的缓冲区设置
% 为2个OFDM符号长度
% 缓冲区c_2是循环使用,当数据填到最后一个位置后,重新从第一个位置填起
k3 = 1; % 经过内插后的数据的缓冲区的下标位置指示
k3_total = 0;
% 定时同步参数设置
Times_short_should_find = 4;
short_tr_timed = 0;
short_tr_detected = 0;
t_short = 1;
symbol_timed = 0;
long_tr_detected = 0;
t_long = 1;
flag_long_index = 0;
% 频偏估计参数设置
Timining_theory = 960;
train_1_received(1:Nfft*2)=0;
train_2_received(1:Nfft*2)=0;
train_1_correct(1:Nfft*2)=0;
train_2_correct(1:Nfft*2)=0;
train_1_fft(1:Nfft*2)=0;
train_2_fft(1:Nfft*2)=0;
train_2_correct_full(1:Nfft*2)=0;
phase_offset_1 = 0; % 小数倍频偏
phase_offset_2 = 0; % 整数倍频偏
% 信道估计参数设置
phase_channel_current(1:Max_symbols,1:2*Nfft)=0;
phase_channel(1:Max_symbols,1:2*Nfft)=0; % 信道相位响应
Ap_channel_current(1:Max_symbols,1:2*Nfft)=1;
Ap_channel(1:Max_symbols,1:2*Nfft)=1;% 信道幅度响应
% 进行解调时FFT运算的参数设置
t = 1;
FFTin_temp(1:Nfft*2)=0;
FFTin(1:Nfft*2)=0;
FFTout_temp(1:Max_symbols,1:2*Nfft)=0;
FFTout_ch_dis(1:Max_symbols,1:2*Nfft)=0;
FFTout(1:Max_symbols,1:2*Nfft)=0;
% 定时跟踪参数设置
% 定时跟踪采样双环路跟踪
sita_tracking(1:Max_symbols)=0;
sita(1:Max_symbols)=0;
pilot_estimated(1:Max_symbols,1:M_pilot)=0;
pilot_value=3*sqrt(2)*(cos(pi)+j*sin(pi));
wn=0.05; % 定时跟踪的环路带宽1
Wwn=0.000001; % 定时跟踪的环路带宽2
Ss=0.7;
f=1;
G1=2*wn*Ss;
G2=wn.^2/f;
WG1=2*Wwn*Ss;
WG2=Wwn.^2/f;
Ks=1;
et(1:Max_symbols)=0;
ett(1:Max_symbols)=0;
wt(1:Max_symbols)=0;
Wwt(1:Max_symbols)=0;
% 信道响应跟踪参数设置
wnp=0.3; % 信道相位响应跟踪的环路带宽
Ssp=0.7;
fp=1;
G1p=2*wnp*Ssp;
G2p=wnp.^2/fp;
Ksp=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -