-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimaxsmsphi.m
38 lines (32 loc) · 892 Bytes
/
minimaxsmsphi.m
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
33
34
35
36
37
38
function [ phir,maxerror ] = minimaxsmsphi( mb,idc,Mxy,z)
% 11/08/2016
% A function that, given a multiband factor, passband indices, slice
% profile and space vector z (on which Mxy is defined) finds the rewind
% area to minimise the maximum phase difference across all the slices
% sas
% 22/03/18 Minimize std directly.
cost = @(phir) nestfun(phir);
phir0 = 1;
phir = fminsearch(cost,phir0);
if 0
figure;
plot(z,abs(Mxy),'b');
hold on;
scatter(z(idc),abs(Mxy(idc)),'r');
dum = 1;
end
maxerror = nestfun(phir);
function maxerr = nestfun(phir)
maxerr = 0;
for i = 1:mb
psb = idc(2*i-1):idc(2*i);
phs = unwrap(angle(Mxy(psb).* exp(-1i*phir*z(psb))));
% err = max ( abs( phs - mean(phs) ) );
% 22/03/18 Minimize std directly.
err = max ( std(phs) );
if err > maxerr
maxerr = err;
end
end
end
end