-
Notifications
You must be signed in to change notification settings - Fork 1
/
inv_spharmonic_tran_s2kit.m
51 lines (44 loc) · 1.34 KB
/
inv_spharmonic_tran_s2kit.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
39
40
41
42
43
44
45
46
47
48
49
50
51
function samples = inv_spharmonic_tran_s2kit(alm, bw, directory)
%INV_SPHARMONIC_TRAN_S2KIT Inverse spherical harmonic transform, a wrapper of
%test_s2_semi_memo_inv.
%
% samples = inv_spharmonic_tran_s2kit(alm, bw, directory);
%
% Inputs:
% alm: the spherical harmonic coefficients. It is a bw-by-(2*bw-1) matrix.
% The entry in the i-th row and the j-th column is the spherical harmonic
% coefficient with l=i-1, m=j-bw.
% bw: the bandwidth of the bandlimited function.
% directory: the directory where you put S2Kit, e.g.,
% /path/to/directory/s2kit10.
%
% Outputs:
% samples: f(\theta_0, \phi_0), f(\theta_0, \phi_1),...
%
% Written by Minjie Fan, 2015
% open the file
fid = fopen('coefs.dat', 'w');
% write to the file
for m = 0:bw-1
for l = m:bw-1
fprintf(fid, '%.15f\n', real(alm(l+1, m+bw)));
fprintf(fid, '%.15f\n', imag(alm(l+1, m+bw)));
end
end
for m = 1-bw:-1
for l = (-m):bw-1
fprintf(fid, '%.15f\n', real(alm(l+1, m+bw)));
fprintf(fid, '%.15f\n', imag(alm(l+1, m+bw)));
end
end
% close the file
fclose(fid);
% inverse spherical harmonic transform
system([directory, '/test_s2_semi_memo_inv', ' coefs.dat samples.dat ', num2str(bw)]);
% remove the file
system('rm coefs.dat');
% obtain the samples
tmp = textread('samples.dat');
samples = tmp(1:2:end);
system('rm samples.dat');
end