forked from sgarrettroe/data_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadTestStability.m
64 lines (57 loc) · 1.47 KB
/
loadTestStability.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
52
53
54
55
56
57
58
59
60
61
62
63
64
function s = loadTestStability(fname,varargin)
step = 1; %number of beam pairs
t_per_scan = 1;
t_units = 'min';
while length(varargin)>=2
arg = varargin{1};
val = varargin{2};
switch lower(arg)
case {'step','npairs','n_pairs'}
step = val;
case {'time','t','t_per_scan'}
t_per_scan = val;
case {'time_units','t_units'}
t_units = val;
otherwise
error(['loadStabilityTest: unknown option ',arg])
end
varargin = varargin(3:end);
end
if exist(fname,'file')
dummy = load(fname);
elseif exist([fname '.dat'],'file')
dummy = load([fname '.dat']);
else
error(['Could not find file ' fname ' or ' fname '.dat'])
end
freq = dummy(1,:);
n_freq = length(freq);
scans = cell(1,step);
for i = 1:step
scans{i} = dummy(1+i:step:end,:);
end
n_scans = size(scans{1},1);
t = (0:n_scans-1)*t_per_scan;
if step >1, warning('the rest of this only works for one pair right now...'),end
figure(1),clf
plot(freq,scans{1}','k')
set(gcf,'windowstyle','docked')
s_hat = fft(scans{1},[],2);
mag = abs(s_hat);
ang = angle(s_hat);
mag(:,1)=0;
mag(:,2)=0;
mag(:,3)=0;
[dummy,ind] = max(mag(1,1:floor(n_freq/2)));
%ind = 5;
dev = (unwrap(ang(:,ind)) - ang(1,5));
%dev = unwrap(dev);
dev =dev*180/pi;
dev3 = dev;
rms_dev3 = std(dev);
figure(4),clf
plot(t,dev3-dev3(1),'ko');
title(['Phase stability of 3D setup ' fname])
ylabel('Phase deviation / deg')
xlabel(['t / ' t_units])
set(gcf,'windowstyle','docked')