% function [Pol_X_phaout,pha_x]=freqPhaseCompensate(X, modFormat)
function [Pol_X_phaout,phase_x]=phaseCompensate_mod_v1(X, modFormat)
%% 频偏估计
N=8; %N是取平均时每组个数
M=floor(length(X)/N); %X的元素数量/N,再取整=组数
%length返回元素个数;floor
jump_pi = 0;
x_prime = X(1:N); %取X的前N个元素
V_p_x_r = real(x_prime);
V_p_x_i = imag(x_prime);
% V_p_2_x_r = V_p_x_r.^2 - V_p_x_i.^2;
V_p_2_x_i = 2*(V_p_x_r.*V_p_x_i);
mean_V_p_2_x_i_b = sum(V_p_2_x_i); %这里的平均是通过求和平均掉相位噪声
for m = 1:M
x_prime = X((m-1)*N+1:m*N); %每次循环针对第m组中的N个码元
V_p_x_r = real(x_prime);
V_p_ x_i = imag(x_prime);
V_p_2_x_r = V_p_x_r.^2 - V_p_x_i.^2;
V_p_2_x_i = 2*(V_p_x_r.*V_p_x_i);
mean_V_p_2_x_r = sum(V_p_2_x_r);
mean_V_p_2_x_i = sum(V_p_2_x_i);
if(mean_V_p_2_x_r <0)
if(mean_V_p_2_x_i >=0 && mean_V_p_2_x_i_b <=0)
jump_pi = mod(jump_pi+1,2);
elseif(mean_V_p_2_x_i <0 && mean_V_p_2_x_i_b >0)
jump_pi = mod(jump_pi+1,2);
end
end
mean_V_p_2_x_i_b = mean_V_p_2_x_i;
PE_x_1_2 = atan(mean_V_p_2_x_i / mean_V_p_2_x_r);
if(mean_V_p_2_x_r<0 && mean_V_p_2_x_i<=0)
PE_x_2 = PE_x_1_2 - pi;
elseif(mean_V_p_2_x_r<0 && mean_V_p_2_x_i>0)
PE_x_2 = PE_x_1_2 + pi;
elseif(mean_V_p_2_x_r>0)
PE_x_2 = PE_x_1_2;
elseif(mean_V_p_2_x_r==0)
if(mean_V_p_2_x_i>0)
PE_x_2 = pi/2;
else
PE_x_2 = -pi/2;
end
end
PE_x = PE_x_2/modFormat+jump_pi*pi;
phase_x((m-1)*N+1:m*N) = PE_x.*(ones(1,N));
VP_k_x = zeros(1,length(x_prime));
for j=1:length(x_prime)
VP_k_x(j) = x_prime(j)*exp(-1i*PE_x);
end
Pol_X_phaout((m-1)*N+1:m*N) = VP_k_x;
end
%% test1 datin
% figure
% subplot(10,1,1);plot(real(Pol_x_Rx_pal(1,1:8100))'-x_intr1);
% subplot(10,1,2);plot(real(Pol_x_Rx_pal(2,1:8100))'-x_intr2);
% subplot(10,1,3);plot(real(Pol_x_Rx_pal(3,1:8100))'-x_intr3);
% subplot(10,1,4);plot(real(Pol_x_Rx_pal(4,1:8100))'-x_intr4);
% subplot(10,1,5);plot(real(Pol_x_Rx_pal(5,1:8100))'-x_intr5);
% subplot(10,1,6);plot(imag(Pol_x_Rx_pal(1,1:8100))'-x_inti1);
% subplot(10,1,7);plot(imag(Pol_x_Rx_pal(2,1:8100))'-x_inti2);
% subplot(10,1,8);plot(imag(Pol_x_Rx_pal(3,1:8100))'-x_inti3);
% subplot(10,1,9);plot(imag(Pol_x_Rx_pal(4,1:8100))'-x_inti4);
% subplot(10,1,10);plot(imag(Pol_x_Rx_pal(5,1:8100))'-x_inti5);
% figure
% subplot(10,1,1);plot(real(Pol_y_Rx_pal(1,1:8100))'-y_intr1);
% subplot(10,1,2);plot(real(Pol_y_Rx_pal(2,1:8100))'-y_intr2);
% subplot(10,1,3);plot(real(Pol_y_Rx_pal(3,1:8100))'-y_intr3);
% subplot(10,1,4);plot(real(Pol_y_Rx_pal(4,1:8100))'-y_intr4);
% subplot(10,1,5);plot(real(Pol_y_Rx_pal(5,1:8100))'-y_intr5);
% subplot(10,1,6);plot(imag(Pol_y_Rx_pal(1,1:8100))'-y_inti1);
% subplot(10,1,7);plot(imag(Pol_y_Rx_pal(2,1:8100))'-y_inti2);
% subplot(10,1,8);plot(imag(Pol_y_Rx_pal(3,1:8100))'-y_inti3);
% subplot(10,1,9);plot(imag(Pol_y_Rx_pal(4,1:8100))'-y_inti4);
% subplot(10,1,10);plot(imag(Pol_y_Rx_pal(5,1:8100))'-y_inti5);
% %% test2 datout
% figure
% subplot(2,1,1);plot(real(Pol_X_CMAout_pal(1,1:8093))'-Xoutr1(8:end));
% subplot(2,1,2);plot(imag(Pol_X_CMAout_pal(1,1:8093))'-Xouti1(8:end));
% %% test3 epsilon
% figure
% plot(epsilonx(1:8089)'-epsilon_dsp(12:end));
% %% test4 mult1/2/3
% figure
% subplot(5,1,1);plot(mult1(1:8086)'-multr1(15:end));
% subplot(5,1,2);plot(real(mult2(1:8086))'-multr2(15:end));
% subplot(5,1,3);plot(imag(mult2(1:8086))'-multi2(15:end));
% subplot(5,1,4);plot(real(mult3(1:8083))'-multr3(18:end));
% subplot(5,1,5);plot(imag(mult3(1:8083))'-multi3(18:end));
% %% test5 H_taps
% figure
% subplot(4,1,1);plot(real(hxx1(1:8082))'-Hxx_dspr1(19:end));
% subplot(4,1,2);plot(imag(hxx1(1:8082))'-Hxx_dspi1(19:end));
% subplot(4,1,3);plot(real(hxx(1,19:8100))'-Hxx_swr1(19:end));
% subplot(4,1,4);plot(imag(hxx(1,19:8100))'-Hxx_swi1(19:end));
评论7