diff --git a/sim_fft-adev/ad_cov.m b/sim_fft-adev/ad_cov.m new file mode 100644 index 0000000..b53ef0a --- /dev/null +++ b/sim_fft-adev/ad_cov.m @@ -0,0 +1,38 @@ +clear all +close all +clc + +N = 1e5; +Ts = 1; + +dc.rate = Ts; +d1.rate = Ts; +d2.rate = Ts; +dd.rate = Ts; + +r = 10; + +com = noise(N, 1, 'brown'); +n1 = r.*noise(N, 1, 'brown'); +n2 = r.*noise(N, 1, 'brown'); + +dc.freq = com; +d1.freq = com.+n1; +d2.freq = com.+n2; +dd.freq = d1.freq; +dd.freq2 = d2.freq; + +[ad_dc, S, err_dc, tau_dc] = allan(dc,2.^[0:20],'dc',0); +[ad_d1, S, err_d1, tau_d1] = allan(d1,2.^[0:20],'d1',0); +[ad_d2, S, err_d2, tau_d2] = allan(d2,2.^[0:20],'d2',0); +[ad_dd, S, err_dd, tau_dd] = allan_cov(dd,2.^[0:20],'dd',0); + +figure +hold on +loglogerr(tau_dc, ad_dc, err_dc, 'mo') +loglogerr(tau_d1, ad_d1, err_d1, 'b') +loglogerr(tau_d2, ad_d2, err_d2, 'r') +loglogerr(tau_dd, ad_dd, err_dd, 'k') +grid on + +ad_dd./ad_dc diff --git a/sim_fft-adev/adev_averaging.m b/sim_fft-adev/adev_averaging.m new file mode 100644 index 0000000..3594bff --- /dev/null +++ b/sim_fft-adev/adev_averaging.m @@ -0,0 +1,36 @@ +clc +close all +clear all + +Ts = 0.2; +N = 1e6; +D = 5; + +data_raw.rate = 1/Ts; +data_raw.freq = 1/2.*noise(N, 1, 'white') + 1.*noise(N, 1, 'pink') + 1.*noise(N, 1, 'brown') + 0e-8.*[0:N-1]'; +t_raw = [0:length(data_raw.freq)-1]; +[ad_raw, S, err_raw, tau_raw] = allan(data_raw, 2.^[0:20].*Ts, 'raw',0); + +data_avg.rate = 1/(Ts*D); +data_avg.freq = mean(reshape(data_raw.freq', [D, N/D]))'; +t_avg = D.*[1:length(data_avg.freq)]; +[ad_avg, S, err_avg, tau_avg] = allan(data_avg, 2.^[0:20].*Ts*D, 'avg',0); + +data_decim.rate = 1/(Ts*D); +data_decim.freq = reshape(data_raw.freq', [D, N/D])(1,:)'; +t_decim = D.*[0:length(data_decim.freq)-1]; +[ad_decim, S, err_decim, tau_decim] = allan(data_decim, 2.^[0:20].*Ts*D, 'decim',0); + +figure +hold on +loglogerr(tau_raw, ad_raw, err_raw, 'b') +loglogerr(tau_decim, ad_decim, err_decim, 'm') +loglogerr(tau_avg, ad_avg, err_avg, 'r') +grid on + +figure +hold on +plot(t_raw, data_raw.freq, 'b') +plot(t_decim, data_decim.freq, 'm') +plot(t_avg, data_avg.freq, 'r') +grid on diff --git a/sim_fft-adev/adev_tf.m b/sim_fft-adev/adev_tf.m new file mode 100644 index 0000000..0884e19 --- /dev/null +++ b/sim_fft-adev/adev_tf.m @@ -0,0 +1,62 @@ +clc +close all +clear all + +%% + +N = 1e5; +G = tf(1, [1e3,1]); + +%% + +data_white.rate = 1; +data_white.freq = noise(N, 1, 'white'); +[ad_white, S, err_white, tau] = allan(data_white, 2.^[0:20], 'white noise',0); + +data_white_f.rate = 1; +data_white_f.freq = lsim(G, data_white.freq, 1:length(data_white.freq)); +[ad_white_f, S, err_white_f, tau] = allan(data_white_f, 2.^[0:20], 'white noise filtered',0); + +%% + +data_pink.rate = 1; +data_pink.freq = noise(N, 1, 'pink'); +[ad_pink, S, err_pink, tau] = allan(data_pink, 2.^[0:20], 'pink noise',0); + +data_pink_f.rate = 1; +data_pink_f.freq = lsim(G, data_pink.freq, 1:length(data_pink.freq)); +[ad_pink_f, S, err_pink_f, tau] = allan(data_pink_f, 2.^[0:20], 'pink noise filtered',0); + +%% + +data_brown.rate = 1; +data_brown.freq = noise(N, 1, 'brown'); +[ad_brown, S, err_brown, tau] = allan(data_brown, 2.^[0:20], 'brown noise',0); + +data_brown_f.rate = 1; +data_brown_f.freq = lsim(G, data_brown.freq, 1:length(data_brown.freq)); +[ad_brown_f, S, err_brown_f, tau] = allan(data_brown_f, 2.^[0:20], 'brown noise filtered',0); + +%% + +data_red.rate = 1; +data_red.freq = noise(N, 1, 'red'); +[ad_red, S, err_red, tau] = allan(data_red, 2.^[0:20], 'red noise',0); + +data_red_f.rate = 1; +data_red_f.freq = lsim(G, data_red.freq, 1:length(data_red.freq)); +[ad_red_f, S, err_red_f, tau] = allan(data_red_f, 2.^[0:20], 'red noise filtered',0); + +%% + +figure +hold on +loglogerr(tau, ad_white, err_white, 'b') +loglogerr(tau, ad_white_f, err_white_f, 'r') +loglogerr(tau, ad_pink, err_pink, 'b-o') +loglogerr(tau, ad_pink_f, err_pink_f, 'r-o') +loglogerr(tau, ad_brown, err_brown, 'b-d') +loglogerr(tau, ad_brown_f, err_brown_f, 'r-d') +loglogerr(tau, ad_red, err_red, 'b-*') +loglogerr(tau, ad_red_f, err_red_f, 'r-*') +grid on diff --git a/sim_fft-adev/psd_tf.m b/sim_fft-adev/psd_tf.m new file mode 100644 index 0000000..91ab2c6 --- /dev/null +++ b/sim_fft-adev/psd_tf.m @@ -0,0 +1,38 @@ +clc +close all +clear all + +%% +N = 1e7; +Fs = 1000; +%% + +data_white.rate = Fs; +data_white.freq = noise(N, 1, 'white'); +[ad_white, S, err_white, tau] = allan(data_white, 2.^[0:nextpow2(length(data_white.freq))]./Fs, 'white noise',0); +[p_white, f_white] = pwelch(data_white.freq, [], [], [], data_white.rate, 'onesided'); + +data_pink.rate = Fs; +data_pink.freq = noise(N, 1, 'pink'); +[ad_pink, S, err_pink, tau] = allan(data_pink, 2.^[0:nextpow2(length(data_pink.freq))]./Fs, 'pink noise',0); +[p_pink, f_pink] = pwelch(data_pink.freq, [], [], [], data_pink.rate, 'onesided'); + + +data_brown.rate = Fs; +data_brown.freq = noise(N, 1, 'brown'); +[ad_brown, S, err_brown, tau] = allan(data_brown, 2.^[0:nextpow2(length(data_brown.freq))]./Fs, 'brown noise',0); +[p_brown, f_brown] = pwelch(data_brown.freq, [], [], [], data_brown.rate, 'onesided'); + +figure +hold on +loglogerr(tau, ad_white, err_white, 'b') +loglogerr(tau, ad_pink, err_pink, 'm') +loglogerr(tau, ad_brown, err_brown, 'k') +grid on + +figure +hold on +semilogx(f_white, 10*log10(p_white), 'b') +semilogx(f_pink, 10*log10(p_pink), 'm') +semilogx(f_brown, 10*log10(p_brown), 'k') +grid on