Journal of Medical Physics
 Home | Search | Ahead of print | Current Issue | Archives | Instructions | Subscription | Login  The official journal of Association of Medical Physicists of India      
 Users online: 485  Home  EMail this page Print this page Decrease font size Default font size Increase font size 

 Table of Contents    
Year : 2020  |  Volume : 45  |  Issue : 1  |  Page : 16-23

Development and validation of a matlab software program for decoding the treatment errors in real-time position management Gating-generated breathing trace

1 Deparment of Radiation Oncology, Max Super Speciality Hospital, New Delhi, India
2 Department of Physics, SPSB Government College, Shahpura, Rajasthan, India

Date of Submission11-Apr-2019
Date of Decision30-Oct-2019
Date of Acceptance13-Nov-2019
Date of Web Publication13-Mar-2020

Correspondence Address:
Mr. Naveen Kumawat
Department of Radiation Oncology, Max Super Spaciality Hospital, New Delhi - 110 017
Login to access the Email id

Source of Support: None, Conflict of Interest: None

DOI: 10.4103/jmp.JMP_30_19

Rights and Permissions



Introduction: The Real-time Position Management (RPM) is used as a motion management tool to reduce normal tissue complication. However, no commercial software is available to quantify the “beam-on” errors in RPM-generated breathing traces. This study aimed to develop and validate an in-house-coded MATLAB program to quantify the “beam-on” errors in the breathing trace. Materials and Methods: A graphical user interface (GUI) was developed using MATLAB (Matrix Laboratory Ra2016) software. The GUI was validated using two phantoms (Varian-gated phantom and Brainlab ET gating phantom) with three regular motion profiles. Treatment time delay was calculated using regular sinusoidal motion profile. Ten patient's irregular breathing profiles were also analyzed using this GUI. Results: The beam-on comparison between the recorded reference trace and irradiated trace profile was done in two ways: (1) beam-on time error and (2) beam-on displacement error. These errors were ≤1.5% with no statistical difference for phase- and amplitude-based treatments. The predicated amplitude levels of reference phase-based profiles, and the actual amplitude levels of amplitude-based irradiated profiles were almost equal. The average treatment time delay was 47 ± 0.003 ms. The irregular breathing profile analysis showed that the amplitude-based gating treatment was more accurate than phase based. Conclusion: The developed GUI gave the same and acceptable results for all regular profiles. These errors were due to the lag time of the linear accelerator with gating treatment. This program can be used as to quantifying the intrafraction “beam-on” errors in breathing trace with both mode of gating techniques for irregular breathing trace, and in addition, it is capable to convert phase-based gating parameters to amplitude-based gating parameters for treatment.

Keywords: Beam-on errors, breathing trace, gating, MATLAB, time delay

How to cite this article:
Kumawat N, Shrotriya AK, Heigrujam MS, Patro K, Kumar S, Bansal AK, Munjal RK, Anand AK. Development and validation of a matlab software program for decoding the treatment errors in real-time position management Gating-generated breathing trace. J Med Phys 2020;45:16-23

How to cite this URL:
Kumawat N, Shrotriya AK, Heigrujam MS, Patro K, Kumar S, Bansal AK, Munjal RK, Anand AK. Development and validation of a matlab software program for decoding the treatment errors in real-time position management Gating-generated breathing trace. J Med Phys [serial online] 2020 [cited 2020 Apr 2];45:16-23. Available from:

   Introduction Top

In radiotherapy, various motion management techniques are practiced such as integration of respiratory movements into treatment planning, deep inspiration breath-hold radiotherapy, self-held breath hold, forced shallow breathing, and respiratory-gated radiotherapy.[1]

There are two gating techniques to deliver radiation: one is internal fiducial marker-based gating with free breathing and the other is external surrogate marker based with coached extended inhale or paused exhale.[2]

