function FRF=FRFsolving(w,fBB,FRF,Theta_Quan)

[N,Num_RF]=size(FRF); 
for m=1:length(w)
    ComputerNumber=w(m);
    factor=fBB;
    InitialTheta=FRF(m,:);
    FFlag=0;
    for n=1:100
        t=mod(n-1,Num_RF-2)+1+2;
        Cand=zeros(1,length(Theta_Quan));
        for p=1:length(Theta_Quan)
            Cand(p)=InitialTheta(3:end)*factor(3:end)-factor(t)*InitialTheta(t)+factor(t)*exp(1j*Theta_Quan(p));
        end
        Y=ComputerNumber-Cand;
        
      
        f1=factor(1);
        f1Angle=angle(f1);f1Moduls=abs(f1);
        f2=factor(2);
        f2Angle=angle(f2);f2Moduls=abs(f2);
        EquationYAngle=angle(Y);EquationYModuls=abs(Y);
        
        Theta1=acos((EquationYModuls.^2+(f1Moduls+f2Moduls)*(f1Moduls-f2Moduls))/2/f1Moduls./EquationYModuls)+EquationYAngle-f1Angle;
        Theta2=-acos((EquationYModuls.^2-(f1Moduls+f2Moduls)*(f1Moduls-f2Moduls))/2/f2Moduls./EquationYModuls)+EquationYAngle-f2Angle;
        
        Theta1=angle(exp(1j*Theta1));
        Theta2=angle(exp(1j*Theta2));
        TempAngleVector=zeros(2,length(Theta2));
        TempAngleVector(1,:)=Theta1;
        TempAngleVector(2,:)=Theta2;
        for z=1:numel(TempAngleVector)
            TempAngle=TempAngleVector(z);
            DeltaAngle=abs(TempAngle-Theta_Quan);
            [~,MinIndex]=min(DeltaAngle);
            TempAngleVector(z)=Theta_Quan(MinIndex);
        end
        Theta1=TempAngleVector(1,:);
        Theta2=TempAngleVector(2,:);
        
        Summary=factor(1)*exp(1j*Theta1)+factor(2)*exp(1j*Theta2)+Cand;
        Deviation=abs(ComputerNumber-Summary);
        

        PreviousTheta=InitialTheta;
        [~,MinIndexD]=min(Deviation);
        InitialTheta(t)=exp(1j*Theta_Quan(MinIndexD));
        InitialTheta(1)=exp(1j*Theta1(MinIndexD));
        InitialTheta(2)=exp(1j*Theta2(MinIndexD));
        
        %==========================================================================================================================
        if sum(PreviousTheta==InitialTheta)==length(InitialTheta)
            FFlag=FFlag+1;
        end
        if FFlag==Num_RF-2
           break;
        end
    end
     FRF(m,:)=InitialTheta;
end