Biological time-series analysis is used to identify hidden dynamical patterns which could yield important insights into underlying physiological mechanisms. Such analysis is complicated by the fact that biological signals are typically both highly irregular and non-stationary, that is, their statistical character changes slowly or intermittently as a result of variations in background influences. Previous statistical analyses of heartbeat dynamics have identified long-range correlations and power-law scaling in the normal heartbeat, but not the phase interactions between the different frequency components of the signal. Here we introduce a new approach, based on the wavelet transform and an analytic signal approach, which can characterize non-stationary behaviour and elucidate such phase interactions. We find that, when suitably rescaled, the distributions of the variations in the beat-to-beat intervals for all healthy subjects are described by a single function stable over a wide range of timescales. However, a similar scaling function does not exist for a group with cardiopulmonary instability caused by sleep apnoea. We attribute the functional form of the scaling observed in the healthy subjects to underlying nonlinear dynamics, which seem to be essential to normal heart function. The approach introduced here should be useful in the analysis of other nonstationary biological signals.