I’m wondering what is the best algorithm for unwrapping phase of a signal whose data type is single (float) that posess the least sensitivity to roundoff error. In my application I need to compute the instantaneous frequency from the unwrapped phase. For example, just for the sake of illustration, lets consider a simple sinusoid at 200 Hz that is sampled at a rate 2000 Hz. I used the code below to compute the instantaneous unwrapped phase
fs = 2000; % sample rate f0 = 200; % carrier frequency T = 32; % duration, the higher T, the more roundoff noise is acrrued t = (single(0):1/fs:T)'; x = cos(*pi*f0*t); xhilb = hilbert(x); xangl = angle(xhilb); puwrp = unwrap(xangl); And then from puwrp, the instantaneous frequency is computed as below
finst = (fs/(2*pi))*diff(puwrp); The $l_\infty$ of the error f0-finst is on the order of 40 Hz.
norm(f0-finst,inf) ans = single 40.8451 Based on a simple perturbation analysis, the culprit dwells in the unwrapping algorithm which has a perturbation gain of 4096!.
theta = xangl; puwrp = unwrap(theta); % Add perturbation (numerically theta and dtheta are the same) dtheta = theta + eps(theta)/2; dpuwrp = unwrap(dtheta); norm(puwrp-dpuwrp,inf)/norm(theta-dtheta,inf) ans = single 4096 ```