4
The Matlab code to unwrap
(
)
is shown below.
%Unwrap the signal xw(n)
xu = xw;
for i=2:length(xw)
difference = xw(i)-xw(i-1);
if difference > pi
xu(i:end) = xu(i:end) - 2*pi;
elseif difference < -pi
xu(i:end) = xu(i:end) + 2*pi;
end
end
figure, plot(xu)
xlabel('Sample index')
ylabel('Unwrapped phase in radians')
axis([0 512 -6.5 6.5])
title('The unwrapped phase')
We can express the unwrapping process mathematically as,
(
)
=
[
(
)
]
=
(
)
+ 2
Where [ ]is the phase unwrapping operation,
(
)
is the unwrapped phase signal and is an
integer.
The wrapped phase signal that is shown in Figure 2(a) is a very simple signal to unwrap. This is
because
(
)
is a simulated signal that does not contain any noise, and also because the sampling
rate is sufficiently high here, as we have 512 samples per period.
Phase unwrapping for practical real-world applications is actually one of the most challenging tasks
in digital signal processing. This is because of two main reasons, which are;
1. The wrapped signal may be noisy
2. The wrapped signal may be under sampled.
We will discuss these two cases in detail below;
As we have explained previously, in order to perform the phase unwrapping process, the difference
between a sample and the preceding sample (directly adjacent on its left) is calculated. When this
difference is larger than +π, or smaller than -π, a phase wrap is detected. Once a phase wrap is
detected, the value of 2π is either added, or subtracted, to/from this sample and also from all the
further samples to the right-hand side of it. Now consider that the phase wrap that has just been
detected can be either a ‘genuine phase wrap’, or might also be a ‘fake wrap’ that has been
produced by noise in the signal. It is this distinction between true phase wraps and apparent phase
wraps that have been caused by noise that make the practical phase unwrapping problem such a
challenging task. The four wraps that were shown in Figure 1(b) are all genuine phase wraps. Now
consider the wrapped phase signal that is shown in Figure 4(a). This signal contains four genuine
phase wraps and one fake wrap.
In the case where a genuine wrap has been detected, the phase unwrapping process continues its
operation successfully. The existence of a fake wrap will affect the unwrapping of the sample where