Commit b25b94030b78cee35878078f152443520fb60a5c
1 parent
419afee41d
Exists in
master
add fs arg and replace spaces with tabs
Showing 1 changed file with 9 additions and 7 deletions Inline Diff
allanplot.m
#!/usr/bin/octave-cli --persist | 1 | 1 | #!/usr/bin/octave-cli --persist | |
2 | 2 | |||
# allanplot.m computes Allan deviation from temporal dataset | 3 | 3 | # allanplot.m computes Allan deviation from temporal dataset | |
# | 4 | 4 | # | |
# use : allanplot.m file.dat column_i gain_i ad_opt | 5 | 5 | # use : allanplot.m file.dat column_i gain_i ad_opt | |
# allanplot.m file.dat [column_i,column_j] [gain_i,gain_j] [ad_opt_i,ad_opt_j] | 6 | 6 | # allanplot.m file.dat [column_i,column_j] [gain_i,gain_j] [ad_opt_i,ad_opt_j] | |
# | 7 | 7 | # | |
# inputs: | 8 | 8 | # inputs: | |
# file.dat : [string] file to load | 9 | 9 | # file.dat : [string] file to load | |
# columns : int or [int] columns to load | 10 | 10 | # columns : int or [int] columns to load | |
11 | # fs : int or [int] sampling frequency | |||
# gains : float or [float] gains to apply | 11 | 12 | # gains : float or [float] gains to apply | |
# ad_opt : int or [int] ad options : | 12 | 13 | # ad_opt : int or [int] ad options : | |
# 0 direct allan computation | 13 | 14 | # 0 direct allan computation | |
# 1 drift removed ad | 14 | 15 | # 1 drift removed ad | |
# 2 relative ad | 15 | 16 | # 2 relative ad | |
# 3 relative drift removed ad | 16 | 17 | # 3 relative drift removed ad | |
17 | 18 | |||
filename = argv(){1}; | 18 | 19 | filename = argv(){1}; | |
col = eval(argv(){2}); | 19 | 20 | col = eval(argv(){2}); | |
mult = eval(argv(){3}); | 20 | 21 | fs = eval(argv(){3}); | |
ad_opt = eval(argv(){4}); | 21 | 22 | mult = eval(argv(){4}); | |
23 | ad_opt = eval(argv(){5}); | |||
22 | 24 | |||
if length(col) == length(mult) | 23 | 25 | if length(col) == length(mult) | |
figure | 24 | 26 | figure | |
hold all | 25 | 27 | hold all | |
grid on | 26 | 28 | grid on | |
cc = 'bkcgmry'; | 27 | 29 | cc = 'bkcgmry'; | |
for i = [1:length(col)] | 28 | 30 | for i = [1:length(col)] | |
data.freq = load(filename)(:,col(i)).*mult(i); | 29 | 31 | data.freq = load(filename)(:,col(i)).*mult(i); | |
if nargin == 4 | 30 | 32 | if nargin == 4 | |
if ad_opt(i) == 1 | 31 | 33 | if ad_opt(i) == 1 | |
printf(strcat(filename, ' col', num2str(col(i)), ' drift removed\n\n')) | 32 | 34 | printf(strcat(filename, ' col', num2str(col(i)), ' drift removed\n\n')) | |
data.freq = detrend(data.freq); | 33 | 35 | data.freq = detrend(data.freq); | |
elseif ad_opt(i) == 2 | 34 | 36 | elseif ad_opt(i) == 2 | |
printf(strcat(filename, ' col', num2str(col(i)), ' relative ad : mean=', num2str(mean(data.freq)), '\n\n')) | 35 | 37 | printf(strcat(filename, ' col', num2str(col(i)), ' relative ad : mean=', num2str(mean(data.freq)), '\n\n')) | |
data.freq = data.freq./mean(data.freq); | 36 | 38 | data.freq = data.freq./mean(data.freq); | |
elseif ad_opt(i) == 3 | 37 | 39 | elseif ad_opt(i) == 3 | |
printf(strcat(filename, ' col', num2str(col(i)), ' drift removed relative ad\n\n')) | 38 | 40 | printf(strcat(filename, ' col', num2str(col(i)), ' drift removed relative ad\n\n')) | |
data.freq = detrend(data.freq./mean(data.freq)); | 39 | 41 | data.freq = detrend(data.freq./mean(data.freq)); | |
end | 40 | 42 | end | |
endif | 41 | 43 | endif | |
data.rate = 1; | 42 | 44 | data.rate = fs(i); | |
[ad, S, err, tau] = allan(data, 2.^[0:nextpow2(length(data.freq))-3]./data.rate, strcat(strsplit(filename, '/'){end}, num2str(i)), 0); | 43 | 45 | [ad, S, err, tau] = allan(data, 2.^[0:nextpow2(length(data.freq))-3]./data.rate, strcat(strsplit(filename, '/'){end}, num2str(i)), 0); | |
loglogerr(tau, ad, err, strcat(cc(mod(i, length(cc))), '-s')) | 44 | 46 | loglogerr(tau, ad, err, strcat(cc(mod(i, length(cc))), '-s')) | |
leg{i} = strcat(filename, ' col', num2str(col(i))); | 45 | 47 | leg{i} = strcat(filename, ' col', num2str(col(i))); | |
axis(10.^ceil(log10([tau(1), tau(end)]))) | 46 | 48 | axis(10.^ceil(log10([tau(1), tau(end)]))) | |
hold on | 47 | 49 | hold on | |
end | 48 | 50 | end | |
legend(leg) | 49 | 51 | legend(leg) | |
input("Press to continue..."); | 50 | 52 | input("Press to continue..."); | |
end | 51 | 53 | end | |
exit | 52 | 54 | exit | |
53 | 55 | |||