Y[0,indice]=c[0]*np.cos(w*indice)-c[1]*np.sin(w*indice)+B[0,indice]
    Y[1,indice]=c[2]*np.cos(w*indice)-c[3]*np.sin(w*indice)+B[1,indice]
    Y[2,indice]=c[4]*np.cos(w*indice)-c[5]*np.sin(w*indice)+B[2,indice]

#calcul du critère
index=0
critere=[]
temps=[]

while index+window < N:
    X=Y[:,index:index+window]
    w0_est,trash,trash=estimate_w_NR_unbalanced(X,w_init,3)
    T=compute_GLRT_statistic(X,w0_est)
    critere=np.append(critere,T)
    temps=np.append(temps,index+(window/2))
    index=index+window

##export csv file
if csv_on==1:

    output=np.array([temps,critere])
    np.savetxt(filename, output.T,header="n,critere", delimiter=",")
    output_signal=np.array([np.arange(0,N),np.arange(0,N)/Fe,Y[0,:],Y[1,:],Y[2,:]])
    np.savetxt(filename_signal, output_signal.T,header="n,t,Phase 1,Phase 2,Phase 3", delimiter=",")

#show figure
if plot_on==1:
    show_signals(Y,Fe=1)
    plt.figure(2)
    plt.plot(temps,critere)
    plt.show()
if type == "unbalanced":
    sym = np.matrix(np.array([-0.5, 0.2, 1, 1, -0.4, 0.1])).T
    filename_signal = "../csv/sym_signal_unbalanced.csv"
    filename = "../csv/sym_est_unbalanced.csv"


# Signal generation
num = sym.T * sym
sigmaB = np.sqrt(np.trace(num / 2) / (np.power(10, SNR / 10.0)))
Y = generate_Y_from_sym(sym, w, N, sigmaB)

z_approx = compute_naive_sym_component(Y, w).A1
z_est = estimate_sym_unbalanced(Y, w).A1


# export csv file
if csv_on == 1:

    output_signal = np.bmat([sym.reshape((3, 2)), z_approx.reshape((3, 2)), z_est.reshape((3, 2))])
    np.savetxt(filename, output_signal, header="symx,symy,z_approxx,z_approxy,px,py", delimiter=",")

    print(output_signal)
    output_signal = np.array([np.arange(0, N), np.arange(0, N) / Fe, Y[0, :].A1, Y[1, :].A1, Y[2, :].A1])
    np.savetxt(filename_signal, output_signal.T, header="n,t,Phase 1,Phase 2,Phase 3", delimiter=",")


if plot_on == 1:
    show_signals(Y)
    plt.show()
    pd_blind[indice]=pd_blind[indice]/Ntest


    print("Probability of Detection (theo): %f" % (pd_theo[indice]))
    print("Probability of Detection (clairvoyant): %f" % (pd_clair[indice]))
    print("Probability of Detection (blind): %f" % (pd_blind[indice]))


#export csv file
if csv_on==1:

    header_string="%s,theo,clairvoyant,blind" % parameter
    comments_string="Simulation Parameter: pfa=%f, N=%d, SNR=%d, sym=%s, Fe=%d, f0=%f, Ntest=%d\n" % (pfa,N,SNR,sym.tolist(),Fe,f0,Ntest)
    output=np.array([x_vect,pd_theo,pd_clair,pd_blind])
    #np.savetxt(filename, output.T,header=header_string, delimiter=",",fmt=['%d','%f','%f','%f'],comments=comments_string)

    output_signal=np.array([np.arange(0,N),np.arange(0,N)/Fe,Y[0,:].A1,Y[1,:].A1,Y[2,:].A1])
    np.savetxt(filename_signal, output_signal.T,header="n,t,Phase 1,Phase 2,Phase 3", delimiter=",",comments=comments_string)


#show figure
if plot_on==1:
    show_signals(Y,1)

    plt.figure(2)
    plt.plot(x_vect,pd_theo,label='PD (theo)')
    plt.plot(x_vect,pd_clair,label='PD (clairvoyant)')
    plt.plot(x_vect,pd_blind,label='PD (blind)')
    plt.legend(loc='lower right')
    plt.show()