TailCorr/script_m/diff_plot_py.m

80 lines
2.5 KiB
Mathematica
Raw Normal View History

%compare FIL with python script
function diff_plot_py(fs,iir_out, Script_out,title1,title2,a,amp,edge)
%
N = min(length(iir_out),length(Script_out));
iir_out = iir_out(1:N);
Script_out = Script_out(1:N);
diff = (iir_out - Script_out)/amp;%
n = (0:1:N-1)/fs;
%
n_edge = find(n>=edge-1e-12);%edge沿
n50 = find(n>=edge+20e-9-1e-12);%沿20ns
n20_40 = find((n>=edge+20e-9-1e-12) & (n<=edge+40e-9+1e-12));%沿20ns40ns
n1000 = find(n>=edge+1000e-9-1e-12);%沿1us
n1000_1100 = find((n>=edge+1000e-9-1e-12) & (n<=edge+1100e-9+1e-12));%沿1us1.1us
ne = find((abs(diff)>=1e-4) & (abs(diff)<1));%
ne(1) = 1;
window_length = 100e-9*fs;
diff_mean_window = movmean(diff,window_length);
diff_std_window = movstd(diff,window_length);
n_mean_window = find((abs(diff_mean_window)>=1e-4) );%100ns
n_std_window = find((abs(diff_std_window)>=1e-4) ); %100ns
n_common = max(n_mean_window(end),n_std_window(end));
%
tiledlayout(2,1)
ax1 = nexttile;
plot(n,iir_out,n,Script_out)
legend(title1,title2)
xlabel('t/s')
xlim(a)
grid on
hold on
%
ax2 = nexttile;
plot(n,diff)
xlabel('t/s')
title('diff')
grid on
hold on
xlim(a)
linkaxes([ax1,ax2],'x');
plot_p = @(x)[
plot(n(x),diff(x),'r*');
text(n(x), diff(x)+diff(x)*0.1, ['(',num2str(n(x)),',',num2str(diff(x)),')'],'color','k');
];
%
%plot_p(n_edge(1));%沿
%plot_p(n50(1)); %沿20ns
%plot_p(n1000(1)); %沿1us
ne(1) = 1;
%plot_p(ne(end)); %
% [diff_max,R_mpos] = max(abs(diff));%
% plot_p(R_mpos);
if a(2) <= 5e-6
plot_p(n_edge(1));%沿
% plot_p(R_mpos);
elseif a(2) > 5e-6
plot_p(n50(1)); %沿20ns
plot_p(n1000(1)); %沿1us
plot_p(ne(end)); %
fprintf("Falling edge of 20ns~40ns mean :%.4e\t std :%.4e\t",mean(diff(n20_40)),std(diff(n20_40)));
fprintf("Falling edge of 1us~1.1us mean :%.4e\t std :%.4e\t",mean(diff(n1000_1100)),std(diff(n1000_1100)));
% fprintf("The error after falling edge of 1us is:%.4e\t",diff(n1000(1)));
% fprintf("The time of erroe less than 1e-4 is :%.4e us\n",(n(ne(end))-n(n_edge(1))));
fprintf("The mean and std stably less than 1e-4 is :%.4e s\n",(n(n_common)-n(n_edge(1))));
end