Online bearing fault diagnosis is still a challenge in real applications because of the complex modulation features and the nonstationary conditions. To realize the online fault diagnosis, a method robust to speed fluctuation and background noise is necessary. In this paper, an iterative generalized demodulation with tunable energy factor (IGDTEF) is proposed, which can map the time-varying trajectories of interest components to their corresponding energy factors. To exploit it in the online fault diagnosis, a phase function estimation strategy is further developed. First, the optimal frequency band of the raw signal is identified by fast kurtogram and then a bandpass filter is designed to separate the impulsive component. Second, Hilbert transform and short-time Fourier transform are applied to the filtered signal jointly obtaining the envelope time-frequency representation (TFR). Then, the instantaneous fault characteristic frequency (IFCF) is estimated roughly by applying an amplitude-sum-based peak search to the TFR. Next, the phase functions of the IFCF, the potential modulation rotating frequency, and their harmonics are calculated. Finally, the IGDTEF is performed to the filtered signal and then fast Fourier transform is applied to the demodulated signal generating the demodulation spectrum. The effectiveness of the method is evaluated by simulated and experimental data.