Commit 9a89127b6634c580711b11e1db8264ccc69d971c
1 parent
7ec25ad9fc
Exists in
master
fix nargin
Showing 1 changed file with 10 additions and 12 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 | |
# arg_save : [int] save adev with one file per column : | 18 | 18 | # arg_save : [int] save adev with one file per column : | |
# 0 without save | 19 | 19 | # 0 without save | |
# 1 save adev result to file-col.sig | 20 | 20 | # 1 save adev result to file-col.sig | |
21 | 21 | |||
filename = argv(){1}; | 22 | 22 | filename = argv(){1}; | |
col = eval(argv(){2}); | 23 | 23 | col = eval(argv(){2}); | |
fs = eval(argv(){3}); | 24 | 24 | fs = eval(argv(){3}); | |
mult = eval(argv(){4}); | 25 | 25 | mult = eval(argv(){4}); | |
ad_opt = eval(argv(){5}); | 26 | 26 | ad_opt = eval(argv(){5}); | |
arg_save = eval(argv(){6}); | 27 | 27 | arg_save = eval(argv(){6}); | |
28 | 28 | |||
if length(col) == length(mult) | 29 | 29 | if length(col) == length(mult) | |
figure | 30 | 30 | figure | |
hold all | 31 | 31 | hold all | |
grid on | 32 | 32 | grid on | |
cc = 'bkcgmry'; | 33 | 33 | cc = 'bkcgmry'; | |
for i = [1:length(col)] | 34 | 34 | for i = [1:length(col)] | |
data.freq = load(filename)(:,col(i)).*mult(i); | 35 | 35 | data.freq = load(filename)(:,col(i)).*mult(i); | |
if nargin == 5 | 36 | 36 | if ad_opt(i) == 1 | |
if ad_opt(i) == 1 | 37 | 37 | printf(strcat(filename, ' col', num2str(col(i)), ' drift removed\n\n')) | |
printf(strcat(filename, ' col', num2str(col(i)), ' drift removed\n\n')) | 38 | 38 | data.freq = detrend(data.freq); | |
data.freq = detrend(data.freq); | 39 | 39 | elseif ad_opt(i) == 2 | |
elseif ad_opt(i) == 2 | 40 | 40 | printf(strcat(filename, ' col', num2str(col(i)), ' relative ad : mean=', num2str(mean(data.freq)), '\n\n')) | |
printf(strcat(filename, ' col', num2str(col(i)), ' relative ad : mean=', num2str(mean(data.freq)), '\n\n')) | 41 | 41 | data.freq = data.freq./mean(data.freq); | |
data.freq = data.freq./mean(data.freq); | 42 | 42 | elseif ad_opt(i) == 3 | |
elseif ad_opt(i) == 3 | 43 | 43 | printf(strcat(filename, ' col', num2str(col(i)), ' drift removed relative ad\n\n')) | |
printf(strcat(filename, ' col', num2str(col(i)), ' drift removed relative ad\n\n')) | 44 | 44 | data.freq = detrend(data.freq./mean(data.freq)); | |
data.freq = detrend(data.freq./mean(data.freq)); | 45 | 45 | end | |
end | 46 | |||
endif | 47 | |||
data.rate = fs(i); | 48 | 46 | 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); | 49 | 47 | [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')) | 50 | 48 | loglogerr(tau, ad, err, strcat(cc(mod(i, length(cc))), '-s')) | |
leg{i} = strcat(filename, ' col', num2str(col(i))); | 51 | 49 | leg{i} = strcat(filename, ' col', num2str(col(i))); | |
axis(10.^ceil(log10([tau(1), tau(end)]))) | 52 | 50 | axis(10.^ceil(log10([tau(1), tau(end)]))) | |
hold on | 53 | 51 | hold on | |
if arg_save ==1 | 54 | 52 | if arg_save ==1 | |
filenameout = strcat(strsplit(filename,'.'){1},'-',num2str(col(i)),'.sig') | 55 | 53 | filenameout = strcat(strsplit(filename,'.'){1},'-',num2str(col(i)),'.sig') | |
datatosave = horzcat(tau', ad', err'); | 56 | 54 | datatosave = horzcat(tau', ad', err'); | |
save('-ascii', filenameout , 'datatosave'); | 57 | 55 | save('-ascii', filenameout , 'datatosave'); | |
end | 58 | 56 | end | |
end | 59 | 57 | end | |
legend(leg) | 60 | 58 | legend(leg) | |
input("Press to continue..."); | 61 | 59 | input("Press to continue..."); | |
end | 62 | 60 | end | |
exit | 63 | 61 | exit | |
64 | 62 | |||