clc; clear all; close all;
P_mp(pos) = (p-(Ns*Nx+(Ns-1)*h+1)/2+(m-1)*(Nx+h));
P_mp1(m,p) = (p-(Ns*Nx+(Ns-1)*h+1)/2+(m-1)*(Nx+h));
E_mp(:,:,i) = exp(-1j*beta*P_mp1(i,:)'*dx*sind(theta));
A_mp(:,:,i) = Ri.*E_mp(:,:,i);
A_mp = awgn(A_mp, SNR, 'measured');
A_mc(:,:,i) = A_mp1(1:Nx - L + 1,:,i);
A_mr(:,:,i) = A_mp1(Nx - L + 1:Nx,:,i);
A_mk(:,:,i) = hankel(A_mc(:,:,i), A_mr(:,:,i));
E_mp_a = [E_mp_a; E_mp(:,:,i)];
A_mp_a = [A_mp_a ;A_mp1(:,:,i)];
Y_ss = [Y_ss ; A_mk(:,:,z)];
z_k = eig(pinv(V1) * V2);
find_theta_realarray_MPM(l,:)= asind((imag(log(z_k))*lambda)/(2*pi*dx))';
rmse_real_mpm(l,:) = sort(theta) - sort(find_theta_realarray_MPM(l,:));
rmse_real_MPM_sum = sum(sum(abs(rmse_real_mpm).^2,1),2);
rmse_real_MPM_sum = sqrt(rmse_real_MPM_sum/(A*K));
rmse_real_MPM_sum1(SNR,Ns)= rmse_real_MPM_sum(rmse_real_MPM_sum ~= 0);
plot(1:SNR1 , rmse_real_MPM_sum1,'-d','LineWidth',1.4)
legend('1-subarray','2-subarray','3-subarray','4-subarray','5-subarray')