Purpose: To develop a computerized method for reliable peak (end inspiration) and valley (end expiration) detection in respiratory waveforms for gated radiotherapy and 4D CT. Method and Materials: A computerized method for peak (end inspiration) and valley (end expiration) detection in respiratory waveforms without flow measurement is described. The respiratory period T was estimated by applying a Fast Fourier Transform. The intercepts of the respiratory waveform with a moving average curve were determined with an averaging width of 2T. Peaks and valleys were defined respectively as the maximum and minimum between pairs of interwoven intercepts. While this method worked well the majority of the time, both automatic corrections and manual user interventions were employed to correct errors and adjust the results. Results: The method was implemented in MATLAB on a PC with a 3.0 GHz Pentium IV CPU and 2.0 GB RAM. On average, the respiratory waveform was 575.3 s long and contained a total of 307 peaks and valleys. For each patient, 99% of all peaks and valleys were correctly located by the automatic algorithm in 2.8 s. Only three (1%) points required manual user adjustment. A user spent 66.8 s for reviewing, and manually adding or deleting points. For nine of the 20 patients, all peaks and valleys were automatically detected. The high efficiency of the automatic algorithm is clear. Conclusion: The results demonstrated that this method was reliable and efficient for peak detection in respirator waveforms with noise and large variations in baseline level, amplitude and period.