RPM is one of the external surrogate marker-based respiratory gating tools, which is jointly developed by the University of California Davis Cancer Center and Varian Medical Systems, which facilitated to treat patients in amplitude window as well as phase window.[3],[4] The breathing pattern is recorded in RPM System (Varian Medical System, Palo Alto, CA, USA) with the help of an external infrared marker block, which is placed on the body surface between xiphoid and umbilicus[5] and charge-coupled device (CCD) camera. [Figure 1](a) shows a patient with IR block placed between xiphoid and umbilicus where maximum breathing amplitude is expected and [Figure 1](b) shows the CCD camera which monitors the surrogate marker at the time of scan as well as treatment delivery.
Figure 1: (a) Surrogate 6 marker IR block placed on patient body and (b) infrared CCD camera mounted on four-dimension computed tomography table

Click here to view

The RPM device is being used to acquire the four-dimension computed tomography (4DCT) for internal target volume (ITV) generation or treat the patient in specific phase window by binning the image set and making average intensity projection of the selected subphases. In the selected sub-phases, the tumor motion is less as compare to complete sub-phases, thus the ITV can be reduced for selected sub-phases resulting in better sparing of surrounding normal tissues and minimized the complication produced by radiation.[6]

A phase-based gating treatment relies on real-time calculations for identifying. When the respiration trace lies within the chosen phase-window set by a reference breathing trace, the radiation is delivered. Here, only limited online breathing pattern is visualized during the treatment [Figure 2]a; hence, it becomes very difficult to identify the error in radiation being delivered outside the breathing window, especially in irregular breathing pattern [Figure 2]b.
Figure 2: (a) Online breathing pattern of a patient from RPM. (b) The complete breathing pattern of the same patient. The patient was audio coached, but during treatment, it was not as regular as scan time recorded pattern and showing error in phase-based treatment (in red circle) outside the selected phase window (green and cyan lines), where yellow part indicates the beam-on area from breathing profile analysis program

Click here to view

To resolve this problem, Vedam et al.[7] suggested a method to convert prospective amplitude gating from retrospective phase gating, because amplitude-based gating treatment does not require real-time calculation; it depends on the present value of breathing pattern. In this method, they obtained amplitude window with an average and maximum amplitude of the breathing trace in the selected phase interval at simulation. The average amplitude window was determined iteratively from simulation data. This amplitude window was used for treatment. This study did not suggest a method to find out the errors in the breathing trace during treatment and they defined the window only in exhale level. However, in inhale amplitude gating treatment, with lower window, upper window level is also required to stop treatment if breathing trace is going out of it.

Dunn and Kenny[8] designed a software tool for analysis of a patient breathing trace created by RPM using MATLAB. This software tool was based on sample entropy algorithm. This was applicable during simulation and during treatment fraction to quantify the breathing irregularity as well as need for breathing coaching. In this study, the authors did not suggest a method for obtaining amplitude-based gating parameters from phase-based simulation parameters and quantify beam-on-associated errors with respect to time and amplitude.

Shi et al.[9] evaluated a new respiratory gating system, “respiratory gating for scanners” (RGSC; Varian Medical Systems), using QUASAR gating phantom and compared with RPM system using an irregular breathing pattern. The results showed that the RPM system has poorer performance than RGSC system in the irregular breathing pattern.

For gating treatment, no commercial software is available to decode the treatment beam-on-associated errors (radiation delivered outside the selected window) in breathing traces and to obtain the amplitude-based gating parameter from phase-based gating parameter. Therefore, we developed a program based on MATLAB which calculates the beam-on time error (radiation delivered outside the window with respect to time) and beam-on displacement error (radiation delivered outside the window with respect to displacement). The program is also capable of calculating amplitude window from selected phase window for treatment, treatment duty cycle, and treatment range and treatment machine time delay of the linear accelerator (LINAC) using regular profile. It can also generate comma-separated values (CSV) format of the breathing trace for quality assurance (QA) purpose on 4D gating phantom.

   Materials and Methods Top

Breathing profile analysis program

