function [f1,aver_FFT,check]=fft_analysis_test(x,Fs,w,percent)


u_NaN = find(~isnan(x));
x=x(u_NaN,:);
w=rectwin(length(x));
NFFT=2^(nextpow2(length(w)));

if NFFT < 2
    disp('Data are not good');
    psd_final=[];
    t=[];
    f=[];
    f1=[];
    aver_FFT=[];
    check=[];
else
    NFFT=1024;  
    
    w_squared=abs(w).^2;
    lwin=length(w);
    numoverlap=lwin*percent;
    non_re_use=lwin-numoverlap;
    
    k = fix((length(x)-numoverlap)/(length(w)-numoverlap));
    FFT=[];
    for i=1:k
          x_detrend=detrend(x(1+(i-1)*non_re_use :(i-1)*non_re_use+lwin),'linear');
          xwin=w.*x_detrend;
        F=fft(xwin,NFFT);
        F=abs(F);
        F=F.^2;
        F=F./var(x_detrend);
        FFT=[FFT F];
    end
    
    
    NumUniquePts=ceil((NFFT+1)/2);
    FFT=FFT(1:NumUniquePts,:); 
    f1=(0:NumUniquePts-1)*Fs/NFFT;
    f1=f1';
    U=sum(w_squared)/lwin;
    aver_FFT=mean(FFT,2);
     aver_FFT=aver_FFT/(lwin*U);
    aver_FFT=2.*aver_FFT./(Fs);
    check=sum(aver_FFT*(f1(3)-f1(2)))

end