1. Spin Echo Spectrum#

The following example shows how to acquire an NMR spectrum with a spin-echo based spectrum sequence written in pypulseq. The example can essentially be broken down as follows:

  1. Create an AcquisitionControl using the default device configuration from the repository. Here we can also set the log level for the log-file and the console log-output.

  2. Construct the spin echo based spectrum sequence. Here we use 20 ms echo time and 200 us RF block pulse duration.

  3. Define the most basic AcquisitionParameter, namely the Larmor frequency \(f_0\) and the decimation factor for DDC. Note that acquisition parameters are defined globally. They are saved on mutation and the latest state is loaded at AcquisitionControl instantiation using the provided path or the default.

  4. Execute the experiment.

  5. Extract the down-sampled raw data.

  6. Apply FFT to obtain the spectrum and calculate the associated frequency axis.

  7. Plot the magnitude spectrum.

  8. Add some note to the meta data of the AcquisitionData and save the results using the write method.

  9. Delete the acquisition control. This is an important step, as the destructor __del__ of the AcquisitionControl class disconnects from the measurement cards.

"""Experiment to acquire a spin echo spectrum."""

import matplotlib.pyplot as plt
import numpy as np

import console
from console.interfaces.acquisition_data import AcquisitionData
from console.spcm_control.acquisition_control import AcquisitionControl
from console.utilities import sequences

# Create acquisition control instance
acq = AcquisitionControl(configuration_file="example_device_config.yaml")

# Construct a spin echo based spectrum sequence
params = {
    "echo_time": 12e-3,
    "rf_duration": 200e-6,
    "use_sinc": False,
}
seq = sequences.se_spectrum.constructor(**params)

# Update global acquisition parameters
console.parameter.larmor_frequency = 2.0395e6

# Run the acquisition
acq.set_sequence(sequence=seq)
acq_data: AcquisitionData = acq.run()

# Get decimated data from acquisition data object
data = acq_data.raw.squeeze()

# Calculate FFT
data_fft = np.fft.fftshift(np.fft.fft(np.fft.fftshift(data)))
fft_freq = np.fft.fftshift(np.fft.fftfreq(data.size, acq_data.dwell_time))

# Plot spectrum
fig, ax = plt.subplots(1, 1, figsize=(10, 5))
ax.plot(fft_freq, np.abs(data_fft))
ax.set_ylabel("Abs. FFT Spectrum [a.u.]")
ax.set_xlabel("Frequency [Hz]")

# Add information to the acquisition data
acq_data.add_info({
    "note": "Example spin echo spectrum experiment",
})

# Write acquisition data object
acq_data.save()

# Delete the acquisition control, which disconnects from the measurement cards
del acq