For decoding the errors in breathing traces, a graphical user interface (GUI) program was designed using MATLAB (The Mathworks Inc., Natick, MA, USA, version R2016a) software [Figure 3]. With the help of this program, the gating profiles can be analyzed with phase based as well as amplitude based in inhale or exhale level with their reference scan. The GUI is divided into six parts. The visiTrax playlist file (.vxp) format breathing trace is inserted in this program, which is generated at the time of scan or treatment. This file has amplitude, relative time, phase, mark, valid flag, and transistor–transistor logic in and out (ttlin and ttlout) related information. Where valid flag stands for the portion in which the trace is valid for treatment or error-free trace, the value of valid flag “0” stands for error-free trace and “1” for error in trace (where the trace does not pass through motion predicted filter and radiation was not delivered in selected window). The ttl stands for transistor–transistor logic; when ttl has value 1, it means radiation is on and 0 for radiation off. Mark for the next phase is to be started and denoted as P in file data.
Figure 3: Breathing profile analysis program graphical user interface

Click here to view

In first part of the GUI, the level is to be selected; it can be inhale or exhale: the level would be inhale for breast treatment or scan and the level would be exhale for lung or liver. Then, the mode needs to be selected; it can be phase based or amplitude based, in which the reference scan or treatment was done. Now, the breathing profile is selected and imported with File tab. With plot tab, the complete breathing trace between time and amplitude is plotted.

In the second part, the time interval of the breathing trace is chosen for which the analysis to be done. ITV margins will also be entered for prediction of the treatment window.

In the third part, the profile is plotted with selected time interval using Plot tab. In this part, the scale is shifted to zero level with averaging of minima for the complete selected profile.

In the fourth part, selected breathing trace is converted into a phase cycle. For inhale level gating, the phase scale starts from 50% to 150%. The 50% to 100% phase is the part of the first cycle and 100% to 150% is the part of the next cycle, where 100% and 150% refers 0% and 50% of the next cycle. To combine both cycles, the scale starts from 50% to 150%. For exhale level, the phase level is started from 0% to 100%. The trace is plotted between amplitude and phase. The gating window is selected in which the patient is being treated. There is a feature in GUI to show the trace where the radiation was delivered with “Beam On” tab. Now, this plot is fitted using sinusoidal function in the form of red line curve. Because it is assumed that the trace is periodic and continuous, it can be fitted with sinusoidal wave function and given by

where A is the displacement at phase value P and Ai, Bi, and Ci are the fitted parameters and i is the index with the range of 1–9. This equation is a linear summation of sinusoidal function up to nine terms, which gives good fitted curve of the breathing trace. From this fitted curve, we determine various parameters such as average displacement, range, and threshold of the breathing trace. To predict lower amplitude window level in inhale-level gating, the average of intersection values of the fitted curve with phase window level was calculated, and for predicting upper window in inhale-level gating, the anterior–posterior ITV margin was added in the lower amplitude window value. The same procedure was followed for exhale-level gating to predict the upper and lower amplitude window level.

In the fifth part, breathing profile is plotted between amplitude and time, which can be enlarged for the selected time interval. It can help us identify the error at a particular time. In this plot, the yellow line indicates the radiation delivered area and green and red lines indicate the predicted lower and upper amplitude window levels, calculated from retrospective reference scan.

The sixth part shows the breathing profile analysis. In this part, “beam-on” time error and “beam-on” displacement error in terms of lower amplitude and higher amplitude, predicted amplitude window for treatment, actual treated amplitude window, and treatment range in terms of amplitude and duty cycle are generated for phase- as well as amplitude-based treatment. The formula used for “Beam-On” error in program is:

where Tbi and Tti refer to time where the beam was ON and the time for the beam was to be ON in selected window of ith breathing cycle, respectively, and n is the total number of breathing cycles. Treatment range is the amplitude window in which the beam was “ON.” We can also generate a CSV format breathing pattern with the help of tab “Export as.csv.”

Program validation

