channel_estimator.m
上传用户:look542
上传日期:2009-06-04
资源大小:784k
文件大小:10k
源码类别:

传真(Fax)编程

开发平台:

Matlab

  1. function [H_data , mse] = channel_estimator( pilot_sym,known_pilot,SISO_CE_Method,MIMO_CE_Method,...
  2.     L_delay,InterpMethod,H_freq,N_Tx_ant,N_Rx_ant,N_subc,N_used,Idx_used,Modulation,var_noise,...
  3.     ch,N_ts,N_sym_ts,N_pilot_sym_ts,N_data_sym_ts,Pos_pilot_sym,Pos_data_sym,N_syn_preamble,...
  4.     frame,Idx_cir,TurnOn ,ChannelEffectTest,SwitchOrthogonalPilot);
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. % 准备实现的信道估计算法
  7. % 一. 单天线信道估计算法,使用导频辅助进行信道估计
  8. % 1 - 基本LS算法; 2 - LS的DFT改进算法; 3 - 加判决反馈的LS-DFT
  9. % 4 - 基本MMSE算法; 5 - MMSE的DFT改进算法; 6 - 加判决反馈的MMSE-DFT
  10. % 7 - SVD分解算法,8 - Robust算法 
  11. % 9 - 自适应滤波器结合单天线信道估计的方法, 10 - EM 方法
  12. % 插值方法: 1 - 线性插值, 2 - 二次插值, 3 - 三次样条插值,  
  13. %            4 - 时域插值, 5 - 低通滤波器插值
  14. % 二. 多天线信道估计方法,使用导频辅助进行信道估计
  15. % 1 - 基本LS算法; 2 - LS的改进算法1; 3 - LS的改进算法2; 4 - LS的改进算法3; 
  16. % 5 - 频域区分子载波的方法,使用 SISO_CE_Method 选择的算法,以及 InterpMethod 选择的插值方法
  17. % 6 - 发送多个OFDM符号,线性组合求得多天线信道响应
  18. % 三. 理想信道估计: 所有导频位置和数据符号位置的信道为已知的。
  19. % 四. 有关信道估计MSE的定义:估计的信道响应和理想响应的差的平方,并平均到每个子载波。
  20. % 文献上给出的MSE,一般定义如下:
  21. % 1) 第1类方法:估计导频位置的信道响应 + 频域和时域插值的方法,MSE定义为信道估计部分的MSE,不包括插值
  22. % 2) 第2类方法:迭代进行估计,如判决反馈,LMS自适应滤波等,MSE定义为全部估计迭代出的信道响应的MSE            
  23. % 在863项目仿真中,MSE应该统一,否则不能比较不同算法总体的性能。
  24. % 定义为:本帧所有导频和数据OFDM符号处,估计的信道响应和理想信道响应的MSE
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26. % 输出为数据时隙的信道响应
  27. H_data = zeros( N_subc, N_data_sym_ts*N_ts ,N_Tx_ant*N_Rx_ant );
  28. Pos_data = zeros( 1,N_data_sym_ts*N_ts );
  29. Pos_pilot = zeros( 1,N_pilot_sym_ts*N_ts );
  30. for ts = 1:N_ts
  31.     Pos_data(1,(ts-1)*N_data_sym_ts + 1:ts*N_data_sym_ts) = Pos_data_sym + (ts-1)*N_sym_ts;
  32.     Pos_pilot(1,(ts-1)*N_pilot_sym_ts + 1:ts*N_pilot_sym_ts) = Pos_pilot_sym + (ts-1)*N_sym_ts;
  33. end
  34. global h_t;
  35. if ( TurnOn & (ChannelEffectTest ~= 2) )  
  36.     
  37.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  39.     %一. 单天线信道估计
  40.     
  41.     if N_Tx_ant == 1
  42.         
  43.         for n_r = 1:N_Rx_ant
  44.             
  45.             if SISO_CE_Method == (1 | 2)
  46.                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47.                 % 1.1 使用LS,LS-DFT, MMSE, SVD分解方法
  48.                 
  49.                 % 先估计出导频点位置的值 H_pilot
  50.                 H_ideal = H_freq(Idx_used,N_syn_preamble + Pos_pilot,n_r);    % 理想的信道响应
  51.                 % 进行LS-DFT改进的估计
  52.                 H_pilot = estimator_ls( pilot_sym(:,:,n_r) , known_pilot , 2 , L_delay , H_ideal ,Idx_cir);
  53.                 
  54.                 % 再进行插值,得到整个帧的信道估计 H_frame
  55.                 H_frame(:,:,n_r) = ( interp1(Pos_pilot',H_pilot.',[1:N_ts*N_sym_ts]','linear') ).'; 
  56.                 
  57.                 % 得到数据时隙的信道响应 H_data
  58.                 H_data(:,:,n_r) = H_frame(:,Pos_data,n_r);
  59.                 
  60.             elseif SISO_CE_Method == 9
  61.                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  62.                 % 1.2 使用自适应滤波方法,DD,Robust,迭代方法
  63.                 
  64.                 % LS信道估计值,帧结构参数,最强径检测参数
  65.                 ReceivedChannelData = estimator_ls( pilot_sym(:,:,n_r) , known_pilot );
  66.                 FrameStruct = struct('N_ts',N_ts,'N_sym_ts',N_sym_ts,'Pos',Pos_pilot_sym,'fd',ch.fd);
  67.                 
  68.                 % 得到整个帧的频域信道响应
  69.                 H_frame(:,:,n_r) = LMS2DChannelEstimationAlgorithm(ReceivedChannelData,...
  70.                     FrameStruct,Idx_cir);   
  71.                 H_data(:,:,n_r) = H_frame(:,Pos_data,n_r);
  72.             end
  73.         end
  74.         
  75.         
  76.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  77.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  78.         % 二. 多天线信道估计        
  79.     else
  80.         
  81.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
  82.         % 2.1 使用联合求解的多天线LS估计方法:
  83.         if MIMO_CE_Method == ( 1 | 2 | 3 | 4)
  84.             
  85.             % 得到导频位置的信道响应  H_pilot
  86.             % 使用多天线的LS估计方法
  87.             K = N_subc;
  88.             K0 = L_delay;
  89.             H_p = zeros(N_subc,N_pilot_sym_ts*N_ts,N_Rx_ant*N_Tx_ant);
  90.             for ts = 1:N_ts
  91.                 for p = 1:N_pilot_sym_ts
  92.                     % 接收到的频域导频样点
  93.                     pilot_rx = pilot_sym(:,(ts-1)*N_pilot_sym_ts + p,:);
  94.                     % 发送的频域导频样点
  95.                     pilot_tx = known_pilot(:,(ts-1)*N_pilot_sym_ts + p,:);
  96.                     % 进行多天线LS估计,得到不同发送天线,本时隙,所有导频位置的信道相应
  97.                     H_tmp = estimator_ls_txdiv(K,K0,N_Tx_ant,N_Rx_ant,pilot_rx,pilot_tx,frame,ts,p,var_noise,0,N_pilot_sym_ts);
  98.                     H_pilot(:,(ts-1)*N_pilot_sym_ts + p,:) = H_tmp;
  99.                 end
  100.             end
  101.             
  102.             % 再进行插值,得到整个帧的信道估计 H_frame
  103.             for nr = 1:N_Rx_ant
  104.                 for nt = 1:N_Tx_ant
  105.                     H_frame(:,:,(nr-1)*N_Tx_ant+nt) = ( interp1(Pos_pilot',H_pilot(:,:,(nr-1)*N_Tx_ant+nt).',...
  106.                         [1:N_ts*N_sym_ts]','linear') ).'; 
  107.                 end
  108.             end
  109.             
  110.             % 输出数据OFDM的信道响应 H_data
  111.             H_data = H_frame(:,Pos_data,:);
  112.             
  113.             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  114.             % 2.2 使用频域区分子载波的方法:
  115.         elseif MIMO_CE_Method == 5
  116.             % 对每一条接收天线
  117.             for n_r = 1:N_Rx_ant
  118.                 % 有多条发送天线
  119.                 for n_t = 1:N_Tx_ant
  120.                     Idx_tx = [n_t:N_Tx_ant:N_used];
  121.                     % 每条发送天线使用不同的子载波组,进行单天线的信道估计
  122.                     pilot_tx = known_pilot(Idx_tx,:,n_t);
  123.                     pilot_rx = pilot_sym(Idx_tx,:,n_r);
  124.                     H_ideal = H_freq(Idx_tx,N_syn_preamble + Pos_pilot,(n_r-1)*N_Tx_ant + n_t);
  125.                     
  126.                     if SISO_CE_Method == 1 
  127.                         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  128.                         H_pilot  = estimator_ls( pilot_rx , pilot_tx , 2 ,L_delay , H_ideal ,Idx_cir );
  129.                         % 频域插值,得到所有子载波位置的信道响应
  130.                         H_interp = interp1( Idx_tx, H_pilot ,[1:N_used] ,'linear','extrap');
  131.                         % 时域插值,得到整个帧所有OFDM符号的信道响应
  132.                         H_frame(:,:,(n_r-1)*N_Tx_ant + n_t) = ...
  133.                             ( interp1(Pos_pilot',H_interp.',[1:N_ts*N_sym_ts]','linear') ).'; 
  134.                         
  135.                     elseif SISO_CE_Method == 9
  136.                         % LS信道估计值,帧结构参数
  137.                         ReceivedChannelData = estimator_ls( pilot_rx , pilot_tx );
  138.                         FrameStruct = struct('N_ts',N_ts,'N_sym_ts',N_sym_ts,'Pos',Pos_pilot_sym,'fd',ch.fd);
  139.                         
  140.                         % 得到整个帧所有OFDM符号的频域信道响应
  141.                         H_tmp = LMS2DChannelEstimationAlgorithm(ReceivedChannelData,...
  142.                            FrameStruct,Idx_cir);   
  143.                         % 频域插值,得到所有子载波的信道响应
  144.                         H_frame(:,:,(n_r-1)*N_Tx_ant + n_t) = interp1( Idx_tx', H_tmp ,[1:N_used]' ,'spline','extrap');
  145.                          
  146. %                         ChannelParameter = struct('SubCarrierNumber',N_subc,'TxAntennaNumber',n_t);
  147. %                         H_frame(:,:,(n_r-1)*N_Tx_ant + n_t) = LMS2D( ReceivedChannelData, ...
  148. %                             FrameStruct, ChannelParameter, Idx_cir );
  149.                     end  
  150.                     
  151.                 end
  152.             end
  153.             
  154.             % 得到数据OFDM符号的信道响应
  155.             H_data = H_frame(:,Pos_data,:);
  156.             
  157.             
  158.             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  159.             % 2.3 使用发送多个OFDM符号,线性组合求得多天线信道响应的方法:
  160.         elseif MIMO_CE_Method == 6
  161.             
  162.             [H_data,H_frame]=estimator_linear_comb(pilot_sym,known_pilot,Idx_cir,...
  163.                 N_Rx_ant,N_Tx_ant,Pos_pilot,N_ts,N_sym_ts,Pos_data, Pos_pilot_sym,N_subc,N_data_sym_ts,...
  164.                 L_delay,SwitchOrthogonalPilot);                       
  165.                 
  166.             
  167.         end
  168.     end
  169.     
  170.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  171.     % 求信道估计的均方误差
  172.     H_frame_ideal = H_freq(:,1 + N_syn_preamble : N_sym_ts*N_ts + N_syn_preamble ,:);
  173.     diff = H_frame_ideal - H_frame;
  174.     mse = sum(sum(sum( abs( diff ).^2 ) )) / ( N_subc*N_ts*N_sym_ts*N_Tx_ant*N_Rx_ant);
  175.     mse_sym = sum(abs(diff).^2)/(N_subc);
  176.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  177.     
  178.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  179.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  180.     % 三. 理想信道估计    
  181. else
  182.     
  183.     % 取出数据OFDM符号对应的理想信道估计
  184.     H_data = zeros( N_subc, N_data_sym_ts*N_ts ,N_Tx_ant*N_Rx_ant );
  185.     H_data = H_freq(:,Pos_data + N_syn_preamble ,:);
  186.     mse = 0;
  187. end