⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rx.asv

📁 mimo2x2天线选择系统的全系统matlab程序,先前的是dsp程序.
💻 ASV
📖 第 1 页 / 共 2 页
字号:
    i_sta = t_first_train_e + 1;
    
     % End of it
    i_end = i_sta + training_len*L - 1 ;
 
%     figure(3);                           
%     subplot(Nr_est,Nc_est,2*fr-1)
    
    H_hat_1 = channel_estimation(   rI_I(i_sta:L:i_end), ...
                                    rI_Q(i_sta:L:i_end), ...
                                    rJ_I(i_sta:L:i_end), ...
                                    rJ_Q(i_sta:L:i_end), ...
                                    tr1_I, tr1_Q , tr2_I, tr2_Q ...
                                 );
                                
%     title(['Ch. estimation 1 - Frame ', num2str(fr)]);
%     drawnow

  
    % Best set selection
      
    % All the following times are used for windowing. They are not expected
    % to be accurate
    
    if (mod((fr-1),refresh_fr) == 0)
        t_start = t_start + switch_len*L;
    else
        t_start = t_start + (switch_len-training_s_len)*L;  
    end
    
    t_end = t_start + (data_len + guard_len + training_len)*L + M_sync;
    
    % Demodulation
    [rA_I, rA_Q, rB_I, rB_Q] = demodulate(Y_R(:,t_start:t_end),A,B,Fc_hat, Fs, t_start, pulse_shape);
                        
    % Channel estimation
    
    % Start of the channel estimation training sequence 
    i_sta = t_first_train ;
    
    % End of it
    i_end = i_sta + training_len*L - 1;

%     figure(3);
%     subplot(Nr_est,Nc_est,2*fr)  
    
    H_hat_2 =  channel_estimation(  rA_I(i_sta:L:i_end), ...
                                    rA_Q(i_sta:L:i_end), ...
                                    rB_I(i_sta:L:i_end), ...
                                    rB_Q(i_sta:L:i_end), ...
                                    tr1_I, tr1_Q , tr2_I, tr2_Q ...
                                 );

                                 
%     title(['Ch. estimation 2 - Frame ', num2str(fr)]);
%     drawnow
                                
    
    % Update H estimations
    
    % Previous estimation Hr_n-1
    H_pre_1 = H([3-A 7-B],fr*2-1:fr*2);
     
    % Update the estimation by Hr_n = lambda*Hr_n-1 + (1-lambda)*H_n
    if fr > 1
        H([3-A 7-B],fr*2+1:fr*2+2) = lambda_H*H_pre_1 + (1-lambda_H)*H_hat_1;
    else
        H([3-A 7-B],fr*2+1:fr*2+2) = H_hat_1;
    end
 
    % Previous estimation Hr_n-1
    H_pre_2 = H([A B],fr*2-1:fr*2);
    
    % Update the estimation by Hr_n = lambda*Hr_n-1 + (1-lambda)*H_n
    if fr > 1
        H([A B],fr*2+1:fr*2+2) = lambda*H_pre_2 + (1-lambda)*H_hat_2;
    else
        H([A B],fr*2+1:fr*2+2) = H_hat_2;
    end   
    
    if (real_ch==0)
        
        if (mod((fr-1),refresh_fr) == 0)
            actual_len = Lf_sync;
        else
            actual_len = Lf;
        end
        
        posi = 2*(n_fr_reg * Lf + n_fr_sync* (Lf+training_s_len*L));
        
        for k=1:actual_len
            H_s(:, posi+2*k-1:posi+2*k) = H_hat_2;
        end    
    end
    
    % Downsample
    % Start of the data in the frame
    % Use synchronization from the second sychronization training sequence
    data_start = i_end + 1;
    data_end = data_start + L*data_len - 1;
    
    rA_data_I = rA_I(data_start:L:data_end);
    rA_data_Q = rA_Q(data_start:L:data_end);
    rB_data_I = rB_I(data_start:L:data_end);
    rB_data_Q = rB_Q(data_start:L:data_end);
   
    %%%%%% end of Channel estimation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
          
        
    % ---------------------------------------------------
    %  Antenna Subset Selection, by type = MBER,MMI,MNP,MMNP
    % ---------------------------------------------------
 
    if (antenna_select)
        [A, B]= antenna_selection(H(:,fr*2+1:fr*2+2),Delta_S_Set,select_type,SNRVar);