For validation, a hypothesis was used that GUI program gives the same result in phase-based and amplitude-based gating treatment with regular motion profiles. 4D-CT scans of the Varian Respiratory Motion Test Gating Phantom [Figure 4]a with sine4 profile and Brainlab ExacTrac (ET) gating phantom [Figure 4]b with regular sinusoidal, and saw-tooth motion profiles were taken and trace was recorded in RPM system, which is called reference breathing profile. The reference profiles (trace) were exported to MATLAB program and analyzed these motion profiles with phase interval of 85% to 15% and 35% to 65% for inhale level and exhale level, respectively; these phase windows were chosen randomly. Now, both phantoms were irradiated with analyzed motion parameters in phase and amplitude mode of gating with respective motion profile in inhale and exhale levels. The phantom motion profiles of the treatment were saved on the RPM system. Then, irradiated motion profiles were imported to in-house-developed MATLAB software program to analyze with respect to the reference profile.
Figure 4: (a) Varian respiratory motion test gating phantom and (b) Brainlab ET gating phantom

Click here to view

The treatment errors were calculated for phantom motion profiles. The term “beam-on time error” was used for the machine “on” at outside position of the selected window with respect to time. It gives the idea of error in machine “on” in duty cycle and calculated in phase-based and amplitude-based gating, respectively.

The term “beam-on displacement error” was used for machine “on” at outside of the selected window with respect to amplitude, which can be better understood with a typical example [Figure 5]. In part (a), blue curved line shows a breathing pattern with black lines as phase window and the yellow pattern shows beam on area. In part (b), according to phase window, a predicted amplitude window is shown. In part (c) and (d), the green area indicates the correct treatment area. The red area on time axis indicates the beam-on time error with phase-based treatment (d). The beam-on displacement error indicates the machine “on” at outside position of the selected window with respect to amplitude. It gives the idea about error of machine “on” in treatment range and is calculated in terms of lower displacement and higher displacement error. In part (d), on amplitude axis, the blue area is denoted as lower displacement error and brown area is denoted as higher displacement error for second breathing trace.
Figure 5: (a) A model of breathing pattern (curved blue line) with assumption, the beam was on at wrong position in second breathing cycle (beam on area in yellow part) and black lines determine the phase window. (b) Predicted amplitude window with the same breathing pattern. (c) Beam-on time error with phase-based treatment in red area. (d) Beam-on higher and lower displacement error with amplitude-based treatment in brown and blue area, respectively

Click here to view

The actual and predicated gating window, calculated treatment range, and duty cycle are also calculated and compared.

Statistical analysis

The beam-on comparison between phase-based gating treatment and amplitude-based gating treatment with regular motion patterns was performed using Statistical Package for Social Sciences (SPSS), IBM Corporation, Chicago, IL, version 24. The Wilcoxon signed-rank test was used to analyzed difference in beam-on errors and P < 0.05 was considered statistically significant.

Gating time delay

To measure the linac time delay, the “Brainlab ET gating phantom” was irradiated with sinusoidal profiles of different time periods and 6 MV energy photon at 600 MU/min dose rate in multiple phase intervals such as 0%–25%, 25%–50%, 50%–75%, and 75%–100%. The RPM-generated breathing profiles were analyzed through the GUI, and during this work, it was assumed that the beam-on and beam-off lag time remain the same. The following formula is used for calculating time delay, which was used by Goharian and Khan[4] to find the time delay for CT simulator using RPM-generated motion profile.

Time delay = “Beam-on” time error × time interval in which the beam is to be on (sec)(3)

Irregular breathing pattern analysis

To evaluate the “beam-on” time and displacement errors, 10 patients' profiles were taken, in which five were used for inhale gating and the rest for exhale gating. These profiles could not be used in Brainlab ET gating as vxp format, so the first profiles were converted in CSV format using GUI program. The Brainlab ET gating phantom was irradiated using these irregular profiles in inhale and exhale levels with phase-based gating and amplitude-based gating.

   Results Top

Beam-on comparison

Beam-on error is divided into two types: (1) beam-on time error and (2) beam-on displacement error. These errors were calculated in inhale- and exhale-level irradiation for phase and amplitude window [Table 1]. The beam-on time errors of phase gating and amplitude gating were compared for inhale and exhale separately and similarly beam-on displacement errors were compared. There was no statistical difference in the beam-on time and displacement errors between phase-based gating and amplitude-based gating for regular motion profiles.
Table 1: Beam-on time error for phase-based and amplitude-based gating

Click here to view

Predicted versus actual amplitude and phase windows

The predicted amplitudes windows, which were generated from reference phase window in inhale- and exhale-level irradiation according to ITV margins for sine4, saw-tooth, and sinusoidal profiles, and actual amplitude windows, which were calculated from irradiated motion profiles of phase-based gating, are almost equal [Table 2]. The calculated phase window for amplitude-based gating and preset phase window for phase-based gating were almost equal for both profiles [Table 3].
Table 2: Predicted amplitude and actual amplitude widow comparison

Click here to view
Table 3: Preset phase windows for phase-based gating and calculated phase window for amplitude-based treatment comparison

Click here to view

Treatment range

The treatment ranges for sine4, saw-tooth, and sinusoidal profiles in inhale- and exhale-level irradiation for phase-based gating and amplitude-based gating are shown in [Table 4], which are almost equal.
Table 4: Treatment ranges for phase-based and amplitude-based gating

Click here to view

Duty cycle

Duty cycle is directly correlated with treatment time, means high duty cycle leads more beam-on time and less total treatment time. It is the ratio of the machine ON time in total breathing cycles to total breathing cycle time. This was again almost equal for both modes in inhale- and exhale-level irradiation [Table 5].
Table 5: Duty cycle for phase-based and amplitude-based gating

Click here to view

Time delay

Time delay was calculated for four different phase intervals with sinusoidal profile of 10 s cycle. The calculated average time delay at 600 MU/min was 47 ± 0.003 ms.

Irregular breathing analysis

In irregular breathing profile analysis, the machine lag time was excluded with the “beam-on” errors manually. It was observed that the beam-on errors in phase-based gating irradiation were more than amplitude-based gating [Figure 6], so the amplitude-based gating treatment is more accurate than phase-based gating treatment. The beam-on errors for phase-based and amplitude-based gating treatment are shown in [Table 6].
Figure 6: Analysis of the RPM-generated motion profile of Brainlab ET gating phantom with (a) phase-based gating and (b) amplitude-based gating irradiation with beam-on errors in red circles

Click here to view
Table 6: Irregular breathing profile analysis

Click here to view

   Discussion Top

The RPM system is one of the gating tools for motion management. With this tool, the duty cycle of gated treatment is lesser than normal treatment, so the overall treatment time is more. For the accurate treatment with this technique, there must be a strong correlation between tumor motion and respiratory cycle.[6],[10] With the help of 4DCT scan, we can establish a relationship between the phase of respiratory cycles and tumor motion.

In the present study, the GUI program is able to determine the amplitude window from phase window in inhale as well as exhale gating level using ITV margin. The calculated amplitude window in phase-based gating and predicted amplitude window for amplitude-based gating are almost equal. The calculated phase window in amplitude based treatment is nearly equal to the selected phase window in reference profile, but if the asymmetric phase window is selected to determine the amplitude window for treatment, for example, 90% to 20%, the calculated phase window for amplitude-based gating may not be the same as selected one. It does not have any significance as the treatment is being done in amplitude window calculated from best-fitted profile curve. The treatment range and duty cycle in both phase and amplitude-based treatment were almost equal, but duty cycle may vary with window selection.

For validation, the beam-on errors were calculated with regular phantom motion trace. The “beam-on” error in phase and amplitude-based treatment was ≤1.5% and there was no statistical significance. The beam-on time and displacement errors occur during the treatment due to the treatment time delay of linac with regular breathing profile.

However, the time delay is inherent to the machines, which affects the precision of treatment; therefore, the time delay should be considered in treatment planning process. Goharian and Khan[4] measured the time delay for CT simulator with two approaches: (1) with phantom and (2) with RPM-generated motion profile. In RPM motion profile approach, the authors directly calculated the time delay from difference between time in which machine was ON and time in which machine was to be ON. In similar manner, the ttlout data (indicates the beam-on position with respect to time and phase) were used to find out time delay in our study. The observed average time delay in our study was 47 ms. Tenn et al.[11] also reported the time delay of 60 ms for Novalis-Tx system using house-made phantom. Smith and Becker[12] reported the average time delay of 90 ms for three different linac systems. The difference in methodology played a role in different observation for time delay, as well as difference in linac model.

