Hilbert transform for instantaneous phase when time data does not begin at zero

19 views (last 30 days)
I have a simple cosine function and would like to extract the instantaneous phase. I am taking a Hilbert transform and computing the unwrapped angle of the analytic function. When my independent data begins at zero, the instantaneous phase matches the true phase. Unfortunately, my independent series cannot begin at zero for my experiment as it is a spatial frequency. When I compute the instantaneous phase from data where the series begins elsewhere, the phase profile is correct, but there is a DC shift in the phase.
How can I correct for this error due to my start position? Thanks!
clc; clear; close;
N = 10000;
t = linspace(0, 100, N);
f = 100;
phase = 2*t*f;
y = cos(phase);
Hy = hilbert(y);
Hphase = unwrap(angle(Hy));
plot(t, phase, t, Hphase, 'o')
  1 Comment
Philippe Strauss
Philippe Strauss on 12 Nov 2022
Foremost, beware that those hilbert functions in matlab and python's scipy are true / accurate on periodic / cyclic definitions of your input signal, in other words it will gives you gibb's phenomenon on non carefully windowed signals.
I'm willing to help you, but my matlab broke the other day, could you translate your matlab code to python numpy/scipy please?

Sign in to comment.

Answers (1)

charan
charan on 18 Jun 2025
Hi,
The DC offset you're observing in the instantaneous phase is due to the initial phase of the signal. This occurs because the Hilbert transform assumes the first sample corresponds to time t=0. If your actual signal doesn't start at t=0, the phase value at the first sample reflects the phase that the signal has at that offset point.
In the case of a cosine, this phase offset corresponds to the phase due to the time shift between your first sample and the true origin. To correct for this, you can subtract the instantaneous phase at the first sample, effectively removing the DC offset and aligning your phase to what it would be if the signal had started at t=0.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!