📄 v06_03_dem_2up_arrange.m
字号:
elseif(I_re(temp_i) >= -2 & I_re(temp_i) < 0)
I_demod(temp_i) = -1;
elseif(I_re(temp_i) >= 0 & I_re(temp_i) < 2)
I_demod(temp_i) = 1;
else
I_demod(temp_i) = 3;
end
if (Q_re(temp_i)< -2)
Q_demod(temp_i) = -3;
elseif(Q_re(temp_i) >= -2 & Q_re(temp_i) < 0)
Q_demod(temp_i) = -1;
elseif(Q_re(temp_i) >= 0 & Q_re(temp_i) < 2)
Q_demod(temp_i) = 1;
else
Q_demod(temp_i) = 3;
end
if(I_demod(temp_i) ~= Imapped(temp_i))
counts_I_error = counts_I_error + 1;
end
if(Q_demod(temp_i) ~= Qmapped(temp_i))
counts_Q_error = counts_Q_error + 1;
end
end
end
end
% 分别记录I,Q两路错码的个数
counts_I_total = counts_I_total + (Nfft-M_pilot);
counts_Q_total = counts_Q_total + (Nfft-M_pilot);
end % end of "if(t > 2)" % 解调出QAM符号
% 定时估计剩余误差跟踪
if (t>2)
% 提取导频信息
pilot_estimated(t,1:M_pilot)=[FFTout(t,3*Nfft/2+Nfft/M_pilot:Nfft/M_pilot:2*Nfft),FFTout(t,Nfft/M_pilot:Nfft/M_pilot:Nfft/2)];
H(t,1:M_pilot)=pilot_estimated(t,1:M_pilot)/pilot_value;
h_ch(t,1:2*M_pilot)=ifft((hamming(M_pilot))'.*H(t,1:M_pilot),2*M_pilot);
powers=0;
for(jj=1:2*M_pilot)
av_h(t,jj)=(h_ch(t,jj))*(h_ch(t,jj))';
powers=powers+av_h(t,jj);
end
% 剩余误差计算
for(ll=1:M_pilot/2)
sx(t,ll)=(pilot_estimated(t,ll)*(pilot_estimated(t,ll+M_pilot/2))');
phase_x(t,ll)=angle(sx(t,ll));
error_u(t,ll)=phase_x(t,ll)*2*Nfft/(2*pi);
end
error_uu=0;
% 跟踪环路
error_control_int=0;
error_control_fra=0;
for(ll=1:M_pilot/2)
error_uu=error_uu+error_u(t,ll);
end;
error_total(t)=error_uu/((Nfft/2)*(M_pilot/2));
error_control_int=round(error_total(t));
error_control_fra=(error_total(t)-error_control_int); % Symbol timing tracking error
;
if(powers>0.15)
et(t)=error_control_fra;
sita(t)=sita(t-1)-error_control_int;% FFT computation window control
ett(t)=error_total(t);
else
et(t)=et(t-1); % hold et and sita
ett(t)=et(t-1);
sita(t)=sita(t-1);
end
sita_tracking(t+1)=sita(t);
wt(t)=wt(t-1)+G1*(et(t)-et(t-1))+G2*et(t);
Wwt(t)=Wwt(t-1)+WG1*(ett(t)-ett(t-1))+WG2*ett(t);
deltaw=Ks*wt(t);
Wdeltaw=Ks*Wwt(t);
% 内插器参数调整
reg=reg+deltaw;
wint=wint-Wdeltaw;
end % end of if(t>3)
% 信道响应跟踪
if(t == 3)
% 提取导频信息
phase_channel(t+1,1:2*Nfft) = phase_channel(t,1:2*Nfft);
Ap_channel(t+1,1:2*Nfft) = Ap_channel(t,1:2*Nfft);
pilot_estimated(t,1:M_pilot)=[FFTout(t,3*Nfft/2+Nfft/M_pilot:Nfft/M_pilot:2*Nfft),FFTout(t,Nfft/M_pilot:Nfft/M_pilot:Nfft/2)];
elseif(t > 3)
% 提取导频信息
pilot_estimated(t,1:M_pilot)=[FFTout(t,3*Nfft/2+Nfft/M_pilot:Nfft/M_pilot:2*Nfft),FFTout(t,Nfft/M_pilot:Nfft/M_pilot:Nfft/2)];
% 剩余误差计算和跟踪环路
phase_tracking_total(t) = 0;
phase_tracking_av(t) = 0;
Ap_tracking_total(t) = 0;
Ap_tracking_av(t) = 0;
for(temp_i = 1:M_pilot)
tracking_current(t,temp_i) = -1*pilot_estimated(t,temp_i)/pilot_estimated(t-1,temp_i);
phase_tracking_current(t,temp_i) = angle(tracking_current(t,temp_i));
phase_tracking_total(t) = phase_tracking_total(t) + phase_tracking_current(t,temp_i);
Ap_tracking_current(t,temp_i) = abs(tracking_current(t,temp_i)) - 1;
Ap_tracking_total(t) = Ap_tracking_total(t) + Ap_tracking_current(t,temp_i);
end
phase_tracking_av(t) = phase_tracking_total(t)/M_pilot;
wtp(t) = wtp(t-1) + G1p*(phase_tracking_av(t) - phase_tracking_av(t-1)) + G2p*phase_tracking_av(t);
wtpp(t)=wtpp(t-1)+wtp(t);
% 对信道相位响应估计值进行调整
phase_channel(t+1,1:2*Nfft) = phase_channel(t,1:2*Nfft) + Ksp*wtpp(t);
Ap_tracking_av(t) = Ap_tracking_total(t)/M_pilot;
wtAp(t) = wtAp(t-1) + G1Ap*(Ap_tracking_av(t) - Ap_tracking_av(t-1)) + G2Ap*Ap_tracking_av(t);
wtAp2(t) = wtAp2(t-1) + wtAp(t);
% 对信道幅度响应估计值进行调整
Ap_channel(t+1,1:2*Nfft) = Ap_channel(t,1:2*Nfft).*(1 + KsAp*wtAp2(t));
end
t=t+1;
end % end of if (rem(k3,2*Ntotal)==0)
end % end of if(symbol_detected==1)
% 缓冲区c_2的位置指示值加1,当指示到最后一个位置后,重第一个位置重新开始
if(k3 == Ntotal*2*2-1)
k3 = Ntotal*2*2;
else
k3 = rem(k3+1,Ntotal*2*2);
end
end % end of reg=<0,i.e. k3
end % end of i, demodulation
end % end of s_no
st=fclose(fidi);
st=fclose(fidq);
% ------------------------------------------------------------------------------------
% 调试和测试中需要观察的变量
% 出错的符号数
counts_I_error
counts_Q_error
% 接收到的有效符号数
counts_I_total
counts_Q_total
% 误符号率
ser_I=counts_I_error/counts_I_total
ser_Q=counts_Q_error/counts_Q_total
% watch some result
figure;
hold on;
for (i=3:45)
for(j=1:2*Nfft)
plot(real(FFTout(i,j)),imag(FFTout(i,j)),'.k');
end;
end;
grid on;
hold off;
title('所有数据OFDM符号的星座图');
figure;
hold on;
i=3;
for(j=1:2*Nfft)
plot(real(FFTout(i,j)),imag(FFTout(i,j)),'.k');
end
grid on;
hold off;
title('第一个数据OFDM符号的星座图');
figure;
hold on;
i=45;
for(j=1:2*Nfft)
plot(real(FFTout(i,j)),imag(FFTout(i,j)),'.k');
end
grid on;
hold off;
title('最后一个数据OFDM符号的星座图');
figure
hold on;
plot(short_tr_mm);
plot(short_tr_power*9/10,'r');
grid on;
hold off;
title('短训练字相关值和能量值');
figure;
hold on;
plot(MMd);
grid on;
hold off;
title('长训练字相关值');
figure;
hold on;
y=angle(PP);
plot((910:length(PP)),y(910:length(PP)));
grid on;
title('小频偏造成的相位偏移量');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -