gr-MRI: A Software Package for Magnetic Resonance Imaging Using Software Deﬁned

The goal of this work is to develop software that enables the rapid implementation of custom MRI spectrometers using commercially-available software defined radios (SDRs). The developed gr-MRI software package comprises a set of Python scripts, flowgraphs, and signal generation and recording blocks for GNU Radio, an open-source SDR software package that is widely used in communications research. gr-MRI implements basic event sequencing functionality, and tools for system calibrations, multi-radio synchronization, and MR signal processing and image reconstruction. It includes four pulse sequences: a single-pulse sequence to record free induction signals, a gradient-recalled echo imaging sequence, a spin echo imaging sequence, and an inversion recovery spin echo imaging sequence. The sequences were used to perform phantom imaging scans with a 0.5Tesla tabletop MRI scanner and two commercially-available SDRs. One SDR was used for RF excitation and reception, and the other for gradient pulse generation. The total SDR hardware cost was approximately $2000. The frequency of radio desynchronization events and the frequency with which the software recovered from those events was also measured, and the SDR's ability to generate frequency-swept RF waveforms was validated and compared to the scanner's commercial spectrometer. The spin echo images geometrically matched those acquired using the commercial spectrometer, with no unexpected distortions. Desynchronization events were more likely to occur at the very beginning of an imaging scan, but were nearly eliminated if the user invoked the sequence for a short period before beginning data recording. The SDR produced a 500kHz bandwidth frequency-swept pulse with high fidelity, while the commercial spectrometer produced a waveform with large frequency spike errors. In conclusion, the developed gr-MRI software can be used to develop high-fidelity, low-cost custom MRI spectrometers using commercially-available SDRs.


ACKNOWLEDGMENTS
Firstly, I want to thank my advisor, Dr. Will Grissom for accepting me into his lab, when I reached out to him as an undergrad in his instrumentation class. His clear enthusiasm for his work, and teaching were what drew me to his lab, and I would likely not be here without him. He has provided a great environment in which I was given the opportunity to learn a great deal from him, but also given the flexibility to learn on my own.  Specifically we show that one can home-build a high performance MR spectrometer, with little hardware modification for roughly $2,000. This chapter discusses the basic components of a magnetic resonance imaging (MRI) system, and MR spectrometer, and gives an overview of the use of field programmable gate array (FPGA) based devices for custom MR spectrometers. We will then discuss the specific gr-MRI software solution and system architecture.

MR System Overview
Modern commercial MRI and nuclear magnetic resonance (NMR) spectrometers are sophisticated devices with very high performance. Figure 1.1 shows a block diagram for a typical modern MR scanner. There are many basic components that comprise a modern RF spectrometer and MRI system, which are defined by the way that MR signals are produced, detected, and processed.

Magnet
The first necessary component of a MR, or NMR system is the magnet that creates the main magnetic field. Some major considerations regarding the magnet are its strength, stability, and field uniformity. The procession frequency at which protons spin in a magnetic field, or the Larmour Frequency, is directly dependent on the strength of the magnetic field. A larger main magnetic field will increase the Larmour Frequency, and thus increase the nec- essary center frequency of the spectrometer system. Additionally, the field must be uniform enough to observe spin features resulting from the physical structure that is being analyzed, which for imaging applications usually requires a field uniformity of roughly 0.1 ppm over the imaged volume [1]. The magnets used for this study were two aligned permanent magnets resulting in a 0.5 Tesla (T) main field, but most modern clinical scanners use super cooled electromagnets with field strengths ranging from 1.5T to upwards of 7T.

RF Probe
The most basic function of the RF probe is to couple nuclear spins to the RF transmitter or receiver. When transmitting, the RF probe generates a magnetic field perpendicular to the main magnetic field, affecting the magnetization vector in the sample. When receiving, the probe converts the magnetic field changes created by the relaxation of nuclear spins into an electrical current which is sent back to the MR spectrometer via an amplifier. The probe is electrically tuned to the Larmour frequency, and typically matched to 50 Ohms impedance.
There have been many sophisticated advances in the field of RF coils, but at its simplest, a probe can simply be a loop of wire.

Magnetic Field Gradients
Magnetic field gradients, referred to simply as gradients in the rest of the paper, are coils which play high voltage DC signals, which purposely create linear field inhomogeneities.
MR imaging depends on the use of gradients to spatially map the received signals to specific frequencies generated by the gradients. Typically during an imaging experiment, gradients are pulsed to create transient field gradients with properties creating desired linear phase or frequency shifts across an object in three dimensions, resulting in the localization of signals. Additionally, gradients are often played during RF transmission to couple nuclear excitation to specific spatial locations.

MR Spectrometer
The MR spectrometer is responsible for the user controlled sequencing of RF and gradient pulses, as well as other gating pulses which control external hardware necessary for MRI. Any modern MR spectrometer consists of several basic components, which when combined, enable MR imaging.

Transmitter
The RF transmitter should be able to adapt to a wide range of potential frequencies and applications in MR. MR spectrometers usually use a highly stable 10MHz crystal oscillator, or something similar, which provides an RF source from which other frequencies can be derived [1]. The spectrometer usually includes a general purpose frequency synthesizer, so that it can produces RF pulses in a wide range of frequencies, as well as high speed, and high resolution digital to analog converters (DACs) to create the actual pulses.
Modern spectrometers allow for user controlled RF transmission through time dependent amplitude modulation, which results in the ability to produce arbitrary pulse shapes. Additionally, spectrometers allow the user to modulate the phase of pulses, which is important for many imaging applications, such as moving the location of slice selective excitation or adiabatic swept pulse generation [2]. The signal produced by the spectrometer is generally too small to create the required magnetic field (normally around 0dBm), so the output from the transmitter is typically run through a power amplifier before being sent to the probe.

Receiver
The receive chain is responsible for converting the small signal detected by the probe into a digital representation of that signal, which is saved in memory. The first step in the receive chain is usually amplified 60-100dB by the preamplifier before the coupling with the spectrometer interface [1]. The spectrometer creates a complex signal by splitting the received signal into two streams and adding 90 degrees of phase to one before they are sent through independent high speed analog to digital converters (ADCs). Modern spectrometers typically used 12-16 bit ADCs which achieve high signal resolution, and typically the preamplifier is scaled so that the received signal uses the full dynamic range of the ADC. At minimum, the ADC must sample at least twice as fast as the highest frequency component in the signal to avoid aliasing, however it is typically advantageous to use as high a receive bandwidth as possible because noise voltage decreases with increased bandwidth. The high sampling rates create a high volume of data, which is typically down sampled before being sent to a computer, or other digital control system.

Digital Control
MR spectrometers also include some sort of high performance digital control such as a computer to coordinate the other spectrometer functions. The computer creates RF pulses, and sets timing for the transmission of those pulses, gradient pulses, and hardware control pulses in a pulse sequence, however most time critical pulses are loaded into the spec-trometer and handled by hardware. The computer also specifies the timing and duration of data acquisition. Further, it defines the data sampling strategy, and keeps track of the data received, which is saved to memory for post processing.

Overview of Software Defined Radios in MR and NMR
While modern commercial spectrometers deliver high performance, many research and development applications in magnetic resonance require more configurable, portable, or scalable spectrometers at a low cost. For example, spectrometers have been developed in-house to meet the unique needs of low-field MRI scanners [3,4], deliver point-of-care relaxometry measurements [5], hyperpolarize exogenous contrast agents [6], increase the number of receive channels in parallel imaging [7,8,9], implement parallel transmission [9,10,11], and acquire signals in NMR field monitoring probes concurrently with imaging [12,13,14]. In particular, many recent systems have been designed around field programmable gate arrays (FPGAs) which perform sequencing and signal processing functions [15,3,16,17,18,5,9]. FPGAs are particularly well-suited for MR at Larmor frequencies of tens to hundreds of megahertz since they can process multiple streams of transmitted and received data in parallel at high speeds.
While FPGAs are well-suited to application in high-frequency MR spectrometers, replicating current FPGA-based spectrometers is challenging for non-electronics experts due to the steep learning curve involved in FPGA programming, and since most are based on custom circuitboard designs that would be difficult for non-experts to recreate. At the same time, communications research has benefited in recent years from the development of the open-source GNU Radio software (gnuradio.org), which enables non-hardware experts to build custom software radios that can be used with a wide range of low-cost softwaredefined radio (SDR) devices; at the time of writing, the GNU Radio website list ten compatible SDR vendors, many of which offer several SDR models [19]. SDR's typically comprise analog-to-digital and digital-to-analog converters, an FPGA for basic filtering and signal down-and up-conversion, and a USB interface. They can be thought of as PC sound cards that operate at RF frequencies, in that they act as an interface between the digital computer and the analog world, while the PC handles most of the real-time digital signal manipulations. Depending on their feature set, commercial GNU Radio-compatible SDR's currently cost between a few hundred and a few thousand dollars and ship with FPGA software images, so the user can focus on implementing the functionality of their radios on the PC side. Software radios are built in the Python programming language (python.org) in GNU Radio, by connecting modular signal processing components together into a flowgraph, the inputs and outputs of which are connected to the SDR via a driver interface.  gr-MRI Software Package Overview and Architecture

Introduction
We describe an open-source software package that extends the functionality of GNU built on top of the active GNU Radio project, the software will be compatible with a wide range of current and future SDR devices. The full package and a detailed user guide can be downloaded at https://bitbucket.org/wgrissom/gnuradio-mri.

A basic single-pulse sequence in GNU Radio
To illustrate how GNU Radio works and to motivate the architecture and features of the gr-MRI package, Figure 2.1a shows an implementation of the most basic NMR pulse sequence using GNU Radio software alone, without gr-MRI. The sequence comprises a single-pulse excitation with simultaneous reception of the free induction decay (FID) signal. Specifically, the figure shows a graphical representation of this sequence's flowgraph in GNU Radio Companion (a GUI-based flowgraph editor packaged with GNU Radio).
A GNU Radio flowgraph is made up of signal generation, signal processing, and input and output blocks, which are connected by virtual wires that transmit baseband signals between them; wires conduct signals in one direction. In this flowgraph, the blocks that produce a block excitation pulse are outlined in box A. The pulse is generated by duplicating a square wave, inverting and delaying its copy, and multiplying the copy by itself.
Then the real-valued block pulse signal is converted to a complex signal type (with zero imaginary component) and passed into the USRP Sink block (box B), which interfaces via a driver to one or more transmit channels of a Universal Software Radio Peripheral SDR (USRP; Ettus Research, Santa Clara, CA, USA). The demodulated received signal comes back into the flowgraph via the USRP Source block (box C), which sends the amplitude of the signal to an oscilloscope block for continuous display (box D). The flowgraph is freerunning, and does not record data. Figure 2.1b shows the oscilloscope window that appears when the flowgraph is executed, which displays the demodulated FID signal in real-time. This example illustrates that GNU Radio flowgraphs run continuously and are not inherently sequenced as is required for MR. Furthermore, the precise timing of transmitted signals is subject to delays on the PC, and the software lacks the ability to generate shaped waveforms such as sinc excitation pulses and gradient trapezoids, as well as the ability to change pulse amplitudes and phases between repetitions. It also lacks the ability to selectively record received signals over specific time intervals. To address these needs, gr-MRI pulse sequences use master clock signals that trigger provided RF and gradient pulse gen-eration and signal recording blocks. gr-MRI further provides tools to calibrate gradient strength, center frequency, and RF power, and to synchronize sequence timing in order to compensate system delays between RF and gradient pulse transmission and signal reception. These tools and features are described in the next sections. shown in Figure 2.2c, which writes a complex data stream from one input to an internal vector whenever its other input is high.
To initiate a gr-MRI scan sequence, the user invokes that sequence's Python script from the IPython shell [20], which creates the RF and gradient waveforms and loads them into     The outlined boxes contain: A) the USRP Source, which converts received data into a complex data stream; B) a group of blocks used to normalize the signal recording gate pulse's amplitude while preserving its phase; C) a multiply conjugate block that removes the signal recording gate pulse's phase from the FID signal phase to correct phase drifts; D) the gated vector sink which stores the raw data to a vector; and E) a QT GUI sink used to display the received signal in real time.
the Gated Vector Sink in box D so that the FID signal is only recorded over the desired interval. Second, it is used to correct spectrometer phase drifts. This is done by the blocks in box B, which normalize the amplitude of signal recording gate pulse, but preserve its phase, and the received FID signal is multiplied with the normalized signal recording gate pulse's complex conjugate in box C. This works because the both the excitation and the signal recording gate pulses originated from the same daughterboard with the same phase.
The far right block in box E is a QT GUI Sink that is used to display the received signal in real time. A representative QT GUI Sink window is shown in Figure 2.5 for the spin echo imaging sequence (described below).
The same strategies used to develop the FID single-pulse sequence were applied to enable gradient waveform generation for 2D and 3D imaging. The gr-MRI package includes three common imaging sequences, and a template sequence to enable development of new sequences. These sequences are described next. The software was built using GNU Radio     Compared to the GRE sequence, the SE sequence adds a block refocusing pulse midway between the excitation pulse and the readout window. Compared to the SE sequence, the IR sequence adds a block inversion pulse played TI (inversion time) seconds before each excitation and signal readout. latency which can be on the order of 20 ms, radio synchronization is essential while running these two-radio pulse sequences. To address this, one radio is designated the 'leader' and the other the 'follower'. It is assumed that the leader radio will produce the RF pulses and transmit enable pulse and the follower radio will generate the gradient waveforms. The gr-MRI sequences use a port on each radio to loop back a ten sample block synchronization pulse into dedicated receive channels on the follower SDR three times per TR.  Both functions save the optimized parameters to a Python pickle file named cal.pkl which is loaded and used by the imaging pulse sequences.

Gradient strength
The gr-MRI package also provides a gradient strength calibration script called grad calibration.
which uses a spin echo sequence to measure one-dimensional profiles of an object of known   should only need to be done once for a given scanner.

Data processing and image reconstruction
All data from a sequence is automatically transferred to an object of class data after a sequence is run. The object contains the raw data from the sequence's Gated Vector Sink, and a time stamp indicating when the sequence was initiated. When the data.recon() function is called, the data is reformatted (and averaged, if averaging was performed) to create an NPE×NRO matrix. If the readout dimension was oversampled with respect to the desired readout bandwidth, the matrix is decimated to the specified matrix size using a 60tap anti-aliasing FIR filter. Finally, a 2D inverse FFT reconstruction is performed, which corrects for RF chopping if it is present. The formatted k-space data matrix is returned in data.kdata and the image is returned in data.imdata. imaging sequence. The diagram shows a workflow step, and the output that the step affects and (where applicable) the input the step receives. A gr-MRI imaging experiment comprises the following steps: Figure 2.8: Workflow illustration for the spinecho.py imaging sequence. Dotted lines in the workflow steps indicate optional steps that can be turned on or off using the interactive mode parameter in the configuration file. The second column shows commands as the user would enter them into the IPython shell. The third column describes the data that is used or produced by each command, and the fourth column shows any images or plots that are created.

Workflow summary
1. RF power and center frequency parameters are determined and saved using FID.py.
2. The user updates the imaging sequence's config file with the desired pulse sequence parameters for their scan (spin config.txt). Then they invoke the imaging sequence script (spinecho.py). The calibrated parameters from Step 1 are automatically loaded, as well as the parameters from the config file.
3. Interactive Mode starts and the raw signal is displayed in real-time, while the user dynamically adjusts sequence parameters or loads saved parameters. This step is optional.
4. The user optionally fine-tunes gradient pulse moments to center the signal in the acquisition window. The figure for the "Tune pre-phasing gradients" step of Figure   2.8 shows an example of a plot that is shown when tuning the slice gradient. The plot is integrated signal amplitude versus a parameter rephase fudge, which is calibrated by the script and will be used to scale the slice rephasing gradient during imaging. The maximum point on this plot corresponds to the scaling of the rephasing gradient amplitude needed to fully cancel the through-slice phase. This step is optional but was required periodically on our scanner due to gradient amplifier nonlinearity, and may not be necessary on other scanners.

The user runs the sequence. The raw signal from each TR is displayed in a GUI
window, and the current phase encode line index is reported, so the user can monitor the scan.
6. After the scan has completed, the user can save the raw k-space data for external reconstruction, or call data.recon() to reconstruct an image.
7. The user can save data or parameters, change parameters, or begin a new scan.

Experiments
Experiments were performed on a 0.  Table 2.5: Mapping of pulse waveforms to transmit and receive channels on the two SDRs used for the imaging experiments. The leader SDR generated and received all RF signals, and the follower SDR generated all gradient pulses.

SDR Hardware
All imaging scans used two Ettus Research USRP1 SDRs with connected clocks. Although the radios perform separate functions, there is a significant difference between the clock speed of individual radios. This results in a significant time drift between the two radios, which would be impractical to correct by the sync() function alone. We therefore connected the clocks following instructions provided on the GNU Radio website. The USRP1 comprises an Altera Cyclone FPGA, a 14 bit (-1 V to 1 V), 128 Ms/sec digital to analog converter, and a 12 bit (-1 V to 1 V), 64 Ms/sec analog to digital converter.
The USRP1 can accommodate up to two transmit daughterboards and two receive daughterboards, each of which provides two channels. Each daughterboard can be driven at a unique frequency. The device connects to the PC by USB. In our experiments the leader radio produced the RF excitation pulse and the signal recording gate pulse on one transmit daughterboard, and DC transmit-enable and synchronizing pulses on a second transmit daughterboard. The follower radio produced the gradient pulses and another synchronizing pulse. Table 2.5 shows the mapping between imaging sequence pulses and radio channels.
The naming convention for the channel used is TX/RX Daughterboard Slot A/B Channel A/B. Because the USRP1 produces a maximum pulse amplitude of 1 V but our RF amplifier required at least 3.3 V to unblank, the transmit-enable pulse was used to drive a transistor switch that connected the SDR's 6 V power supply to the RF amplifier's unblanking input.

Imaging Scans
Gradient-recalled echo, spin echo, and inversion recovery spin echo imaging experiments were run with the sequence parameters shown in Table 2 Table 2.6: Imaging scan parameters.

Frequency-swept pulse generation
To validate the software and the SDR's ability to generate frequency-swept waveforms, an experiment was performed in which a Triggered Vector Source was used to produce a 500 µs frequency-swept waveform originally designed for Bloch-Siegert B + 1 mapping [21] (Figure 2.12, left). The small signal RF pulse was looped back into a USRP1 receive channel and recorded. For comparison, the same waveform was generated using the Maran scanner's spectrometer, and recorded the same way.  As stated in the Chapter 1, the RF probe is responsible for exciting magnetic spins in the sample, which then induce a current in the probe when the spins relax back to the main magnetic field. There are many sophisticated probes, however because our setup is small, we used a simple 10 turn solenoid coil. Solenoid coils are very sensitive, and create relatively homogeneous magnetic fields inside the coil. We wound a 10 turn coil tightly around the 15mm sample tube in order to place the conductor as close as possible to the sample, and secured it with insulating Kapton tape. We used 24 AWG insulated copper wire because it is easy to pack many close turns, and it is capable of carrying a 21MHz signal with low losses. When constructing a coil, one generally wants the smallest amount of real resistance possible. RF signals typically flow mostly on the surface of conductors, but depending on frequency and electrical properties of the conductor they penetrate a certain distance, which is referred to as the skin depth. If the wire gauge is too small, then the coil will add resistance, which reflects RF power and lowers the sensitivity of the coil. The skin depth for a 21MHz signal flowing on a copper wire is roughly 14 µm, which is far smaller than the 0.25 mm radius of 24 AWG wire. In order to get the most sensitive coil, so that the transmit voltage remains low, and the greatest possible signal is detected, the coil must be coupled to the spins in the sample.

