-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtime_series_to_kinematics_file.m
More file actions
74 lines (59 loc) · 2.48 KB
/
time_series_to_kinematics_file.m
File metadata and controls
74 lines (59 loc) · 2.48 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function time_series_to_kinematics_file(time, alpha, phi, theta, file, nfft)
%% time_series_to_kinematics_file(time, alpha, phi, theta, file, nfft)
%--------------------------------------------------------------------------
% from a given time series of the angles alpha, phi and theta, perform a
% Fourier approximation (i.e. it is possible to use less Fourier modes
% in order to apply smoothing), and write the Fourier coefficients to a
% kinematics file useable in FLUSI code.
%--------------------------------------------------------------------------
% INPUT:
% time, alpha, phi, theta: the time series of the angles to be approximated
% file: kinematics.in file to be written to
% nfft: 3x1 vector with the number of Fourier modes for the 3 angles. If
% all are zero, then we'll run interactive mode
% OUTPUT:
% written to the file "file" directly.
%--------------------------------------------------------------------------
mode='';
if (sum(nfft)==0)
mode='interactive';
end
if (max(alpha)<2*pi)
warning('max(alpha)<2*pi: maybe you gave me radiants? I need degrees!');
end
if (max(phi)<2*pi)
warning('max(phi)<2*pi: maybe you gave me radiants? I need degrees!');
end
if (max(theta)<2*pi)
warning('max(theta)<2*pi: maybe you gave me radiants? I need degrees!');
end
if (strcmp(mode,'interactive'))
%% decide nfft for alpha,phi,theta interactively
h=msgbox('determine nfft interactively for ALPHA'); uiwait(h);
nfft(1) = interactive_fourier_fit( time, alpha );
h=msgbox('determine nfft interactively for PHI'); uiwait(h);
nfft(2) = interactive_fourier_fit( time, phi );
h=msgbox('determine nfft interactively for THETA'); uiwait(h);
nfft(3) = interactive_fourier_fit( time, theta );
end
%% do the fourier approximation:
kine.nfft_alpha = nfft(1);
kine.nfft_phi = nfft(2);
kine.nfft_theta = nfft(3);
% get Fourier coefficients (by least squares fit)
[ai_alpha,bi_alpha] = Fseries (time, alpha,kine.nfft_alpha);
[ai_phi,bi_phi] = Fseries (time, phi, kine.nfft_phi);
[ai_theta,bi_theta] = Fseries (time, theta,kine.nfft_theta);
% store coefficients in a struct
kine.a0_alpha = ai_alpha(1);
kine.ai_alpha = ai_alpha(2:end);
kine.bi_alpha = bi_alpha;
kine.a0_phi = ai_phi(1);
kine.ai_phi = ai_phi(2:end);
kine.bi_phi = bi_phi;
kine.a0_theta = ai_theta(1);
kine.ai_theta = ai_theta(2:end);
kine.bi_theta = bi_theta;
% write to file - be happy!
write_kinematics_file(file, kine, 'kinematics file generated by time_series_to_kinematics_file' )
end