problem with MATLAB unwrap() function ?
11 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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 件のコメント
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