%          disp(['Frame ', num2str(fr),'Antenna Selection=',num2str(A),num2str(B)]);
%         %---------------------------------------------------
%         verify the DSP code with MATLAB
%         write_float32_hex('C:\ti\myprojects\mimo\receiver\Hr.dat',real(H(:,fr*2+1:fr*2+2))');
%         write_float32_hex('C:\ti\myprojects\mimo\receiver\Hi.dat',imag(H(:,fr*2+1:fr*2+2))');
%         write_float32_hex('C:\ti\myprojects\mimo\receiver\SNR.dat',10^(SNRVar/10));
%         SNR=read_float32_hex('C:\ti\myprojects\mimo\receiver\SNR.dat');

    end
        
    % Detector using type = ML,JMMSE, or ZF to find S_hat
    [rA_data_I, rA_data_Q, rB_data_I, rB_data_Q] =...
        Detector(H_hat_2,rA_data_I, rA_data_Q, rB_data_I, rB_data_Q,detect_type,SNRVar);

    %%%%%%%%%%%%%%%%Minimum distance de-modulator%%%%%%%%%%%%%%%%%%%%%%
    
    % For plotting the constellation
    r1_data_I_block = [r1_data_I_block, rA_data_I];
    r1_data_Q_block = [r1_data_Q_block, rA_data_Q];
    
    % Start of the data burst
    s_start = 1 + data_len_bits*(fr-1);
    
    % End of the data burst
    s_end = data_len_bits*(fr);

    % Detector from symbols to bits
    data_split_rec(1,s_start:s_end) = detect(rA_data_I , rA_data_Q , 1 );
    data_split_rec(2,s_start:s_end) = detect(rB_data_I , rB_data_Q , 1 );

end

% Parallel To Serial
data_rec(1:2:end) = (data_split_rec(1,:));
data_rec(2:2:end) = (data_split_rec(2,:));

% Find where the errors are
n_bits = data_len_bits*2*nr_frames;
positions1 = zeros(1,data_len_bits);
positions2 = zeros(1,data_len_bits);
for p=1:n_bits
    if(data_rec(p) ~= data_sent(p))
        p = mod(p, data_len_bits*2)+1;
        if mod(p,2)
            positions1((p+1)/2)=positions1((p+1)/2)+1;
        else
            positions2(p/2)=positions2(p/2)+1;
        end
    end
end

% Plot the location of the errors in a frame
figure(1);
subplot(Nr,Nc,4);
stem([1:data_len_bits],positions1)
title('Bit errors on stream 1')
subplot(Nr,Nc,5);
stem([1:data_len_bits],positions2,'r')
title('Bit errors on stream 1')

% Compute the BER

BER = sum(abs(data_rec-data_sent))/(length(data_sent));
disp(['Eb/N0 = ', num2str(10*log10(Es_bb/2/4/N0))]);
disp(['BER = ', num2str(BER)]);
disp('End');

% ---------------------------------------------------
% Training sequence constellation
% ---------------------------------------------------

figure(1);
subplot(Nr,Nc,6);
plot(rA_I(i_sta:L:i_end),rA_Q(i_sta:L:i_end),'*r');
grid on;
hold on;
plot(tr1_I,tr1_Q,'*b')
axis equal
title('Constellation of the ch. training seq')

% ---------------------------------------------------
% Channel estimation results
% ---------------------------------------------------

figure(4);
Nc_c = 2;
Nr_c = 1;

if (real_ch)
    
    subplot(Nr_c,Nc_c,1);
    hold on;
    grid on;
    plot(angle(H(1,1:2:end)),'b');
    plot(angle(H(1,2:2:end)),'b-. ');
    plot(angle(H(2,1:2:end)),'g');
    plot(angle(H(2,2:2:end)),'g--');
    plot(angle(H(3,1:2:end)),'r');
    plot(angle(H(3,2:2:end)),'r-. ');
    plot(angle(H(4,1:2:end)),'k');
    plot(angle(H(4,2:2:end)),'k--');
    legend('h11','h12','h21','h22','h31','h32','h41','h42')
    ylabel('Phase');
    
    subplot(Nr_c,Nc_c,2);
    hold on;
    grid on;
    plot(abs(H(1,1:2:end)),'b');
    plot(abs(H(1,2:2:end)),'b-. ');
    plot(abs(H(2,1:2:end)),'g');
    plot(abs(H(2,2:2:end)),'g--');
    plot(abs(H(3,1:2:end)),'r');
    plot(abs(H(3,2:2:end)),'r-. ');
    plot(abs(H(4,1:2:end)),'k');
    plot(abs(H(4,2:2:end)),'k--');
    legend('h11','h12','h21','h22','h31','h32','h41','h42')
    ylabel('Amplitude');
    
else
    subplot(Nr_c,Nc_c,1);
    hold on;
    grid on;
    plot(angle(H_s(1,1:2:end)),'b');
    plot(angle(H_s(1,2:2:end)),'b-. ');

    plot(angle(H_s(1,1:2:end)),'r');
    plot(angle(H_s(2,2:2:end)),'r-. ');

    legend('h11','h12','h31','h32')
    ylabel('Phase');
    title('Estimates')
    
    subplot(Nr_c,Nc_c,2);
    hold on;
    grid on;
    
    plot(abs(H_s(1,1:2:end)*2),'b');
    plot(abs(H_s(1,2:2:end)*2),'b-. ');
    plot(abs(H_s(2,1:2:end)*2),'r');
    plot(abs(H_s(2,2:2:end)*2),'r-. ');
    
    plot(abs(H_var(1,1:2:end)),'m');
    plot(abs(H_var(1,2:2:end)),'m-.');
    plot(abs(H_var(3,1:2:end)),'g');
    plot(abs(H_var(3,2:2:end)),'g-.');    
    
    legend('h11','h12','h31','h32','h11','h12','h31','h32')
    ylabel('Amplitude');    
    title('Estimates and Real values ')
end

% ---------------------------------------------------
% Constellation
% ---------------------------------------------------

if (detect_type~=ML)
    figure;
    Nr = 1;
    Nc = 1;
    
    subplot(Nr,Nc,1);
    plot(r1_data_I_block,r1_data_Q_block,'*b')
    grid on;
    title('Constellation')
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -