.. include:: .. index:: Tutorial5 .. _Tutorial5: .. role:: bash(code) :language: bash Tutorial 5: TF and Fourier transforms ===================================== In this tutorial, we will inspect a transverse-field (TF) μSR dataset using Fourier analysis and multi-component fitting. The data are detector calibrations performed with a quartz sample at 1.142 T on the HAL-9500 instrument (run 2 in 2025). This instrument is dedicated to TF with a high temporal resolution on the order of 70 ps. .. warning:: Primary data have fine time steps of 25 ps, such that there are about half a million data points per histogram. Moreover, there are eight detectors around the sample. Due to the large number of data points, data from this instrument are usually analyzed on GPUs. For this tutorial, we have reduced the data accordingly in the templates to achieve reasonable fitting performance on an ordinary computer. Multi-component TF template ------------------------------ Quartz has a large fraction of muonium with a large electron-muon hyperfine coupling on the order of 4.5 GHz, which results in muon precession frequencies in the GHz regime. The corresponding Breit-Rabi diagram is shown in the figure below .. figure:: images/muonium_breit_rabi_quartz.png :width: 40% :align: center Breit–Rabi diagram for muonium in quartz. The two allowed transverse-field muonium transitions, :math:`\nu_{34}` (upper branch) and :math:`\nu_{12}` (lower branch), are shown as a function of magnetic field. The dashed vertical line marks the applied magnetic field :math:`B_{\mathrm{actual}}` and the corresponding markers the transition frequencies observed in this tutorial. Since there is also a fraction of diamagnetic muons inside quartz, there is a total of three precession frequencies in TF μSR data data. There is a template for a three-component fit in ``tutorials/5.0/template/02_HAL_template.msr``. We will use this template to fit the precession frequencies later, after having refined the initial values. If you were to fit directly, the current suboptimal initial values would result in lengthy calculations. Based on what you learnt in previous tutorials, examine how the fit is set up in the template file. Identify detector-specific parameters that require mapping and how these are combined to the three-component precession function parametrized by .. math:: P(t) = f_{12}\, e^{-\lambda_{12} t} \cos\!\left(2\pi \nu_{12} t + \phi_{12}\right) + f_{34}\, e^{-\lambda_{34} t} \cos\!\left(2\pi \nu_{34} t + \phi_{34}\right) + f_{\mu}\, e^{-\lambda_{\mu} t} \cos\!\left(2\pi \nu_{\mu} t + \phi_{\mu}\right), with :math:`f_{\mu} = 1 - f_{12} - f_{34}`. To interpret the detector-specific quantities (F1, F3, F5, F7), it is important to consider the actual detector geometry shown below. The TF detector has eight positron detectors that are distributed uniformly in azimuth around the sample, so that all angular directions of the transverse muon spin polarization are sampled. Under normal circumstances, the full set of eight detectors is included in the analysis, which generally requires GPU acceleration due to the large number of data points. For this tutorial, only four detectors are analyzed to simplify the workflow and focus on the key aspects of TF μSR data analysis. Having understood the structure of the .msr template, we now want to fit the data. Since there are three narrow lines with a very large frequency separation in-between, we will make use of the Fourier transform to inspect each line and provide close-to-optimum initial parameters. .. figure:: images/detector_scheme_tutorial.png :width: 30% :align: center TF detector geometry. Eight positron detectors (F1–F8) are arranged symmetrically around the sample position. The orange disk marks the sample, while the arrow indicates the muon spin direction :math:`\mu` set by the spin rotator. Fourier analysis of TF μSR data ------------------------------- Before performing a full time-domain fit, it is instructive to inspect the data in the frequency domain by making use of the Fourier transform. In *musrfit*, the Fourier transform of TF μSR data can be computed in two different ways: 1. **Via musrview** |musrview|, which displays the data together with the fitted model and allows interactive inspection in both the time and frequency domains. 2. **Via the raw Fourier mode** |musrFT|, which computes a Fourier transform of the data without reference to any fitting model. .. |musrview| image:: images/musrview.svg .. |musrFT| image:: images/musrFT.svg In this tutorial, we will use **musrview** |musrview|, as it provides a convenient and interactive way to relate features in the frequency domain directly to the time-domain signal and fit components. As you learnt in the previous tutorials, a call to **musrview** will open the time domain spectrum with the configuration in the PLOT block. For Fourier analysis, there is a FOURIER block with the following parameters: :: ############################################################### FOURIER units MHz # units either 'Gauss', 'Tesla', 'MHz', or 'Mc/s' fourier_power 13 # 2^13 < # data points in window to 2 us apodization STRONG # NONE, WEAK, MEDIUM, STRONG dc-corrected FALSE # TRUE, FALSE plot POWER # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE #range 1800 2700 These parameters are `documented here `_\ . In this tutorial, we will examine the effect of the parameters ``apodization``, ``fourier_power``, and ``range`` on the Fourier spectra. Note that another important parameter is ``dc-corrected``, which subtracts the DC offset of the time-domain trace before computing the Fourier transform. This parameter is of particular relevance if strongly damped TF signals are analyzed, where notable DC offsets are common. In order to compute and analyze data in the frequency domain with **musrview**, the following keyboard shortcuts are of relevance : .. list-table:: :header-rows: 1 :widths: 15 85 * - Key - Action * - ``f`` - Perform the Fourier transformation of the **selected** data and show the result. * - ``d`` - Show the difference between the **selected** data and the fit. * - ``a`` - Show the average of the **selected** data, e.g. the averaged Fourier power spectra of various detectors. * - ``u`` - Reset the plotting range to the area given in the msr file (“un-zoom”).. * - ``c`` - Toggles between normal and cross-hair cursor to read off values. * - ``q`` - Quit *musrview*. Each command that operates on selected data requires one to click onto the plot region before typing the shortcut. Accordingly, to get a first overview as shown in the figure below, open **musrview** |musrview|, compute the Fourier transform by typing ``f`` (after selecting the data), and average the power spectra by typing ``a`` (after selecting the data) .. figure:: images/t5_FT_init.svg :width: 30% :align: center Fourier transform of template after averaging all detectors. Spectral range and frequency folding ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The histograms are recorded with a native time resolution of 25 ps. This corresponds to a Nyquist frequency of .. math:: \nu_{\mathrm{Nyq}} = \frac{1}{2\,\Delta t} = 20\ \mathrm{GHz}, which is well above muonium precession frequencies. The data can thus be binned, which is parametrized by ``view_packing`` in the PLOT block. To illustrate the importance of appropriate binning, progressively increase ``view_packing`` and observe the highest frequencies being folded back at :math:`\nu_{\mathrm{Nyq}}`. Spectral interpolation: Zero padding ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ When zooming in to a particular peak, you notice that there are only few data points per peak. For visual inspection, it is desirable to interpolate the spectra to a finer grid. A widely used technique for spectral interpolation is to append zeros to the time-domain spectrum before computing the Fourier transform. In this way, the Fourier transform is computed on additional frequency points. While this procedure preserves the linewidth of the spectral lines and improves the visual appearance, it is important to keep in mind that zero padding does not improve the spectral resolution! In musrfit, the parameter ``fourier_power`` sets the power of two (N) defining how many points (2^N) are used in the Fourier transform. The current value (N=13) in the template corresponds to the setting where (2^N) is yet shorter than the number of data points. Examine the effect of zero padding on the diamagnetic fraction. To avoid zooming after each Fourier transformation, constrain the ``range`` in the FOURIER block to the muon peak, e.g. to 145 - 165 MHz. Afterwards, progressively increase ``fourier_power`` to larger numbers. Note that for N>17, you will start to notice that it takes a while for the Fourier transform to compute. Of course, this will depend on the resources of your computer, so make sure you do not go too high. Also avoid having too many open instances of musrview. A setting of N=17 is largely sufficient for this tutorial and you should be able to compare 2-3 spectra, thus requiring three instances of musrview. Eventually, you can also speedup calculations by a factor of 4 by restraining the Fourier analysis to a single histogram by selecting only one dataset in ``runs`` in the PLOT section. If your computer can cope with these settings, then also increase the ``range`` of the time domain data that is currently constrained to 2 μs in the PLOT section. Keep these settings for the next exercises. Spectral leakage: Apodization ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Up to this point, you have computed Fourier spectra with ``apodization STRONG``. In order to understand why apodization is needed at all, we now deliberately switch it off by setting ``apodization NONE``. Recompute the Fourier power spectrum with no apodization at the muon line. You will observe pronounced oscillatory structures and elevated background levels that were not visible in the apodized spectra. These features are not physical signals but arise from *spectral leakage*. Spectral leakage originates from the fact that the Fourier transform is computed from a finite time window. The abrupt start and end of the time-domain signal act as a sharp window, which produces side lobes in the frequency domain. As a consequence, power from a strong, narrow line spreads into neighboring frequency regions and can mask weaker spectral features. Apodization reduces this effect by multiplying the time-domain signal with a smooth window function before computing the Fourier transform. This suppresses the sharp edges of the time window and strongly reduces leakage into adjacent frequencies. The improvement becomes immediately apparent when switching back to ``WEAK``, ``MEDIUM``, or ``STRONG`` apodization and comparing the spectra. The price paid for reduced spectral leakage is a broadening of the spectral lines, since the effective time window is shortened. Apodization therefore introduces a trade-off between minimizing leakage and preserving frequency resolution. Averaging of power spectra ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ In many practical applications, Fourier analysis is performed using power spectra. This is often sufficient, because the primary interest lies in the locations and widths of spectral lines, while phase information is not required. Power spectra therefore provide a convenient and intuitive representation of TF μSR data, especially for identifying precession frequencies and estimating initial fit parameters. However, it is important to keep in mind that power spectra are *not linear*. They are proportional to the squared amplitude of the Fourier transform and therefore obey different statistical properties than the underlying time-domain signal. As a consequence, averaging and interpretation of power spectra are subject to important limitations. One limitation becomes apparent when dealing with very broad spectral lines whose amplitude is comparable to the noise floor. In such cases, the signal power may be difficult to distinguish from noise, and averaging can raise the baseline level while suppressing fluctuations, potentially obscuring weak features. A second limitation arises when two spectral components overlap in frequency, particularly if they differ in phase. Since phase information is discarded in the power spectrum, overlapping oscillatory components do not combine linearly. Interference effects that would be visible in the complex Fourier spectrum are lost, and the resulting power spectrum may not faithfully represent the underlying time-domain signal. These effects should be kept in mind when averaging power spectra across detectors or datasets. While averaging reduces statistical fluctuations, it also modifies the noise floor and can mask subtle spectral features. In situations where phase relationships are important or where components strongly overlap, inspection of the complex Fourier spectrum or direct time-domain fitting may be required. As an exercise with the data at hand, please look at the muon line with the different ``plot`` options available in FOURIER. Since these depend on phase, you have to provide an extra setting to the FOURIER block, namely ``phase``. Substitute the phase that you find in the different detector-specific phases, namely PhsF1_mu, PhsF3_mu, etc. By selecting the appropriate ``runs`` in the PLOT section, you can see how the different phases of the detectors change the real and imaginary components of the Fourier transform. When you set the phase correctly, you should recognize the absorption and dispersion linshapes of the real and imaginary components, respectively. Recall that the absorption spectrum for an exponentially decaying time-domain signal is a Lorentian, thus a symmetric peak at the resonance - exactly the same spectral shape as the power spectrum. The imaginary component, on the contrary, is an anti-symmetric function with zero crossing at resonance. After having inspected the complex Fourier spectrum on the muon line, turn now to the noise floor by selecting a spectral ``range`` between the peaks, e.g. 495 - 505 MHz. Compare now the spectra, if possible with all the four histograms in ``runs``. Compare the noise floor qualitatively by zooming in on the Y axis (left-click and drag on axis). Focus particularly on the baseline. The non-negativity in the power spectrum results in different statistical properties. In brief, averaging complex spectra reduces noise, while averaging power spectra redistributes noise into a smoother but higher baseline. Fitting the dataset ------------------------------- After the basics of Fourier analysis in the previous section, you can now move forward to actually fit the dataset. To do so, refine the frequencies of all the three components for a close-to-optimum initial guess. From this guess, the fit should then converge rather fast, even on a slower computer. Your fit should in the end look like ``tutorials/5.0/solution/02_HAL_solution.msr``.