problem with MATLAB unwrap() function ?

12 visualizzazioni (ultimi 30 giorni)
Hi,
Step 1: I created a 2D phase function.
x = -1:1/128:1-(1/128);
[X,Y] = meshgrid(x,x);
phi = 3*pi*X.^2 + 3*pi*Y.^2;
Step 2: I wrapped it from -pi tp +pi.
wrapped_phi = phi; % copy phase to another 2D array
for vrt = 1:1:256
for hrz = 1:1:256
x = phi(vrt,hrz);
if (x > pi)
k = round(x/(2*pi));
x = x - k*(2*pi);
wrapped_phi(vrt,hrz) = x;
end
if (x < -pi)
k = round(abs(x)/(2*pi));
x = x + k*(2*pi);
wrapped_phi(vrt,hrz) = x;
end
end
end
Step 3: I used MATLAB unwrap() function.
But I did not get same phase function.
Phase values also are different (please see colorbars).
figure
imagesc(unwrap(wrapped_phi));colorbar; title('Using MATLAB unwrap function')
Why ?
Please see attached jpg images (which are outcomes of the above code snippets).
Any help will be appreciated.

Risposta accettata

David Goodmanson
David Goodmanson il 14 Lug 2017
Hello Swapnil, like many Matlab functions, for 2d arrays unwrap works down the columns only unless told otherwise. You need to unwrap in both dimensions, so try
imagesc(unwrap(unwrap(wrapped_phi,[],2),[],1));
which works, although there may be some luck involved.
  2 Commenti
Swapnil Prabhudesai
Swapnil Prabhudesai il 14 Lug 2017
Modificato: Swapnil Prabhudesai il 14 Lug 2017
Thanks. It worked. But as you said is there really a luck factor(!), because, as you see in the attached images below, each pixel value (or phase value) after unwrapping is decreased by the same constant factor? Difference between true phase and unwrapped phase is a constant 2D function. Why is this so ?
And here is difference between true phase and unwrapped phase:
David Goodmanson
David Goodmanson il 14 Lug 2017
Modificato: David Goodmanson il 14 Lug 2017
Hi Swapnil,
Your original function goes from 0 at the center to 6 pi at any corner, or close to it. The wrapped function takes away the 6 pi and is close to 0 at the corners. Unwrap starts counting up phase beginning at the edges and starts out with those small values. The net result is that unwrap ends up with close to 0 at the corners and -6 pi at the center.
The net change from center to corner is the same in both cases, + 6 pi, which is correct. So the constant difference you are seeing is 6 pi = 18.8496. I am beginning to suspect that the answer is due less to luck than I thought.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by