Commit 7bd874638204421dc61ac002be17f2203bd3efc3
1 parent
c4b4eae8c4
Exists in
master
allanplot.m: add save option
Showing 1 changed file with 9 additions and 0 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 | |
# fs : int or [int] sampling frequency | 11 | 11 | # fs : int or [int] sampling frequency | |
# gains : float or [float] gains to apply | 12 | 12 | # gains : float or [float] gains to apply | |
# ad_opt : int or [int] ad options : | 13 | 13 | # ad_opt : int or [int] ad options : | |
# 0 direct allan computation | 14 | 14 | # 0 direct allan computation | |
# 1 drift removed ad | 15 | 15 | # 1 drift removed ad | |
# 2 relative ad | 16 | 16 | # 2 relative ad | |
# 3 relative drift removed ad | 17 | 17 | # 3 relative drift removed ad | |
18 | # arg_save : [int] save adev with one file per column : | |||
19 | # 0 without save | |||
20 | # 1 save adev result to file-col.sig | |||
18 | 21 | |||
filename = argv(){1}; | 19 | 22 | filename = argv(){1}; | |
col = eval(argv(){2}); | 20 | 23 | col = eval(argv(){2}); | |
fs = eval(argv(){3}); | 21 | 24 | fs = eval(argv(){3}); | |
mult = eval(argv(){4}); | 22 | 25 | mult = eval(argv(){4}); | |
ad_opt = eval(argv(){5}); | 23 | 26 | ad_opt = eval(argv(){5}); | |
27 | arg_save = eval(argv(){6}); | |||
24 | 28 | |||
if length(col) == length(mult) | 25 | 29 | if length(col) == length(mult) | |
figure | 26 | 30 | figure | |
hold all | 27 | 31 | hold all | |
grid on | 28 | 32 | grid on | |
cc = 'bkcgmry'; | 29 | 33 | cc = 'bkcgmry'; | |
for i = [1:length(col)] | 30 | 34 | for i = [1:length(col)] | |
data.freq = load(filename)(:,col(i)).*mult(i); | 31 | 35 | data.freq = load(filename)(:,col(i)).*mult(i); | |
if nargin == 5 | 32 | 36 | if nargin == 5 | |
if ad_opt(i) == 1 | 33 | 37 | if ad_opt(i) == 1 | |
printf(strcat(filename, ' col', num2str(col(i)), ' drift removed\n\n')) | 34 | 38 | printf(strcat(filename, ' col', num2str(col(i)), ' drift removed\n\n')) | |
data.freq = detrend(data.freq); | 35 | 39 | data.freq = detrend(data.freq); | |
elseif ad_opt(i) == 2 | 36 | 40 | elseif ad_opt(i) == 2 | |
printf(strcat(filename, ' col', num2str(col(i)), ' relative ad : mean=', num2str(mean(data.freq)), '\n\n')) | 37 | 41 | printf(strcat(filename, ' col', num2str(col(i)), ' relative ad : mean=', num2str(mean(data.freq)), '\n\n')) | |
data.freq = data.freq./mean(data.freq); | 38 | 42 | data.freq = data.freq./mean(data.freq); | |
elseif ad_opt(i) == 3 | 39 | 43 | elseif ad_opt(i) == 3 | |
printf(strcat(filename, ' col', num2str(col(i)), ' drift removed relative ad\n\n')) | 40 | 44 | printf(strcat(filename, ' col', num2str(col(i)), ' drift removed relative ad\n\n')) | |
data.freq = detrend(data.freq./mean(data.freq)); | 41 | 45 | data.freq = detrend(data.freq./mean(data.freq)); | |
end | 42 | 46 | end | |
endif | 43 | 47 | endif | |
data.rate = fs(i); | 44 | 48 | data.rate = fs(i); | |
[ad, S, err, tau] = allan(data, horzcat(reshape([1:0.1:9]'.*10.^[0:round(log10(length(data.freq)))-1],1,[]), 10^(round(log10(length(data.freq)))-1))./data.rate, strcat(strsplit(filename, '/'){end}, num2str(i)), 0); | 45 | 49 | [ad, S, err, tau] = allan(data, horzcat(reshape([1:0.1:9]'.*10.^[0:round(log10(length(data.freq)))-1],1,[]), 10^(round(log10(length(data.freq)))-1))./data.rate, strcat(strsplit(filename, '/'){end}, num2str(i)), 0); | |
loglogerr(tau, ad, err, strcat(cc(mod(i, length(cc))), '-s')) | 46 | 50 | loglogerr(tau, ad, err, strcat(cc(mod(i, length(cc))), '-s')) | |
leg{i} = strcat(filename, ' col', num2str(col(i))); | 47 | 51 | leg{i} = strcat(filename, ' col', num2str(col(i))); | |
axis(10.^ceil(log10([tau(1), tau(end)]))) | 48 | 52 | axis(10.^ceil(log10([tau(1), tau(end)]))) | |
hold on | 49 | 53 | hold on | |
54 | if arg_save ==1 | |||
55 | filenameout = strcat(strsplit(filename,'.'){1},'-',num2str(col(i)),'.sig') | |||
56 | datatosave = horzcat(tau', ad', err'); | |||
57 | save('-ascii', filenameout , 'datatosave'); | |||
58 | end | |||
end | 50 | 59 | end | |
legend(leg) | 51 | 60 | legend(leg) |