-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriedelPhaseRandom.m
More file actions
33 lines (27 loc) · 938 Bytes
/
friedelPhaseRandom.m
File metadata and controls
33 lines (27 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function PhaseFridRand = friedelPhaseRandom(phaseSize,flag)
%********************************************************************
%Creat an random phase array to an array which satisfy Friedel's law
%*********************************************************************
phase = rand(phaseSize).*2*pi;
dimNum = length(phaseSize);
switch dimNum
case 1
objFlip = flip(phase,1);
case 2
objFlip = flip(flip(phase,1),2);
case 3
objFlip = flip(flip(flip(phase,1),2),3);
otherwise
fprintf('Invalid dimension\n');
end
PhaseFridRand1 = phase - objFlip;
% The center of phi(000) is in the middle of array "PhaseFridRand" which is
% 0. And I always assume the dimension sizes are odd
switch flag
case 'centered'
PhaseFridRand = PhaseFridRand1;
case 'cornered'
PhaseFridRand = ifftshift(PhaseFridRand1);
otherwise
PhaseFridRand = ifftshift(PhaseFridRand1);
end