Thus, our breathing profile analysis program can be used to calculate the treatment time delay using regular breathing profile and gating phantom. If the patient breathing pattern is largely deviated from reference breathing profile, leading to more beam-on error, which can be quantified with this GUI, the patient can be advised for recoaching.

   Conclusion Top

In existing gating treatment techniques, the “beam-on” errors are unaccountable due to the lack of commercially available software. The developed program can be used as QA tool to detect and quantify the beam-on errors during phase-based as well as amplitude-based RPM gating treatment.

Financial support and sponsorship


Conflicts of interest

There are no conflicts of interest.

   References Top

Keall PJ, Mageras GS, Balter JM, Emery RS, Forster KM, Jiang SB, et al. The management of respiratory motion in radiation oncology report of AAPM Task Group 76. Med Phys 2006;33:3874-900.  Back to cited text no. 1
Beddar AS, Kainz K, Briere TM, Tsunashima Y, Pan T, Prado K, et al. Correlation between internal fiducial tumor motion and external marker motion for liver tumors imaged with 4D-CT. Int J Radiat Oncol Biol Phys 2007;67:630-8.  Back to cited text no. 2
Kubo HD, Len PM, Minohara S, Mostafavi H. Breathing-synchronized radiotherapy program at the University of California Davis cancer center. Med Phys 2000;27:346-53.  Back to cited text no. 3
Goharian M, Khan RF. Measurement of time delay for a prospectively gated CT simulator. J Med Phys 2010;35:123-7.  Back to cited text no. 4
[PUBMED]  [Full text]  
Rietzel E, Pan T, Chen GT. Four-dimensional computed tomography: Image formation and clinical protocol. Med Phys 2005;32:874-89.  Back to cited text no. 5
Lefebvre L, Doré M, Giraud P. New techniques and potential benefits for radiotherapy of lung cancer. Cancer Radiother 2014;18:473-9.  Back to cited text no. 6
Vedam S, Archambault L, Starkschall G, Mohan R, Beddar S. Determination of prospective displacement-based gate threshold for respiratory-gated radiation delivery from retrospective phase-based gate threshold selected at 4D CT simulation. Med Phys 2007;34:4247-55.  Back to cited text no. 7
Dunn L, Kenny J. A software platform for statistical evaluation of patient respiratory patterns in radiation therapy. Phys Med 2017;42:135-40.  Back to cited text no. 8
Shi C, Tang X, Chan M. Evaluation of the new respiratory gating system. Precis Radiat Oncol 2017;1:127-33.  Back to cited text no. 9
Vedam SS, Keall PJ, Kini VR, Mohan R. Determining parameters for respiration-gated radiotherapy. Med Phys 2001;28:2139-46.  Back to cited text no. 10
Tenn SE, Solberg TD, Medin PM. Targeting accuracy of an image guided gating system for stereotactic body radiotherapy. Phys Med Biol 2005;50:5443-62.  Back to cited text no. 11
Smith W, Becker N. Time delays and margins in gated radiotherapy. J Appl Clin Med Phys 2009;10:140-154.  Back to cited text no. 12


  [Figure 1], [Figure 2], [Figure 3], [Figure 4], [Figure 5], [Figure 6]

  [Table 1], [Table 2], [Table 3], [Table 4], [Table 5], [Table 6]


Print this article  Email this article


    Similar in PUBMED
   Search Pubmed for
   Search in Google Scholar for
 Related articles
    Article in PDF (1,511 KB)
    Citation Manager
    Access Statistics
    Reader Comments
    Email Alert *
    Add to My List *
* Registration required (free)  

    Materials and Me...
    Article Figures
    Article Tables

 Article Access Statistics
    PDF Downloaded58    
    Comments [Add]    

Recommend this journal