problem with MATLAB unwrap() function ?

조회 수: 15 (최근 30일)
Swapnil Prabhudesai
Swapnil Prabhudesai 2017년 7월 13일
편집: David Goodmanson 2017년 7월 14일
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.

채택된 답변

David Goodmanson
David Goodmanson 2017년 7월 14일
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
Swapnil Prabhudesai
Swapnil Prabhudesai 2017년 7월 14일
편집: Swapnil Prabhudesai 2017년 7월 14일
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 2017년 7월 14일
편집: David Goodmanson 2017년 7월 14일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by