Frequency Map Analysis

Frequency map analysis finds the tunes of tracked particles from their coordinates turn by turn. The function naff (Numerical Analysis of Fundamental Frequencies) computes the main frequencies of signals, one signal per row of a matrix. For example, the horizontal tunes of four particles at different amplitudes in a FODO cell with sextupoles:

@elements begin
  qf = Quadrupole(Kn1=0.36, L=0.5)
  sf = Sextupole(Kn2=20.0, L=0.2)
  d = Drift(L=1.0)
  b = SBend(L=2.0, angle=pi/20)
  qd = Quadrupole(Kn1=-0.36, L=0.5)
  sd = Sextupole(Kn2=-30.0, L=0.2)
end
fodo = Beamline([qf, sf, d, b, d, qd, sd, d, b, d], species_ref=Species("electron"),
                pc_ref=18e9)

v0 = zeros(4, 6)
v0[:, 1] = [1e-4, 1e-3, 3e-3, 6e-3] # x in m
res = track(fodo, v0=v0, n_turns=1023)

tw = twiss(fodo)
β, α = tw.beta1[1], tw.alpha1[1]
x, px = res.x[turn=:], res.px[turn=:] # [particle, turn]
q, amp = naff(x .- im .* (β .* px .+ α .* x))
q # 4×1 matrix: 0.15497, 0.15497, 0.15493, 0.15483
4×1 Matrix{Float64}:
 0.15497087638130302
 0.15496628441352803
 0.1549294452021345
 0.15482906445229266

Each row of the matrix is the signal of one particle, from turn 0 to turn 1023. The complex signal \(x - i(\beta p_x + \alpha x)\), with the Twiss parameters at the start, turns in one direction in the complex plane, so its frequency is the tune including its sign. A real signal, such as x alone, has the frequencies \(\pm q\), and either one can be found. The signals must not have a constant part: subtract the closed orbit if it is not zero (naff warns otherwise).

At small amplitude, the tune agrees with the tune q1 of twiss, here to 5e-8:

q[1], tw.q1 # (0.1549708764, 0.1549709220)
(0.15497087638130302, 0.1549709220498885)

At larger amplitudes the tune decreases. This is the detuning with amplitude, which twiss gives as the derivatives of q1 with respect to the action J₁ (see Chromatic and amplitude-dependent quantities).

naff(data, n) computes the first n frequencies of each signal, and their complex amplitudes. The algorithm works on all signals at once, so with the data on a GPU (e.g. a CUDA.CuArray), all signals are analyzed in parallel there.

naff — Function.

naff(data::AbstractMatrix, n_frequencies=1; window_order=1) -> (frequencies, amplitudes)

Performs a batched Numerical Analysis of Fundamental Frequencies (NAFF) method for the (complex) signals in each row of data, computing the first n_frequencies frequencies from the signal. A Hanning window with order window_order is applied to the signal in order to gain a more accurate computation of the frequencies.

Arguments

  • data::AbstractMatrix: a matrix of size num_signals x n_samples to do NAFF on

  • n_frequencies = 1: number of frequencies to compute with NAFF

Keyword Arguments

  • window_order = 1: order of the Hanning window applied to the signal throughout NAFF

  • warnings = true: display warnings

Output

  • frequencies: a matrix of size num_signals x n_frequencies containing the frequencies

  • amplitudes: a matrix of size num_signals x n_frequencies containing the complex amplitudes associated with each frequency