n=3
CC[k_, n_] := Binomial[n, k]
Pnm1[n_, y_] :=
Expand[Sum[CC[k, 2*n  1]*y^k*(1  y)^(n  1  k), {k, 0, n  1}]]
A[n_,z_]:=Sum[a[p]*Exp[2*Pi*I*z*p],{p,0,n1}]
Cond[n_,z_]:=Pnm1[n,(Sin[Pi*z])^2]Conjugate[A[n,z]]*A[n,z]
m0[n_,z_]:=((1+Exp[2*Pi*I*z])/2)^n*A[n,z]
x1 = Cond[n, z]
x2 = TrigToExp[ComplexExpand[x1]]
d = Exponent[x2, Exp[I*Pi*z]]
x3 = Collect[x2*Exp[d*I*Pi*z], Exp[I*Pi*z]]
L=CoefficientList[x3, Exp[I*Pi*z]]
eqs=Map[Function[x, x == 0], L]
eqs2 = Map[Function[x, Im[a[x]] == 0], Range[0, n1]]
eqs3={ A[n,0]==1 }
vars = Map[Function[x, a[x]], Range[0, n1]]
sol=NSolve[Join[eqs, eqs2,eqs3], vars]
x4 = m0[n, z] /. sol[[1]]
x5=Collect[x4, Exp[I*Pi*z]]
LL=CoefficientList[x5, Exp[2*I*Pi*z]]
h=Map[Function[x,Sqrt[2]*x],LL]