Tuning and Matching Networks
This means that the coil must be tuned to the Larmour Frequency, and impedance matched to 50 Ohms, which matches the impedance of the rest of the RF system. Fig 2.13 shows the general "pi" configuration of a tuning and matching network, and is the configuration that was used for the presented experiments. The resonant frequency of an LC circuit can be calculated according to the following equation: In practice, when tuning and matching the coil, an inductance meter was used measure the inductance of the coil, and the necessary tuning capacitance was derived according the the previous equation, and assuming a resonant frequency of 21.3 MHz. The circuit was then connected to a network analyzer, and matching capacitors were chosen to minimize the reflected RF power at the center frequency. Variable capacitors were used in parallel with the tuning capacitor and one of the matching capacitors to allow optimization of the circuit when it was loaded with a sample, and placed into the magnet. The circuit used for the following experiments was tuned to 21.27 MHz and had a reflected power, or S11, of roughly -40dB at that frequency which is suitable for imaging.

Coil Housing
A custom coil housing was designed to accommodate these experiments as well as to enable future experiments. The housing, and experimental setup for the described imaging sessions is shown in Fig 2.14. The coil is shown on the left side of the box (a) and connects to the tuning and matching circuits (c) via a solderless junction (b). This housing allows the connection of two independent coils The two tuning and matching circuits shown in which will become important when using multiple closely tuned coils for transmit and receive. The coil shown here is used for transmit and receive, so the transmit and receive inputs and outputs are connected by a pair of crossed diodes, shown in Fig 2.14d. The crossed diodes allow the high power RF excitation pulses through during transmit, but isolate the transmit chain during receive. The entire housing box is made out of copper clad FR4 board. The copper housing serves as a common ground for the elements contained in the box, and electrically shields the coil from outside RF noise.

Unblanking Circuit
The dynamic range of the SDR output is -1V to 1V, and the required voltage to trip the TTL switch on the RF amplifier is 3.3V, so we could not directly use the output from the SDR to control the amplifier. To work around this issue, we built a small transistor switch Figure 2.15: Transistor circuit used to convert the 1V square output from the SDR to a 5V TTL pulse used to enable the RF Amplifier during RF Transmission. Resistor values were chosen to limit the current drawn by the circuit, and to convert the 6V input from the SDR power jack to a 5V output.
that used the 1V pulse created by the SDR to drive a MOSFET, which allowed the 6V input to be connected to the output circuit. The circuit diagram is shown in Fig 2.15. The output circuit simply consisted of a voltage divider, shown as R2 and R3, which converts the input 6V signal to 5V and limits the current to roughly 10mA. The resistor labeled R1 was simply used to limit the current fed to the gating pin of the MOSFET.

Chapter 3
Conclusions and Future Work gr-MRI Enables commercially-available software-defined radios to be used as low-cost custom MRI spectrometers, with fidelity that is comparable to or better than commercial spectrometers. It was designed to be highly customizable and reconfigurable. This will make it easier for researchers and engineers to develop custom spectrometers, without requiring significant spectrometer hardware development or FPGA programming.
In the near future, we can use this SDR platform to implement frequency swept Bloch-Siegert pulses for RF gradient encoding, or to implement other advanced pulse sequences.
This could include expanding the current library of pulse sequences to support a similar simple calibration of RF and gradient waveforms for non-cartesian trajectories such as radial or spiral. As it exists now, a user can create these pulses outside of the program, and load them before running a scan, but it would be nice to allow for an integrated system in which the pulses could be created when running the scan. Much in the way that GNU Radio is constructed, we would like to enable the integration of other user created functions in a sort of plug-in format, which could allow for a broadening of the system as a whole and enable novel pulse development and rapid testing of those pulses.
Future work would also include adapting this system to operate at higher fields, and to interface with clinical scanners. The USRP1 radio, or any other radio that runs the software is small, and would give researchers the ability to carry a custom spectrometer to any scanner on which they are working, so it would be beneficial for the system to operate at clinically relevant frequencies.