Valentí Massana
Subscriber

Hi Genyi,

Thank you for your interest. As of today I have the result of this question and let me expose here the solution that I have found (surely there is more than one).
The interest of the problem was to do the DFT (Discrete Fourier Transform) from the Cartesian components of the magnetic induction field, Bx and By, on a circle of radius R (drawn outside the model). Let's say we take 16 points on that circle (the number of points must always be of the type 2^n).
Also, mention that in a "pure" quadrupole only the Fourier component b2 should survive, and that the allowed components are b6, b10, b14, etc... The others are "forbidden" by symmetry.
The point is that to construct a cost function to minimize, for example, the harmonic b6 from the Cartesian components Bx and By, we have to keep in mind that in the analysis of the harmonics of the field, the angular dependence of the harmonic j goes as Exp[i (j-1) k*phi/N], where k=0,1,2....N-1. 
Thus in our case:
b6=By(p1)Cos[0]+By(p2)Cos[1*10π/16]+By(p3)Cos[2*10π/16]+By(p4)Cos[3*10π/16]+...+By(p16)Cos[(15*10π/16],
where By(p1), By(p2), ... refers to the value of By at the point p1, p2, around the circle of radius R. Say that 3 of the 16 terms are directly zero.
In the case of wanting to minimize b10: summation of [Cos[(k - 1)*18π/16], k=0,1,2....N-1.
Solution: My idea was to first define in "Field overlays->Calculator" the values By(pn) and then construct the cost function as a sum of j terms, as I have previously defined the harmonic b6. And minimize this function.
This way of solving the problem worked for me, I don't know if it is possible to use in Ansys other simpler solving methods.