From a7160ad3467e5f49981c9f83d24cce38ce9a091b Mon Sep 17 00:00:00 2001 From: andre-fuchs-uni-oldenburg <64791323+andre-fuchs-uni-oldenburg@users.noreply.github.com> Date: Fri, 16 Sep 2022 11:46:34 +0200 Subject: [PATCH] Add files via upload --- Functions_v5-MATLAB/FIT_KM.m | 1932 ++++++++-------- Functions_v5-MATLAB/KM_Calculation.m | 2 + Functions_v5-MATLAB/KM_STP_optimization.m | 4 + Functions_v5-MATLAB/KM_plot.m | 4 + Functions_v5-MATLAB/KM_plot_raw.m | 4 + Functions_v5-MATLAB/OPTI_IFT_dij.m | 774 +++---- Functions_v5-MATLAB/PART_I.m | 6 +- Functions_v5-MATLAB/PART_II.m | 2 +- Functions_v5-MATLAB/PART_III.m | 5 +- Functions_v5-MATLAB/Struc_flip_test.m | 2 + Functions_v5-MATLAB/ZeroCrossings.m | 3 +- Functions_v5-MATLAB/checkFT.m | 718 +++--- Functions_v5-MATLAB/conditional_PDF_markov.m | 37 +- Functions_v5-MATLAB/conditional_moment.m | 1 + Functions_v5-MATLAB/frequency_filter.m | 619 ++--- Functions_v5-MATLAB/length_scales.m | 2008 ++++++++--------- Functions_v5-MATLAB/main.m | 3 + Functions_v5-MATLAB/plot_conditional_moment.m | 266 +-- Functions_v5-MATLAB/plot_entropy.m | 3 + Functions_v5-MATLAB/plot_increment_pdf.m | 8 +- Functions_v5-MATLAB/plot_pointwise_KM.m | 12 +- Functions_v5-MATLAB/spectrum.m | 2 + 22 files changed, 3246 insertions(+), 3169 deletions(-) diff --git a/Functions_v5-MATLAB/FIT_KM.m b/Functions_v5-MATLAB/FIT_KM.m index 8522c27..bdd520c 100644 --- a/Functions_v5-MATLAB/FIT_KM.m +++ b/Functions_v5-MATLAB/FIT_KM.m @@ -1,965 +1,969 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% This function performs the surface fit with a linear function for $D^{(1)}\left(u_r,r\right)$ -% and a parabolic function for $D^{(2)}\left(u_r,r\right)$ to the optimized and non-optimized KMC's. -% Coefficients $d_{ij}(r)$ in the fits are functions of scale~$r$ of the form -% $\alpha (r/\lambda)^{\beta}+\gamma$. After fitting, this function plots the optimized $D^{(1,2)}$ -% and its surface fits. This function also plots the parameters $d_{11}$, $d_{20}$, $d_{21}$ and -% $d_{22}$ as a function of $\frac{r}{\lambda}$ for optimized and non-optimized -% $D^{(1,2)}\left(u_r,r\right)$. -% -% Arguments IN -% evaluated_point = struct array calculated in the function 'conditional_moment' -% increment_bin = number of bins -% taylor_L = Taylor length scale in meters -% Fs = Acquisition/Sampling Frequency in Hz -% m_data = mean of the data -% markov = markov length in number of samples -% multi_point = weather to do multi-point analysis or not 1=Yes, 0=No -% condition = condition for multi-point analysis -% -% Arguments OUT -% co_KM_opti = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients using the surface fits -% co_KM_opti_old = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients using the -% surface fits without an offset -% co_no_opti = Coefficients $d_{ij}(r)$ of the non-optimized Kramers-Moyal coefficients using the surface fits -% fitresult_D1_conf = Confidence intervals for fit coefficients of D1 -% fitresult_D2_conf = Confidence intervals for fit coefficients of D2 -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function[co_KM_opti,co_KM_opti_old,co_no_opti,fitresult_D1_conf,fitresult_D2_conf]=FIT_KM(evaluated_point,increment_bin,taylor_L,Fs,m_data,markov,multi_point,condition,norm_ur,norm_r,save_path,save_name) - -% taylor_L=1; - -if multi_point==1 - for k=1:length(condition) - my_field = sprintf('point_eval_%d', k); - co_KM_opti.(my_field) = struct('a',NaN(1,2),'ea',nan,'b',NaN(1,6),'eb',NaN(1,3)); - co_KM_opti_old.(my_field) = struct('a',NaN(1,2),'ea',nan,'b',NaN(1,6),'eb',NaN(1,3)); - co_no_opti.(my_field) = struct('a',NaN(1,2),'ea',nan,'b',NaN(1,6),'eb',NaN(1,3)); - end - - for k=1:length(condition) - my_field = sprintf('point_eval_%d', k); - clear evaluated - evaluated = evaluated_point.(my_field); - - tmp=0; - for scal = 1:length(evaluated) - tmp = tmp+sum(evaluated(scal).x_bin_not_nan>0); - end - - if tmp>0 - xx = nan(length(evaluated),increment_bin); - y = nan(length(evaluated),increment_bin); - z1 = nan(length(evaluated),increment_bin); - z1e = nan(length(evaluated),increment_bin); - z2 = nan(length(evaluated),increment_bin); - z2e = nan(length(evaluated),increment_bin); - z1_opti = nan(length(evaluated),increment_bin); - z2_opti = nan(length(evaluated),increment_bin); - z4 = nan(length(evaluated),increment_bin); - - % for i=find((evaluated.r)/taylor_L>4):length(evaluated) - for i=1:length(evaluated) - xx(i,1:sum(evaluated(i).x_bin_not_nan))=evaluated(i).y_mean_bin(evaluated(i).x_bin_not_nan); - if norm_r==1 - y(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).r./taylor_L); - else - y(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).r); - end - z1(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1(evaluated(i).x_bin_not_nan)); - z1e(i,1:sum(evaluated(i).x_bin_not_nan))=abs(1./(evaluated(i).eD1(evaluated(i).x_bin_not_nan))); - - z2(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2(evaluated(i).x_bin_not_nan)); - z2e(i,1:sum(evaluated(i).x_bin_not_nan))=abs(1./(evaluated(i).eD2(evaluated(i).x_bin_not_nan))); - - z1_opti(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1_opti); - z2_opti(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2_opti); - - z4(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D4(evaluated(i).x_bin_not_nan)); - end - - %TEST Beginn - % y=y-(((markov./Fs).*m_data)/taylor_L); - %TEst Ende - - - %% D1-Fit - [fitresult_D1, xData, yData, zData, weights] = FIT_D1(xx, y, z1_opti, z1e); - fitresult_D1_conf = confint(fitresult_D1); - - h(1) = figure; - % surf(xx, y, z1_opti,'EdgeColor','none') - scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - hold on - surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D1,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') -% surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),... -% (-0.36.*repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100).^(-1).*repmat(linspace(min(xData),max(xData),100),100,1)),'FaceColor',[0.501960813999176 0.501960813999176 0.501960813999176],'EdgeColor',[0.501960813999176 0.501960813999176 0.501960813999176]) - - % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) - set(gca,'yScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') - % zlabel('$D1 (x,r) / [\frac{m}{s^2}]$', 'interpreter','latex') - colormap (parula(200)) - % colorbar - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - % zlim([-0.005 0.005]) - axis square - set(gca,'YDir','reverse'); - title('optimized KM, optimized fit','interpreter','latex'); - % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') - % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') - rotate3d on - colorbar('north','TickLabelInterpreter','latex','AxisLocation','out'); - fig_setup - legend off - txt = {'(a)'}; - a=text(4,0.5,txt); - a.Units='normalized'; - - %%%%% 2019 %%%%%%%% - % optimized coefficients - % D1(x,y) = (a1*y^ra1+a11)*x - co_KM_opti.(my_field).a = [fitresult_D1.a1 fitresult_D1.a11]; - co_KM_opti.(my_field).ea = [fitresult_D1.ra1]; - - % non-optimized coefficients - [fitresult_D1_o, xData_o1, yData_o1, zData_o1, weights] = FIT_D1(xx, y, z1, z1e); - %%%%% 2019 %%%%%%%% - % D1(x,y) = (a1*y^ra1+a11)*x - co_no_opti.(my_field).a = [fitresult_D1_o.a1 fitresult_D1_o.a11]; - co_no_opti.(my_field).ea = [fitresult_D1_o.ra1]; - - % optimized coefficients no offset - % D1(x,y) = (a1*y^ra1)*x - ft = fittype( '(a1*y^ra1)*x', 'independent', {'x', 'y'}, 'dependent', 'z' ); - opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); - % opts.DiffMinChange = 1e-12; - % opts.Display = 'Off'; - % opts.MaxFunEvals = 1000; - % opts.MaxIter = 1000; - % opts.TolFun = 1e-12; - % opts.TolX = 1e-12; - opts.Weights = weights; - - % opts.StartPoint = [-0.1 -1]; - % opts.Lower = [-2 -2]; - % opts.Upper = [0 0]; - - opts.StartPoint = [0 0]; - opts.Lower = [-1 -Inf]; - opts.Upper = [1 0]; - - [fitresult_D1_old, gof] = fit( [xData, yData], zData, ft, opts ); - co_KM_opti_old.(my_field).a = [fitresult_D1_old.a1 0]; - co_KM_opti_old.(my_field).ea = [fitresult_D1_old.ra1]; - - % figure - % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra0) - % hold on - % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra1) - % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^0) - % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a3.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra3) - % set(gca,'xScale','log') - % axis square - % set(gcf, 'Color', 'w') - % % grid on - % xlabel('$r / \lambda$', 'interpreter','latex') - % legend('d_{10}(r)','d_{11}(r)','d_{12}(r)','d_{13}(r)') - % xlim([min(y(:,1)) max(y(:,1))]) - - - - %% D2-Fit - [fitresult_D2, xData, yData, zData, weights] = FIT_D2(xx, y, z2_opti, z2e); - fitresult_D2_conf = confint(fitresult_D2); - h(2) = figure; - % surf(xx, y, z2_opti,'EdgeColor','none') - scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - hold on - surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D2,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') -% surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),... -% (0.0144.*repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100).^(-1).*repmat(linspace(min(xData),max(xData),100),100,1).^(2)),'FaceColor',[0.501960813999176 0.501960813999176 0.501960813999176],'EdgeColor',[0.501960813999176 0.501960813999176 0.501960813999176]) - % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) - set(gca,'yScale','log') - % set(gca,'zScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - % zlabel('$D2 (x,r) / [\frac{m^2}{s^3}]$', 'interpreter','latex') - zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') - colormap (parula(200)) - % colorbar - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - % zlim([0 2*max(zData)]) - % caxis([0 max(zData)]) - axis square - % close - set(gca,'YDir','reverse'); - set(gca,'TickLabelInterpreter','latex'); - title('optimized KM, optimized fit','interpreter','latex'); - % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') - % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') - rotate3d on - colorbar('north','TickLabelInterpreter','latex','AxisLocation','out'); - fig_setup - legend off - txt = {'(b)'}; - b=text(4,0.5,txt); - b.Units='normalized'; - - % optimized coefficients - %%%%% 2019 %%%%%%%% - % D2(x,y) = (b0*y^rb0+b00) + (b1*y^rb1+b11)*x + (b2*y^rb2+b22)*x^2 - co_KM_opti.(my_field).b = [fitresult_D2.b0 fitresult_D2.b00 fitresult_D2.b1 fitresult_D2.b11 fitresult_D2.b2 fitresult_D2.b22]; - co_KM_opti.(my_field).eb = [fitresult_D2.rb0 fitresult_D2.rb1 fitresult_D2.rb2 ]; % for D2 - - % non-optimized coefficients - [fitresult_D2_o, xData_o2, yData_o2, zData_o2, weights] = FIT_D2(xx, y, z2, z2e); - %%%%% 2019 %%%%%%%% - % D2(x,y) = (b0*y^rb0+b00) + (b1*y^rb1+b11)*x + (b2*y^rb2+b22)*x^2 - co_no_opti.(my_field).b = [fitresult_D2_o.b0 fitresult_D2_o.b00 fitresult_D2_o.b1 fitresult_D2_o.b11 fitresult_D2_o.b2 fitresult_D2_o.b22]; - co_no_opti.(my_field).eb = [ fitresult_D2_o.rb0 fitresult_D2_o.rb1 fitresult_D2_o.rb2 ]; % for D2 - - - % optimized coefficients no offset - ft = fittype( '(b0*y^rb0) + (b1*y^rb1)*x + (b2*y^rb2)*x^2', 'independent', {'x', 'y'}, 'dependent', 'z' ); - opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); - % opts.DiffMinChange = 1e-12; - % opts.Display = 'Off'; - % opts.MaxFunEvals = 1000; - % opts.MaxIter = 1000; - % opts.TolFun = 1e-12; - % opts.TolX = 1e-12; - opts.Weights = weights; - - % opts.StartPoint = [0.2 -0.02 0.007 0.001 -1 -0.3]; - % opts.Lower = [0 -1 0 0 -2 -2]; - % opts.Upper = [1 1 1 2 2 0]; - - opts.StartPoint = [0 0 0 0 0 0]; - opts.Lower = [-1 -1 -1 0 -Inf -Inf]; - opts.Upper = [1 1 1 Inf Inf 0]; - - [fitresult_D2_old, gof] = fit( [xData, yData], zData, ft, opts ); - co_KM_opti_old.(my_field).b = [fitresult_D2_old.b0 0 fitresult_D2_old.b1 0 fitresult_D2_old.b2 0]; - co_KM_opti_old.(my_field).eb = [fitresult_D2_old.rb0 fitresult_D2_old.rb1 fitresult_D2_old.rb2 ]; % for D2 - - - %% d_ij(r) plots - h(3) = figure; - subplot(2,2,1); - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D1.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra1+fitresult_D1.a11,'LineWidth',2) - hold on - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D1_o.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1_o.ra1+fitresult_D1_o.a11,'LineWidth',2) -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% fitresult_D1_old.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1_old.ra1,'LineWidth',2,'Color','k') -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% (-0.36).*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^(-1),'LineWidth',2,'Color',[0.501960813999176 0.501960813999176 0.501960813999176]) - axis square - ylabel('$d_{11}$', 'interpreter','latex') - if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') - end - xlim([min(y(:,1)) max(y(:,1))]) - set(gca, 'FontSize',12) - % - subplot(2,2,2); - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb0+fitresult_D2.b00,'LineWidth',2) - hold on - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2_o.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb0+fitresult_D2_o.b00,'LineWidth',2) - -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% fitresult_D2_old.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb0,'LineWidth',2,'Color','k') - axis square - ylabel('$d_{20}$', 'interpreter','latex') - if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') - end - xlim([min(y(:,1)) max(y(:,1))]) - set(gca, 'FontSize',12) - % - subplot(2,2,3); - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb1+fitresult_D2.b11,'LineWidth',2) - hold on - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2_o.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb1+fitresult_D2_o.b11,'LineWidth',2) -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% fitresult_D2_old.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb1,'LineWidth',2,'Color','k') - axis square - ylabel('$d_{21}$', 'interpreter','latex') - if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') - end - xlim([min(y(:,1)) max(y(:,1))]) - set(gca, 'FontSize',12) - % - subplot(2,2,4); - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb2+fitresult_D2.b22,'LineWidth',2) - hold on - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2_o.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb2+fitresult_D2_o.b22,'LineWidth',2) -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% fitresult_D2_old.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb2,'LineWidth',2,'Color','k') -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% 0.0144.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^(-1),'LineWidth',2,'Color',[0.501960813999176 0.501960813999176 0.501960813999176]) - axis square - ylabel('$d_{22}$', 'interpreter','latex') - if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') - end - xlim([min(y(:,1)) max(y(:,1))]) - set(gca, 'FontSize',14) - set(gca,'TickLabelInterpreter','latex'); - set(gcf, 'Color', 'w') - %legend('optimized','non-optimized','Location','NorthWest') -% legend({'Optimized','Non-optimized','Optimized no offset','K62'},'Position',[0.45 0.5 0.1 0.05]) - legend({'Optimized','Non-optimized','K62'},'Position',[0.45 0.5 0.1 0.05]) - - close all - disp(['point:' num2str(k) '/' num2str(length(condition)) ]) - end - end -else - evaluated = evaluated_point; - xx = nan(length(evaluated),increment_bin); - y = nan(length(evaluated),increment_bin); - z1 = nan(length(evaluated),increment_bin); - z1e = nan(length(evaluated),increment_bin); - z2 = nan(length(evaluated),increment_bin); - z2e = nan(length(evaluated),increment_bin); - z1_opti = nan(length(evaluated),increment_bin); - z2_opti = nan(length(evaluated),increment_bin); - z4 = nan(length(evaluated),increment_bin); - - % for i=find((evaluated.r)/taylor_L>4):length(evaluated) - for i=1:length(evaluated) - xx(i,1:sum(evaluated(i).x_bin_not_nan))=evaluated(i).y_mean_bin(evaluated(i).x_bin_not_nan); - if norm_r==1 - y(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).r./taylor_L); - else - y(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).r); - end - z1(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1(evaluated(i).x_bin_not_nan)); - z1e(i,1:sum(evaluated(i).x_bin_not_nan))=abs(1./(evaluated(i).eD1(evaluated(i).x_bin_not_nan))); - - z2(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2(evaluated(i).x_bin_not_nan)); - z2e(i,1:sum(evaluated(i).x_bin_not_nan))=abs(1./(evaluated(i).eD2(evaluated(i).x_bin_not_nan))); - - z1_opti(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1_opti); - z2_opti(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2_opti); - - z4(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D4(evaluated(i).x_bin_not_nan)); - end - -% z1_opti=z1_opti.*0.5; -% z2_opti=z2_opti.*0.5; - - %TEST Beginn - % y=y-(((markov./Fs).*m_data)/taylor_L); - %TEst Ende - - - %% D1-Fit - [fitresult_D1, xData, yData, zData, weights] = FIT_D1(xx, y, z1_opti, z1e); - fitresult_D1_conf = confint(fitresult_D1); - - h(1) = figure; - % surf(xx, y, z1_opti,'EdgeColor','none') - scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - hold on - surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D1,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') -% surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),... -% (-0.36.*repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100).^(-1).*repmat(linspace(min(xData),max(xData),100),100,1)),'FaceColor',[0.501960813999176 0.501960813999176 0.501960813999176],'EdgeColor',[0.501960813999176 0.501960813999176 0.501960813999176]) - - % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) - set(gca,'yScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') - % zlabel('$D1 (x,r) / [\frac{m}{s^2}]$', 'interpreter','latex') - colormap (parula(200)) - % colorbar - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - % zlim([-0.005 0.005]) - axis square - set(gca,'YDir','reverse'); -% title('optimized KM, optimized fit','interpreter','latex'); - % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') - % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') - rotate3d on - colorbar('north','TickLabelInterpreter','latex','AxisLocation','out'); - fig_setup - legend off - txt = {'(a)'}; - a=text(4,0.5,txt); - a.Units='normalized'; - - - %%%%% 2019 %%%%%%%% - % optimized coefficients - % D1(x,y) = (a1*y^ra1+a11)*x - co_KM_opti.a = [fitresult_D1.a1 fitresult_D1.a11]; - co_KM_opti.ea = [fitresult_D1.ra1]; - - % non-optimized coefficients - [fitresult_D1_o, xData_o1, yData_o1, zData_o1, weights] = FIT_D1(xx, y, z1, z1e); - %%%%% 2019 %%%%%%%% - % D1(x,y) = (a1*y^ra1+a11)*x - co_no_opti.a = [fitresult_D1_o.a1 fitresult_D1_o.a11]; - co_no_opti.ea = [fitresult_D1_o.ra1]; - - % optimized coefficients no offset - % D1(x,y) = (a1*y^ra1)*x - ft = fittype( '(a1*y^ra1)*x', 'independent', {'x', 'y'}, 'dependent', 'z' ); - opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); - % opts.DiffMinChange = 1e-12; - % opts.Display = 'Off'; - % opts.MaxFunEvals = 1000; - % opts.MaxIter = 1000; - % opts.TolFun = 1e-12; - % opts.TolX = 1e-12; - opts.Weights = weights; - - % opts.StartPoint = [-0.1 -1]; - % opts.Lower = [-2 -2]; - % opts.Upper = [0 0]; - - opts.StartPoint = [0 0]; - opts.Lower = [-1 -Inf]; - opts.Upper = [1 0]; - - [fitresult_D1_old, gof] = fit( [xData, yData], zData, ft, opts ); - co_KM_opti_old.a = [fitresult_D1_old.a1 0]; - co_KM_opti_old.ea = [fitresult_D1_old.ra1]; - - % figure - % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra0) - % hold on - % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra1) - % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^0) - % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a3.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra3) - % set(gca,'xScale','log') - % axis square - % set(gcf, 'Color', 'w') - % % grid on - % xlabel('$r / \lambda$', 'interpreter','latex') - % legend('d_{10}(r)','d_{11}(r)','d_{12}(r)','d_{13}(r)') - % xlim([min(y(:,1)) max(y(:,1))]) - - - - %% D2-Fit - [fitresult_D2, xData, yData, zData, weights] = FIT_D2(xx, y, z2_opti, z2e); - fitresult_D2_conf = confint(fitresult_D2); - h(2) = figure; - % surf(xx, y, z2_opti,'EdgeColor','none') - scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - hold on - surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D2,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') -% surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),... -% (0.0144.*repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100).^(-1).*repmat(linspace(min(xData),max(xData),100),100,1).^(2)),'FaceColor',[0.501960813999176 0.501960813999176 0.501960813999176],'EdgeColor',[0.501960813999176 0.501960813999176 0.501960813999176]) - % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) - set(gca,'yScale','log') - % set(gca,'zScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - % zlabel('$D2 (x,r) / [\frac{m^2}{s^3}]$', 'interpreter','latex') - zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') - colormap (parula(200)) - % colorbar - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - % zlim([0 2*max(zData)]) - % caxis([0 max(zData)]) - axis square - % close - set(gca,'YDir','reverse'); - set(gca,'TickLabelInterpreter','latex'); -% title('optimized KM, optimized fit','interpreter','latex'); - % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') - % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') - rotate3d on - colorbar('north','TickLabelInterpreter','latex','AxisLocation','out'); - fig_setup - legend off - txt = {'(b)'}; - b=text(4,0.5,txt); - b.Units='normalized'; - - font=22; - a.FontSize = font; - b.FontSize = font; - pos_txt=[-0.22 0.8]; - a.Position=pos_txt; - b.Position=[-0.25 0.8]; - - % optimized coefficients - %%%%% 2019 %%%%%%%% - % D2(x,y) = (b0*y^rb0+b00) + (b1*y^rb1+b11)*x + (b2*y^rb2+b22)*x^2 - co_KM_opti.b = [fitresult_D2.b0 fitresult_D2.b00 fitresult_D2.b1 fitresult_D2.b11 fitresult_D2.b2 fitresult_D2.b22]; - co_KM_opti.eb = [fitresult_D2.rb0 fitresult_D2.rb1 fitresult_D2.rb2 ]; % for D2 - - % non-optimized coefficients - [fitresult_D2_o, xData_o2, yData_o2, zData_o2, weights] = FIT_D2(xx, y, z2, z2e); - %%%%% 2019 %%%%%%%% - % D2(x,y) = (b0*y^rb0+b00) + (b1*y^rb1+b11)*x + (b2*y^rb2+b22)*x^2 - co_no_opti.b = [fitresult_D2_o.b0 fitresult_D2_o.b00 fitresult_D2_o.b1 fitresult_D2_o.b11 fitresult_D2_o.b2 fitresult_D2_o.b22]; - co_no_opti.eb = [ fitresult_D2_o.rb0 fitresult_D2_o.rb1 fitresult_D2_o.rb2 ]; % for D2 - - - % optimized coefficients no offset - ft = fittype( '(b0*y^rb0) + (b1*y^rb1)*x + (b2*y^rb2)*x^2', 'independent', {'x', 'y'}, 'dependent', 'z' ); - opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); - % opts.DiffMinChange = 1e-12; - % opts.Display = 'Off'; - % opts.MaxFunEvals = 1000; - % opts.MaxIter = 1000; - % opts.TolFun = 1e-12; - % opts.TolX = 1e-12; - opts.Weights = weights; - - % opts.StartPoint = [0.2 -0.02 0.007 0.001 -1 -0.3]; - % opts.Lower = [0 -1 0 0 -2 -2]; - % opts.Upper = [1 1 1 2 2 0]; - - opts.StartPoint = [0 0 0 0 0 0]; - opts.Lower = [-1 -1 -1 0 -Inf -Inf]; - opts.Upper = [1 1 1 Inf Inf 0]; - - [fitresult_D2_old, gof] = fit( [xData, yData], zData, ft, opts ); - co_KM_opti_old.b = [fitresult_D2_old.b0 0 fitresult_D2_old.b1 0 fitresult_D2_old.b2 0]; - co_KM_opti_old.eb = [fitresult_D2_old.rb0 fitresult_D2_old.rb1 fitresult_D2_old.rb2 ]; % for D2 - - - %% d_ij(r) plots - h(3) = figure; - subplot(2,2,1); - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D1.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra1+fitresult_D1.a11,'LineWidth',2) - hold on - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D1_o.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1_o.ra1+fitresult_D1_o.a11,'LineWidth',2) -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% fitresult_D1_old.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1_old.ra1,'LineWidth',2,'Color','k') -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% (-0.36).*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^(-1),'LineWidth',2,'Color',[0.501960813999176 0.501960813999176 0.501960813999176]) - axis square - ylabel('$d_{11}$', 'interpreter','latex') - if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') - end - xlim([min(y(:,1)) max(y(:,1))]) - set(gca, 'FontSize',14) - fig_setup - legend off - txt = {'(a)'}; - a=text(4,0.5,txt); - a.Units='normalized'; - % - subplot(2,2,2); - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb0+fitresult_D2.b00,'LineWidth',2) - hold on - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2_o.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb0+fitresult_D2_o.b00,'LineWidth',2) - -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% fitresult_D2_old.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb0,'LineWidth',2,'Color','k') - axis square - ylabel('$d_{20}$', 'interpreter','latex') - if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r\ (m)$', 'interpreter','latex') - end - xlim([min(y(:,1)) max(y(:,1))]) - set(gca, 'FontSize',14) - fig_setup - legend off - txt = {'(b)'}; - b=text(4,0.5,txt); - b.Units='normalized'; - - % - subplot(2,2,3); - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb1+fitresult_D2.b11,'LineWidth',2) - hold on - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2_o.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb1+fitresult_D2_o.b11,'LineWidth',2) -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% fitresult_D2_old.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb1,'LineWidth',2,'Color','k') - axis square - ylabel('$d_{21}$', 'interpreter','latex') - if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r\ (m)$', 'interpreter','latex') - end - xlim([min(y(:,1)) max(y(:,1))]) - set(gca, 'FontSize',14) - fig_setup - legend off - txt = {'(c)'}; - c=text(4,0.5,txt); - c.Units='normalized'; - - - % - subplot(2,2,4); - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb2+fitresult_D2.b22,'LineWidth',2) - hold on - plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... - fitresult_D2_o.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb2+fitresult_D2_o.b22,'LineWidth',2) -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% fitresult_D2_old.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb2,'LineWidth',2,'Color','k') -% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... -% 0.0144.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^(-1),'LineWidth',2,'Color',[0.501960813999176 0.501960813999176 0.501960813999176]) - axis square - ylabel('$d_{22}$', 'interpreter','latex') - if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r\ (m)$', 'interpreter','latex') - end - xlim([min(y(:,1)) max(y(:,1))]) - set(gca, 'FontSize',14) - set(gca,'TickLabelInterpreter','latex'); - set(gcf, 'Color', 'w') - %legend('optimized','non-optimized','Location','NorthWest') -% legend({'Optimized','Non-optimized','Optimized no offset','K62'},'Position',[0.45 0.5 0.1 0.05]) - legend({'Optimized','Non-optimized','K62'},'Position',[0.45 0.5 0.1 0.05]) - fig_setup -% legend off - txt = {'(d)'}; - d=text(4,0.5,txt); - d.Units='normalized'; - - font=22; - a.FontSize = font; - b.FontSize = font; - c.FontSize = font; - d.FontSize = font; - - pos_txt=[-0.68 0.9]; - a.Position=pos_txt; - b.Position=pos_txt; - c.Position=pos_txt; - d.Position=pos_txt; - - %% 3D plots - figure - % surf(xx, y, z1_opti,'EdgeColor','none') - scatter3(xData_o1, yData_o1, zData_o1,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - hold on - surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D1,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') - % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) - set(gca,'yScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') - % zlabel('$D1 (x,r) / [\frac{m}{s^2}]$', 'interpreter','latex') - colormap (parula(200)) - % colorbar - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - % zlim([-0.005 0.005]) - axis square - set(gca,'YDir','reverse'); - set(gca,'TickLabelInterpreter','latex'); - title('non-optimized KM, optimized fit','interpreter','latex'); - close - - - figure - % surf(xx, y, z2_opti,'EdgeColor','none') - scatter3(xData_o2,yData_o2,zData_o2,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - hold on - surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D2,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') - % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) - set(gca,'yScale','log') - % set(gca,'zScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - % zlabel('$D2 (x,r) / [\frac{m^2}{s^3}]$', 'interpreter','latex') - zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') - colormap (parula(200)) - % colorbar - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - % zlim([0 2*max(zData)]) - % caxis([0 max(zData)]) - axis square - % close - set(gca,'YDir','reverse'); - set(gca,'TickLabelInterpreter','latex'); - % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') - % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') - title('non-optimized KM, optimized fit','interpreter','latex'); - close - - figure - scatter3(xData_o1, yData_o1, zData_o1,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - hold on - surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D1_o,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') - set(gca,'yScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') - colormap (parula(200)) - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - axis square - set(gca,'YDir','reverse'); - set(gca,'TickLabelInterpreter','latex'); - title('non-optimized KM, non-optimized fit','interpreter','latex'); - close - - - figure - scatter3(xData_o2,yData_o2,zData_o2,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - hold on - surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D2_o,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') - set(gca,'yScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') - colormap (parula(200)) - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - axis square - set(gca,'YDir','reverse'); - set(gca,'TickLabelInterpreter','latex'); - title('non-optimized KM, non-optimized fit','interpreter','latex'); - set(gca,'TickLabelInterpreter','latex'); - close - - - - - z1=nan(length(evaluated),increment_bin); - z2=nan(length(evaluated),increment_bin); - xx_no_opti = nan(length(evaluated),increment_bin); - - for i=1:length(evaluated) -% xx_no_opti(i,:)=evaluated(i).y_mean_bin; -% z1(i,:)=(evaluated(i).D1); -% z2(i,:)=(evaluated(i).D2); - xx_no_opti=xx; - z1(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1(evaluated(i).x_bin_not_nan)); - z2(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2(evaluated(i).x_bin_not_nan)); - end - - [xData, yData, zData] = prepareSurfaceData( xx, y, z1_opti); - tmp_u=repmat(linspace(min(xData),max(xData),100),100,1); - tmp_r=repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100); - - h(4) = figure; -% scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - scatter3(xData,yData,zData,'MarkerFaceColor',[0 0.4470 0.7410],'MarkerEdgeColor',[1 1 1]) - hold on - [xData, yData, zData] = prepareSurfaceData( xx_no_opti, y, z1); - scatter3(xData,yData,zData,'MarkerFaceColor',[0.8500, 0.3250, 0.0980],'MarkerEdgeColor',[1 1 1]) - set(gca,'yScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') - % zlabel('$D1 (x,r) / [\frac{m}{s^2}]$', 'interpreter','latex') - colormap (parula(200)) - % colorbar - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - % zlim([-0.005 0.005]) - axis square - set(gca,'YDir','reverse'); - rotate3d on - legend({'Optimized','Non-optimized'},'Position',[0.5 0.7 0.3 0.1]) - - - - [xData, yData, zData] = prepareSurfaceData( xx, y, z2_opti); - tmp_u=repmat(linspace(min(xData),max(xData),100),100,1); - tmp_r=repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100); - h(5) = figure; -% scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) - scatter3(xData,yData,zData,'MarkerFaceColor',[0 0.4470 0.7410],'MarkerEdgeColor',[1 1 1]) - hold on - [xData, yData, zData] = prepareSurfaceData( xx_no_opti, y, z2); - tmp_u=repmat(linspace(min(xData),max(xData),100),100,1); - tmp_r=repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100); - scatter3(xData,yData,zData,'MarkerFaceColor',[0.8500, 0.3250, 0.0980],'MarkerEdgeColor',[1 1 1]) - % surf(tmp_u,tmp_r,... - % (d20_R+d21_R.*tmp_u+d22_R.*tmp_u.^2)... - % ,'FaceColor',[0.831372559070587 0.815686285495758 0.7843137383461]) - set(gca,'yScale','log') - % set(gca,'zScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - if norm_ur==1 - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - else - xlabel('$u_r\ (m/s)$', 'interpreter','latex') - end - if norm_r==1 - ylabel('$r / \lambda$', 'interpreter','latex') - else - ylabel('$r\ (m)$', 'interpreter','latex') - end - % zlabel('$D2 (x,r) / [\frac{m^2}{s^3}]$', 'interpreter','latex') - zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') - colormap (parula(200)) - % colorbar - grid off - xlim([min(xData) max(xData)]) - ylim([min(y(:,1)) max(y(:,1))]) - % zlim([0 2*max(zData)]) - caxis([0 max(zData)]) - axis square - % close - set(gca,'YDir','reverse'); - rotate3d on - legend({'Optimized','Non-optimized'},'Position',[0.5 0.7 0.3 0.1]) - - if ischar(save_path) - savefig(h,fullfile(save_path,append(save_name,'_','KM_Fit.fig')),'compact') - for a = 1:length(h) - exportgraphics(h(a),fullfile(save_path,append(save_name,'_',sprintf('KM_Fit_%d.png', a)))) - end - end - -end -for i=1:5 - tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); - uiwait(gcf); - delete(tmp_ui); - close -end +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% This function performs the surface fit with a linear function for $D^{(1)}\left(u_r,r\right)$ +% and a parabolic function for $D^{(2)}\left(u_r,r\right)$ to the optimized and non-optimized KMC's. +% Coefficients $d_{ij}(r)$ in the fits are functions of scale~$r$ of the form +% $\alpha (r/\lambda)^{\beta}+\gamma$. After fitting, this function plots the optimized $D^{(1,2)}$ +% and its surface fits. This function also plots the parameters $d_{11}$, $d_{20}$, $d_{21}$ and +% $d_{22}$ as a function of $\frac{r}{\lambda}$ for optimized and non-optimized +% $D^{(1,2)}\left(u_r,r\right)$. +% +% Arguments IN +% evaluated_point = struct array calculated in the function 'conditional_moment' +% increment_bin = number of bins +% taylor_L = Taylor length scale in meters +% Fs = Acquisition/Sampling Frequency in Hz +% m_data = mean of the data +% markov = markov length in number of samples +% multi_point = weather to do multi-point analysis or not 1=Yes, 0=No +% condition = condition for multi-point analysis +% norm_ur = normalization of the data using $\sigma_\infty$? data 1=Yes, 0=No +% norm_r = normalization of the scale using $\lambda$? data 1=Yes, 0=No +% save_path = path for saving figures and files +% save_name = name for saving files +% +% Arguments OUT +% co_KM_opti = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients using the surface fits +% co_KM_opti_old = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients using the +% surface fits without an offset +% co_no_opti = Coefficients $d_{ij}(r)$ of the non-optimized Kramers-Moyal coefficients using the surface fits +% fitresult_D1_conf = Confidence intervals for fit coefficients of D1 +% fitresult_D2_conf = Confidence intervals for fit coefficients of D2 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function[co_KM_opti,co_KM_opti_old,co_no_opti,fitresult_D1_conf,fitresult_D2_conf]=FIT_KM(evaluated_point,increment_bin,taylor_L,Fs,m_data,markov,multi_point,condition,norm_ur,norm_r,save_path,save_name) + +% taylor_L=1; + +if multi_point==1 + for k=1:length(condition) + my_field = sprintf('point_eval_%d', k); + co_KM_opti.(my_field) = struct('a',NaN(1,2),'ea',nan,'b',NaN(1,6),'eb',NaN(1,3)); + co_KM_opti_old.(my_field) = struct('a',NaN(1,2),'ea',nan,'b',NaN(1,6),'eb',NaN(1,3)); + co_no_opti.(my_field) = struct('a',NaN(1,2),'ea',nan,'b',NaN(1,6),'eb',NaN(1,3)); + end + + for k=1:length(condition) + my_field = sprintf('point_eval_%d', k); + clear evaluated + evaluated = evaluated_point.(my_field); + + tmp=0; + for scal = 1:length(evaluated) + tmp = tmp+sum(evaluated(scal).x_bin_not_nan>0); + end + + if tmp>0 + xx = nan(length(evaluated),increment_bin); + y = nan(length(evaluated),increment_bin); + z1 = nan(length(evaluated),increment_bin); + z1e = nan(length(evaluated),increment_bin); + z2 = nan(length(evaluated),increment_bin); + z2e = nan(length(evaluated),increment_bin); + z1_opti = nan(length(evaluated),increment_bin); + z2_opti = nan(length(evaluated),increment_bin); + z4 = nan(length(evaluated),increment_bin); + + % for i=find((evaluated.r)/taylor_L>4):length(evaluated) + for i=1:length(evaluated) + xx(i,1:sum(evaluated(i).x_bin_not_nan))=evaluated(i).y_mean_bin(evaluated(i).x_bin_not_nan); + if norm_r==1 + y(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).r./taylor_L); + else + y(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).r); + end + z1(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1(evaluated(i).x_bin_not_nan)); + z1e(i,1:sum(evaluated(i).x_bin_not_nan))=abs(1./(evaluated(i).eD1(evaluated(i).x_bin_not_nan))); + + z2(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2(evaluated(i).x_bin_not_nan)); + z2e(i,1:sum(evaluated(i).x_bin_not_nan))=abs(1./(evaluated(i).eD2(evaluated(i).x_bin_not_nan))); + + z1_opti(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1_opti); + z2_opti(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2_opti); + + z4(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D4(evaluated(i).x_bin_not_nan)); + end + + %TEST Beginn + % y=y-(((markov./Fs).*m_data)/taylor_L); + %TEst Ende + + + %% D1-Fit + [fitresult_D1, xData, yData, zData, weights] = FIT_D1(xx, y, z1_opti, z1e); + fitresult_D1_conf = confint(fitresult_D1); + + h(1) = figure; + % surf(xx, y, z1_opti,'EdgeColor','none') + scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + hold on + surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D1,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') +% surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),... +% (-0.36.*repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100).^(-1).*repmat(linspace(min(xData),max(xData),100),100,1)),'FaceColor',[0.501960813999176 0.501960813999176 0.501960813999176],'EdgeColor',[0.501960813999176 0.501960813999176 0.501960813999176]) + + % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) + set(gca,'yScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') + % zlabel('$D1 (x,r) / [\frac{m}{s^2}]$', 'interpreter','latex') + colormap (parula(200)) + % colorbar + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + % zlim([-0.005 0.005]) + axis square + set(gca,'YDir','reverse'); + title('optimized KM, optimized fit','interpreter','latex'); + % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') + % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') + rotate3d on + colorbar('north','TickLabelInterpreter','latex','AxisLocation','out'); + fig_setup + legend off + txt = {'(a)'}; + a=text(4,0.5,txt); + a.Units='normalized'; + + %%%%% 2019 %%%%%%%% + % optimized coefficients + % D1(x,y) = (a1*y^ra1+a11)*x + co_KM_opti.(my_field).a = [fitresult_D1.a1 fitresult_D1.a11]; + co_KM_opti.(my_field).ea = [fitresult_D1.ra1]; + + % non-optimized coefficients + [fitresult_D1_o, xData_o1, yData_o1, zData_o1, weights] = FIT_D1(xx, y, z1, z1e); + %%%%% 2019 %%%%%%%% + % D1(x,y) = (a1*y^ra1+a11)*x + co_no_opti.(my_field).a = [fitresult_D1_o.a1 fitresult_D1_o.a11]; + co_no_opti.(my_field).ea = [fitresult_D1_o.ra1]; + + % optimized coefficients no offset + % D1(x,y) = (a1*y^ra1)*x + ft = fittype( '(a1*y^ra1)*x', 'independent', {'x', 'y'}, 'dependent', 'z' ); + opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); + % opts.DiffMinChange = 1e-12; + % opts.Display = 'Off'; + % opts.MaxFunEvals = 1000; + % opts.MaxIter = 1000; + % opts.TolFun = 1e-12; + % opts.TolX = 1e-12; + opts.Weights = weights; + + % opts.StartPoint = [-0.1 -1]; + % opts.Lower = [-2 -2]; + % opts.Upper = [0 0]; + + opts.StartPoint = [0 0]; + opts.Lower = [-1 -Inf]; + opts.Upper = [1 0]; + + [fitresult_D1_old, gof] = fit( [xData, yData], zData, ft, opts ); + co_KM_opti_old.(my_field).a = [fitresult_D1_old.a1 0]; + co_KM_opti_old.(my_field).ea = [fitresult_D1_old.ra1]; + + % figure + % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra0) + % hold on + % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra1) + % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^0) + % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a3.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra3) + % set(gca,'xScale','log') + % axis square + % set(gcf, 'Color', 'w') + % % grid on + % xlabel('$r / \lambda$', 'interpreter','latex') + % legend('d_{10}(r)','d_{11}(r)','d_{12}(r)','d_{13}(r)') + % xlim([min(y(:,1)) max(y(:,1))]) + + + + %% D2-Fit + [fitresult_D2, xData, yData, zData, weights] = FIT_D2(xx, y, z2_opti, z2e); + fitresult_D2_conf = confint(fitresult_D2); + h(2) = figure; + % surf(xx, y, z2_opti,'EdgeColor','none') + scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + hold on + surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D2,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') +% surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),... +% (0.0144.*repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100).^(-1).*repmat(linspace(min(xData),max(xData),100),100,1).^(2)),'FaceColor',[0.501960813999176 0.501960813999176 0.501960813999176],'EdgeColor',[0.501960813999176 0.501960813999176 0.501960813999176]) + % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) + set(gca,'yScale','log') + % set(gca,'zScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + % zlabel('$D2 (x,r) / [\frac{m^2}{s^3}]$', 'interpreter','latex') + zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') + colormap (parula(200)) + % colorbar + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + % zlim([0 2*max(zData)]) + % caxis([0 max(zData)]) + axis square + % close + set(gca,'YDir','reverse'); + set(gca,'TickLabelInterpreter','latex'); + title('optimized KM, optimized fit','interpreter','latex'); + % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') + % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') + rotate3d on + colorbar('north','TickLabelInterpreter','latex','AxisLocation','out'); + fig_setup + legend off + txt = {'(b)'}; + b=text(4,0.5,txt); + b.Units='normalized'; + + % optimized coefficients + %%%%% 2019 %%%%%%%% + % D2(x,y) = (b0*y^rb0+b00) + (b1*y^rb1+b11)*x + (b2*y^rb2+b22)*x^2 + co_KM_opti.(my_field).b = [fitresult_D2.b0 fitresult_D2.b00 fitresult_D2.b1 fitresult_D2.b11 fitresult_D2.b2 fitresult_D2.b22]; + co_KM_opti.(my_field).eb = [fitresult_D2.rb0 fitresult_D2.rb1 fitresult_D2.rb2 ]; % for D2 + + % non-optimized coefficients + [fitresult_D2_o, xData_o2, yData_o2, zData_o2, weights] = FIT_D2(xx, y, z2, z2e); + %%%%% 2019 %%%%%%%% + % D2(x,y) = (b0*y^rb0+b00) + (b1*y^rb1+b11)*x + (b2*y^rb2+b22)*x^2 + co_no_opti.(my_field).b = [fitresult_D2_o.b0 fitresult_D2_o.b00 fitresult_D2_o.b1 fitresult_D2_o.b11 fitresult_D2_o.b2 fitresult_D2_o.b22]; + co_no_opti.(my_field).eb = [ fitresult_D2_o.rb0 fitresult_D2_o.rb1 fitresult_D2_o.rb2 ]; % for D2 + + + % optimized coefficients no offset + ft = fittype( '(b0*y^rb0) + (b1*y^rb1)*x + (b2*y^rb2)*x^2', 'independent', {'x', 'y'}, 'dependent', 'z' ); + opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); + % opts.DiffMinChange = 1e-12; + % opts.Display = 'Off'; + % opts.MaxFunEvals = 1000; + % opts.MaxIter = 1000; + % opts.TolFun = 1e-12; + % opts.TolX = 1e-12; + opts.Weights = weights; + + % opts.StartPoint = [0.2 -0.02 0.007 0.001 -1 -0.3]; + % opts.Lower = [0 -1 0 0 -2 -2]; + % opts.Upper = [1 1 1 2 2 0]; + + opts.StartPoint = [0 0 0 0 0 0]; + opts.Lower = [-1 -1 -1 0 -Inf -Inf]; + opts.Upper = [1 1 1 Inf Inf 0]; + + [fitresult_D2_old, gof] = fit( [xData, yData], zData, ft, opts ); + co_KM_opti_old.(my_field).b = [fitresult_D2_old.b0 0 fitresult_D2_old.b1 0 fitresult_D2_old.b2 0]; + co_KM_opti_old.(my_field).eb = [fitresult_D2_old.rb0 fitresult_D2_old.rb1 fitresult_D2_old.rb2 ]; % for D2 + + + %% d_ij(r) plots + h(3) = figure; + subplot(2,2,1); + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D1.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra1+fitresult_D1.a11,'LineWidth',2) + hold on + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D1_o.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1_o.ra1+fitresult_D1_o.a11,'LineWidth',2) +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% fitresult_D1_old.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1_old.ra1,'LineWidth',2,'Color','k') +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% (-0.36).*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^(-1),'LineWidth',2,'Color',[0.501960813999176 0.501960813999176 0.501960813999176]) + axis square + ylabel('$d_{11}$', 'interpreter','latex') + if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') + end + xlim([min(y(:,1)) max(y(:,1))]) + set(gca, 'FontSize',12) + % + subplot(2,2,2); + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb0+fitresult_D2.b00,'LineWidth',2) + hold on + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2_o.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb0+fitresult_D2_o.b00,'LineWidth',2) + +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% fitresult_D2_old.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb0,'LineWidth',2,'Color','k') + axis square + ylabel('$d_{20}$', 'interpreter','latex') + if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') + end + xlim([min(y(:,1)) max(y(:,1))]) + set(gca, 'FontSize',12) + % + subplot(2,2,3); + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb1+fitresult_D2.b11,'LineWidth',2) + hold on + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2_o.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb1+fitresult_D2_o.b11,'LineWidth',2) +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% fitresult_D2_old.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb1,'LineWidth',2,'Color','k') + axis square + ylabel('$d_{21}$', 'interpreter','latex') + if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') + end + xlim([min(y(:,1)) max(y(:,1))]) + set(gca, 'FontSize',12) + % + subplot(2,2,4); + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb2+fitresult_D2.b22,'LineWidth',2) + hold on + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2_o.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb2+fitresult_D2_o.b22,'LineWidth',2) +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% fitresult_D2_old.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb2,'LineWidth',2,'Color','k') +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% 0.0144.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^(-1),'LineWidth',2,'Color',[0.501960813999176 0.501960813999176 0.501960813999176]) + axis square + ylabel('$d_{22}$', 'interpreter','latex') + if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') + end + xlim([min(y(:,1)) max(y(:,1))]) + set(gca, 'FontSize',14) + set(gca,'TickLabelInterpreter','latex'); + set(gcf, 'Color', 'w') + %legend('optimized','non-optimized','Location','NorthWest') +% legend({'Optimized','Non-optimized','Optimized no offset','K62'},'Position',[0.45 0.5 0.1 0.05]) + legend({'Optimized','Non-optimized','K62'},'Position',[0.45 0.5 0.1 0.05]) + + close all + disp(['point:' num2str(k) '/' num2str(length(condition)) ]) + end + end +else + evaluated = evaluated_point; + xx = nan(length(evaluated),increment_bin); + y = nan(length(evaluated),increment_bin); + z1 = nan(length(evaluated),increment_bin); + z1e = nan(length(evaluated),increment_bin); + z2 = nan(length(evaluated),increment_bin); + z2e = nan(length(evaluated),increment_bin); + z1_opti = nan(length(evaluated),increment_bin); + z2_opti = nan(length(evaluated),increment_bin); + z4 = nan(length(evaluated),increment_bin); + + % for i=find((evaluated.r)/taylor_L>4):length(evaluated) + for i=1:length(evaluated) + xx(i,1:sum(evaluated(i).x_bin_not_nan))=evaluated(i).y_mean_bin(evaluated(i).x_bin_not_nan); + if norm_r==1 + y(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).r./taylor_L); + else + y(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).r); + end + z1(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1(evaluated(i).x_bin_not_nan)); + z1e(i,1:sum(evaluated(i).x_bin_not_nan))=abs(1./(evaluated(i).eD1(evaluated(i).x_bin_not_nan))); + + z2(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2(evaluated(i).x_bin_not_nan)); + z2e(i,1:sum(evaluated(i).x_bin_not_nan))=abs(1./(evaluated(i).eD2(evaluated(i).x_bin_not_nan))); + + z1_opti(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1_opti); + z2_opti(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2_opti); + + z4(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D4(evaluated(i).x_bin_not_nan)); + end + +% z1_opti=z1_opti.*0.5; +% z2_opti=z2_opti.*0.5; + + %TEST Beginn + % y=y-(((markov./Fs).*m_data)/taylor_L); + %TEst Ende + + + %% D1-Fit + [fitresult_D1, xData, yData, zData, weights] = FIT_D1(xx, y, z1_opti, z1e); + fitresult_D1_conf = confint(fitresult_D1); + + h(1) = figure; + % surf(xx, y, z1_opti,'EdgeColor','none') + scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + hold on + surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D1,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') +% surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),... +% (-0.36.*repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100).^(-1).*repmat(linspace(min(xData),max(xData),100),100,1)),'FaceColor',[0.501960813999176 0.501960813999176 0.501960813999176],'EdgeColor',[0.501960813999176 0.501960813999176 0.501960813999176]) + + % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) + set(gca,'yScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') + % zlabel('$D1 (x,r) / [\frac{m}{s^2}]$', 'interpreter','latex') + colormap (parula(200)) + % colorbar + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + % zlim([-0.005 0.005]) + axis square + set(gca,'YDir','reverse'); +% title('optimized KM, optimized fit','interpreter','latex'); + % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') + % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') + rotate3d on + colorbar('north','TickLabelInterpreter','latex','AxisLocation','out'); + fig_setup + legend off + txt = {'(a)'}; + a=text(4,0.5,txt); + a.Units='normalized'; + + + %%%%% 2019 %%%%%%%% + % optimized coefficients + % D1(x,y) = (a1*y^ra1+a11)*x + co_KM_opti.a = [fitresult_D1.a1 fitresult_D1.a11]; + co_KM_opti.ea = [fitresult_D1.ra1]; + + % non-optimized coefficients + [fitresult_D1_o, xData_o1, yData_o1, zData_o1, weights] = FIT_D1(xx, y, z1, z1e); + %%%%% 2019 %%%%%%%% + % D1(x,y) = (a1*y^ra1+a11)*x + co_no_opti.a = [fitresult_D1_o.a1 fitresult_D1_o.a11]; + co_no_opti.ea = [fitresult_D1_o.ra1]; + + % optimized coefficients no offset + % D1(x,y) = (a1*y^ra1)*x + ft = fittype( '(a1*y^ra1)*x', 'independent', {'x', 'y'}, 'dependent', 'z' ); + opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); + % opts.DiffMinChange = 1e-12; + % opts.Display = 'Off'; + % opts.MaxFunEvals = 1000; + % opts.MaxIter = 1000; + % opts.TolFun = 1e-12; + % opts.TolX = 1e-12; + opts.Weights = weights; + + % opts.StartPoint = [-0.1 -1]; + % opts.Lower = [-2 -2]; + % opts.Upper = [0 0]; + + opts.StartPoint = [0 0]; + opts.Lower = [-1 -Inf]; + opts.Upper = [1 0]; + + [fitresult_D1_old, gof] = fit( [xData, yData], zData, ft, opts ); + co_KM_opti_old.a = [fitresult_D1_old.a1 0]; + co_KM_opti_old.ea = [fitresult_D1_old.ra1]; + + % figure + % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra0) + % hold on + % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra1) + % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^0) + % plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),fitresult_D1.a3.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra3) + % set(gca,'xScale','log') + % axis square + % set(gcf, 'Color', 'w') + % % grid on + % xlabel('$r / \lambda$', 'interpreter','latex') + % legend('d_{10}(r)','d_{11}(r)','d_{12}(r)','d_{13}(r)') + % xlim([min(y(:,1)) max(y(:,1))]) + + + + %% D2-Fit + [fitresult_D2, xData, yData, zData, weights] = FIT_D2(xx, y, z2_opti, z2e); + fitresult_D2_conf = confint(fitresult_D2); + h(2) = figure; + % surf(xx, y, z2_opti,'EdgeColor','none') + scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + hold on + surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D2,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') +% surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),... +% (0.0144.*repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100).^(-1).*repmat(linspace(min(xData),max(xData),100),100,1).^(2)),'FaceColor',[0.501960813999176 0.501960813999176 0.501960813999176],'EdgeColor',[0.501960813999176 0.501960813999176 0.501960813999176]) + % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) + set(gca,'yScale','log') + % set(gca,'zScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + % zlabel('$D2 (x,r) / [\frac{m^2}{s^3}]$', 'interpreter','latex') + zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') + colormap (parula(200)) + % colorbar + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + % zlim([0 2*max(zData)]) + % caxis([0 max(zData)]) + axis square + % close + set(gca,'YDir','reverse'); + set(gca,'TickLabelInterpreter','latex'); +% title('optimized KM, optimized fit','interpreter','latex'); + % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') + % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') + rotate3d on + colorbar('north','TickLabelInterpreter','latex','AxisLocation','out'); + fig_setup + legend off + txt = {'(b)'}; + b=text(4,0.5,txt); + b.Units='normalized'; + + font=22; + a.FontSize = font; + b.FontSize = font; + pos_txt=[-0.22 0.8]; + a.Position=pos_txt; + b.Position=[-0.25 0.8]; + + % optimized coefficients + %%%%% 2019 %%%%%%%% + % D2(x,y) = (b0*y^rb0+b00) + (b1*y^rb1+b11)*x + (b2*y^rb2+b22)*x^2 + co_KM_opti.b = [fitresult_D2.b0 fitresult_D2.b00 fitresult_D2.b1 fitresult_D2.b11 fitresult_D2.b2 fitresult_D2.b22]; + co_KM_opti.eb = [fitresult_D2.rb0 fitresult_D2.rb1 fitresult_D2.rb2 ]; % for D2 + + % non-optimized coefficients + [fitresult_D2_o, xData_o2, yData_o2, zData_o2, weights] = FIT_D2(xx, y, z2, z2e); + %%%%% 2019 %%%%%%%% + % D2(x,y) = (b0*y^rb0+b00) + (b1*y^rb1+b11)*x + (b2*y^rb2+b22)*x^2 + co_no_opti.b = [fitresult_D2_o.b0 fitresult_D2_o.b00 fitresult_D2_o.b1 fitresult_D2_o.b11 fitresult_D2_o.b2 fitresult_D2_o.b22]; + co_no_opti.eb = [ fitresult_D2_o.rb0 fitresult_D2_o.rb1 fitresult_D2_o.rb2 ]; % for D2 + + + % optimized coefficients no offset + ft = fittype( '(b0*y^rb0) + (b1*y^rb1)*x + (b2*y^rb2)*x^2', 'independent', {'x', 'y'}, 'dependent', 'z' ); + opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); + % opts.DiffMinChange = 1e-12; + % opts.Display = 'Off'; + % opts.MaxFunEvals = 1000; + % opts.MaxIter = 1000; + % opts.TolFun = 1e-12; + % opts.TolX = 1e-12; + opts.Weights = weights; + + % opts.StartPoint = [0.2 -0.02 0.007 0.001 -1 -0.3]; + % opts.Lower = [0 -1 0 0 -2 -2]; + % opts.Upper = [1 1 1 2 2 0]; + + opts.StartPoint = [0 0 0 0 0 0]; + opts.Lower = [-1 -1 -1 0 -Inf -Inf]; + opts.Upper = [1 1 1 Inf Inf 0]; + + [fitresult_D2_old, gof] = fit( [xData, yData], zData, ft, opts ); + co_KM_opti_old.b = [fitresult_D2_old.b0 0 fitresult_D2_old.b1 0 fitresult_D2_old.b2 0]; + co_KM_opti_old.eb = [fitresult_D2_old.rb0 fitresult_D2_old.rb1 fitresult_D2_old.rb2 ]; % for D2 + + + %% d_ij(r) plots + h(3) = figure; + subplot(2,2,1); + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D1.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1.ra1+fitresult_D1.a11,'LineWidth',2) + hold on + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D1_o.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1_o.ra1+fitresult_D1_o.a11,'LineWidth',2) +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% fitresult_D1_old.a1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D1_old.ra1,'LineWidth',2,'Color','k') +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% (-0.36).*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^(-1),'LineWidth',2,'Color',[0.501960813999176 0.501960813999176 0.501960813999176]) + axis square + ylabel('$d_{11}$', 'interpreter','latex') + if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') + end + xlim([min(y(:,1)) max(y(:,1))]) + set(gca, 'FontSize',14) + fig_setup + legend off + txt = {'(a)'}; + a=text(4,0.5,txt); + a.Units='normalized'; + % + subplot(2,2,2); + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb0+fitresult_D2.b00,'LineWidth',2) + hold on + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2_o.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb0+fitresult_D2_o.b00,'LineWidth',2) + +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% fitresult_D2_old.b0.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb0,'LineWidth',2,'Color','k') + axis square + ylabel('$d_{20}$', 'interpreter','latex') + if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r\ (m)$', 'interpreter','latex') + end + xlim([min(y(:,1)) max(y(:,1))]) + set(gca, 'FontSize',14) + fig_setup + legend off + txt = {'(b)'}; + b=text(4,0.5,txt); + b.Units='normalized'; + + % + subplot(2,2,3); + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb1+fitresult_D2.b11,'LineWidth',2) + hold on + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2_o.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb1+fitresult_D2_o.b11,'LineWidth',2) +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% fitresult_D2_old.b1.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb1,'LineWidth',2,'Color','k') + axis square + ylabel('$d_{21}$', 'interpreter','latex') + if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r\ (m)$', 'interpreter','latex') + end + xlim([min(y(:,1)) max(y(:,1))]) + set(gca, 'FontSize',14) + fig_setup + legend off + txt = {'(c)'}; + c=text(4,0.5,txt); + c.Units='normalized'; + + + % + subplot(2,2,4); + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2.rb2+fitresult_D2.b22,'LineWidth',2) + hold on + plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... + fitresult_D2_o.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_o.rb2+fitresult_D2_o.b22,'LineWidth',2) +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% fitresult_D2_old.b2.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^fitresult_D2_old.rb2,'LineWidth',2,'Color','k') +% plot(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100),... +% 0.0144.*logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).^(-1),'LineWidth',2,'Color',[0.501960813999176 0.501960813999176 0.501960813999176]) + axis square + ylabel('$d_{22}$', 'interpreter','latex') + if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r\ (m)$', 'interpreter','latex') + end + xlim([min(y(:,1)) max(y(:,1))]) + set(gca, 'FontSize',14) + set(gca,'TickLabelInterpreter','latex'); + set(gcf, 'Color', 'w') + %legend('optimized','non-optimized','Location','NorthWest') +% legend({'Optimized','Non-optimized','Optimized no offset','K62'},'Position',[0.45 0.5 0.1 0.05]) + legend({'Optimized','Non-optimized','K62'},'Position',[0.45 0.5 0.1 0.05]) + fig_setup +% legend off + txt = {'(d)'}; + d=text(4,0.5,txt); + d.Units='normalized'; + + font=22; + a.FontSize = font; + b.FontSize = font; + c.FontSize = font; + d.FontSize = font; + + pos_txt=[-0.68 0.9]; + a.Position=pos_txt; + b.Position=pos_txt; + c.Position=pos_txt; + d.Position=pos_txt; + + %% 3D plots + figure + % surf(xx, y, z1_opti,'EdgeColor','none') + scatter3(xData_o1, yData_o1, zData_o1,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + hold on + surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D1,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') + % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) + set(gca,'yScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') + % zlabel('$D1 (x,r) / [\frac{m}{s^2}]$', 'interpreter','latex') + colormap (parula(200)) + % colorbar + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + % zlim([-0.005 0.005]) + axis square + set(gca,'YDir','reverse'); + set(gca,'TickLabelInterpreter','latex'); + title('non-optimized KM, optimized fit','interpreter','latex'); + close + + + figure + % surf(xx, y, z2_opti,'EdgeColor','none') + scatter3(xData_o2,yData_o2,zData_o2,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + % scatter3(xData,yData,yData.*zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + hold on + surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D2,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') + % surf(repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100),feval(fitresult_D1,repmat(linspace(-4,4,100),100,1),repmat(linspace(min(y(:,1)),max(y(:,1)),100).',1,100))) + set(gca,'yScale','log') + % set(gca,'zScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + % zlabel('$D2 (x,r) / [\frac{m^2}{s^3}]$', 'interpreter','latex') + zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') + colormap (parula(200)) + % colorbar + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + % zlim([0 2*max(zData)]) + % caxis([0 max(zData)]) + axis square + % close + set(gca,'YDir','reverse'); + set(gca,'TickLabelInterpreter','latex'); + % title(['$(', num2str(fitresult_D1.a1,'%1.1E'), ' * r / \lambda^{' num2str(fitresult_D1.ra1,'%1.1E') '} ) * u_r $'],'interpreter','latex') + % title(['$\left(',num2str(fitresult_D1.a1),'\cdot r/\lambda^{',num2str(fitresult_D1.ra1),'} +',num2str(fitresult_D1.a11),' \right)\cdot u_r $'],'interpreter','latex') + title('non-optimized KM, optimized fit','interpreter','latex'); + close + + figure + scatter3(xData_o1, yData_o1, zData_o1,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + hold on + surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D1_o,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') + set(gca,'yScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') + colormap (parula(200)) + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + axis square + set(gca,'YDir','reverse'); + set(gca,'TickLabelInterpreter','latex'); + title('non-optimized KM, non-optimized fit','interpreter','latex'); + close + + + figure + scatter3(xData_o2,yData_o2,zData_o2,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + hold on + surf(repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100),feval(fitresult_D2_o,repmat(linspace(min(xData),max(xData),100),100,1),repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100)),'EdgeColor','none') + set(gca,'yScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') + colormap (parula(200)) + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + axis square + set(gca,'YDir','reverse'); + set(gca,'TickLabelInterpreter','latex'); + title('non-optimized KM, non-optimized fit','interpreter','latex'); + set(gca,'TickLabelInterpreter','latex'); + close + + + + + z1=nan(length(evaluated),increment_bin); + z2=nan(length(evaluated),increment_bin); + xx_no_opti = nan(length(evaluated),increment_bin); + + for i=1:length(evaluated) +% xx_no_opti(i,:)=evaluated(i).y_mean_bin; +% z1(i,:)=(evaluated(i).D1); +% z2(i,:)=(evaluated(i).D2); + xx_no_opti=xx; + z1(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D1(evaluated(i).x_bin_not_nan)); + z2(i,1:sum(evaluated(i).x_bin_not_nan))=(evaluated(i).D2(evaluated(i).x_bin_not_nan)); + end + + [xData, yData, zData] = prepareSurfaceData( xx, y, z1_opti); + tmp_u=repmat(linspace(min(xData),max(xData),100),100,1); + tmp_r=repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100); + + h(4) = figure; +% scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + scatter3(xData,yData,zData,'MarkerFaceColor',[0 0.4470 0.7410],'MarkerEdgeColor',[1 1 1]) + hold on + [xData, yData, zData] = prepareSurfaceData( xx_no_opti, y, z1); + scatter3(xData,yData,zData,'MarkerFaceColor',[0.8500, 0.3250, 0.0980],'MarkerEdgeColor',[1 1 1]) + set(gca,'yScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + zlabel('$D^{(1)} (u_r,r)$', 'interpreter','latex') + % zlabel('$D1 (x,r) / [\frac{m}{s^2}]$', 'interpreter','latex') + colormap (parula(200)) + % colorbar + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + % zlim([-0.005 0.005]) + axis square + set(gca,'YDir','reverse'); + rotate3d on + legend({'Optimized','Non-optimized'},'Position',[0.5 0.7 0.3 0.1]) + + + + [xData, yData, zData] = prepareSurfaceData( xx, y, z2_opti); + tmp_u=repmat(linspace(min(xData),max(xData),100),100,1); + tmp_r=repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100); + h(5) = figure; +% scatter3(xData,yData,zData,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[1 1 1]) + scatter3(xData,yData,zData,'MarkerFaceColor',[0 0.4470 0.7410],'MarkerEdgeColor',[1 1 1]) + hold on + [xData, yData, zData] = prepareSurfaceData( xx_no_opti, y, z2); + tmp_u=repmat(linspace(min(xData),max(xData),100),100,1); + tmp_r=repmat(logspace(log10(min(y(:,1))),log10(max(y(:,1))),100).',1,100); + scatter3(xData,yData,zData,'MarkerFaceColor',[0.8500, 0.3250, 0.0980],'MarkerEdgeColor',[1 1 1]) + % surf(tmp_u,tmp_r,... + % (d20_R+d21_R.*tmp_u+d22_R.*tmp_u.^2)... + % ,'FaceColor',[0.831372559070587 0.815686285495758 0.7843137383461]) + set(gca,'yScale','log') + % set(gca,'zScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + if norm_ur==1 + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + else + xlabel('$u_r\ (m/s)$', 'interpreter','latex') + end + if norm_r==1 + ylabel('$r / \lambda$', 'interpreter','latex') + else + ylabel('$r\ (m)$', 'interpreter','latex') + end + % zlabel('$D2 (x,r) / [\frac{m^2}{s^3}]$', 'interpreter','latex') + zlabel('$D^{(2)} (u_r,r)$', 'interpreter','latex') + colormap (parula(200)) + % colorbar + grid off + xlim([min(xData) max(xData)]) + ylim([min(y(:,1)) max(y(:,1))]) + % zlim([0 2*max(zData)]) + caxis([0 max(zData)]) + axis square + % close + set(gca,'YDir','reverse'); + rotate3d on + legend({'Optimized','Non-optimized'},'Position',[0.5 0.7 0.3 0.1]) + + if ischar(save_path) + savefig(h,fullfile(save_path,append(save_name,'_','KM_Fit.fig')),'compact') + for a = 1:length(h) + exportgraphics(h(a),fullfile(save_path,append(save_name,'_',sprintf('KM_Fit_%d.png', a)))) + end + end + +end +for i=1:5 + tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); + uiwait(gcf); + delete(tmp_ui); + close +end end \ No newline at end of file diff --git a/Functions_v5-MATLAB/KM_Calculation.m b/Functions_v5-MATLAB/KM_Calculation.m index 26a872a..fbf5584 100644 --- a/Functions_v5-MATLAB/KM_Calculation.m +++ b/Functions_v5-MATLAB/KM_Calculation.m @@ -24,9 +24,11 @@ % m_data = mean of the data % multi_point = Multipoint condition 1=YES or 2=NO % condition = This input is for multipoint statistics +% norm_r = normalization of the scale using $\lambda$? data 1=Yes, 0=No % % Arguments OUT % evaluated = a modified/updated struct 'evaluated' array +% Enclosed in a "evaluated": % r is the scale in meters at which moments will be calculated and hence this r will % be the same at which D1 & D2 will be calculated===>r2 % r_samp is nothing but the r in number of samples==>r2 diff --git a/Functions_v5-MATLAB/KM_STP_optimization.m b/Functions_v5-MATLAB/KM_STP_optimization.m index a938bfc..fedd25a 100644 --- a/Functions_v5-MATLAB/KM_STP_optimization.m +++ b/Functions_v5-MATLAB/KM_STP_optimization.m @@ -25,6 +25,10 @@ % tol_opti = Optimization: Tolerance of the range of Kramers-Moyal coefficients in % % It is the percentage(For Ex: 0.1 for 10 percent or 0.2 for 20 percent)of D1 or D2 % within these limit which you want to optimize these coeffcients D1 & D2 +% norm_ur = normalization of the data using $\sigma_\infty$? data 1=Yes, 0=No +% norm_r = normalization of the scale using $\lambda$? data 1=Yes, 0=No +% save_path = path for saving figures and files +% save_name = name for saving files % % Arguments OUT % evaluated = a modified/updated struct 'evaluated' array with optimized value of D1 & D2 diff --git a/Functions_v5-MATLAB/KM_plot.m b/Functions_v5-MATLAB/KM_plot.m index 00e616d..712d62c 100644 --- a/Functions_v5-MATLAB/KM_plot.m +++ b/Functions_v5-MATLAB/KM_plot.m @@ -11,6 +11,10 @@ % taylor_L = Taylor length scale in meters % multi_point = Multipoint condition 1=YES or 2=NO % condition = This input is for multipoint statistics +% norm_ur = normalization of the data using $\sigma_\infty$? data 1=Yes, 0=No +% norm_r = normalization of the scale using $\lambda$? data 1=Yes, 0=No +% save_path = path for saving figures and files +% save_name = name for saving files %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function KM_plot(co,evaluated,Fs,taylor_L,int_L,multi_point,condition,norm_ur,norm_r,save_path,save_name,varargin) diff --git a/Functions_v5-MATLAB/KM_plot_raw.m b/Functions_v5-MATLAB/KM_plot_raw.m index 4313e09..4750d8c 100644 --- a/Functions_v5-MATLAB/KM_plot_raw.m +++ b/Functions_v5-MATLAB/KM_plot_raw.m @@ -9,6 +9,10 @@ % taylor_L = Taylor length scale in meters % point = Multipoint condition 1=YES or 2=NO % condition = This input is for multipoint statistics +% norm_ur = normalization of the data using $\sigma_\infty$? data 1=Yes, 0=No +% norm_r = normalization of the scale using $\lambda$? data 1=Yes, 0=No +% save_path = path for saving figures and files +% save_name = name for saving files %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function KM_plot_raw(evaluated,Fs,taylor_L,point,condition,norm_ur,norm_r,save_path,save_name) diff --git a/Functions_v5-MATLAB/OPTI_IFT_dij.m b/Functions_v5-MATLAB/OPTI_IFT_dij.m index 9415a93..29d152c 100644 --- a/Functions_v5-MATLAB/OPTI_IFT_dij.m +++ b/Functions_v5-MATLAB/OPTI_IFT_dij.m @@ -1,386 +1,390 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% This function performs the pointwise optimization of Kramers-Moyal coefficients towards the -% integral fluctuation theorem will be done. Thereby the separation of scales/step increment -% (in samples) referred to the sequence from large to small scales in the cascade trajectory is set -% to a minimum of 1 sample and for the optimization, independent cascade trajectories (z=3) are used. -% Note, we use here a separation that is less than or equal to the Einstein-Markov length of $\Delta_{EM}$. -% -% This function performs the optimization of $D^{(1,2)}\left(u_r,r\right)$ at each scale and at each -% value of velocity increment in order to satisfy the integral fluctuation theorem with minimum -% possible error and plots the optimized $d_{ij}$ as a function of $r$. The optimization procedure -% systematically changes $D^{(1,2)}\left(u_r,r\right)$ until the error function -% \begin{eqnarray} -% \xi =|1-\langle e^{\mathrm{-}\Delta S_{tot}} \rangle_{max(N)}| -% \end{eqnarray} -% is minimized. -% -% Arguments IN -% tol_D1 = Tolerance of the range of Kramers-Moyal coefficients in %% for the Optimization -% tol_D2 = tol_D1; -% evaluated = a modified/updated struct 'evaluated' array with in function 'KM_STP_optimization' -% co_KM_opti = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients towards the best -% Fokker-Planck equation to reproduce the conditional PDF's using the surface fits -% fitresult_D1_conf = Confidence intervals for fit coefficients of D1 (co_KM_opti) -% fitresult_D2_conf = Confidence intervals for fit coefficients of D2 (co_KM_opti) -% int_L = Integral length scale in meters -% taylor_L = Taylor length scale in meters -% m_data = mean of the data -% Fs = Acquisition/Sampling Frequency in Hz -% data = filtered data -% z = This is the parameter which decides how to compute entropy using different methods using either -% overlapping or independent trajectories -% z = 1 ==> Overlapping trajectories -% z = 3 ==> Independent trajectories -% iter = The maximum number of iteration used for the optimization algorithms -% markov = markov length in number of samples -% trajec = 1 ==> The start/end of the cascade trajectory will be adjusted. -% dr_ind = Separation of scales/step increment (in samples) referred to the sequence from large to small scales in the cascade trajectory -% -% Arguments OUT -% co_IFT_opti = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients towards the -% integral fluctuation theorem using the surface fits -% history = details of the optimization for every single iteration -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function [co_IFT_opti,history]=OPTI_IFT_dij(tol_D1,tol_D2,evaluated,co_KM_opti,fitresult_D1_conf,fitresult_D2_conf,int_L,taylor_L,m_data,Fs,data,z,iter,markov,trajec,dr_ind,norm_ur,norm_r,save_path,save_name) -set(groot, 'defaultAxesTickLabelInterpreter','latex'); -set(groot, 'defaulttextinterpreter','latex'); -set(groot, 'defaultLegendInterpreter','latex'); -set(groot, 'defaultAxesTitle','latex'); - -% if z==1 -% [Sm,Ds,DS,~,~,~,~]=checkFT(evaluated,int_L,taylor_L,Fs,data,m_data,z,co_KM_opti,1,markov,trajec,dr_ind); -% %Plot of Entropy -% plot_entropy(Sm,Ds,DS) -% set(gca, 'FontSize',10) -% data_length=str2double(inputdlg({'Data length for optimization in samples:'})); -% clear Sm Ds DS -% end - - -%% Initial D1 and D2 before optimization -clear r_norm -r_norm = nan(1,length(evaluated)); - -if norm_r==1 - for i=1:length(evaluated) - r_norm(1,i) = (evaluated(i).r./taylor_L); - end -else - for i=1:length(evaluated) - r_norm(1,i) = (evaluated(i).r); - end -end - - -% fitresult_D1 -d11 = co_KM_opti.a(1).*r_norm.^co_KM_opti.ea(1)+co_KM_opti.a(2); -% fitresult_D2 -d20 = co_KM_opti.b(1).*r_norm.^co_KM_opti.eb(1)+co_KM_opti.b(2); -d21 = co_KM_opti.b(3).*r_norm.^co_KM_opti.eb(2)+co_KM_opti.b(4); -% d21=0.*d21; -d22 = co_KM_opti.b(5).*r_norm.^co_KM_opti.eb(3)+co_KM_opti.b(6); -x0 = [d11 d20 d21 d22]; - - -%% Tolerance of the range of Kramers-Moyal coefficients -clear x1 lb ub -% x1(1:length(x0)) = nan; -lb(1:length(x0)) = nan; -ub(1:length(x0)) = nan; - -% percent of the range -% D1 Opti -t = length(r_norm); -lb(1:t) = x0(1:t)-abs(x0(1:t).*tol_D1); % Lower bound -ub(1:t) = x0(1:t)+abs(x0(1:t).*tol_D1); % Upper bound - -% D2 Opti -for i=1:3 - lb(t*i+1:(t*i+1)+t-1) = x0(t*i+1:(t*i+1)+t-1)-abs(x0(t*i+1:(t*i+1)+t-1).*tol_D2); - ub(t*i+1:(t*i+1)+t-1) = x0(t*i+1:(t*i+1)+t-1)+abs(x0(t*i+1:(t*i+1)+t-1).*tol_D2); -end - - -% constant value 10% of max/min value -% D1 Opti -% t = length(r_norm); -% lb(1:t) = x0(1:t)-(max(abs(x0(1:t))).*tol_D1); -% ub(1:t) = x0(1:t)+(max(abs(x0(1:t))).*tol_D1); - -% D2 Opti -% for i=1:3 -% lb(t*i+1:(t*i+1)+t-1) = x0(t*i+1:(t*i+1)+t-1)-(max(abs(x0(t*i+1:(t*i+1)+t-1))).*tol_D2); -% ub(t*i+1:(t*i+1)+t-1) = x0(t*i+1:(t*i+1)+t-1)+(max(abs(x0(t*i+1:(t*i+1)+t-1))).*tol_D2); -% end - - -% fix to min and max value -% d11 -% lb(1:t) = min(lb(1:t)); -% ub(1:t) = max(ub(1:t)); - -% d20 -% lb(t*1+1:(t*1+1)+t-1) = min(lb(t*1+1:(t*1+1)+t-1)); -% ub(t*1+1:(t*1+1)+t-1) = max(ub(t*1+1:(t*1+1)+t-1)); - -% d21 -% lb(t*2+1:(t*2+1)+t-1) = min(lb(t*2+1:(t*2+1)+t-1)); -% ub(t*2+1:(t*2+1)+t-1) = max(ub(t*2+1:(t*2+1)+t-1)); - -% d22 -% lb(t*3+1:(t*3+1)+t-1) = min(lb(t*3+1:(t*3+1)+t-1)); -% ub(t*3+1:(t*3+1)+t-1) = max(ub(t*3+1:(t*3+1)+t-1)); - - -% using confidence intervals for fit coefficients of D1 and D2 (co_KM_opti) -% D1 Opti -% lb(1:2) = [fitresult_D1_conf(1,1:2)]; -% lb(9) = [fitresult_D1_conf(1,3)]; -% ub(1:2) = [fitresult_D1_conf(2,1:2)]; -% ub(9) = [fitresult_D1_conf(2,3)]; - -% D2 Opti -% lb(3:8) = [fitresult_D2_conf(1,1:6)]; -% lb(10:end) = [fitresult_D2_conf(1,7:9)]; -% ub(3:8) = [fitresult_D2_conf(2,1:6)]; -% ub(10:end) = [fitresult_D2_conf(2,7:9)]; - -% lb(isnan(lb))=0; -% ub(isnan(ub))=0; - - -%% The constraints were set in a physically and mathematically meaningful way: -% (see for more details \textbf{\textit{FIT\_KM}}) -% d11 <= 0 -if ub(1:t)>0 - ub(ub(1:t)>0) = 0; -end -% d20 >= 0 -if lb(t*1+1:(t*1+1)+t-1)<0 - lb(lb(t*1+1:(t*1+1)+t-1)<0) = 0; -end -% d22 >= 0 -if lb(t*3+1:(t*3+1)+t-1)<0 - lb(lb(t*3+1:(t*3+1)+t-1)) = 0; -end - - - -%% Selcet dij for the optimization -if askYesno('Do you want to perform the pointwise optimization of d_11?', 'Yes') -else - lb(1:t) = x0(1:t); % Lower bound - ub(1:t) = x0(1:t); % Upper bound -end - -if askYesno('Do you want to perform the pointwise optimization of d_20?', 'Yes') -else - lb(t*1+1:(t*1+1)+t-1) = x0(t*1+1:(t*1+1)+t-1); - ub(t*1+1:(t*1+1)+t-1) = x0(t*1+1:(t*1+1)+t-1); -end - -if askYesno('Do you want to perform the pointwise optimization of d_21?', 'Yes') -else - lb(t*2+1:(t*2+1)+t-1) = x0(t*2+1:(t*2+1)+t-1); - ub(t*2+1:(t*2+1)+t-1) = x0(t*2+1:(t*2+1)+t-1); -end - -if askYesno('Do you want to perform the pointwise optimization of d_22?', 'Yes') -else - lb(t*3+1:(t*3+1)+t-1) = x0(t*3+1:(t*3+1)+t-1); - ub(t*3+1:(t*3+1)+t-1) = x0(t*3+1:(t*3+1)+t-1); -end - - -%% Plot dij(r) and optimizaiton range -figure -subplot(2,2,1); -plot(r_norm,... - lb(1:t),'LineWidth',2,'LineStyle','--') -hold on -plot(r_norm,... - d11,'k','LineWidth',2) -plot(r_norm,... - ub(1:t),'LineWidth',2,'LineStyle','--') -axis square -ylabel('$d_{11}$', 'interpreter','latex') -if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') -end -xlim([min(r_norm) max(r_norm)]) -set(gca, 'FontSize',24) -% -subplot(2,2,2); -plot(r_norm,... - lb(t*1+1:(t*1+1)+t-1),'LineWidth',2,'LineStyle','--') -hold on -plot(r_norm,... - d20,'k','LineWidth',2) -plot(r_norm,... - ub(t*1+1:(t*1+1)+t-1),'LineWidth',2,'LineStyle','--') -axis square -ylabel('$d_{d20}$', 'interpreter','latex') -if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') -end -xlim([min(r_norm) max(r_norm)]) -set(gca, 'FontSize',24) -% -subplot(2,2,3); -plot(r_norm,... - lb(t*2+1:(t*2+1)+t-1),'LineWidth',2,'LineStyle','--') -hold on -plot(r_norm,... - d21,'k','LineWidth',2) -plot(r_norm,... - ub(t*2+1:(t*2+1)+t-1),'LineWidth',2,'LineStyle','--') -axis square -ylabel('$d_{d21}$', 'interpreter','latex') -if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') -end -xlim([min(r_norm) max(r_norm)]) -set(gca, 'FontSize',24) -% -subplot(2,2,4); -plot(r_norm,... - lb(t*3+1:(t*3+1)+t-1),'LineWidth',2,'LineStyle','--') -hold on -plot(r_norm,... - d22,'k','LineWidth',2) -plot(r_norm,... - ub(t*3+1:(t*3+1)+t-1),'LineWidth',2,'LineStyle','--') -axis square -ylabel('$d_{d22}$', 'interpreter','latex') -if norm_r==1 - xlabel('$r / \lambda$', 'interpreter','latex') - else - xlabel('$r/m $', 'interpreter','latex') -end -xlim([min(r_norm) max(r_norm)]) -set(gca, 'FontSize',24) -set(gcf, 'Color', 'w') - - -%% Fix length of trajectories -if trajec==1 - L = 0; - % Generally each Overlapping/Non-Overlapping trajectory starts at L and - % ends at Lambda for the calculation of the entropy; but its a choice - % So we ask you at which biggest scale you want to start the trajectory - tmp = str2double(inputdlg({'Adjustment: Start of trajectory 1=Yes, 0=No'})); - if tmp == 1 - % Here, if you want to start your trajectories at scale smaller than L then - % you should enter a value between 0 & 1 - % For ex: if your L=1 meters and you enter 0.9 your trajectory will start at 0.9 meters - L = str2double(inputdlg({'Start of trajectory in multiples of Integral length scale:'}))*int_L/taylor_L; - else - L = int_L/taylor_L; % dimless integral scale - end - % So we ask you at which smallest scale you want to end the trajectory - tmp = str2double(inputdlg({'Adjustment: End of trajectory 1=Yes, 0=No'})); - if tmp == 1 - % Here, if you want to end your trajectories at scale bigger than lambda then - % you should enter a value between 1 and (L/lambda) - % For ex: if your lambda=1 cm and if you enter 5 your - % trajectory will end at 5 cms - l = str2double(inputdlg({'End of trajectory in multiples of Taylor length scale:'}))*taylor_L/taylor_L; - else - l = evaluated(1).r/taylor_L;% dimless smallest scale by D1 and D2 - end -else % start=L, end=lambda - L = int_L/taylor_L; - l = 1; -end - -x = m_data.*(1:ceil(1.1*L*Fs*taylor_L/m_data)).'./Fs; -x = x/taylor_L; % dimless position -Lind = find(abs(x(:,1)-L )==min(abs(x(:,1)-L )), 1, 'last' ); % index for x showing the LAST entry where x is within range lambda..L -lind = find(abs(x(:,1)-l )==min(abs(x(:,1)-l )), 1, 'first'); % index for x showing the FIRST entry where x is within range lambda..L - -% Index for calculating the increment using data -Lind = Lind+1; -lind = lind+1; - -if lind<2 - lind = 2; -end - -rindful = 1:Lind; % index-vector for all scales -rind = fliplr(rindful(lind:Lind)); % index-vector only for scales from start to end of the cascade trajectory -% rind = round(linspace(Lind,lind,floor(L/l)+1)); % index-vector for scales in inertial range in steps of lambda -stp = Lind; % index used to cut v(x) in non-overlapping pieces of length equal to integral scale -% R(k).r = x(rind); % scales from index-vector -if norm_r==1 - r = x(rind); % scales from index-vector -else - r = x(rind).*taylor_L; % scales from index-vector -end -clear x -clear Sm Ds DS tmp_Sm tmp_Ds tmp_DS not_nan_index u x - - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% calc Entropy - overlapping trajectories -% if z==1 -% %% PDF of start/end of the cascade trajectory ==> Entropy of the system or the Shanon entropy -% rind_tmp = rind(1:dr_ind:end); -% end_L = size(data,1); -% tmp_size = size(data,1)-stp+1; -% u_tmp = nan( tmp_size, 2 ); -% -% for i=0:end_L-stp -% %% u -% % u_tmp(i+1,:) = (data([rind_tmp(1)+i,rind_tmp(end)+i])- data(1+i)).'; -% %% u_s -% u_tmp(i+1,:) = (data([rind_tmp(2)+i,rind_tmp(end-1)+i])- data(1+i)).'; -% end -% -% nbins=301; -% [fuL, uL] = hist(u_tmp(:,1),nbins); -% puL = fuL / ( nansum(fuL) * mean(diff(uL)) ); % relative frequency to approximate p(u,r=L) -% -% [ful, ul] = hist(u_tmp(:,2),uL); -% pul = ful / ( nansum(ful) * mean(diff(ul)) ); % relative frequency to approximate p(u,r=lambda) -% clear u_tmp -% -% [history] = runfmincon_overlap(x0,lb,ub,data(1:data_length),stp,r, uL, puL, ul, pul,rind,iter,r_norm,t,co_KM_opti); -% [history, x1] = runfmincon_overlap(x0,lb,ub,data(1:10^4),stp,r, uL, puL, ul, pul,rind,iter); -% end - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% calc Entropy - non-overlapping trajectories -if z==3 - tmp_size = ceil(numel(data)/stp); - [u] = create_us(data,r,rind,stp); -% [u] = create_us(data(1:0.5*10^7),r,rind,stp); - [history] = runfmincon(x0,lb,ub,u,r,tmp_size,iter,r_norm,t,co_KM_opti,markov,taylor_L,Fs,m_data,trajec,dr_ind,z); -end - - -% Find minimized error function -index = find(history.fval==min(history.fval),1,'first'); -[fit_d11] = FIT_d1j(r_norm,history.x1_iter(index,1:t)); -[fit_d20, fit_d21, fit_d22] = FIT_d2j(r_norm,history.x1_iter(index,:),t); - - -%% IFT optimzed dij coefficients -co_IFT_opti.a = [fit_d11.a1 fit_d11.a11]; -co_IFT_opti.ea = [fit_d11.ra1]; -co_IFT_opti.b = [fit_d20.b0 fit_d20.b00 fit_d21.b1 fit_d21.b11 fit_d22.b2 fit_d22.b22]; -co_IFT_opti.eb = [fit_d20.rb0 fit_d21.rb1 fit_d22.rb2]; - - -%% Plot: comparision co_KM_opti and co_IFT_opti dij coefficients -OPTI_IFT_plot(data,stp,r,rind,co_KM_opti,co_IFT_opti,evaluated,Fs,taylor_L,lb,ub,t,history,index,d11,d20,d21,d22,m_data,markov,trajec,dr_ind,z,norm_ur,norm_r,save_path,save_name) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% This function performs the pointwise optimization of Kramers-Moyal coefficients towards the +% integral fluctuation theorem will be done. Thereby the separation of scales/step increment +% (in samples) referred to the sequence from large to small scales in the cascade trajectory is set +% to a minimum of 1 sample and for the optimization, independent cascade trajectories (z=3) are used. +% Note, we use here a separation that is less than or equal to the Einstein-Markov length of $\Delta_{EM}$. +% +% This function performs the optimization of $D^{(1,2)}\left(u_r,r\right)$ at each scale and at each +% value of velocity increment in order to satisfy the integral fluctuation theorem with minimum +% possible error and plots the optimized $d_{ij}$ as a function of $r$. The optimization procedure +% systematically changes $D^{(1,2)}\left(u_r,r\right)$ until the error function +% \begin{eqnarray} +% \xi =|1-\langle e^{\mathrm{-}\Delta S_{tot}} \rangle_{max(N)}| +% \end{eqnarray} +% is minimized. +% +% Arguments IN +% tol_D1 = Tolerance of the range of Kramers-Moyal coefficients in %% for the Optimization +% tol_D2 = tol_D1; +% evaluated = a modified/updated struct 'evaluated' array with in function 'KM_STP_optimization' +% co_KM_opti = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients towards the best +% Fokker-Planck equation to reproduce the conditional PDF's using the surface fits +% fitresult_D1_conf = Confidence intervals for fit coefficients of D1 (co_KM_opti) +% fitresult_D2_conf = Confidence intervals for fit coefficients of D2 (co_KM_opti) +% int_L = Integral length scale in meters +% taylor_L = Taylor length scale in meters +% m_data = mean of the data +% Fs = Acquisition/Sampling Frequency in Hz +% data = filtered data +% z = This is the parameter which decides how to compute entropy using different methods using either +% overlapping or independent trajectories +% z = 1 ==> Overlapping trajectories +% z = 3 ==> Independent trajectories +% iter = The maximum number of iteration used for the optimization algorithms +% markov = markov length in number of samples +% trajec = 1 ==> The start/end of the cascade trajectory will be adjusted. +% dr_ind = Separation of scales/step increment (in samples) referred to the sequence from large to small scales in the cascade trajectory +% norm_ur = normalization of the data using $\sigma_\infty$? data 1=Yes, 0=No +% norm_r = normalization of the scale using $\lambda$? data 1=Yes, 0=No +% save_path = path for saving figures and files +% save_name = name for saving files +% +% Arguments OUT +% co_IFT_opti = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients towards the +% integral fluctuation theorem using the surface fits +% history = details of the optimization for every single iteration +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [co_IFT_opti,history]=OPTI_IFT_dij(tol_D1,tol_D2,evaluated,co_KM_opti,fitresult_D1_conf,fitresult_D2_conf,int_L,taylor_L,m_data,Fs,data,z,iter,markov,trajec,dr_ind,norm_ur,norm_r,save_path,save_name) +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +set(groot, 'defaulttextinterpreter','latex'); +set(groot, 'defaultLegendInterpreter','latex'); +set(groot, 'defaultAxesTitle','latex'); + +% if z==1 +% [Sm,Ds,DS,~,~,~,~]=checkFT(evaluated,int_L,taylor_L,Fs,data,m_data,z,co_KM_opti,1,markov,trajec,dr_ind); +% %Plot of Entropy +% plot_entropy(Sm,Ds,DS) +% set(gca, 'FontSize',10) +% data_length=str2double(inputdlg({'Data length for optimization in samples:'})); +% clear Sm Ds DS +% end + + +%% Initial D1 and D2 before optimization +clear r_norm +r_norm = nan(1,length(evaluated)); + +if norm_r==1 + for i=1:length(evaluated) + r_norm(1,i) = (evaluated(i).r./taylor_L); + end +else + for i=1:length(evaluated) + r_norm(1,i) = (evaluated(i).r); + end +end + + +% fitresult_D1 +d11 = co_KM_opti.a(1).*r_norm.^co_KM_opti.ea(1)+co_KM_opti.a(2); +% fitresult_D2 +d20 = co_KM_opti.b(1).*r_norm.^co_KM_opti.eb(1)+co_KM_opti.b(2); +d21 = co_KM_opti.b(3).*r_norm.^co_KM_opti.eb(2)+co_KM_opti.b(4); +% d21=0.*d21; +d22 = co_KM_opti.b(5).*r_norm.^co_KM_opti.eb(3)+co_KM_opti.b(6); +x0 = [d11 d20 d21 d22]; + + +%% Tolerance of the range of Kramers-Moyal coefficients +clear x1 lb ub +% x1(1:length(x0)) = nan; +lb(1:length(x0)) = nan; +ub(1:length(x0)) = nan; + +% percent of the range +% D1 Opti +t = length(r_norm); +lb(1:t) = x0(1:t)-abs(x0(1:t).*tol_D1); % Lower bound +ub(1:t) = x0(1:t)+abs(x0(1:t).*tol_D1); % Upper bound + +% D2 Opti +for i=1:3 + lb(t*i+1:(t*i+1)+t-1) = x0(t*i+1:(t*i+1)+t-1)-abs(x0(t*i+1:(t*i+1)+t-1).*tol_D2); + ub(t*i+1:(t*i+1)+t-1) = x0(t*i+1:(t*i+1)+t-1)+abs(x0(t*i+1:(t*i+1)+t-1).*tol_D2); +end + + +% constant value 10% of max/min value +% D1 Opti +% t = length(r_norm); +% lb(1:t) = x0(1:t)-(max(abs(x0(1:t))).*tol_D1); +% ub(1:t) = x0(1:t)+(max(abs(x0(1:t))).*tol_D1); + +% D2 Opti +% for i=1:3 +% lb(t*i+1:(t*i+1)+t-1) = x0(t*i+1:(t*i+1)+t-1)-(max(abs(x0(t*i+1:(t*i+1)+t-1))).*tol_D2); +% ub(t*i+1:(t*i+1)+t-1) = x0(t*i+1:(t*i+1)+t-1)+(max(abs(x0(t*i+1:(t*i+1)+t-1))).*tol_D2); +% end + + +% fix to min and max value +% d11 +% lb(1:t) = min(lb(1:t)); +% ub(1:t) = max(ub(1:t)); + +% d20 +% lb(t*1+1:(t*1+1)+t-1) = min(lb(t*1+1:(t*1+1)+t-1)); +% ub(t*1+1:(t*1+1)+t-1) = max(ub(t*1+1:(t*1+1)+t-1)); + +% d21 +% lb(t*2+1:(t*2+1)+t-1) = min(lb(t*2+1:(t*2+1)+t-1)); +% ub(t*2+1:(t*2+1)+t-1) = max(ub(t*2+1:(t*2+1)+t-1)); + +% d22 +% lb(t*3+1:(t*3+1)+t-1) = min(lb(t*3+1:(t*3+1)+t-1)); +% ub(t*3+1:(t*3+1)+t-1) = max(ub(t*3+1:(t*3+1)+t-1)); + + +% using confidence intervals for fit coefficients of D1 and D2 (co_KM_opti) +% D1 Opti +% lb(1:2) = [fitresult_D1_conf(1,1:2)]; +% lb(9) = [fitresult_D1_conf(1,3)]; +% ub(1:2) = [fitresult_D1_conf(2,1:2)]; +% ub(9) = [fitresult_D1_conf(2,3)]; + +% D2 Opti +% lb(3:8) = [fitresult_D2_conf(1,1:6)]; +% lb(10:end) = [fitresult_D2_conf(1,7:9)]; +% ub(3:8) = [fitresult_D2_conf(2,1:6)]; +% ub(10:end) = [fitresult_D2_conf(2,7:9)]; + +% lb(isnan(lb))=0; +% ub(isnan(ub))=0; + + +%% The constraints were set in a physically and mathematically meaningful way: +% (see for more details \textbf{\textit{FIT\_KM}}) +% d11 <= 0 +if ub(1:t)>0 + ub(ub(1:t)>0) = 0; +end +% d20 >= 0 +if lb(t*1+1:(t*1+1)+t-1)<0 + lb(lb(t*1+1:(t*1+1)+t-1)<0) = 0; +end +% d22 >= 0 +if lb(t*3+1:(t*3+1)+t-1)<0 + lb(lb(t*3+1:(t*3+1)+t-1)) = 0; +end + + + +%% Selcet dij for the optimization +if askYesno('Do you want to perform the pointwise optimization of d_11?', 'Yes') +else + lb(1:t) = x0(1:t); % Lower bound + ub(1:t) = x0(1:t); % Upper bound +end + +if askYesno('Do you want to perform the pointwise optimization of d_20?', 'Yes') +else + lb(t*1+1:(t*1+1)+t-1) = x0(t*1+1:(t*1+1)+t-1); + ub(t*1+1:(t*1+1)+t-1) = x0(t*1+1:(t*1+1)+t-1); +end + +if askYesno('Do you want to perform the pointwise optimization of d_21?', 'Yes') +else + lb(t*2+1:(t*2+1)+t-1) = x0(t*2+1:(t*2+1)+t-1); + ub(t*2+1:(t*2+1)+t-1) = x0(t*2+1:(t*2+1)+t-1); +end + +if askYesno('Do you want to perform the pointwise optimization of d_22?', 'Yes') +else + lb(t*3+1:(t*3+1)+t-1) = x0(t*3+1:(t*3+1)+t-1); + ub(t*3+1:(t*3+1)+t-1) = x0(t*3+1:(t*3+1)+t-1); +end + + +%% Plot dij(r) and optimizaiton range +figure +subplot(2,2,1); +plot(r_norm,... + lb(1:t),'LineWidth',2,'LineStyle','--') +hold on +plot(r_norm,... + d11,'k','LineWidth',2) +plot(r_norm,... + ub(1:t),'LineWidth',2,'LineStyle','--') +axis square +ylabel('$d_{11}$', 'interpreter','latex') +if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') +end +xlim([min(r_norm) max(r_norm)]) +set(gca, 'FontSize',24) +% +subplot(2,2,2); +plot(r_norm,... + lb(t*1+1:(t*1+1)+t-1),'LineWidth',2,'LineStyle','--') +hold on +plot(r_norm,... + d20,'k','LineWidth',2) +plot(r_norm,... + ub(t*1+1:(t*1+1)+t-1),'LineWidth',2,'LineStyle','--') +axis square +ylabel('$d_{d20}$', 'interpreter','latex') +if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') +end +xlim([min(r_norm) max(r_norm)]) +set(gca, 'FontSize',24) +% +subplot(2,2,3); +plot(r_norm,... + lb(t*2+1:(t*2+1)+t-1),'LineWidth',2,'LineStyle','--') +hold on +plot(r_norm,... + d21,'k','LineWidth',2) +plot(r_norm,... + ub(t*2+1:(t*2+1)+t-1),'LineWidth',2,'LineStyle','--') +axis square +ylabel('$d_{d21}$', 'interpreter','latex') +if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') +end +xlim([min(r_norm) max(r_norm)]) +set(gca, 'FontSize',24) +% +subplot(2,2,4); +plot(r_norm,... + lb(t*3+1:(t*3+1)+t-1),'LineWidth',2,'LineStyle','--') +hold on +plot(r_norm,... + d22,'k','LineWidth',2) +plot(r_norm,... + ub(t*3+1:(t*3+1)+t-1),'LineWidth',2,'LineStyle','--') +axis square +ylabel('$d_{d22}$', 'interpreter','latex') +if norm_r==1 + xlabel('$r / \lambda$', 'interpreter','latex') + else + xlabel('$r/m $', 'interpreter','latex') +end +xlim([min(r_norm) max(r_norm)]) +set(gca, 'FontSize',24) +set(gcf, 'Color', 'w') + + +%% Fix length of trajectories +if trajec==1 + L = 0; + % Generally each Overlapping/Non-Overlapping trajectory starts at L and + % ends at Lambda for the calculation of the entropy; but its a choice + % So we ask you at which biggest scale you want to start the trajectory + tmp = str2double(inputdlg({'Adjustment: Start of trajectory 1=Yes, 0=No'})); + if tmp == 1 + % Here, if you want to start your trajectories at scale smaller than L then + % you should enter a value between 0 & 1 + % For ex: if your L=1 meters and you enter 0.9 your trajectory will start at 0.9 meters + L = str2double(inputdlg({'Start of trajectory in multiples of Integral length scale:'}))*int_L/taylor_L; + else + L = int_L/taylor_L; % dimless integral scale + end + % So we ask you at which smallest scale you want to end the trajectory + tmp = str2double(inputdlg({'Adjustment: End of trajectory 1=Yes, 0=No'})); + if tmp == 1 + % Here, if you want to end your trajectories at scale bigger than lambda then + % you should enter a value between 1 and (L/lambda) + % For ex: if your lambda=1 cm and if you enter 5 your + % trajectory will end at 5 cms + l = str2double(inputdlg({'End of trajectory in multiples of Taylor length scale:'}))*taylor_L/taylor_L; + else + l = evaluated(1).r/taylor_L;% dimless smallest scale by D1 and D2 + end +else % start=L, end=lambda + L = int_L/taylor_L; + l = 1; +end + +x = m_data.*(1:ceil(1.1*L*Fs*taylor_L/m_data)).'./Fs; +x = x/taylor_L; % dimless position +Lind = find(abs(x(:,1)-L )==min(abs(x(:,1)-L )), 1, 'last' ); % index for x showing the LAST entry where x is within range lambda..L +lind = find(abs(x(:,1)-l )==min(abs(x(:,1)-l )), 1, 'first'); % index for x showing the FIRST entry where x is within range lambda..L + +% Index for calculating the increment using data +Lind = Lind+1; +lind = lind+1; + +if lind<2 + lind = 2; +end + +rindful = 1:Lind; % index-vector for all scales +rind = fliplr(rindful(lind:Lind)); % index-vector only for scales from start to end of the cascade trajectory +% rind = round(linspace(Lind,lind,floor(L/l)+1)); % index-vector for scales in inertial range in steps of lambda +stp = Lind; % index used to cut v(x) in non-overlapping pieces of length equal to integral scale +% R(k).r = x(rind); % scales from index-vector +if norm_r==1 + r = x(rind); % scales from index-vector +else + r = x(rind).*taylor_L; % scales from index-vector +end +clear x +clear Sm Ds DS tmp_Sm tmp_Ds tmp_DS not_nan_index u x + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% calc Entropy - overlapping trajectories +% if z==1 +% %% PDF of start/end of the cascade trajectory ==> Entropy of the system or the Shanon entropy +% rind_tmp = rind(1:dr_ind:end); +% end_L = size(data,1); +% tmp_size = size(data,1)-stp+1; +% u_tmp = nan( tmp_size, 2 ); +% +% for i=0:end_L-stp +% %% u +% % u_tmp(i+1,:) = (data([rind_tmp(1)+i,rind_tmp(end)+i])- data(1+i)).'; +% %% u_s +% u_tmp(i+1,:) = (data([rind_tmp(2)+i,rind_tmp(end-1)+i])- data(1+i)).'; +% end +% +% nbins=301; +% [fuL, uL] = hist(u_tmp(:,1),nbins); +% puL = fuL / ( nansum(fuL) * mean(diff(uL)) ); % relative frequency to approximate p(u,r=L) +% +% [ful, ul] = hist(u_tmp(:,2),uL); +% pul = ful / ( nansum(ful) * mean(diff(ul)) ); % relative frequency to approximate p(u,r=lambda) +% clear u_tmp +% +% [history] = runfmincon_overlap(x0,lb,ub,data(1:data_length),stp,r, uL, puL, ul, pul,rind,iter,r_norm,t,co_KM_opti); +% [history, x1] = runfmincon_overlap(x0,lb,ub,data(1:10^4),stp,r, uL, puL, ul, pul,rind,iter); +% end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% calc Entropy - non-overlapping trajectories +if z==3 + tmp_size = ceil(numel(data)/stp); + [u] = create_us(data,r,rind,stp); +% [u] = create_us(data(1:0.5*10^7),r,rind,stp); + [history] = runfmincon(x0,lb,ub,u,r,tmp_size,iter,r_norm,t,co_KM_opti,markov,taylor_L,Fs,m_data,trajec,dr_ind,z); +end + + +% Find minimized error function +index = find(history.fval==min(history.fval),1,'first'); +[fit_d11] = FIT_d1j(r_norm,history.x1_iter(index,1:t)); +[fit_d20, fit_d21, fit_d22] = FIT_d2j(r_norm,history.x1_iter(index,:),t); + + +%% IFT optimzed dij coefficients +co_IFT_opti.a = [fit_d11.a1 fit_d11.a11]; +co_IFT_opti.ea = [fit_d11.ra1]; +co_IFT_opti.b = [fit_d20.b0 fit_d20.b00 fit_d21.b1 fit_d21.b11 fit_d22.b2 fit_d22.b22]; +co_IFT_opti.eb = [fit_d20.rb0 fit_d21.rb1 fit_d22.rb2]; + + +%% Plot: comparision co_KM_opti and co_IFT_opti dij coefficients +OPTI_IFT_plot(data,stp,r,rind,co_KM_opti,co_IFT_opti,evaluated,Fs,taylor_L,lb,ub,t,history,index,d11,d20,d21,d22,m_data,markov,trajec,dr_ind,z,norm_ur,norm_r,save_path,save_name) end \ No newline at end of file diff --git a/Functions_v5-MATLAB/PART_I.m b/Functions_v5-MATLAB/PART_I.m index ac1e995..a0ddda7 100644 --- a/Functions_v5-MATLAB/PART_I.m +++ b/Functions_v5-MATLAB/PART_I.m @@ -95,7 +95,7 @@ %% Estimation of fundamental length scales lenght_scales = askYesno('Do you want to estimate the fundamental length scales?', 'Yes'); if lenght_scales==1 - C2 = askInput({sprintf('Enter the value of Kolmogorov constant, C_2 associated with second order structure function(in between 2.0 to 2.2)')}, {'2.1'}); + C2 = askInput({sprintf('Enter the value of constant, C_2 associated with second order structure function:')}, {'2.0'}); [int_L,taylor_L,int_L_calc, taylor_L_calc,epsi,epsi_calc,diss_scale,Ce, Ce_calc, Re, Re_lambda ] = length_scales(data_filter,Fs,low_freq,kin_vis,C2,increment_bin,m_data,save_path,save_name); else int_L = str2double(inputdlg({'Enter the integral length scale in meter:'})); @@ -117,7 +117,7 @@ %% Wether to flip the Hot-wire data or not? flip_data = askYesno('Do you want to check if you have to flip the data?', 'Yes'); -norm_ur = askYesno('Do you want to perform the normalization of the data using $\sigma_\infty$?', 'Yes'); +norm_ur = askYesno('Do you want to perform the normalization of the data using $\sigma_\infty$?', 'Yes'); norm_r = askYesno('Do you want to perform the normalization of the scale using $\lambda$?', 'Yes'); if flip_data==1 Struc_flip_test(Fs,data_filter,int_L,taylor_L,save_path,save_name) @@ -145,4 +145,4 @@ close(bar) save(fullfile(save_path,append(save_name,'_','evaluated.mat')),'-v7.3') end -end +end \ No newline at end of file diff --git a/Functions_v5-MATLAB/PART_II.m b/Functions_v5-MATLAB/PART_II.m index 135c3cd..9ced8fb 100644 --- a/Functions_v5-MATLAB/PART_II.m +++ b/Functions_v5-MATLAB/PART_II.m @@ -66,7 +66,7 @@ %% Plot conditional moments plot_moment = askYesno('Do you want to plot conditional moments?', 'Yes'); if plot_moment==1 - plot_conditional_moment(askInput({sprintf('Plot: number of Scale:')}, {num2str(scale_steps)}),askInput({sprintf('Plot: number of a bin (value of the velocity increment u_r):')}, {num2str(ceil(increment_bin/2))}),evaluated,step_con_moment,markov,multi_point,increment_bin,condition,tol,data_filter,save_path,save_name) + plot_conditional_moment(askInput({sprintf('Plot: number of Scale:')}, {num2str(scale_steps)}),askInput({sprintf('Plot: number of a bin (value of the velocity increment u_r):')}, {num2str(ceil(increment_bin/2))}),evaluated,step_con_moment,markov,multi_point,increment_bin,condition,tol,data_filter,save_path,save_name); end waitbar(13/ikx,bar,'Calculation of Kramers-Moyal coefficients'); diff --git a/Functions_v5-MATLAB/PART_III.m b/Functions_v5-MATLAB/PART_III.m index 16b0aa0..d453c9c 100644 --- a/Functions_v5-MATLAB/PART_III.m +++ b/Functions_v5-MATLAB/PART_III.m @@ -51,11 +51,12 @@ %% Optimization of Kramers-Moyal coefficients Fit: IFT opti close all -opti_IFT = askYesno('Do you want to perform the pointwise optimization of Kramers-Moyal coefficients towards the integral fluctuation theorem?', 'Yes'); +opti_IFT = askYesno('Do you want to perform the pointwise optimization of Kramers-Moyal coefficients relatively to the integral fluctuation theorem?', 'Yes'); if opti_IFT==1 bar = waitbar(20/ikx,'Optimization of Kramers-Moyal coefficients: IFT','Position', tmp_bar); % z = 3; - dr_ind = 1; +% dr_ind = 1; + dr_ind = askInput({sprintf('Enter the separation of scales/step increment (in samples) referred to the sequence from large to small scales in the cascade trajectory:')},{num2str(1)}); iter = askInput({sprintf('Enter the maximum number of iteration used for the optimization algorithms:')}, {'5'}); tol_D1 = askInput({sprintf('Optimization: Tolerance of the range of Kramers-Moyal coefficients in %%')}, {'10'})/100; tol_D2 = tol_D1; diff --git a/Functions_v5-MATLAB/Struc_flip_test.m b/Functions_v5-MATLAB/Struc_flip_test.m index 8933727..11757d2 100644 --- a/Functions_v5-MATLAB/Struc_flip_test.m +++ b/Functions_v5-MATLAB/Struc_flip_test.m @@ -14,6 +14,8 @@ % Fs = Acquisition/Sampling Frequency in Hz % int_L = Integral length scale in meters % taylor_L = Taylors length scale in meters +% save_path = path for saving figures and files +% save_name = name for saving files %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function Struc_flip_test(Fs,data,int_L,taylor_L,save_path,save_name) diff --git a/Functions_v5-MATLAB/ZeroCrossings.m b/Functions_v5-MATLAB/ZeroCrossings.m index ac1d013..6493afe 100644 --- a/Functions_v5-MATLAB/ZeroCrossings.m +++ b/Functions_v5-MATLAB/ZeroCrossings.m @@ -228,7 +228,8 @@ % EpsNew = trapz(x_achse_k_spektrum_2pi(1:ind_2),y_tmp(1:ind_2)); % else % [xData, yData] = prepareCurveData( x_achse_k_spektrum_2pi(ind_1:ind_2), y_tmp(ind_1:ind_2)); - EpsNew = trapz(x_achse_k_spektrum_2pi(1:ind_1),y_tmp(1:ind_1))+trapz(xData,feval(fitresult,xData)); +% EpsNew = trapz(x_achse_k_spektrum_2pi(1:ind_1),y_tmp(1:ind_1))+trapz(xData,feval(fitresult,xData)); + EpsNew = trapz(x_achse_k_spektrum_2pi(1:ind_1),y_tmp(1:ind_1))+trapz(x_achse_k_spektrum_2pi(ind_1:end),feval(fitresult,x_achse_k_spektrum_2pi(ind_1:end))); % not more than 5% should be modeld % p(1).*ind_1.^(p(3)+1)/(p(3)+1); % end diff --git a/Functions_v5-MATLAB/checkFT.m b/Functions_v5-MATLAB/checkFT.m index 47b0463..38a97b3 100644 --- a/Functions_v5-MATLAB/checkFT.m +++ b/Functions_v5-MATLAB/checkFT.m @@ -1,359 +1,361 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% The calculation leading towards the integral fluctuation theorem will be done. In the spirit of -% non-equilibrium stochastic thermodynamics \cite{seifert2012stochastic} it is possible to associate -% with every individual cascade trajectory $\left[u(\cdot) \right]$ a total entropy variation -% $\Delta S_{tot}$. In this investigation it is assumed that a single cascade trajectory represents -% one realization of the turbulent cascade process and a large number of these trajectories reflect -% the statistics caused by the process. -% The set of measured cascade trajectories results in a set of total entropy variation values -% $\Delta S_{tot}$. This function calculates the system entropy, medium entropy and the total -% entropy variation for all the independent cascade trajectories. -% -% Arguments IN -% evaluated = a modified/updated struct 'evaluated' array with in function 'KM_STP_optimization' -% int_L = Integral length scale in meters -% taylor_L = Taylor length scale in meters -% Fs = Acquisition/Sampling Frequency in Hz -% data = filtered data -% m_data = mean of the data -% z = This is the parameter which decides how to compute entropy using different methods using either -% overlapping or independent trajectories -% z = 1 ==> Overlapping trajectories -% z = 3 ==> Independent trajectories -% co = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients, where first entry is -% zeroth power and power laws for r-dependency with exponents co.ae and co.be, for each power -% in D1 and D2 respectively -% data_length = A value between 0 & 1 ==> how much of data you want to consider for this calculation -% data_length = 1 for all the data i.e. data(1:end) -% data_length = 0.5 for the data i.e data(1:end/2) <== For 50% of the data -% markov = markov length in number of samples -% trajec = 1 ==> The start/end of the cascade trajectory will be adjusted. -% dr_ind = Separation of scales/step increment (in samples) referred to the sequence from large to small scales in the cascade trajectory -% -% Arguments OUT -% Sm = Entropy of the medium -% Ds = Entropy of the system or the Shanon entropy -% DS = Total entropy production=Sm+Ds -% r = Normalized scale vector from the start to end of the cascade trajectory -% ind_trajec = index-vector of the trajectories (important vector for the recalculation of the trajectories from data) -% rind = index-vector from the start to end of the cascade trajectory -% dr = separation of scales/step increment (in normalized scale) referred to the sequence from -% large to small scales in the cascade trajectory -% r_s = mid-point scale vector (Stratonovich convention) -% u = used trajectoires (only z=3 ==> Independent trajectories) -% A = action functional, pathintegral of Lagrangian -% Lag,p,H,tmpvar,H1,H2,ur_s_tmp (are not yet included/used in the current version) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function[Sm,Ds,DS,r,ind_trajec,rind,dr,r_s,u,Lag,A,p,H,tmpvar,H1,H2,ur_s_tmp]=checkFT(evaluated,int_L,taylor_L,Fs,data,m_data,z,co,data_length,markov,trajec,dr_ind,norm_ur,norm_r) -set(groot, 'defaultAxesTickLabelInterpreter','latex'); -set(groot, 'defaulttextinterpreter','latex'); -set(groot, 'defaultLegendInterpreter','latex'); -set(groot, 'defaultAxesTitle','latex'); - -%% Fix length of trajectories -if trajec==1 - L = 0; - % Generally each Overlapping/Non-Overlapping trajectory starts at L and - % ends at Lambda for the calculation of the entropy; but its a choice - % So we ask you at which biggest scale you want to start the trajectory - tmp = str2double(inputdlg({'Adjustment: Start of trajectory 1=Yes, 0=No'})); - if tmp == 1 - % Here, if you want to start your trajectories at scale smaller than L then - % you should enter a value between 0 & 1 - % For ex: if your L=1 meters and you enter 0.9 your trajectory will start at 0.9 meters - L = str2double(inputdlg({'Start of trajectory in multiples of Integral length scale:'}))*int_L/taylor_L; - else - L = int_L/taylor_L; % dimless integral scale - end - % So we ask you at which smallest scale you want to end the trajectory - tmp = str2double(inputdlg({'Adjustment: End of trajectory 1=Yes, 0=No'})); - if tmp == 1 - % Here, if you want to end your trajectories at scale bigger than lambda then - % you should enter a value between 1 and (L/lambda) - % For ex: if your lambda=1 cm and if you enter 5 your - % trajectory will end at 5 cms - l = str2double(inputdlg({'End of trajectory in multiples of Taylor length scale:'}))*taylor_L/taylor_L; - else - l = evaluated(1).r/taylor_L;% dimless smallest scale by D1 and D2 - end -else % start=L, end=lambda - L = int_L/taylor_L; - l = 1; -end - -x = m_data.*(1:ceil(1.1*L*Fs*taylor_L/m_data)).'./Fs; -x = x/taylor_L; % dimless position -Lind = find(abs(x(:,1)-L )==min(abs(x(:,1)-L )), 1, 'last' ); % index for x showing the LAST entry where x is within range lambda..L -lind = find(abs(x(:,1)-l )==min(abs(x(:,1)-l )), 1, 'first'); % index for x showing the FIRST entry where x is within range lambda..L - -% Index for calculating the increment using data -Lind = Lind+1; -lind = lind+1; - -if lind<2 - lind = 2; -end - -rindful = 1:Lind; % index-vector for all scales -rind = fliplr(rindful(lind:Lind)); % index-vector only for scales from start to end of the cascade trajectory -% rind = round(linspace(Lind,lind,floor(L/l)+1)); % index-vector for scales in inertial range in steps of lambda -stp = Lind; % index used to cut v(x) in non-overlapping pieces of length equal to integral scale -% R(k).r = x(rind); % scales from index-vector - -if norm_r==1 - r = x(rind); % scales from index-vector -else - r = x(rind)*taylor_L; % scales from index-vector -end - -clear x -clear Sm Ds DS tmp_Sm tmp_Ds tmp_DS not_nan_index u x - - - -%% calc Entropy - overlapping trajectories -if z==1 - %% PDF of start/end of the cascade trajectory ==> Entropy of the system or the Shanon entropy - rind_tmp = rind(1:dr_ind:end); - end_L = size(data,1); - tmp_size = size(data,1)-stp+1; - u_tmp = nan( tmp_size, 2 ); - - for i=0:end_L-stp - %% u - % u_tmp(i+1,:) = (data([rind_tmp(1)+i,rind_tmp(end)+i])- data(1+i)).'; - %% u_s - u_tmp(i+1,:) = (data([rind_tmp(2)+i,rind_tmp(end-1)+i])- data(1+i)).'; - end - - nbins=301; - [fuL, uL] = hist(u_tmp(:,1),nbins); - puL = fuL / ( nansum(fuL) * mean(diff(uL)) ); % relative frequency to approximate p(u,r=L) - - [ful, ul] = hist(u_tmp(:,2),uL); - pul = ful / ( nansum(ful) * mean(diff(ul)) ); % relative frequency to approximate p(u,r=lambda) - - figure - plot(uL,puL,'LineWidth',2) - hold on - plot(ul,pul,'LineWidth',2) - norm1 = pdf(fitdist(u_tmp(:,1),'Normal'),uL); - plot(uL,norm1,'LineWidth',2,'LineStyle','--','Color',[0.501960813999176 0.501960813999176 0.501960813999176]) - norm1 = pdf(fitdist(u_tmp(:,2),'Normal'),uL); - plot(ul,norm1,'LineWidth',2,'LineStyle','--','Color',[0.501960813999176 0.501960813999176 0.501960813999176]) - set(gca,'yScale','log') - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') - ylabel('$p(u_r / \sigma_\infty)$','interpreter','latex') - axis square - legend('u_L','u_\lambda'); - xlim([min(uL) max(uL)]) - ylim([0.0000001*max(puL) 2*max(pul)]) - tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); - uiwait(gcf); - delete(tmp_ui); - close - clear u_tmp - - - %% Preallocating (considering the available RAM) - data = data(1:ceil(length(data)*data_length)); - giga = askInput({sprintf('Enter available RAM in GB:')},{num2str(8)}) * 1.07*10^9; %1 GB in bytes - k_split = ceil((12*4*length(data)*length(r))/giga) - data = reshape(data((1:floor(numel(data)/k_split)*k_split)),[],k_split); - - A = nan( size(data,1)-stp+1,k_split ); - Sm = nan( size(data,1)-stp+1,k_split ); - Ds = nan( size(data,1)-stp+1,k_split ); - DS = nan( size(data,1)-stp+1,k_split ); - ind_trajec = nan( size(data,1)-stp+1,k_split ); - % Q_hk = nan( size(data,1)-stp+1,k_split ); - % Q_med = nan( size(data,1)-stp+1,k_split ); - % Q_ex = nan( size(data,1)-stp+1,k_split ); - % Q_med_xi = nan; - - clear tmp - tmp(1:k_split) = struct('Sm_tmp',nan(size(data,1)-stp+1,1),'Ds_tmp',nan(size(data,1)-stp+1,1),'DS_tmp',nan(size(data,1)-stp+1,1), 'ind_trajec_tmp',nan(size(data,1)-stp+1,1), 'A_tmp',nan(size(data,1)-stp+1,1)); - % tmp(1:k_split) = struct('Sm_tmp',nan(size(data,1)-stp+1,1),'Ds_tmp',nan(size(data,1)-stp+1,1),'DS_tmp',nan(size(data,1)-stp+1,1), 'ind_trajec_tmp',nan(size(data,1)-stp+1,1),... - %'Q_hk_tmp',nan(size(data,1)-stp+1,1),'Q_med_tmp',nan(size(data,1)-stp+1,1),'Q_ex',nan(size(data,1)-stp+1,1)); - f = uifigure; - d = uiprogressdlg(f,'Title','Please Wait','ShowPercentage','on'); - - - %% calc Entropy - for k=1:k_split - [u,ind_trajec_tmp] = create_us_overlap(data(:,k),r,rind,stp); - [Sm_tmp,Ds_tmp,DS_tmp,dr,r_s,~,~,~,A_tmp,~,~,~,~,~,~] = calcDS(z,u,r.', co,markov,taylor_L,Fs,m_data,dr_ind, uL, puL, ul, pul); - tmp(k).A_tmp(1:length(A_tmp)) = A_tmp; - tmp(k).Sm_tmp(1:length(Sm_tmp)) = Sm_tmp; - tmp(k).Ds_tmp(1:length(Ds_tmp)) = Ds_tmp; - tmp(k).DS_tmp(1:length(DS_tmp)) = DS_tmp; - % [Q_hk_tmp, Q_med_tmp, Q_ex_tmp,~] = heat(u,r.', co); - % tmp(k).Q_hk_tmp(1:length(Q_hk_tmp)) = Q_hk_tmp; - % tmp(k).Q_med_tmp(1:length(Q_med_tmp)) = Q_med_tmp; - % tmp(k).Q_ex_tmp(1:length(Q_ex_tmp)) = Q_ex_tmp; - - if k==1 - tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = ind_trajec_tmp; - else - % tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = (size(data,1)-stp)*(k-1)+ind_trajec_tmp+1; - % tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = tmp(k-1).ind_trajec_tmp(length(ind_trajec_tmp))+ind_trajec_tmp+1; - % tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = tmp(k-1).ind_trajec_tmp(length(ind_trajec_tmp))+stp+ind_trajec_tmp+1; - tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = tmp(k-1).ind_trajec_tmp(length(ind_trajec_tmp))+stp+ind_trajec_tmp; - end - d.Value=k/k_split; - k/k_split - end - - close(d); - close(f); - - for k=1:k_split - A(1:length(tmp(k).A_tmp),k) = tmp(k).A_tmp; - Sm(1:length(tmp(k).Sm_tmp),k) = tmp(k).Sm_tmp; - Ds(1:length(tmp(k).Ds_tmp),k) = tmp(k).Ds_tmp; - DS(1:length(tmp(k).DS_tmp),k) = tmp(k).DS_tmp; - ind_trajec(1:length(tmp(k).ind_trajec_tmp),k) = tmp(k).ind_trajec_tmp; - % Q_hk(1:length(tmp(k).Q_hk_tmp),k) = tmp(k).Q_hk_tmp; - % Q_med(1:length(tmp(k).Q_med_tmp),k) = tmp(k).Q_med_tmp; - % Q_ex(1:length(tmp(k).Q_ex_tmp),k) = tmp(k).Q_ex_tmp; - end - clear tmp - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% calc Entropy - non-overlapping trajectories -elseif z==3 - %% Preallocating (considering the available RAM) - tmp_size = ceil(numel(data)/stp); - data = data(1:ceil(length(data)*data_length)); -% giga = askInput({sprintf('Enter available RAM in GB:')},{num2str(8)}) * 1.07*10^9; %1 GB in bytes - giga = 8* 1.07*10^9; - k_split = ceil((20*4*tmp_size*length(r(1:dr_ind:end)))/giga); - data = reshape(data((1:floor(numel(data)/k_split)*k_split)),[],k_split); - - Sm = nan( tmp_size, k_split ); - Ds = nan( tmp_size, k_split ); - DS = nan( tmp_size, k_split ); - ind_trajec = nan( tmp_size, k_split ); - A = nan( tmp_size, k_split ); -% Lag = nan( tmp_size, k_split ); -% p = nan( tmp_size, k_split ); -% H = nan( tmp_size, k_split ); -% tmpvar = nan( tmp_size, k_split ); -% H1 = nan( tmp_size, k_split ); -% H2 = nan( tmp_size, k_split ); -% u = nan( tmp_size, k_split ); -% Q_hk = nan( tmp_size,1 ); -% Q_med = nan( tmp_size,1 ); -% Q_ex = nan( tmp_size,1 ); -% not_nan_index = nan( tmp_size, k_split ); - - - %% calc Entropy - f = uifigure; - d = uiprogressdlg(f,'Title','Please Wait','ShowPercentage','on'); - for k=1:k_split - [u_tmp,ind_trajec_tmp] = create_us(data(:,k),r,rind,stp); - [Sm_tmp,Ds_tmp,DS_tmp,dr,r_s,~,~,L_tmp,A_tmp,p_tmp,H_tmp,tmpvar_tmp,H1_tmp,H2_tmp,ur_s_tmp] = calcDS(z,u_tmp,r.',co,markov,taylor_L,Fs,m_data,dr_ind); - % [Q_hk_tmp, Q_med_tmp, Q_ex_tmp,Q_med_xi] = heat(u_tmp,r.', co, r(end)); - - A(1:sum(~isnan(DS_tmp),1),k) = A_tmp(~isnan(DS_tmp)); - ind_trajec(1:sum(~isnan(DS_tmp),1),k) = ind_trajec_tmp(~isnan(DS_tmp)); - Sm(1:sum(~isnan(DS_tmp),1),k) = Sm_tmp(~isnan(DS_tmp)); - Ds(1:sum(~isnan(DS_tmp),1),k) = Ds_tmp(~isnan(DS_tmp)); - DS(1:sum(~isnan(DS_tmp),1),k) = DS_tmp(~isnan(DS_tmp)); - - if k_split==1 -% Lag(1:sum(~isnan(DS_tmp),1),:) = L_tmp(~isnan(DS_tmp),:); -% p(1:sum(~isnan(DS_tmp),1),:) = p_tmp(~isnan(DS_tmp),:); -% H(1:sum(~isnan(DS_tmp),1),:) = H_tmp(~isnan(DS_tmp),:); -% tmpvar(1:sum(~isnan(DS_tmp),1),:) = tmpvar_tmp(~isnan(DS_tmp),:); - ur_s_tmp(1:sum(~isnan(DS_tmp),1),:) = ur_s_tmp(~isnan(DS_tmp),:); -% H1(1:sum(~isnan(DS_tmp),1),:) = H1_tmp(~isnan(DS_tmp),:); -% H2(1:sum(~isnan(DS_tmp),1),:) = H2_tmp(~isnan(DS_tmp),:); - u(1:sum(~isnan(DS_tmp),1),:) = u_tmp(~isnan(DS_tmp),:); - end -% Q_hk(1:sum(~isnan(DS_tmp),1),k) = Q_hk_tmp(~isnan(DS_tmp)); -% Q_med(1:sum(~isnan(DS_tmp),1),k) = Q_med_tmp(~isnan(DS_tmp)); -% Q_ex(1:sum(~isnan(DS_tmp),1),k) = Q_ex_tmp(~isnan(DS_tmp)); -% not_nan = (0:tmp_size).'; -% not_nan_index(1:sum(~isnan(DS_tmp),1),k) = not_nan(~isnan(DS_tmp)); - clear ind_trajec_tmp Sm_tmp Ds_tmp DS_tmp u_tmp - - d.Value=k/k_split; - end - close(d); - close(f); -end - -A = reshape(A,[],1); -Sm = reshape(Sm,[],1); -Ds = reshape(Ds,[],1); -DS = reshape(DS,[],1); -% Q_hk = reshape(Q_hk,[],1); -% Q_med = reshape(Q_med,[],1); -% Q_ex = reshape(Q_ex,[],1); - -% cut-out NaN's due to vanishing or negative D2 -DS(isinf(DS)) = nan; -A = A(~isnan(DS)); - -% if z==1 - Lag = nan; - p = nan; - H = nan; - tmpvar = nan; - H1 = nan; - H2 = nan; - if k_split>1 - ur_s_tmp = nan; - u = nan; - end -% end - -% if z==3 - % L = reshape(L,[],1); - % p = reshape(p,[],1); - % H = reshape(H,[],1); - % tmpvar = reshape(tmpvar,[],1); - % H1 = reshape(H1,[],1); - % H2 = reshape(H2,[],1); -% end -% if z==3 -% Lag = Lag(~isnan(DS),:); -% p = p(~isnan(DS),:); -% H = H(~isnan(DS),:); -% tmpvar = tmpvar(~isnan(DS),:); -% ur_s_tmp = ur_s_tmp(~isnan(DS),:); -% H1 = H1(~isnan(DS),:); -% H2 = H2(~isnan(DS),:); - if k_split==1 - ur_s_tmp = ur_s_tmp(~isnan(DS),:); - u = u(~isnan(DS),:); - end -% end - -Sm = Sm(~isnan(DS)); -Ds = Ds(~isnan(DS)); -% Q_hk = Q_hk(~isnan(DS)); -% Q_med = Q_med(~isnan(DS)); -% Q_ex = Q_ex(~isnan(DS)); - -ind_trajec = reshape(ind_trajec,[],1); -ind_trajec = ind_trajec(~isnan(DS)); -% not_nan_index = ~isnan(DS); - -DS = DS(~isnan(DS)); - -if z==1 - Sm = Sm(1:end-1); - Ds = Ds(1:end-1); - DS = DS(1:end-1); - ind_trajec = ind_trajec(1:end-1); -end -r_s = r_s(1,:); +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% The calculation leading towards the integral fluctuation theorem will be done. In the spirit of +% non-equilibrium stochastic thermodynamics \cite{seifert2012stochastic} it is possible to associate +% with every individual cascade trajectory $\left[u(\cdot) \right]$ a total entropy variation +% $\Delta S_{tot}$. In this investigation it is assumed that a single cascade trajectory represents +% one realization of the turbulent cascade process and a large number of these trajectories reflect +% the statistics caused by the process. +% The set of measured cascade trajectories results in a set of total entropy variation values +% $\Delta S_{tot}$. This function calculates the system entropy, medium entropy and the total +% entropy variation for all the independent cascade trajectories. +% +% Arguments IN +% evaluated = a modified/updated struct 'evaluated' array with in function 'KM_STP_optimization' +% int_L = Integral length scale in meters +% taylor_L = Taylor length scale in meters +% Fs = Acquisition/Sampling Frequency in Hz +% data = filtered data +% m_data = mean of the data +% z = This is the parameter which decides how to compute entropy using different methods using either +% overlapping or independent trajectories +% z = 1 ==> Overlapping trajectories +% z = 3 ==> Independent trajectories +% co = Coefficients $d_{ij}(r)$ of the optimized Kramers-Moyal coefficients, where first entry is +% zeroth power and power laws for r-dependency with exponents co.ae and co.be, for each power +% in D1 and D2 respectively +% data_length = A value between 0 & 1 ==> how much of data you want to consider for this calculation +% data_length = 1 for all the data i.e. data(1:end) +% data_length = 0.5 for the data i.e data(1:end/2) <== For 50% of the data +% markov = markov length in number of samples +% trajec = 1 ==> The start/end of the cascade trajectory will be adjusted. +% dr_ind = Separation of scales/step increment (in samples) referred to the sequence from large to small scales in the cascade trajectory +% norm_ur = normalization of the data using $\sigma_\infty$? data 1=Yes, 0=No +% norm_r = normalization of the scale using $\lambda$? data 1=Yes, 0=No +% +% Arguments OUT +% Sm = Entropy of the medium +% Ds = Entropy of the system or the Shanon entropy +% DS = Total entropy production=Sm+Ds +% r = Normalized scale vector from the start to end of the cascade trajectory +% ind_trajec = index-vector of the trajectories (important vector for the recalculation of the trajectories from data) +% rind = index-vector from the start to end of the cascade trajectory +% dr = separation of scales/step increment (in normalized scale) referred to the sequence from +% large to small scales in the cascade trajectory +% r_s = mid-point scale vector (Stratonovich convention) +% u = used trajectoires (only z=3 ==> Independent trajectories) +% A = action functional, pathintegral of Lagrangian +% Lag,p,H,tmpvar,H1,H2,ur_s_tmp (are not yet included/used in the current version) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function[Sm,Ds,DS,r,ind_trajec,rind,dr,r_s,u,Lag,A,p,H,tmpvar,H1,H2,ur_s_tmp]=checkFT(evaluated,int_L,taylor_L,Fs,data,m_data,z,co,data_length,markov,trajec,dr_ind,norm_ur,norm_r) +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +set(groot, 'defaulttextinterpreter','latex'); +set(groot, 'defaultLegendInterpreter','latex'); +set(groot, 'defaultAxesTitle','latex'); + +%% Fix length of trajectories +if trajec==1 + L = 0; + % Generally each Overlapping/Non-Overlapping trajectory starts at L and + % ends at Lambda for the calculation of the entropy; but its a choice + % So we ask you at which biggest scale you want to start the trajectory + tmp = str2double(inputdlg({'Adjustment: Start of trajectory 1=Yes, 0=No'})); + if tmp == 1 + % Here, if you want to start your trajectories at scale smaller than L then + % you should enter a value between 0 & 1 + % For ex: if your L=1 meters and you enter 0.9 your trajectory will start at 0.9 meters + L = str2double(inputdlg({'Start of trajectory in multiples of Integral length scale:'}))*int_L/taylor_L; + else + L = int_L/taylor_L; % dimless integral scale + end + % So we ask you at which smallest scale you want to end the trajectory + tmp = str2double(inputdlg({'Adjustment: End of trajectory 1=Yes, 0=No'})); + if tmp == 1 + % Here, if you want to end your trajectories at scale bigger than lambda then + % you should enter a value between 1 and (L/lambda) + % For ex: if your lambda=1 cm and if you enter 5 your + % trajectory will end at 5 cms + l = str2double(inputdlg({'End of trajectory in multiples of Taylor length scale:'}))*taylor_L/taylor_L; + else + l = evaluated(1).r/taylor_L;% dimless smallest scale by D1 and D2 + end +else % start=L, end=lambda + L = int_L/taylor_L; + l = 1; +end + +x = m_data.*(1:ceil(1.1*L*Fs*taylor_L/m_data)).'./Fs; +x = x/taylor_L; % dimless position +Lind = find(abs(x(:,1)-L )==min(abs(x(:,1)-L )), 1, 'last' ); % index for x showing the LAST entry where x is within range lambda..L +lind = find(abs(x(:,1)-l )==min(abs(x(:,1)-l )), 1, 'first'); % index for x showing the FIRST entry where x is within range lambda..L + +% Index for calculating the increment using data +Lind = Lind+1; +lind = lind+1; + +if lind<2 + lind = 2; +end + +rindful = 1:Lind; % index-vector for all scales +rind = fliplr(rindful(lind:Lind)); % index-vector only for scales from start to end of the cascade trajectory +% rind = round(linspace(Lind,lind,floor(L/l)+1)); % index-vector for scales in inertial range in steps of lambda +stp = Lind; % index used to cut v(x) in non-overlapping pieces of length equal to integral scale +% R(k).r = x(rind); % scales from index-vector + +if norm_r==1 + r = x(rind); % scales from index-vector +else + r = x(rind)*taylor_L; % scales from index-vector +end + +clear x +clear Sm Ds DS tmp_Sm tmp_Ds tmp_DS not_nan_index u x + + + +%% calc Entropy - overlapping trajectories +if z==1 + %% PDF of start/end of the cascade trajectory ==> Entropy of the system or the Shanon entropy + rind_tmp = rind(1:dr_ind:end); + end_L = size(data,1); + tmp_size = size(data,1)-stp+1; + u_tmp = nan( tmp_size, 2 ); + + for i=0:end_L-stp + %% u + % u_tmp(i+1,:) = (data([rind_tmp(1)+i,rind_tmp(end)+i])- data(1+i)).'; + %% u_s + u_tmp(i+1,:) = (data([rind_tmp(2)+i,rind_tmp(end-1)+i])- data(1+i)).'; + end + + nbins=301; + [fuL, uL] = hist(u_tmp(:,1),nbins); + puL = fuL / ( nansum(fuL) * mean(diff(uL)) ); % relative frequency to approximate p(u,r=L) + + [ful, ul] = hist(u_tmp(:,2),uL); + pul = ful / ( nansum(ful) * mean(diff(ul)) ); % relative frequency to approximate p(u,r=lambda) + + figure + plot(uL,puL,'LineWidth',2) + hold on + plot(ul,pul,'LineWidth',2) + norm1 = pdf(fitdist(u_tmp(:,1),'Normal'),uL); + plot(uL,norm1,'LineWidth',2,'LineStyle','--','Color',[0.501960813999176 0.501960813999176 0.501960813999176]) + norm1 = pdf(fitdist(u_tmp(:,2),'Normal'),uL); + plot(ul,norm1,'LineWidth',2,'LineStyle','--','Color',[0.501960813999176 0.501960813999176 0.501960813999176]) + set(gca,'yScale','log') + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + xlabel('$u_r / \sigma_\infty$', 'interpreter','latex') + ylabel('$p(u_r / \sigma_\infty)$','interpreter','latex') + axis square + legend('u_L','u_\lambda'); + xlim([min(uL) max(uL)]) + ylim([0.0000001*max(puL) 2*max(pul)]) + tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); + uiwait(gcf); + delete(tmp_ui); + close + clear u_tmp + + + %% Preallocating (considering the available RAM) + data = data(1:ceil(length(data)*data_length)); + giga = askInput({sprintf('Enter available RAM in GB:')},{num2str(8)}) * 1.07*10^9; %1 GB in bytes + k_split = ceil((12*4*length(data)*length(r))/giga) + data = reshape(data((1:floor(numel(data)/k_split)*k_split)),[],k_split); + + A = nan( size(data,1)-stp+1,k_split ); + Sm = nan( size(data,1)-stp+1,k_split ); + Ds = nan( size(data,1)-stp+1,k_split ); + DS = nan( size(data,1)-stp+1,k_split ); + ind_trajec = nan( size(data,1)-stp+1,k_split ); + % Q_hk = nan( size(data,1)-stp+1,k_split ); + % Q_med = nan( size(data,1)-stp+1,k_split ); + % Q_ex = nan( size(data,1)-stp+1,k_split ); + % Q_med_xi = nan; + + clear tmp + tmp(1:k_split) = struct('Sm_tmp',nan(size(data,1)-stp+1,1),'Ds_tmp',nan(size(data,1)-stp+1,1),'DS_tmp',nan(size(data,1)-stp+1,1), 'ind_trajec_tmp',nan(size(data,1)-stp+1,1), 'A_tmp',nan(size(data,1)-stp+1,1)); + % tmp(1:k_split) = struct('Sm_tmp',nan(size(data,1)-stp+1,1),'Ds_tmp',nan(size(data,1)-stp+1,1),'DS_tmp',nan(size(data,1)-stp+1,1), 'ind_trajec_tmp',nan(size(data,1)-stp+1,1),... + %'Q_hk_tmp',nan(size(data,1)-stp+1,1),'Q_med_tmp',nan(size(data,1)-stp+1,1),'Q_ex',nan(size(data,1)-stp+1,1)); + f = uifigure; + d = uiprogressdlg(f,'Title','Please Wait','ShowPercentage','on'); + + + %% calc Entropy + for k=1:k_split + [u,ind_trajec_tmp] = create_us_overlap(data(:,k),r,rind,stp); + [Sm_tmp,Ds_tmp,DS_tmp,dr,r_s,~,~,~,A_tmp,~,~,~,~,~,~] = calcDS(z,u,r.', co,markov,taylor_L,Fs,m_data,dr_ind, uL, puL, ul, pul); + tmp(k).A_tmp(1:length(A_tmp)) = A_tmp; + tmp(k).Sm_tmp(1:length(Sm_tmp)) = Sm_tmp; + tmp(k).Ds_tmp(1:length(Ds_tmp)) = Ds_tmp; + tmp(k).DS_tmp(1:length(DS_tmp)) = DS_tmp; + % [Q_hk_tmp, Q_med_tmp, Q_ex_tmp,~] = heat(u,r.', co); + % tmp(k).Q_hk_tmp(1:length(Q_hk_tmp)) = Q_hk_tmp; + % tmp(k).Q_med_tmp(1:length(Q_med_tmp)) = Q_med_tmp; + % tmp(k).Q_ex_tmp(1:length(Q_ex_tmp)) = Q_ex_tmp; + + if k==1 + tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = ind_trajec_tmp; + else + % tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = (size(data,1)-stp)*(k-1)+ind_trajec_tmp+1; + % tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = tmp(k-1).ind_trajec_tmp(length(ind_trajec_tmp))+ind_trajec_tmp+1; + % tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = tmp(k-1).ind_trajec_tmp(length(ind_trajec_tmp))+stp+ind_trajec_tmp+1; + tmp(k).ind_trajec_tmp(1:length(ind_trajec_tmp)) = tmp(k-1).ind_trajec_tmp(length(ind_trajec_tmp))+stp+ind_trajec_tmp; + end + d.Value=k/k_split; + k/k_split + end + + close(d); + close(f); + + for k=1:k_split + A(1:length(tmp(k).A_tmp),k) = tmp(k).A_tmp; + Sm(1:length(tmp(k).Sm_tmp),k) = tmp(k).Sm_tmp; + Ds(1:length(tmp(k).Ds_tmp),k) = tmp(k).Ds_tmp; + DS(1:length(tmp(k).DS_tmp),k) = tmp(k).DS_tmp; + ind_trajec(1:length(tmp(k).ind_trajec_tmp),k) = tmp(k).ind_trajec_tmp; + % Q_hk(1:length(tmp(k).Q_hk_tmp),k) = tmp(k).Q_hk_tmp; + % Q_med(1:length(tmp(k).Q_med_tmp),k) = tmp(k).Q_med_tmp; + % Q_ex(1:length(tmp(k).Q_ex_tmp),k) = tmp(k).Q_ex_tmp; + end + clear tmp + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% calc Entropy - non-overlapping trajectories +elseif z==3 + %% Preallocating (considering the available RAM) + tmp_size = ceil(numel(data)/stp); + data = data(1:ceil(length(data)*data_length)); +% giga = askInput({sprintf('Enter available RAM in GB:')},{num2str(8)}) * 1.07*10^9; %1 GB in bytes + giga = 8* 1.07*10^9; + k_split = ceil((20*4*tmp_size*length(r(1:dr_ind:end)))/giga); + data = reshape(data((1:floor(numel(data)/k_split)*k_split)),[],k_split); + + Sm = nan( tmp_size, k_split ); + Ds = nan( tmp_size, k_split ); + DS = nan( tmp_size, k_split ); + ind_trajec = nan( tmp_size, k_split ); + A = nan( tmp_size, k_split ); +% Lag = nan( tmp_size, k_split ); +% p = nan( tmp_size, k_split ); +% H = nan( tmp_size, k_split ); +% tmpvar = nan( tmp_size, k_split ); +% H1 = nan( tmp_size, k_split ); +% H2 = nan( tmp_size, k_split ); +% u = nan( tmp_size, k_split ); +% Q_hk = nan( tmp_size,1 ); +% Q_med = nan( tmp_size,1 ); +% Q_ex = nan( tmp_size,1 ); +% not_nan_index = nan( tmp_size, k_split ); + + + %% calc Entropy + f = uifigure; + d = uiprogressdlg(f,'Title','Please Wait','ShowPercentage','on'); + for k=1:k_split + [u_tmp,ind_trajec_tmp] = create_us(data(:,k),r,rind,stp); + [Sm_tmp,Ds_tmp,DS_tmp,dr,r_s,~,~,L_tmp,A_tmp,p_tmp,H_tmp,tmpvar_tmp,H1_tmp,H2_tmp,ur_s_tmp] = calcDS(z,u_tmp,r.',co,markov,taylor_L,Fs,m_data,dr_ind); + % [Q_hk_tmp, Q_med_tmp, Q_ex_tmp,Q_med_xi] = heat(u_tmp,r.', co, r(end)); + + A(1:sum(~isnan(DS_tmp),1),k) = A_tmp(~isnan(DS_tmp)); + ind_trajec(1:sum(~isnan(DS_tmp),1),k) = ind_trajec_tmp(~isnan(DS_tmp)); + Sm(1:sum(~isnan(DS_tmp),1),k) = Sm_tmp(~isnan(DS_tmp)); + Ds(1:sum(~isnan(DS_tmp),1),k) = Ds_tmp(~isnan(DS_tmp)); + DS(1:sum(~isnan(DS_tmp),1),k) = DS_tmp(~isnan(DS_tmp)); + + if k_split==1 +% Lag(1:sum(~isnan(DS_tmp),1),:) = L_tmp(~isnan(DS_tmp),:); +% p(1:sum(~isnan(DS_tmp),1),:) = p_tmp(~isnan(DS_tmp),:); +% H(1:sum(~isnan(DS_tmp),1),:) = H_tmp(~isnan(DS_tmp),:); +% tmpvar(1:sum(~isnan(DS_tmp),1),:) = tmpvar_tmp(~isnan(DS_tmp),:); + ur_s_tmp(1:sum(~isnan(DS_tmp),1),:) = ur_s_tmp(~isnan(DS_tmp),:); +% H1(1:sum(~isnan(DS_tmp),1),:) = H1_tmp(~isnan(DS_tmp),:); +% H2(1:sum(~isnan(DS_tmp),1),:) = H2_tmp(~isnan(DS_tmp),:); + u(1:sum(~isnan(DS_tmp),1),:) = u_tmp(~isnan(DS_tmp),:); + end +% Q_hk(1:sum(~isnan(DS_tmp),1),k) = Q_hk_tmp(~isnan(DS_tmp)); +% Q_med(1:sum(~isnan(DS_tmp),1),k) = Q_med_tmp(~isnan(DS_tmp)); +% Q_ex(1:sum(~isnan(DS_tmp),1),k) = Q_ex_tmp(~isnan(DS_tmp)); +% not_nan = (0:tmp_size).'; +% not_nan_index(1:sum(~isnan(DS_tmp),1),k) = not_nan(~isnan(DS_tmp)); + clear ind_trajec_tmp Sm_tmp Ds_tmp DS_tmp u_tmp + + d.Value=k/k_split; + end + close(d); + close(f); +end + +A = reshape(A,[],1); +Sm = reshape(Sm,[],1); +Ds = reshape(Ds,[],1); +DS = reshape(DS,[],1); +% Q_hk = reshape(Q_hk,[],1); +% Q_med = reshape(Q_med,[],1); +% Q_ex = reshape(Q_ex,[],1); + +% cut-out NaN's due to vanishing or negative D2 +DS(isinf(DS)) = nan; +A = A(~isnan(DS)); + +% if z==1 + Lag = nan; + p = nan; + H = nan; + tmpvar = nan; + H1 = nan; + H2 = nan; + if k_split>1 + ur_s_tmp = nan; + u = nan; + end +% end + +% if z==3 + % L = reshape(L,[],1); + % p = reshape(p,[],1); + % H = reshape(H,[],1); + % tmpvar = reshape(tmpvar,[],1); + % H1 = reshape(H1,[],1); + % H2 = reshape(H2,[],1); +% end +% if z==3 +% Lag = Lag(~isnan(DS),:); +% p = p(~isnan(DS),:); +% H = H(~isnan(DS),:); +% tmpvar = tmpvar(~isnan(DS),:); +% ur_s_tmp = ur_s_tmp(~isnan(DS),:); +% H1 = H1(~isnan(DS),:); +% H2 = H2(~isnan(DS),:); + if k_split==1 + ur_s_tmp = ur_s_tmp(~isnan(DS),:); + u = u(~isnan(DS),:); + end +% end + +Sm = Sm(~isnan(DS)); +Ds = Ds(~isnan(DS)); +% Q_hk = Q_hk(~isnan(DS)); +% Q_med = Q_med(~isnan(DS)); +% Q_ex = Q_ex(~isnan(DS)); + +ind_trajec = reshape(ind_trajec,[],1); +ind_trajec = ind_trajec(~isnan(DS)); +% not_nan_index = ~isnan(DS); + +DS = DS(~isnan(DS)); + +if z==1 + Sm = Sm(1:end-1); + Ds = Ds(1:end-1); + DS = DS(1:end-1); + ind_trajec = ind_trajec(1:end-1); +end +r_s = r_s(1,:); end \ No newline at end of file diff --git a/Functions_v5-MATLAB/conditional_PDF_markov.m b/Functions_v5-MATLAB/conditional_PDF_markov.m index fcfd9d0..fbb0000 100644 --- a/Functions_v5-MATLAB/conditional_PDF_markov.m +++ b/Functions_v5-MATLAB/conditional_PDF_markov.m @@ -21,6 +21,9 @@ % second_condi = increment of the second condition % num_bin = Number of bins % min_events = minimum number of events to consider in a single bin +% norm_ur = normalization of the scale using $\lambda$? data 1=Yes, 0=No +% save_path = path for saving figures and files +% save_name = name for saving files %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function conditional_PDF_markov(data,Fs,m_data,markov,second_condi,num_bin,min_events,norm_ur,save_path,save_name) @@ -84,12 +87,15 @@ function conditional_PDF_markov(data,Fs,m_data,markov,second_condi,num_bin,min_e %% single conditional probability [P_AIB,P_BIA,P_AnB,P_A,P_B,binP_AIB,x_mean_bin,y_mean_bin,events_1,counter_A,counter_B] = distribution(tau2,tau1,incr1,incr2,num_bin,dx,dy,x,y,dA); +P_AIB_div = P_AIB; +P_AIB_div(counter_A=min_events); x_input = x_mean_bin(counter_A>=min_events); -P_AIB = P_AIB(counter_A>=min_events,counter_B>=min_events); -P_AnB = P_AnB(counter_A>=min_events,counter_B>=min_events); +P_AIB = P_AIB(counter_A>=min_events,counter_B>=min_events); +P_AnB = P_AnB(counter_A>=min_events,counter_B>=min_events); P_A = P_A(counter_A>=min_events); P_B = P_B(counter_B>=min_events); @@ -121,6 +127,8 @@ function conditional_PDF_markov(data,Fs,m_data,markov,second_condi,num_bin,min_e % cut for the second conditon (incr3) index = find(incr3>-tol+second_condi & incr3=min_events); @@ -148,6 +156,31 @@ function conditional_PDF_markov(data,Fs,m_data,markov,second_condi,num_bin,min_e legend({'$p(u_{r_2}|u_{r_1})$','$p(u_{r_2}|u_{r_1},u_{r_0})$'}, 'interpreter','latex','Location','northwest') + + + +% Titel hier einfügen +%% weighted mean square error function in logarithmic space; conditional probability densities +d_M_1 = 0; +d_M_2 = 0; +for j =1:num_bin + for i =1:num_bin + if (P_AIB_div_2(i,j) > 0) && (P_AIB_div(i,j) > 0) + d_M_1 = d_M_1 + ((P_AIB_div_2(i,j) + P_AIB_div(i,j)).*... + (log(P_AIB_div_2(i,j)) - log(P_AIB_div(i,j))).^2); + d_M_2 = d_M_2 + ((P_AIB_div_2(i,j) + P_AIB_div(i,j)).*... + (log(P_AIB_div_2(i,j)).^2 + log(P_AIB_div(i,j)).^2)); + end +% if (P_verbund_n(i,j) < 0) +% d_M_1 = d_M_1 + 10.^(10); +% end + end +end +fval = d_M_1/d_M_2; + +title(['$\xi_{\Delta_{EM}}$=' num2str(fval,2)]) + + fig_setup txt = {'(a)'}; a=text(4,0.5,txt); diff --git a/Functions_v5-MATLAB/conditional_moment.m b/Functions_v5-MATLAB/conditional_moment.m index 5742cc3..065f3c8 100644 --- a/Functions_v5-MATLAB/conditional_moment.m +++ b/Functions_v5-MATLAB/conditional_moment.m @@ -25,6 +25,7 @@ % Arguments OUT % evaluated = struct array containing all the information about conditional moments for each scale and for each bin % step_con_moment = the steps at which the value of conditional moments are calculated +% Enclosed in a "evaluated": % r is the scale in meters at which moments will be calculated and hence this r will % be the same at which D1 & D2 will be calculated===>r2 % r_samp is the r in number of samples==>r2 diff --git a/Functions_v5-MATLAB/frequency_filter.m b/Functions_v5-MATLAB/frequency_filter.m index fc32d86..a6ebac6 100644 --- a/Functions_v5-MATLAB/frequency_filter.m +++ b/Functions_v5-MATLAB/frequency_filter.m @@ -1,310 +1,311 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% This function returns the filtered data using the low pass filter at the previously set frequency -% (using $\textbf{\textit{butter}}$ and $\textbf{\textit{filtfilt}}$ function of MATLAB). The -% filtered data named as $\textbf{data\_filter}$ for all the further data post-processing. If the -% filtering was negated in the previous step, $\textbf{data\_filter}$ and $\textbf{data}$ are equal. -% In addition, different representation/normalization of the energy spectrum density with respect to -% frequency $f$, scale $r$, wave number $k$ will also be plotted. -% -% Arguments IN -% data = 1D array of data to which you would like to apply the low pass filter -% Fs = Acquisition/Sampling Frequency in Hz -% low_freq = Frequency at which you would like to use the low-pass filter in Hz -% kin_vis = Kinematic viscosity of fluid in m^2/sec -% -% Arguments OUT -% tmps = this is the filtered data which will be returned by this function -% x_achse_k_spektrum_2pi_filter = 2 pi k waven umbers(1/m) after filtering -% E_k = Wavenumber Spectrum (m^3/sec^2) after filtering -% x_achse_spektrum_meter_filter = k Spektrum; Scales,r (m) -% Dr_avg_filter = Dissipation Spectrum; scale domain; after filtering -% Dk_avg_filter = Dissipation Spectrum; wave number domain; after filtering -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function [tmps,x_achse_f_spektrum_filter,spek_smooth_filter,x_achse_k_spektrum_2pi_filter,E_k,x_achse_spektrum_meter_filter,Dr_avg_filter,Dk_avg_filter] = frequency_filter(data, Fs, low_freq,I,kin_vis,filter,save_path,save_name) -set(groot, 'defaultAxesTickLabelInterpreter','latex'); -set(groot, 'defaulttextinterpreter','latex'); -set(groot, 'defaultLegendInterpreter','latex'); -set(groot, 'defaultAxesTitle','latex'); - -close -if mod(length(data),2)==1 - data=data(1:end-1); % This is to make length of data array even -end - -m_data=nanmean(data); % Mean of the data -if filter==1 - % butter is MATLAB function to design a filter of desired order and at desired cut-off frequency - order=20; - [b,a] = butter(order,low_freq/(Fs/2),'low'); - % tmps will be the array returned by this function - tmps = filtfilt (b, a, data); % For filtfilt see the MATLAB documentation - - % For a fixed cutoff frequency used in butter filter there is a threashold of order of butter - % filter at which we can apply the filter successfully. - % Next loop tries to design a highest order of butter filter for a fixed cut-off low frequency - % We repeat line 16,17 & 18 in the following while loop - while (sum(isnan(tmps))>0 || (length(tmps)-nnz(tmps))>0 || var(tmps)>var(data)) - % sum(isnan(tmps))>0 ==> To avoid nan entries in filtered data - % (length(tmps)-nnz(tmps))>0 ==> To avoid zeros in filterd data - % var(tmps)>var(data) ==>variance of the filtered data will always be - % lesser than the variance of the unfilterd data - clear tmps; - order=order-1; - clear b a; - [b,a] = butter(order,low_freq/(Fs/2),'low'); - tmps = filtfilt (b, a, data); %tmps will be the array returned by this function - end - % PSD of the fluctuations after filtering; mean value does not play a role in spectrum - data_filter = tmps-m_data; -else - tmps = data; -end - -% PSD of the fluctuations before filtering; mean value does not play a role in spectrum -data = data-m_data; -L = length(data); % length of the data - -% spek = abs(fft(data,L)).^2/L; % Power spectral density(PSD) -spek = abs(fft(data,L)).^2/(L*Fs); % Energy spectral density(ESD) using a fft -spek = 2.*spek(2:L/2+1); % FFt will yield half number of unique points - -f = Fs/2*linspace(0,1,L/2+1).'; % Nyquist frequency of the signal==Fs/2 -f = f(2:end); % Remove zero Hz component - -% moving average with equally spaced frequency interval in log-space -intervall = unique(round(logspace(0,log10(L/2),3001)),'stable'); - -% moving average with equally spaced frequency interval in lin-space -% intervall=unique(round(linspace(1,L/2,plot_length)),'stable'); - -plot_length = length(intervall); % Number of points for plotting averaged spectrum - -% Initializing the arrays/preallocation -spek_smooth = zeros(plot_length-2,1); -x_achse_f_spektrum = zeros(plot_length-2,1); - -% Averaging of spectrum and hence smoothing -for i=2:(plot_length-1) - x_achse_f_spektrum(i-1,1) = mean(f(intervall(i-1):intervall(i+1))); - spek_smooth(i-1,1) = mean(spek(intervall(i-1):intervall(i+1))); -end -% ------------------------Windowing / averaging end ------------------------ - - - -%%%%%%%%% Filter data -%% PSD of the fluctuations after filtering -if filter==0 - data_filter = data; -end - -spek_filter = abs(fft(data_filter,L)).^2/(L*Fs); % Energy spectral density(ESD) -spek_filter = 2.*spek_filter(1:L/2+1); % FFt will yield half number of unique points - -f_filter = Fs/2*linspace(0,1,L/2+1).'; % Nyquist frequency of the signal - -% %moving average with equally spaced frequency interval in log-space -% intervall=unique(round(logspace(0,log10(L/2),plot_length)),'stable'); -% plot_length=length(intervall); - -spek_smooth_filter = zeros(plot_length-2,1); -x_achse_f_spektrum_filter = zeros(plot_length-2,1); - -% Averaging of spectrum and hence smoothing -for i=2:(plot_length-1) - spek_smooth_filter(i-1,1) = mean(spek_filter(intervall(i-1):intervall(i+1))); - x_achse_f_spektrum_filter(i-1,1) = mean(f_filter(intervall(i-1):intervall(i+1))); -end -% ------------------------Windowing / averaging end ------------------------ - - -id = round(logspace(0,log10(length(spek)),10^5)); -id(end) = length(spek); -f_plot = f(id); -spek_plot = spek(id); - -%%%PLOTTING -% Plot of Frequency Vs. Energy spectral density(ESD) -h(1) = figure; -% Plot of Frequency Vs. Energy spectral density(ESD) without smoothing -loglog(f_plot,spek_plot) -hold on -%Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing -loglog(x_achse_f_spektrum,spek_smooth,'LineWidth',2) -% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing & Filtering -loglog(x_achse_f_spektrum_filter,spek_smooth_filter,'LineWidth',2) -set(groot, 'defaultLegendInterpreter','latex'); -% xlabel('f / Hz','interpreter','latex'); -% ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') -xlabel('$f\ (Hz)$','interpreter','latex'); -ylabel('$E\ (m^2/s)$', 'interpreter','latex') -title(['Low-pass filter frequency =',num2str(low_freq,'%1.0f'), ' Hz'],'interpreter','latex') -set(gca,'FontSize',18) -set(gcf, 'Color', 'w') -xlim([min(x_achse_f_spektrum_filter) max(x_achse_f_spektrum_filter)]*2) -ylim([min(spek) max(spek)]*2) -axis square -% vline(low_freq,'k') - -% vline(m_data/int_L,'k') -% vline(m_data/taylor_L,'k') -set(groot, 'defaultAxesTickLabelInterpreter','latex'); -% title(['$ti=$',num2str(std(data)/m_data,'%1.3f')],'interpreter','latex') %% Turbulence Intensity of the flow -legend('raw','averaged','low-pass filtered','Location','southwest') -set(gca,'XTick',[10^-4 10^-2 10^0 10^2 10^4]); - - -% savefig(fullfile(save_path,append(save_name,'_','spectrum_filter.fig')),'compact') -fig_setup - -f_start = find(f_plot>I(1), 1,'first'); -f_end = find(f_plot<=I(2), 1,'last'); - -[xData, yData] = prepareCurveData( f_plot(f_start:f_end), spek_plot(f_start:f_end)); -ft = fittype( 'a*x^(-5/3)', 'independent', 'x', 'dependent', 'y' ); -opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); -[fitresult, gof] = fit( xData, yData, ft, opts ); - -plot(f_plot,feval(fitresult,f_plot),'Color',[0 0 0],'LineWidth',2,'LineStyle','--') -legend('raw','averaged','low-pass filtered','$f^{(-5/3)}$') -ylim([min(spek_plot) max(spek_plot)]*4) - -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); - -if ischar(save_path) - % savefig(fullfile(save_path,append(save_name,'_','spectrum_var_domain.fig'))) -% savefig(h,fullfile(save_path,append(save_name,'_','spectrum_filter.fig')),'compact') -% for a = 1:length(h) - exportgraphics(h(1),fullfile(save_path,append(save_name,'_',sprintf('spectrum_filter_%d.png', 1)))) -% export_fig(h(a), fullfile(save_path,append(save_name,'_',sprintf('spectrum_filter_%d.png', a)))); -% end -end - - -% Wavenumber Spectrum (m^3/sec^2) -E_k = ((spek_smooth_filter.*m_data)./(2*pi)); -% 2-pi - k Spektrum; Wavenumbers(1/m) -x_achse_k_spektrum_2pi_filter = (2.*pi.*x_achse_f_spektrum_filter)./m_data; -% k Spektrum; Scales,r (m) -x_achse_spektrum_meter_filter = m_data./(2*pi*x_achse_f_spektrum_filter); - -Dr_avg_filter=(spek_smooth_filter.*x_achse_f_spektrum_filter.^2)./m_data; -Dk_avg_filter=15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi_filter).^2; - - -h(2) = figure; -set(gcf, 'Color', 'w') -subplot(2,2,1) -loglog(x_achse_f_spektrum_filter,spek_smooth_filter,'-','LineWidth',1)%% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing & Filtering -% xlabel('f / Hz','interpreter','latex'); -% ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') -xlabel('$f\ (Hz)$','interpreter','latex'); -ylabel('$E\ (m^2/s)$', 'interpreter','latex') -xlim([min(x_achse_f_spektrum_filter) 2*max(x_achse_f_spektrum_filter)]) -ylim([min(spek_smooth_filter) max(spek_smooth_filter)]*2) -title('frequency domain','interpreter','latex') -set(gca,'FontSize',12) -set(groot, 'defaultAxesTickLabelInterpreter','latex'); -% plot([10^3 10^3],[10^-6 10^-2],'y = x ','-','LineWidth',1) -% h = vline(10^3,'k','The Answer') -% text(245,spek_smooth(find(x_achse_f_spektrum>245,1,'first')),'\leftarrow sin(\pi) = 0','FontSize',16) -set(gca,'XTick',sort([10^-2 10^0 10^2 10^4 low_freq])); -hold on -vline(low_freq,'k') - -txt = {'(a)'}; -a=text(4,0.5,txt); -a.Units='normalized'; - -subplot(2,2,2) -loglog(x_achse_k_spektrum_2pi_filter,E_k,'-','LineWidth',1)%% Plot of Wavenumber(k) Vs. Energy(k)(m^3/sec^2) with smoothing & Filtering -% loglog(x_achse_k_spektrum_2pi_filter,x_achse_k_spektrum_2pi_filter.^(-5/3).*(max(spek_smooth).*200),'--','color','k','LineWidth',2) -% xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); -% ylabel('$E(k)=\frac{E(f) }{2 \pi}$ / $\frac{m^3}{s^2}$', 'interpreter','latex') -xlabel('$k=\frac{2 \pi f}{}\ (1/m)$','interpreter','latex'); -ylabel('$\frac{E }{2 \pi}\ (m^3/s^2)$', 'interpreter','latex') -xlim([min(x_achse_k_spektrum_2pi_filter) 2*max(x_achse_k_spektrum_2pi_filter)]) -ylim([min(E_k) max(E_k)]*2) -title('wave number domain','interpreter','latex') -set(gca,'FontSize',12) -set(gca,'XTick',sort([10^-2 10^0 10^2 10^4 round(2*pi*low_freq/m_data)])); -set(gca,'XTick',sort([10^-2 10^0 10^2 round(2*pi*low_freq/m_data)])); -hold on -vline(2*pi*low_freq/m_data,'k') -txt = {'(b)'}; -b=text(4,0.5,txt); -b.Units='normalized'; - -subplot4=subplot(2,2,3); -loglog(x_achse_spektrum_meter_filter,Dr_avg_filter,'-','LineWidth',1)%% Plot of Scales,r(m) Vs. Energy(r)(m/sec^2) with smoothing & Filtering -% xlabel('$r=\frac{}{2 \pi f} / m$', 'interpreter','latex'); -% ylabel('$E(r)=\frac{E(f) f^2}{}$ / $\frac{m}{s^2}$', 'interpreter','latex') -xlabel('$r=\frac{}{2 \pi f}\ (m)$','interpreter','latex'); -ylabel('$\frac{E\ f^2}{}\ (m/s^2)$', 'interpreter','latex') -set(subplot4, 'Xdir', 'reverse') -xlim([0.5* min(x_achse_spektrum_meter_filter) max(x_achse_spektrum_meter_filter)]) -ylim([min((spek_smooth_filter.*x_achse_f_spektrum_filter.^2)./m_data) max((spek_smooth_filter.*x_achse_f_spektrum_filter.^2)./m_data)]*2) -set(gca,'FontSize',12) -set(gca,'XTick',sort([10^-2 10^0 10^2 10^4 m_data/(2*pi*low_freq)])); -title('dissipation spectrum','interpreter','latex') -hold on -vline(m_data/(2*pi*low_freq),'k') -txt = {'(c)'}; -c=text(4,0.5,txt); -c.Units='normalized'; - - -% Dissipation Spectrum -% kin_vis = 15.328737178409*10^-6; -subplot(2,2,4) -loglog(x_achse_k_spektrum_2pi_filter,Dk_avg_filter,'-','LineWidth',1)%% Plot of Wavenumber(k) Vs. Dissipation(k)(m/sec^2) with smoothing & Filtering -% xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); -% ylabel('E(k)$\cdot k^2$ / $\frac{m}{s^2}$', 'interpreter','latex') -xlabel('$k=\frac{2 \pi f}{}\ (1/m)$','interpreter','latex'); -ylabel('$\frac{E }{2 \pi}\ k^2 \ (m/s^2)$', 'interpreter','latex') - -xlim([min(x_achse_k_spektrum_2pi_filter) 2*max(x_achse_k_spektrum_2pi_filter)]) -ylim([min(15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi_filter).^2) max(15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi_filter).^2)]*2) -title('dissipation spectrum','interpreter','latex') -set(gca,'FontSize',12) -set(gca,'XTick',sort([10^-2 10^0 10^2 10^4 round(2*pi*low_freq/m_data)])); -set(gca,'XTick',sort([10^-2 10^0 10^2 round(2*pi*low_freq/m_data)])); -hold on -vline(2*pi*low_freq/m_data,'k') -txt = {'(d)'}; -d=text(4,0.5,txt); -d.Units='normalized'; - -% font=22; -% a.FontSize = font; -% b.FontSize = font; -% c.FontSize = font; -% d.FontSize = font; - -pos_txt=[-0.25 0.9]; -a.Position=pos_txt; -b.Position=pos_txt; -c.Position=pos_txt; -d.Position=pos_txt; - -datacursormode on - - -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); - -if ischar(save_path) - % savefig(fullfile(save_path,append(save_name,'_','spectrum_var_domain.fig'))) - savefig(h,fullfile(save_path,append(save_name,'_','spectrum_filter.fig')),'compact') -% for a = 1:length(h) - exportgraphics(h(2),fullfile(save_path,append(save_name,'_',sprintf('spectrum_filter_%d.png', 2)))) -% export_fig(h(a), fullfile(save_path,append(save_name,'_',sprintf('spectrum_filter_%d.png', a)))); -% end -end -close all +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% This function returns the filtered data using the low pass filter at the previously set frequency +% (using $\textbf{\textit{butter}}$ and $\textbf{\textit{filtfilt}}$ function of MATLAB). The +% filtered data named as $\textbf{data\_filter}$ for all the further data post-processing. If the +% filtering was negated in the previous step, $\textbf{data\_filter}$ and $\textbf{data}$ are equal. +% In addition, different representation/normalization of the energy spectrum density with respect to +% frequency $f$, scale $r$, wave number $k$ will also be plotted. +% +% Arguments IN +% data = 1D array of data to which you would like to apply the low pass filter +% Fs = Acquisition/Sampling Frequency in Hz +% low_freq = Frequency at which you would like to use the low-pass filter in Hz +% kin_vis = Kinematic viscosity of fluid in m^2/sec +% +% Arguments OUT +% tmps = this is the filtered data which will be returned by this function +% x_achse_k_spektrum_2pi_filter = 2 pi k waven umbers(1/m) after filtering +% spek_smooth_filter = Frequency Spectrum after filtering +% E_k = Wavenumber Spectrum (m^3/sec^2) after filtering +% x_achse_spektrum_meter_filter = r Spektrum; Scales,r (m) +% Dr_avg_filter = Dissipation Spectrum; scale domain; after filtering +% Dk_avg_filter = Dissipation Spectrum; wave number domain; after filtering +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [tmps,x_achse_f_spektrum_filter,spek_smooth_filter,x_achse_k_spektrum_2pi_filter,E_k,x_achse_spektrum_meter_filter,Dr_avg_filter,Dk_avg_filter] = frequency_filter(data, Fs, low_freq,I,kin_vis,filter,save_path,save_name) +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +set(groot, 'defaulttextinterpreter','latex'); +set(groot, 'defaultLegendInterpreter','latex'); +set(groot, 'defaultAxesTitle','latex'); + +close +if mod(length(data),2)==1 + data=data(1:end-1); % This is to make length of data array even +end + +m_data=nanmean(data); % Mean of the data +if filter==1 + % butter is MATLAB function to design a filter of desired order and at desired cut-off frequency + order=20; + [b,a] = butter(order,low_freq/(Fs/2),'low'); + % tmps will be the array returned by this function + tmps = filtfilt (b, a, data); % For filtfilt see the MATLAB documentation + + % For a fixed cutoff frequency used in butter filter there is a threashold of order of butter + % filter at which we can apply the filter successfully. + % Next loop tries to design a highest order of butter filter for a fixed cut-off low frequency + % We repeat line 16,17 & 18 in the following while loop + while (sum(isnan(tmps))>0 || (length(tmps)-nnz(tmps))>0 || var(tmps)>var(data)) + % sum(isnan(tmps))>0 ==> To avoid nan entries in filtered data + % (length(tmps)-nnz(tmps))>0 ==> To avoid zeros in filterd data + % var(tmps)>var(data) ==>variance of the filtered data will always be + % lesser than the variance of the unfilterd data + clear tmps; + order=order-1; + clear b a; + [b,a] = butter(order,low_freq/(Fs/2),'low'); + tmps = filtfilt (b, a, data); %tmps will be the array returned by this function + end + % PSD of the fluctuations after filtering; mean value does not play a role in spectrum + data_filter = tmps-m_data; +else + tmps = data; +end + +% PSD of the fluctuations before filtering; mean value does not play a role in spectrum +data = data-m_data; +L = length(data); % length of the data + +% spek = abs(fft(data,L)).^2/L; % Power spectral density(PSD) +spek = abs(fft(data,L)).^2/(L*Fs); % Energy spectral density(ESD) using a fft +spek = 2.*spek(2:L/2+1); % FFt will yield half number of unique points + +f = Fs/2*linspace(0,1,L/2+1).'; % Nyquist frequency of the signal==Fs/2 +f = f(2:end); % Remove zero Hz component + +% moving average with equally spaced frequency interval in log-space +intervall = unique(round(logspace(0,log10(L/2),3001)),'stable'); + +% moving average with equally spaced frequency interval in lin-space +% intervall=unique(round(linspace(1,L/2,plot_length)),'stable'); + +plot_length = length(intervall); % Number of points for plotting averaged spectrum + +% Initializing the arrays/preallocation +spek_smooth = zeros(plot_length-2,1); +x_achse_f_spektrum = zeros(plot_length-2,1); + +% Averaging of spectrum and hence smoothing +for i=2:(plot_length-1) + x_achse_f_spektrum(i-1,1) = mean(f(intervall(i-1):intervall(i+1))); + spek_smooth(i-1,1) = mean(spek(intervall(i-1):intervall(i+1))); +end +% ------------------------Windowing / averaging end ------------------------ + + + +%%%%%%%%% Filter data +%% PSD of the fluctuations after filtering +if filter==0 + data_filter = data; +end + +spek_filter = abs(fft(data_filter,L)).^2/(L*Fs); % Energy spectral density(ESD) +spek_filter = 2.*spek_filter(1:L/2+1); % FFt will yield half number of unique points + +f_filter = Fs/2*linspace(0,1,L/2+1).'; % Nyquist frequency of the signal + +% %moving average with equally spaced frequency interval in log-space +% intervall=unique(round(logspace(0,log10(L/2),plot_length)),'stable'); +% plot_length=length(intervall); + +spek_smooth_filter = zeros(plot_length-2,1); +x_achse_f_spektrum_filter = zeros(plot_length-2,1); + +% Averaging of spectrum and hence smoothing +for i=2:(plot_length-1) + spek_smooth_filter(i-1,1) = mean(spek_filter(intervall(i-1):intervall(i+1))); + x_achse_f_spektrum_filter(i-1,1) = mean(f_filter(intervall(i-1):intervall(i+1))); +end +% ------------------------Windowing / averaging end ------------------------ + + +id = round(logspace(0,log10(length(spek)),10^5)); +id(end) = length(spek); +f_plot = f(id); +spek_plot = spek(id); + +%%%PLOTTING +% Plot of Frequency Vs. Energy spectral density(ESD) +h(1) = figure; +% Plot of Frequency Vs. Energy spectral density(ESD) without smoothing +loglog(f_plot,spek_plot) +hold on +%Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing +loglog(x_achse_f_spektrum,spek_smooth,'LineWidth',2) +% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing & Filtering +loglog(x_achse_f_spektrum_filter,spek_smooth_filter,'LineWidth',2) +set(groot, 'defaultLegendInterpreter','latex'); +% xlabel('f / Hz','interpreter','latex'); +% ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') +xlabel('$f\ (Hz)$','interpreter','latex'); +ylabel('$E\ (m^2/s)$', 'interpreter','latex') +title(['Low-pass filter frequency =',num2str(low_freq,'%1.0f'), ' Hz'],'interpreter','latex') +set(gca,'FontSize',18) +set(gcf, 'Color', 'w') +xlim([min(x_achse_f_spektrum_filter) max(x_achse_f_spektrum_filter)]*2) +ylim([min(spek) max(spek)]*2) +axis square +% vline(low_freq,'k') + +% vline(m_data/int_L,'k') +% vline(m_data/taylor_L,'k') +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +% title(['$ti=$',num2str(std(data)/m_data,'%1.3f')],'interpreter','latex') %% Turbulence Intensity of the flow +legend('raw','averaged','averaged \& low-pass filtered','Location','southwest') +set(gca,'XTick',[10^-4 10^-2 10^0 10^2 10^4]); + + +% savefig(fullfile(save_path,append(save_name,'_','spectrum_filter.fig')),'compact') +fig_setup + +f_start = find(f_plot>I(1), 1,'first'); +f_end = find(f_plot<=I(2), 1,'last'); + +[xData, yData] = prepareCurveData( f_plot(f_start:f_end), spek_plot(f_start:f_end)); +ft = fittype( 'a*x^(-5/3)', 'independent', 'x', 'dependent', 'y' ); +opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); +[fitresult, gof] = fit( xData, yData, ft, opts ); + +plot(f_plot,feval(fitresult,f_plot),'Color',[0 0 0],'LineWidth',2,'LineStyle','--') +legend('raw','averaged','averaged \& low-pass filtered','$f^{(-5/3)}$','Location','southwest') +ylim([min(spek_plot) max(spek_plot)]*4) + +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); + +if ischar(save_path) + % savefig(fullfile(save_path,append(save_name,'_','spectrum_var_domain.fig'))) +% savefig(h,fullfile(save_path,append(save_name,'_','spectrum_filter.fig')),'compact') +% for a = 1:length(h) + exportgraphics(h(1),fullfile(save_path,append(save_name,'_',sprintf('spectrum_filter_%d.png', 1)))) +% export_fig(h(a), fullfile(save_path,append(save_name,'_',sprintf('spectrum_filter_%d.png', a)))); +% end +end + + +% Wavenumber Spectrum (m^3/sec^2) +E_k = ((spek_smooth_filter.*m_data)./(2*pi)); +% 2-pi - k Spektrum; Wavenumbers(1/m) +x_achse_k_spektrum_2pi_filter = (2.*pi.*x_achse_f_spektrum_filter)./m_data; +% k Spektrum; Scales,r (m) +x_achse_spektrum_meter_filter = m_data./(2*pi*x_achse_f_spektrum_filter); + +Dr_avg_filter=(spek_smooth_filter.*x_achse_f_spektrum_filter.^2)./m_data; +Dk_avg_filter=15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi_filter).^2; + + +h(2) = figure; +set(gcf, 'Color', 'w') +subplot(2,2,1) +loglog(x_achse_f_spektrum_filter,spek_smooth_filter,'-','LineWidth',1)%% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing & Filtering +% xlabel('f / Hz','interpreter','latex'); +% ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') +xlabel('$f\ (Hz)$','interpreter','latex'); +ylabel('$E\ (m^2/s)$', 'interpreter','latex') +xlim([min(x_achse_f_spektrum_filter) 2*max(x_achse_f_spektrum_filter)]) +ylim([min(spek_smooth_filter) max(spek_smooth_filter)]*2) +title('frequency domain','interpreter','latex') +set(gca,'FontSize',12) +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +% plot([10^3 10^3],[10^-6 10^-2],'y = x ','-','LineWidth',1) +% h = vline(10^3,'k','The Answer') +% text(245,spek_smooth(find(x_achse_f_spektrum>245,1,'first')),'\leftarrow sin(\pi) = 0','FontSize',16) +set(gca,'XTick',sort([10^-2 10^0 10^2 10^4 low_freq])); +hold on +vline(low_freq,'k') + +txt = {'(a)'}; +a=text(4,0.5,txt); +a.Units='normalized'; + +subplot(2,2,2) +loglog(x_achse_k_spektrum_2pi_filter,E_k,'-','LineWidth',1)%% Plot of Wavenumber(k) Vs. Energy(k)(m^3/sec^2) with smoothing & Filtering +% loglog(x_achse_k_spektrum_2pi_filter,x_achse_k_spektrum_2pi_filter.^(-5/3).*(max(spek_smooth).*200),'--','color','k','LineWidth',2) +% xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); +% ylabel('$E(k)=\frac{E(f) }{2 \pi}$ / $\frac{m^3}{s^2}$', 'interpreter','latex') +xlabel('$k=\frac{2 \pi f}{}\ (1/m)$','interpreter','latex'); +ylabel('$\frac{E }{2 \pi}\ (m^3/s^2)$', 'interpreter','latex') +xlim([min(x_achse_k_spektrum_2pi_filter) 2*max(x_achse_k_spektrum_2pi_filter)]) +ylim([min(E_k) max(E_k)]*2) +title('wave number domain','interpreter','latex') +set(gca,'FontSize',12) +set(gca,'XTick',sort([10^-2 10^0 10^2 10^4 round(2*pi*low_freq/m_data)])); +set(gca,'XTick',sort([10^-2 10^0 10^2 round(2*pi*low_freq/m_data)])); +hold on +vline(2*pi*low_freq/m_data,'k') +txt = {'(b)'}; +b=text(4,0.5,txt); +b.Units='normalized'; + +subplot4=subplot(2,2,3); +loglog(x_achse_spektrum_meter_filter,Dr_avg_filter,'-','LineWidth',1)%% Plot of Scales,r(m) Vs. Energy(r)(m/sec^2) with smoothing & Filtering +% xlabel('$r=\frac{}{2 \pi f} / m$', 'interpreter','latex'); +% ylabel('$E(r)=\frac{E(f) f^2}{}$ / $\frac{m}{s^2}$', 'interpreter','latex') +xlabel('$r=\frac{}{2 \pi f}\ (m)$','interpreter','latex'); +ylabel('$\frac{E\ f^2}{}\ (m/s^2)$', 'interpreter','latex') +set(subplot4, 'Xdir', 'reverse') +xlim([0.5* min(x_achse_spektrum_meter_filter) max(x_achse_spektrum_meter_filter)]) +ylim([min((spek_smooth_filter.*x_achse_f_spektrum_filter.^2)./m_data) max((spek_smooth_filter.*x_achse_f_spektrum_filter.^2)./m_data)]*2) +set(gca,'FontSize',12) +set(gca,'XTick',sort([10^-2 10^0 10^2 10^4 m_data/(2*pi*low_freq)])); +title('dissipation spectrum','interpreter','latex') +hold on +vline(m_data/(2*pi*low_freq),'k') +txt = {'(c)'}; +c=text(4,0.5,txt); +c.Units='normalized'; + + +% Dissipation Spectrum +% kin_vis = 15.328737178409*10^-6; +subplot(2,2,4) +loglog(x_achse_k_spektrum_2pi_filter,Dk_avg_filter,'-','LineWidth',1)%% Plot of Wavenumber(k) Vs. Dissipation(k)(m/sec^2) with smoothing & Filtering +% xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); +% ylabel('E(k)$\cdot k^2$ / $\frac{m}{s^2}$', 'interpreter','latex') +xlabel('$k=\frac{2 \pi f}{}\ (1/m)$','interpreter','latex'); +ylabel('$\frac{E }{2 \pi}\ k^2 \ (m/s^2)$', 'interpreter','latex') + +xlim([min(x_achse_k_spektrum_2pi_filter) 2*max(x_achse_k_spektrum_2pi_filter)]) +ylim([min(15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi_filter).^2) max(15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi_filter).^2)]*2) +title('dissipation spectrum','interpreter','latex') +set(gca,'FontSize',12) +set(gca,'XTick',sort([10^-2 10^0 10^2 10^4 round(2*pi*low_freq/m_data)])); +set(gca,'XTick',sort([10^-2 10^0 10^2 round(2*pi*low_freq/m_data)])); +hold on +vline(2*pi*low_freq/m_data,'k') +txt = {'(d)'}; +d=text(4,0.5,txt); +d.Units='normalized'; + +% font=22; +% a.FontSize = font; +% b.FontSize = font; +% c.FontSize = font; +% d.FontSize = font; + +pos_txt=[-0.25 0.9]; +a.Position=pos_txt; +b.Position=pos_txt; +c.Position=pos_txt; +d.Position=pos_txt; + +datacursormode on + + +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); + +if ischar(save_path) + % savefig(fullfile(save_path,append(save_name,'_','spectrum_var_domain.fig'))) + savefig(h,fullfile(save_path,append(save_name,'_','spectrum_filter.fig')),'compact') +% for a = 1:length(h) + exportgraphics(h(2),fullfile(save_path,append(save_name,'_',sprintf('spectrum_filter_%d.png', 2)))) +% export_fig(h(a), fullfile(save_path,append(save_name,'_',sprintf('spectrum_filter_%d.png', a)))); +% end +end +close all end \ No newline at end of file diff --git a/Functions_v5-MATLAB/length_scales.m b/Functions_v5-MATLAB/length_scales.m index 9e9cce9..427c457 100644 --- a/Functions_v5-MATLAB/length_scales.m +++ b/Functions_v5-MATLAB/length_scales.m @@ -1,1005 +1,1005 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% In this function the integral length scale $L$, Taylor length scale $\lambda$ and Kolmogorov -% length scale are estimated using different methods of calculation. Within this function, pop-up -% dialog boxes will be generated to enter the values of the integral, Taylor length scale in $m$ -% and energy dissipation rate in $m^2/s^3$ on which the further processing of data (solving the -% FPE and extracting cascade trajectories) should be referred. The entered length scales will be -% round towards the nearest integer sample. The proposed value in the pop-up dialog box is the -% median length scale for all methods. -% COMMENT: All velocity increments in this script are taken as right hand increment i.e. -% dV=V(t2)-V(t1) where t2>t1; t1,t2 in seconds -% -% Arguments IN -% data = it is the filtered data -% Fs = Acquisition/Sampling Frequency in Hz -% low_freq = Frequency at which you would like to use the low-pass filter in Hz -% kin_vis = Kinematic viscosity of fluid in m^2/sec -% C2 = Kolmogorov constant, C2 associated with second order structure function(in between 2.0 to 2.2) -% -% Arguments OUT -% int_L = Integral length scale in meters -% taylor_L = Taylors length scale in meters -% diss_scale = Kolmogorv lenght scale in meters -% int_L_calc = 1D array of integral length scale calculated by different methods/formula -% taylor_L_calc = 1D array of Taylor's length scale calculated by different methods/formula -% epsi = mean energy dissipation rate -% epsi_calc = 1D array of mean energy dissipation rate calculated by different methods/formula -% Ce = is the non-dimentional / normalized energy dissipation rate -% Ce_calc = 1D array of Ce calculated by different methods/formula -% Re = Reynolds Number based on integral length scale -% Re_lambda= Reynolds Number based on Taylor's length scale -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function [int_L,taylor_L,int_L_calc, taylor_L_calc,epsi, epsi_calc,diss_scale,Ce, Ce_calc, Re, Re_lambda]=length_scales(data,Fs,low_freq,kin_vis,C2,increment_bin,m_data,save_path,save_name) -set(groot, 'defaultAxesTickLabelInterpreter','latex'); -set(groot, 'defaulttextinterpreter','latex'); -set(groot, 'defaultLegendInterpreter','latex'); -set(groot, 'defaultAxesTitle','latex'); - -maxnumattempts = 2; - - -% Pressure calculation: -% http://www.peacesoftware.de/einigewerte/luft_e.html -% https://www.einheiten-umrechnen.de/einheiten-rechner.php?typ=druck -% The higher the pressure the lower the kinematic viscosity, -% the higher the temperature the higher the kinematic viscosity. -% High Pressure: 1040hPa = 1,04 Bar, at 0 Celsius: 13.00*10^-6 at 20 Celsius: 14.73*10^-6 -% 1000hPa = 1 Bar, at 0 Celsius: 13.52*10^-6 at 20 Celsius: 15.32*10^-6 -% Low pressure: 960hPa = 0,96 Bar, at 0 Celsius: 17.24*10^-6 at 20 Celsius: 14.73*10^-6 - -% SHREK: Helium -% http://hbcponline.com/faces/documents/06_45/06_45_0001.xhtml?search=true -% 10^-6 *10*10^-4*3.259/0.1448402 -% kin_vis = 3.259*10^-6 / (0.1448402*10^3) % at 2 Kelvin -% kin_vis = 1.468*10^-6 / (0.1456217*10^3) % at 2.5 Kelvin -% kin_vis = 2.1*10^-8 - -if mod(length(data),2)==1 - data=data(1:end-1);% This is to make length of data array even -end - -% mean of the filtered data which is nothing but the mean of unfiltered data==>Filtering does not change the mean value -% m_data = mean(data); -% standard deviation of the filtered data which will always be lesser than the standard deviation of the unfiltered data -uprime = std(data); -% variance of the data -uprimesquared = uprime^2; - -% PSD of the fluctuations after filtering; mean value does not play a role in spectrum -daten = data-mean(data); -L = length(daten); %Length of the data - -% spek = abs(fft(daten,L)).^2/L; % Power spectral density(PSD) -spek = abs(fft(daten,L)).^2/(L*Fs); % Energy spectral density(ESD) using a fft -spek = 2.*spek(2:L/2+1); % FFt will yield half number of unique points - -f = Fs/2*linspace(0,1,L/2+1).'; % Nyquist frequency of the signal==Fs/2 -f = f(2:end); % Remove zero Hz component - - -% moving average with equally spaced frequency interval in log-space -plot_length = increment_bin*10; -if mod(plot_length,2) == 0 - plot_length = plot_length +1; -end - -intervall = unique(round(logspace(0,log10(L/2),plot_length)),'stable'); -plot_length = length(intervall); - -% Initializing the arrays/preallocation -spek_smooth = zeros(plot_length-2,1); -x_achse_f_spektrum = zeros(plot_length-2,1); - -% Averaging of spectrum and hence smoothing -for i=2:(plot_length-1) - x_achse_f_spektrum(i-1,1) = mean(f(intervall(i-1):intervall(i+1))); - spek_smooth(i-1,1) = mean(spek(intervall(i-1):intervall(i+1))); -end -% ------------------------Windowing / averaging end ------------------------ - -E_k = ((spek_smooth.*m_data)./(2*pi)); -% 2-pi - k Spektrum; Wavenumbers(1/m) -x_achse_k_spektrum_2pi = (2.*pi.*x_achse_f_spektrum)./m_data; - - - -% Wavenumber Spectrum (m^3/sec^2) -k = (2.*pi.*f(1:end))./m_data; -Ek = ((spek(1:end).*m_data)./(2.*pi)); -low_freq_k = (2*pi*low_freq)/m_data; - - -h(1) = figure; -% Plot of Frequency Vs. Power Spectral Density(m^2/sec) without smoothing -loglog(f,spek) -hold on -% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing -loglog(x_achse_f_spektrum,spek_smooth,'-','LineWidth',2) -xlabel('f / Hz','interpreter','latex'); -ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') -xlabel('$f\ (Hz)$','interpreter','latex'); -ylabel('$E\ (m^2/s)$', 'interpreter','latex') - -% title('energy density spectrum','interpreter','latex') -set(gca,'FontSize',10) -set(gcf, 'Color', 'w') -% xlim([min(x_achse_f_spektrum) max(x_achse_f_spektrum)]*2) -xlim([min(x_achse_f_spektrum) 10^2]) -grid on -axis square -% datacursormode on -fig_setup -legend off -grid off -set(gca,'XTick',[10^-2 10^0 10^2 10^4]); -waitfor(msgbox('Use interactive data cursor to select the range of frequency which will be used to linearly extrapolate the value of ESD at a frequency of 0 Hz (see readme).')); -% tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -% uiwait(gcf); -% delete(tmp_ui); - - - -%% First Method==> Calculating Ef0 with using Robust property -% Calculate the integral length scale (macro scale) Roach Eqn 15 -% In this method we will ask you to choose two values of frequencies in Hz such as -% f_start & f_end ===> [f_start0 -trying = true; -attemptcount = 1; -while trying - try - [I,yy] = ginput(2); - if I(1)>I(2) - I = flip(I); - yy = flip(yy); - end - tmp_ui = uicontrol('Position',[10 10 100 40],'String','Processing','Callback','uiresume(gcbf)'); - - f_start_plot = askInput({sprintf('Lowest frequency of constant range in Hz:')}, {num2str(I(1),'%.8f')}); - f_end_plot = askInput({sprintf('Highest frequency of constant range in Hz:')}, {num2str(I(2),'%.8f')}); - f_start = find(f>f_start_plot, 1,'first'); - f_end = find(f<=f_end_plot, 1,'last'); - - % Ef0 = mean(spek(f_start:f_end)); - % Ef0 = median(spek(f_start:f_end)); - - % IntegralLengthScale_1 = (Ef0*m_data)/(4*uprimesquared); % Integral Scale in meters - - %Second Method==> Calculating Ef0 from fit without using Robust property - [xData, yData] = prepareCurveData( f(f_start:f_end),(spek(f_start:f_end))); - - ft = fittype( 'poly1' ); - opts = fitoptions( 'Method', 'LinearLeastSquares' ); - % opts.Algorithm = 'Levenberg-Marquardt'; - % opts.Display = 'Off'; - opts.Lower = [0 0 ]; - % opts.StartPoint = [0.5 0.1]; - [fitresult, gof] = fit( xData, yData, ft, opts ); - IntegralLengthScale_2 = (fitresult.p2*m_data)/(4*uprimesquared); % Integral Scale in meters - fitresult.p1=0; - plot(f,feval(fitresult,f),'k','LineWidth',2,'LineStyle','-') - vline(f_start_plot,'k') % Construct a verticle line at f_start - vline(f_end_plot,'k') % Construct a verticle line at f_end - legend('raw','averaged','Location','southwest') - - trying = false; - catch - waitfor(msgbox('Please try again: f_start should be smaller than f_end and the decimal separator should be "."(period).')); - if attemptcount>maxnumattempts - waitfor(msgbox('Function failed.', 'Error','error')); - error('Function failed after %d times',maxnumattempts) - end - attemptcount=attemptcount+1; - end -end - - -% %Third Method==> Calculating Ef0 from fit with using Robust property='LAR' specifies the least absolute residual method. -% [xData, yData] = prepareCurveData( f(f_start:f_end),spek(f_start:f_end)); -% ft = fittype( 'a*x*0+b', 'independent', 'x', 'dependent', 'y' ); -% opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); -% opts.Algorithm = 'Levenberg-Marquardt'; -% opts.Display = 'Off'; -% opts.Robust = 'LAR'; -% opts.StartPoint = [0.0 0.01]; -% [fitresult, gof] = fit( xData, yData, ft, opts ); -% IntegralLengthScale_3 = (fitresult.b*m_data)/(4*uprimesquared); -% -% %%Fourth Method==> Calculating Ef0 from fit with using Robust property='Bisquare' specifies the bisquare weights method. -% [xData, yData] = prepareCurveData( f(f_start:f_end),spek(f_start:f_end)); -% ft = fittype( 'a*x*0+b', 'independent', 'x', 'dependent', 'y' ); -% opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); -% opts.Algorithm = 'Levenberg-Marquardt'; -% opts.Display = 'Off'; -% opts.Robust = 'Bisquare'; -% opts.StartPoint = [0.0 0.01]; -% [fitresult, gof] = fit( xData, yData, ft, opts ); -% IntegralLengthScale_4 = (fitresult.b*m_data)/(4*uprimesquared); - - - -%% Dissipation from different methods -trying = true; -attemptcount = 1; -while trying - try - clear r tau step stepp - r = unique(round(logspace(log10((1./Fs).*m_data*10^6),log10(20*IntegralLengthScale_2*10^6),increment_bin))./10^6,'stable'); - - tau(1:length(r)) = nan; - step(1:length(r)) = nan; - - for z=1:length(r) - tau(z) = r(z)/m_data; - step(z) = round(tau(z)*Fs); - end - stepp = unique(step); - stepp = stepp(stepp>0); - - clear r R S_exp_3 S_exp_2 - r(1:length(stepp)) = nan; - R(1:length(stepp)) = nan; - S_exp_3(1:length(stepp))=nan; % Third order structure function - S_exp_2(1:length(stepp))=nan; % Second order structure function - - parfor z=1:length(stepp) - % z/length(stepp) - tau = stepp(z) % In steps, just a number - r(z) = (tau./Fs).*m_data; % in meters - incr = (data(tau+1:L) - data(1:L-tau)).'; % velocity Increment in steps of tau - S_exp_2(z) = mean(incr.^2); % Second order structure function - S_exp_3(z) = mean(incr.^3); % Third order structure function - % Autocorr André - R(1,z) = mean(daten(tau+1:L).*daten(1:L-tau))/uprimesquared; - end - - % HIT = Homogeneous Isotropic Turbulence - eps_2 = (1./(r)).*((S_exp_2./C2).^(3/2)); % Estimation of dissipation from S_exp_2 using HIT - eps_3 = -(5/4).*(S_exp_3./r); % Estimation of dissipation from S_exp_3 using HIT - - I0 = find( eps_2==max(eps_2),1); % Finding the maximum value of dissipation in inertial range - I1 = find(-eps_3==max(-eps_3),1); % Finding the maximum value of dissipation in inertial range - - % dissipation rate m^2.s^-3 from S2 - epsi_S2 = mean(eps_2(1,I0-2:I0+2)); % finding the mean amongst 5 points closest to peak value; - % dissipation rate m^2.s^-3 from S3 - epsi_S3 = mean(-eps_3(1,I1-2:I1+2)); % finding the mean amongst 5 points closest to peak value; - - trying = false; - catch -% waitfor(msgbox(' f_start should be smaller than f_end should be. ')); - increment_bin = askInput({sprintf('Please try again by increasing the number of Bin''s used (must be larger than:):')}, {num2str(increment_bin,'%1.0f')}); - if attemptcount>maxnumattempts - waitfor(msgbox('Function failed.', 'Error','error')); - error('Function failed after %d times',maxnumattempts) - end - attemptcount=attemptcount+1; - end -end - -delete(tmp_ui); - - -% figure -% loglog(r,S_exp_2) - - -%% Integral length scale from Auto-corelation or structure function -%% Autocorr André -low_freq_r = m_data/low_freq; - -% Full integration -int_L_full = trapz(r,R); -% trapz(r,abs(R)) - -% integrate up to the first zero crossing -tmp_zero=(find(R<0,1,'first'))-1; -if isempty(tmp_zero) - int_L_0 = nan; -else - % r(tmp_zero) - int_L_0 = trapz(r(1:tmp_zero),R(1:tmp_zero)); -end - -% integrate up to the first 1/e crossing -tmp_exp=(find(R<1/exp(1),1,'first')); -if isempty(tmp_exp) - int_L_1_exp=nan; - theo_exp_Funktion = nan; -else - int_L_1_exp = trapz(r(1:tmp_exp),R(1:tmp_exp)); - % local minimum - % index1 = find(diff(sign(diff(R))) ~= 0,2,'first')+1; - % r(index1) - % int_L_min=trapz(r(1:index1),abs(R(1:index1))); - - %exp Fit to R; Fitregion r=1/exp(1):2*low_freq_r - tmp_up = (find(r>4*low_freq_r,1,'first')); - tmp_low = (find(R<1/exp(1),1,'first')); - - if tmp_up10*IntegralLengthScale_2))))); % Auto-correlation coefficient Using std from S_exp_2 ==>This is a dimentionless quantity -Ruu = [1,Ruu]; % Auto-correlation is 1 at scale=0 -r_Ruu = [0,r]; % Auto-correlation is 1 at scale=0 -LL = (cumsum(Ruu(1,1:end-1).*diff(r_Ruu)))'; % Cumulative integration of Ruu with respect to r -pks = findpeaks(LL,3); % Finding the peaks in LL -Npks = size(pks,1); - -if Npks == 0 -IntegralLengthScale_5 = trapz(r_Ruu,Ruu); % If no peaks are found then simply take the area under the curve which will be in meters -else -IntegralLengthScale_5 = pks(1); % in meters At this length we should reach an asymptotic value on the plot of r Vs. LL -end - -lambda_S2 = (sqrt(15*kin_vis*uprimesquared./epsi_S2)); % Taylors length scale in meters from epsi_S2 and hence from S_exp_2 -lambda_S3 = (sqrt(15*kin_vis*uprimesquared./epsi_S3)); % Taylors length scale in meters from epsi_S3 and hence from S_exp_3 - - - -%% Integral length scale from auto-corelation function 'xcorr' of MATLAB -% tau = 1/Fs; % time in seconds/Time per sample in secs -% [Ruu_xcorr,tau_xcorr] = xcorr(data - mean(data),size(data,1)/2,'unbiased'); -% Ruu_xcorr = Ruu_xcorr(tau_xcorr>=0); -% tau_xcorr = tau_xcorr(tau_xcorr>=0); -% Ruu_xcorr = Ruu_xcorr./max(Ruu_xcorr); -% dist_xcorr = tau_xcorr.*tau.*m_data; -% Ruu_xcorr = Ruu_xcorr'; -% LL_xcorr = (cumsum(Ruu_xcorr(1,1:end-1).*diff(dist_xcorr(1,1:end)))); -% pks_xcorr = findpeaks(LL_xcorr); -% Npks_xcorr = size(pks_xcorr,1); -% -% if Npks_xcorr == 0 -% IntegralLengthScale_6 = trapz(dist_xcorr,Ruu_xcorr); % If no peaks are found then simply take the area under the curve -% else -% IntegralLengthScale_6 = pks_xcorr(1); % in meters at this length we should reach an asymptotic value on plot of r Vs. LL -% end -% -% figure; -% plot(r,R,'-k','LineWidth',2) -% hold on -% plot(r_Ruu,Ruu,'LineWidth',2) -% plot(dist_xcorr,Ruu_xcorr,'LineWidth',2) -% xlim([0 1500*low_freq_r]) - - -% figure; -% plot(r_Ruu(1:end-1),LL,'LineWidth',2) -% hold on -% plot(dist_xcorr(1:end-1),LL_xcorr,'LineWidth',2) - - - -%% Zero-crossing method: Martin Obligado -delete(tmp_ui); -[int_L_zero_cros,lambda_zero_cros,lambda1_zero_cros,Eps_zero_cros,h]=ZeroCrossings(data,Fs,m_data,kin_vis,low_freq,x_achse_k_spektrum_2pi,E_k,h); - -%% -% int_L_calc = [IntegralLengthScale_2,int_L_full,int_L_0,int_L_1_exp,theo_exp_Funktion,IntegralLengthScale_5,IntegralLengthScale_6,int_L_zero_cros];%% meter -int_L_calc = [IntegralLengthScale_2,int_L_full,int_L_0,int_L_1_exp,theo_exp_Funktion,IntegralLengthScale_5,int_L_zero_cros];%% meter - -% Choose the best estimate of integral and Taylor length scale on which you would like to rely on -h(3) = figure; -plot(int_L_calc,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) -xlabel('method', 'interpreter','latex') -ylabel('L/m', 'interpreter','latex') -ylabel('$L\ (m)$','interpreter','latex'); -axis square -set(gcf, 'Color', 'w') -set(gca, 'FontSize',18) -fig_setup -legend off -set(gca,'XTick',[1 2 3 4 5 6 7 8]); -datacursormode on -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); -int_L = askInput({sprintf('Enter the integral length scale in meter. Median integral length scale in meter:')}, {num2str(nanmedian(int_L_calc),'%.5f')}); - - - - - - -%% Taylor length by different methods -%% using Autocorrelation function -trying = true; -attemptcount = 1; -while trying - try - figure; - plot(r_Ruu,Ruu,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) - ylabel('$R_{\widetilde{u}\widetilde{u}}$', 'interpreter','latex') - xlabel('r/m', 'interpreter','latex') - xlabel('$r\ (m)$','interpreter','latex'); - axis square - set(gcf, 'Color', 'w') - set(gca, 'FontSize',18) - ylim([0.7 1.05]) - xlim([0 r_Ruu(find(Ruu<0.7,1,'first'))]) - datacursormode on - waitfor(msgbox('Use interactive data cursor to select the range of scales which will be used to estimate Taylor lenght scalee (see readme).')); - [I,yy] = ginput(1); - i_tmp = askInput({sprintf(['Fit Region Auto-correlation Coefficient e.g. = ' ,num2str(0.98,'%1.2f')])}, {num2str(yy(1),'%.2f')}); - close - - - [xData, yData] = prepareCurveData( r_Ruu(1:(find(Rmaxnumattempts - waitfor(msgbox('Function failed.', 'Error','error')); - error('Function failed after %d times',maxnumattempts) - end - attemptcount=attemptcount+1; - end -end - -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); - - - - -%% numerical differentiation -%<(du/dx)^2> -du_dx = mean((diff(daten)./(m_data*(1/Fs))).^2); -lambda_direct = sqrt(uprimesquared/du_dx); - -% Aronson and Löfdahl -tmp = sqrt((uprimesquared.*r.^2)./S_exp_2); -h(5) = figure; -plot(r,tmp,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) -hold on -xlabel('r/m', 'interpreter','latex') -xlabel('$r\ (m)$','interpreter','latex'); -ylabel('$\sqrt{\frac{u''^2 r^2}{S^{2}(r)}}/m$', 'interpreter','latex') -ylabel('$\sqrt{\frac{u''^2 r^2}{S^{2}}}\ (m)$', 'interpreter','latex') -axis square -set(gcf, 'Color', 'w') -set(gca, 'FontSize',18) -xlim([0 25*low_freq_r]) -datacursormode on -waitfor(msgbox('Use interactive data cursor to select the range of scales which will be used to estimate Taylor lenght scalee (see readme).')); - -tmp_up = (find(r>4*low_freq_r,1,'first')); -vline(r(tmp_up),'k') - -trying = true; -attemptcount = 1; -while trying - try - [I,yy] = ginput(1); - % i_tmp = str2double(inputdlg({'Fit Region rmin ='})); - % tmp_up = (find(r>i_tmp,1,'first')); - i_tmp = askInput({sprintf(['Fit Region r_max e.g. = ' ,num2str(20*low_freq_r,'%0.2f')])}, {num2str(I(1),'%.2f')}); - tmp_low = (find(rmaxnumattempts - waitfor(msgbox('Function failed.', 'Error','error')); - error('Function failed after %d times',maxnumattempts) - end - attemptcount=attemptcount+1; - end -end - -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); - - -% Dissipationspectrum -k_end = find(k<=low_freq_k, 1,'last'); -lambda_spec_low_freq = sqrt(trapz(k(1:k_end),Ek(1:k_end))/trapz(k(1:k_end),Ek(1:k_end).*k(1:k_end).^2)); -lambda_spec_full = sqrt(uprimesquared/trapz(k,Ek.*k.^2)); -% trapz(k,2.*Ek.*k.^2) anstatt trapz(k,Ek.*k.^2) -% lambda_1=sqrt(uprimesquared/trapz(k,2.*Ek.*k.^2)) -% lambda_2=sqrt(trapz(k,2.*Ek)/trapz(k,2.*Ek.*k.^2)) - -% take everthing of the specturm -% lambda_1=sqrt(uprimesquared/trapz(k,Ek.*k.^2)); -% lambda_1=sqrt(uprimesquared/trapz(x_achse_k_spektrum_2pi(2:end),E_k.*x_achse_k_spektrum_2pi(2:end).^2)) -% lambda_2=sqrt(trapz(k,Ek)/trapz(x_achse_k_spektrum_2pi(2:end),E_k.*x_achse_k_spektrum_2pi(2:end).^2)) - -% find Minimum at high frequencies -% k_start = find(k>0.2*10^4, 1,'first'); -% k_end = find(k<=5*10^4, 1,'last'); -% lambda_1_kurz = sqrt(uprimesquared/trapz(k(1:find(spek==min(spek(k_start:k_end)))),Ek(1:find(spek==min(spek(k_start:k_end)))).*k(1:find(spek==min(spek(k_start:k_end)))).^2)); - -% lambda_4 = sqrt(uprimesquared/du_dx_4); -% lambda_6 = sqrt((10*kin_vis/m_data) * (uprimesquared/(uprimesquared/(m_data*(1/Fs))))); - -% taylor_L_calc = [lambda_autocorr,lambda_direct,A_L_lambda,lambda_spec_low_freq,lambda_spec_full, lambda_S2, lambda_S3,lambda_zero_cros,lambda1_zero_cros];%% meter -taylor_L_calc = [lambda_autocorr,lambda_direct,A_L_lambda,lambda_spec_low_freq,lambda_spec_full,lambda_zero_cros,lambda1_zero_cros];%% meter - - -h(6) = figure; -plot(taylor_L_calc,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) -xlabel('method', 'interpreter','latex') -ylabel('$\lambda/m$', 'interpreter','latex') -ylabel('$\lambda\ (m)$', 'interpreter','latex') -axis square -set(gcf, 'Color', 'w') -set(gca, 'FontSize',18) -fig_setup -legend off -set(gca,'XTick',[1 2 3 4 5 6 7]); -datacursormode on -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); -taylor_L = askInput({sprintf('Enter the Taylor length scale in meter. Median Taylor length scale in meter:')}, {num2str(nanmedian(taylor_L_calc),'%.5f')}); - - - -%% Dissipation from different methods -% epsi_1 = 15*kin_vis*trapz(k(1:k_end),Ek(1:k_end).*k(1:k_end).^2); %% From dissipation Spectrum untill cutoff frequency -% epsi_2 = 15*kin_vis*trapz(k,Ek.*k.^2); %%From entire dissipation Spectrum - -% epsi_2 = trapz(k,2.*kin_vis.*Ek.*k.^2); -% epsi_3 = 15*kin_vis*du_dx_3; -% epsi_4 = 15*kin_vis*du_dx_4; -% epsi_5 = 15*kin_vis*du_dx_5; - -% epsi_5 = (m_data/2) * (mean(diff(daten.^2)/(m_data*(1/Fs)))); -% epsi_6 = (3*m_data/2) * (var(diff(daten)./(m_data*(1/Fs)))); -% epsi_7 = 15*kin_vis*(uprimesquared/lambda_1^2); -% epsi_7a= 30*kin_vis*(uprimesquared/lambda_1^2) %longitudinale microscale -% epsi_7b= 15*kin_vis*(uprimesquared/(lambda_1/sqrt(2))^2) %trasnversale microscale -% epsi_8 = m_data^3/int_L - -% epsi_1/m_data -% var(daten)/(m_data*(1/Fs)) -% std(daten)/(m_data*(1/Fs)) -% epsi_calc = [epsi_1, epsi_2, epsi_3, epsi_5, epsi_S2,epsi_S3]; - - -h(7) = figure; -semilogx(r,eps_2,'LineWidth',2) -hold on -semilogx(r,-eps_3,'LineWidth',2) -xlim([min(r)*0.5 max(r)*2]) -xlabel('r/m', 'interpreter','latex') -xlabel('$r\ (m)$','interpreter','latex'); -ylabel('$\epsilon(r)/\frac{m^2}{s^3}$', 'interpreter','latex') -ylabel('$\epsilon\ (m^2/s^3)$','interpreter','latex'); -set(gca,'FontSize',16) -set(gcf, 'Color', 'w') -fig_setup -axis square -% vline(r(I0),'r') -% vline(r(I1),'k') - -plot(linspace(min(r)*0.5,max(r)*2,1000),eps_2(I0).*ones(1000,1),'k','LineWidth',2) -plot(linspace(min(r)*0.5,max(r)*2,1000),-eps_3(I1).*ones(1000,1),'k','LineWidth',2) -legend('$\frac{1}{r}\left[\frac{S^{2}(r)}{C_{2}}\right]^{3/2}$','$-\frac{5}{4}\left[\frac{S^{3}(r)}{r}\right]$','Location','south') - -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); - -etaflow_S2 = ((kin_vis^3/epsi_S2)^(1/4)); % Kolmogorov length scale in meters from epsi_S2 and hence from S_exp_2 -etaflow_S3 = ((kin_vis^3/epsi_S3)^(1/4)); % Kolmogorov length scale in meters from epsi_S3 and hence from S_exp_3 - - - -%% Spectrum-Fit -epsi_calc = [epsi_S2,epsi_S3,(15*kin_vis*(uprimesquared/taylor_L^2))]; - -h(8) = figure; -loglog(x_achse_k_spektrum_2pi,E_k,'-','LineWidth',2) -hold on -a=find(x_achse_k_spektrum_2pi<=(2*pi*((1/(int_L/m_data))/(2*pi))/m_data), 1,'last'); -b=find(x_achse_k_spektrum_2pi>=(2*pi*((1/(taylor_L/m_data))/(2*pi))/m_data), 1,'first'); - -% b=find(x_achse_k_spektrum_2pi>=(1)/diss_scale, 1,'first'); -% a=1; -% b=length(x_achse_k_spektrum_2pi); -[xData, yData] = prepareCurveData( x_achse_k_spektrum_2pi(a:b), E_k(a:b) ); -% [xData, yData] = prepareCurveData( x_achse_f_spektrum,spek_smooth); -% [xData, yData] = prepareCurveData(k, Ek ); - -opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); -opts.DiffMinChange = 1e-12; -opts.Display = 'Off'; -opts.MaxFunEvals = 1200; -opts.MaxIter = 1200; - -ft = fittype( 'a*b^(2/3)*(x-d)^(-5/3)', 'independent', 'x', 'dependent', 'y' ); -% opts.Lower = [0 median(epsi_calc) -Inf]; -% opts.Upper = [Inf median(epsi_calc) Inf]; -opts.Lower = [0 0 -Inf]; -opts.Upper = [Inf Inf Inf]; -opts.StartPoint = [0.5 nanmedian(epsi_calc) 0]; -try - [fitresult, gof] = fit( xData, yData, ft, opts ); - ft2 = fittype( 'a*b^(2/3)*(x)^(-5/3)', 'independent', 'x', 'dependent', 'y' ); - % opts.Lower = [0 nanmedian(epsi_calc)]; - % opts.Upper = [Inf nanmedian(epsi_calc)]; - opts.Lower = [0 0]; - opts.Upper = [Inf Inf]; - opts.StartPoint = [0.5 nanmedian(epsi_calc)]; - [fitresult2, gof] = fit( xData, yData, ft2, opts ); - plot(x_achse_k_spektrum_2pi, feval(fitresult,x_achse_k_spektrum_2pi),'-','LineWidth',2) - plot(x_achse_k_spektrum_2pi, feval(fitresult2,x_achse_k_spektrum_2pi),'-','LineWidth',2) -catch -end -set(gca,'XScale','log'); -set(gca,'YScale','log'); -xlabel('$k= / \frac{1}{m}$', 'interpreter','latex'); -ylabel('$E(k)$ / $\frac{m^3}{s^2}$', 'interpreter','latex') -xlabel('$k\ (1/m)$','interpreter','latex'); -ylabel('$\frac{E }{2 \pi}\ (m^3/s^2)$', 'interpreter','latex') - -xlim([min(x_achse_k_spektrum_2pi) 2*max(x_achse_k_spektrum_2pi)]) -ylim([min(E_k) 2*max(E_k)]) -axis square -% vline(x_achse_k_spektrum_2pi(a),'k') -% vline(x_achse_k_spektrum_2pi(b),'k') -% vline((1)/diss_scale,'k') -set(gcf, 'Color', 'w') -legend('$\frac{E }{2 \pi}$','$C_k\langle \epsilon \rangle^{2/3}(k-k_0)^{-5/3}$','$C_k\langle \epsilon \rangle^{2/3}k^{-5/3}$','Location','south') -fig_setup -set(gca,'XTick',[10^-2 10^0 10^2 10^4]); -% fitresult; -% fitresult2; -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); - -% figure -% plot( fitresult, xData, yData ); -% hold on -% plot( fitresult2, xData, yData ); -% plot( fitresult, xData, yData ); -% loglog(x_achse_k_spektrum_2pi,E_k) -% set(gca,'XScale','log'); -% set(gca,'YScale','log'); - - -epsi_calc = [epsi_S2,epsi_S3, (15*kin_vis*(uprimesquared/taylor_L^2)), fitresult2.b,fitresult.b, Eps_zero_cros]; - -h(9) = figure; -plot(epsi_calc,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) -xlabel('method', 'interpreter','latex') -ylabel('$\langle \epsilon \rangle/\frac{m^2}{s^3}$', 'interpreter','latex') -ylabel('$\langle \epsilon \rangle\ (m^2/s^3)$', 'interpreter','latex') -axis square -set(gcf, 'Color', 'w') -set(gca, 'FontSize',18) -fig_setup -legend off -set(gca,'XTick',[1 2 3 4 5 6 7 ]); -datacursormode on -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); -epsi = askInput({sprintf('Enter the energy dissipation rate in $m^2/s^3$. Median energy dissipation rate in $m^2/s^3$:')}, {num2str(nanmedian(epsi_calc),'%.5f')}); - - - - -Re = m_data*int_L/kin_vis; -% Re_lambda = uprime*lambda_1_kurz_low_freq/kin_vis; -Re_lambda = uprime*taylor_L/kin_vis; -% Re_lambda = uprime*lambda_1/kin_vis; - -% Calculate the dissipation length scale (micro scale) Roach Eqn 8 -% Z=((2*pi^2)/(m_data^2*uprimesquared))*trapz((f(2:end).^2),spek(2:L/2+1)); % Use trapezoid rule for integration -% DissipationScale=sqrt(1/Z) - -DissipationScale_1 = ((kin_vis^3)/epsi)^0.25; -% DissipationScale_2 = sqrt(1/(trapz(f,spek.*f.^2)*((2*pi^2)/(m_data^2*uprimesquared)))) -% DissipationScale_3 = int_L/(Re^0.75); - -% kolmogorov_calc = [DissipationScale_1, etaflow_S2,etaflow_S3];%% meter -diss_scale = DissipationScale_1; - -%%Non dimentional dissipation constant -Ce = 15*(int_L/taylor_L)/Re_lambda; -Ce_b = epsi*int_L/uprime^3; - -% Ce = 15*(int_L/lambda_1_kurz_low_freq)/Re_lambda; -% Ce_1 = epsi_1*int_L/uprime^3; -% Ce_2 = epsi_2*int_L/uprime^3; -% Ce_3 = epsi_3*int_L/uprime^3; -% Ce_5 = epsi_5*int_L/uprime^3; - -% Ce_calc =[Ce, Ce_1, Ce_2, Ce_3, Ce_5]; -Ce_calc = [Ce, Ce_b]; -Ce = mean(Ce_calc); - - -%% Plot Spectrum -h(10) = figure; -set(gcf, 'Color', 'w') -yyaxis left -loglog(x_achse_k_spektrum_2pi,E_k,'-','LineWidth',2) -% hold on -% loglog(x_achse_k_spektrum_2pi,(x_achse_k_spektrum_2pi.^(-5/3).*ones(length(E_k)).*10),'-','LineWidth',1,'color','k') -% loglog(x_achse_k_spektrum_2pi,(x_achse_k_spektrum_2pi.^(-2).*ones(length(E_k)).*0.7.*10^2),'-','LineWidth',1,'color','k') -% loglog(x_achse_k_spektrum_2pi,(x_achse_k_spektrum_2pi.^(-3).*ones(length(E_k)).*0.6.*10^5),'-','LineWidth',1,'color','k') -% xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); -xlabel('$k= / \frac{1}{m}$', 'interpreter','latex'); -% ylabel('$E(k)=\frac{E(f) }{2 \pi}$ / $\frac{m^3}{s^2}$', 'interpreter','latex') -ylabel('$E(k)$ / $\frac{m^3}{s^2}$', 'interpreter','latex') -%xlabel('k'); -%ylabel('E(k)') -xlabel('$k\ (1/m)$','interpreter','latex'); -ylabel('$\frac{E }{2 \pi}\ (m^3/s^2)$', 'interpreter','latex') -xlim([min(x_achse_k_spektrum_2pi) 2*max(x_achse_k_spektrum_2pi)]) -% ylim([10^-10 1]) -axis square -hold on -yyaxis right -% loglog(x_achse_k_spektrum_2pi,15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi).^2,'-','LineWidth',2) -loglog(x_achse_k_spektrum_2pi,E_k.*(x_achse_k_spektrum_2pi).^2,'-','LineWidth',2) -ylabel('E(k)$\cdot k^2$ / $\frac{m}{s^2}$', 'interpreter','latex') -ylabel('$\frac{E }{2 \pi} k^2\ (m/s^2)$', 'interpreter','latex') - -set(gca,'YScale','log'); -set(gca,'FontSize',24) -% vline(low_freq_k,'r') -% vline((1/(int_L/m_data))/m_data,'k') -vline((2*pi*((1/(int_L/m_data))/(2*pi))/m_data),'k') -vline((2*pi*((1/(taylor_L/m_data))/(2*pi))/m_data),'k') -vline((2*pi*((1/(diss_scale/m_data))/(2*pi))/m_data),'k') -fig_setup -set(gca,'XTick',[10^-2 10^0 10^2 10^4]); -legend off - - - -h(11) = figure; -set(gcf, 'Color', 'w') -yyaxis left -% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing -loglog(x_achse_f_spektrum,spek_smooth,'-','LineWidth',2) -xlabel('f / Hz','interpreter','latex'); -ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') -xlabel('$f\ (Hz)$','interpreter','latex'); -ylabel('$E\ (m^2/s)$', 'interpreter','latex') -set(gca,'FontSize',10) -set(gcf, 'Color', 'w') -xlim([min(x_achse_f_spektrum) max(x_achse_f_spektrum)]*2) -% xlim([min(x_achse_f_spektrum) 10^2]) -grid on -axis square -datacursormode on -fig_setup -grid off -legend off -set(gca,'XTick',[10^-2 10^0 10^2 10^4]); -vline((1/(int_L/m_data))/(2*pi),'k') -vline((1/(taylor_L/m_data))/(2*pi),'k') -vline((1/(diss_scale/m_data))/(2*pi),'k') - -yyaxis right -% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing -loglog(x_achse_f_spektrum,spek_smooth.*x_achse_f_spektrum.^(5/3),'-','LineWidth',2) -ylabel('$E(f)f^{5/3}$ / $\frac{m^2}{s}$', 'interpreter','latex') -ylabel('$E\ f^{5/3}\ (m^2/s)$', 'interpreter','latex') -xlim([min(x_achse_f_spektrum) max(x_achse_f_spektrum)]*2) -ylim([min(spek_smooth.*x_achse_f_spektrum.^(5/3)) max(spek_smooth.*x_achse_f_spektrum.^(5/3))]*2) - - - - -% k Spektrum; Scales,r (m) -x_achse_spektrum_meter = m_data./(2*pi*x_achse_f_spektrum); -Dr_avg_filter=(spek_smooth.*x_achse_f_spektrum.^2)./m_data; -Dk_avg_filter=15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi).^2; - - - -figure; -set(gcf, 'Color', 'w') -subplot(2,2,1) -loglog(x_achse_f_spektrum,spek_smooth,'-','LineWidth',1)%% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing & Filtering -xlabel('f / Hz','interpreter','latex'); -ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') -xlabel('$f\ (Hz)$','interpreter','latex'); -ylabel('$E\ (m^2/s)$', 'interpreter','latex') -xlim([min(x_achse_f_spektrum) 2*max(x_achse_f_spektrum)]) -ylim([min(spek_smooth) max(spek_smooth)]*2) -title('frequency domain','interpreter','latex') -set(gca,'FontSize',12) -set(groot, 'defaultAxesTickLabelInterpreter','latex'); -% plot([10^3 10^3],[10^-6 10^-2],'y = x ','-','LineWidth',1) -% h = vline(10^3,'k','The Answer') -% text(245,spek_smooth(find(x_achse_f_spektrum>245,1,'first')),'\leftarrow sin(\pi) = 0','FontSize',16) -set(gca,'XTick',[10^-2 10^0 10^2 10^4]); -hold on -vline((1/(int_L/m_data))/(2*pi),'k') -vline((1/(taylor_L/m_data))/(2*pi),'k') -vline((1/(diss_scale/m_data))/(2*pi),'k') -txt = {'(a)'}; -a=text(4,0.5,txt); -a.Units='normalized'; - -subplot(2,2,2) -loglog(x_achse_k_spektrum_2pi,E_k,'-','LineWidth',1)%% Plot of Wavenumber(k) Vs. Energy(k)(m^3/sec^2) with smoothing & Filtering -% loglog(x_achse_k_spektrum_2pi,x_achse_k_spektrum_2pi.^(-5/3).*(max(spek_smooth).*200),'--','color','k','LineWidth',2) -xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); -ylabel('$E(k)=\frac{E(f) }{2 \pi}$ / $\frac{m^3}{s^2}$', 'interpreter','latex') -xlabel('$k=\frac{2 \pi f}{}\ (1/m)$','interpreter','latex'); -ylabel('$\frac{E }{2 \pi}\ (m^3/s^2)$', 'interpreter','latex') -xlim([min(x_achse_k_spektrum_2pi) 2*max(x_achse_k_spektrum_2pi)]) -ylim([min(E_k) max(E_k)]*2) -title('wave number domain','interpreter','latex') -set(gca,'FontSize',12) -set(gca,'XTick',[10^-2 10^0 10^2 10^4]); -hold on -vline((2*pi*((1/(int_L/m_data))/(2*pi))/m_data),'k') -vline((2*pi*((1/(taylor_L/m_data))/(2*pi))/m_data),'k') -vline((2*pi*((1/(diss_scale/m_data))/(2*pi))/m_data),'k') -txt = {'(b)'}; -b=text(4,0.5,txt); -b.Units='normalized'; - -subplot4=subplot(2,2,3); -loglog(x_achse_spektrum_meter,Dr_avg_filter,'-','LineWidth',1)%% Plot of Scales,r(m) Vs. Energy(r)(m/sec^2) with smoothing & Filtering -xlabel('$r=\frac{}{2 \pi f} / m$', 'interpreter','latex'); -ylabel('$E(r)=\frac{E(f) f^2}{}$ / $\frac{m}{s^2}$', 'interpreter','latex') -xlabel('$r=\frac{}{2 \pi f}\ (m)$','interpreter','latex'); -ylabel('$\frac{E\ f^2}{}\ (m/s^2)$', 'interpreter','latex') -set(subplot4, 'Xdir', 'reverse') -xlim([0.5* min(x_achse_spektrum_meter) max(x_achse_spektrum_meter)]) -ylim([min((spek_smooth.*x_achse_f_spektrum.^2)./m_data) max((spek_smooth.*x_achse_f_spektrum.^2)./m_data)]*2) -set(gca,'FontSize',12) -set(gca,'XTick',[10^-2 10^0 10^2 10^4]); -title('dissipation spectrum','interpreter','latex') -vline(int_L,'k') -vline(taylor_L,'k') -vline(diss_scale,'k') -txt = {'(c)'}; -c=text(4,0.5,txt); -c.Units='normalized'; - - - -% Dissipation Spectrum -% kin_vis = 15.328737178409*10^-6; -subplot(2,2,4) -loglog(x_achse_k_spektrum_2pi,Dk_avg_filter,'-','LineWidth',1)%% Plot of Wavenumber(k) Vs. Dissipation(k)(m/sec^2) with smoothing & Filtering -xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); -ylabel('E(k)$\cdot k^2$ / $\frac{m}{s^2}$', 'interpreter','latex') -xlabel('$k=\frac{2 \pi f}{}\ (1/m)$','interpreter','latex'); -ylabel('$\frac{E }{2 \pi}\ k^2 \ (m/s^2)$', 'interpreter','latex') -xlim([min(x_achse_k_spektrum_2pi) 2*max(x_achse_k_spektrum_2pi)]) -ylim([min(15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi).^2) max(15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi).^2)]*2) -title('dissipation spectrum','interpreter','latex') -set(gca,'FontSize',12) -set(gca,'XTick',[10^-2 10^0 10^2 10^4]); -datacursormode on -hold on -vline((2*pi*((1/(int_L/m_data))/(2*pi))/m_data),'k') -vline((2*pi*((1/(taylor_L/m_data))/(2*pi))/m_data),'k') -vline((2*pi*((1/(diss_scale/m_data))/(2*pi))/m_data),'k') -txt = {'(d)'}; -d=text(4,0.5,txt); -d.Units='normalized'; - -% font=22; -% a.FontSize = font; -% b.FontSize = font; -% c.FontSize = font; -% d.FontSize = font; - -pos_txt=[-0.25 0.9]; -a.Position=pos_txt; -b.Position=pos_txt; -c.Position=pos_txt; -d.Position=pos_txt; - - - - - - - - -if ischar(save_path) - savefig(h,fullfile(save_path,append(save_name,'_','length_scales.fig')),'compact') - for a = 1:length(h) - exportgraphics(h(a),fullfile(save_path,append(save_name,'_',sprintf('length_scales_%d.png', a)))) - end -end -close all +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% In this function the integral length scale $L$, Taylor length scale $\lambda$ and Kolmogorov +% length scale are estimated using different methods of calculation. Within this function, pop-up +% dialog boxes will be generated to enter the values of the integral, Taylor length scale in $m$ +% and energy dissipation rate in $m^2/s^3$ on which the further processing of data (solving the +% FPE and extracting cascade trajectories) should be referred. The entered length scales will be +% round towards the nearest integer sample. The proposed value in the pop-up dialog box is the +% median length scale for all methods. +% COMMENT: All velocity increments in this script are taken as right hand increment i.e. +% dV=V(t2)-V(t1) where t2>t1; t1,t2 in seconds +% +% Arguments IN +% data = it is the filtered data +% Fs = Acquisition/Sampling Frequency in Hz +% low_freq = Frequency at which you would like to use the low-pass filter in Hz +% kin_vis = Kinematic viscosity of fluid in m^2/sec +% C2 = constant, C2 associated with second order structure function(in between 2.0 to 2.2) +% +% Arguments OUT +% int_L = Integral length scale in meters +% taylor_L = Taylors length scale in meters +% int_L_calc = 1D array of integral length scale calculated by different methods/formula +% taylor_L_calc = 1D array of Taylor's length scale calculated by different methods/formula +% epsi = mean energy dissipation rate +% epsi_calc = 1D array of mean energy dissipation rate calculated by different methods/formula +% diss_scale = Kolmogorv lenght scale in meters +% Ce = is the non-dimentional / normalized energy dissipation rate +% Ce_calc = 1D array of Ce calculated by different methods/formula +% Re = Reynolds Number based on integral length scale +% Re_lambda= Reynolds Number based on Taylor's length scale +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [int_L,taylor_L,int_L_calc, taylor_L_calc,epsi, epsi_calc,diss_scale,Ce, Ce_calc, Re, Re_lambda]=length_scales(data,Fs,low_freq,kin_vis,C2,increment_bin,m_data,save_path,save_name) +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +set(groot, 'defaulttextinterpreter','latex'); +set(groot, 'defaultLegendInterpreter','latex'); +set(groot, 'defaultAxesTitle','latex'); + +maxnumattempts = 2; + + +% Pressure calculation: +% http://www.peacesoftware.de/einigewerte/luft_e.html +% https://www.einheiten-umrechnen.de/einheiten-rechner.php?typ=druck +% The higher the pressure the lower the kinematic viscosity, +% the higher the temperature the higher the kinematic viscosity. +% High Pressure: 1040hPa = 1,04 Bar, at 0 Celsius: 13.00*10^-6 at 20 Celsius: 14.73*10^-6 +% 1000hPa = 1 Bar, at 0 Celsius: 13.52*10^-6 at 20 Celsius: 15.32*10^-6 +% Low pressure: 960hPa = 0,96 Bar, at 0 Celsius: 17.24*10^-6 at 20 Celsius: 14.73*10^-6 + +% SHREK: Helium +% http://hbcponline.com/faces/documents/06_45/06_45_0001.xhtml?search=true +% 10^-6 *10*10^-4*3.259/0.1448402 +% kin_vis = 3.259*10^-6 / (0.1448402*10^3) % at 2 Kelvin +% kin_vis = 1.468*10^-6 / (0.1456217*10^3) % at 2.5 Kelvin +% kin_vis = 2.1*10^-8 + +if mod(length(data),2)==1 + data=data(1:end-1);% This is to make length of data array even +end + +% mean of the filtered data which is nothing but the mean of unfiltered data==>Filtering does not change the mean value +% m_data = mean(data); +% standard deviation of the filtered data which will always be lesser than the standard deviation of the unfiltered data +uprime = std(data); +% variance of the data +uprimesquared = uprime^2; + +% PSD of the fluctuations after filtering; mean value does not play a role in spectrum +daten = data-mean(data); +L = length(daten); %Length of the data + +% spek = abs(fft(daten,L)).^2/L; % Power spectral density(PSD) +spek = abs(fft(daten,L)).^2/(L*Fs); % Energy spectral density(ESD) using a fft +spek = 2.*spek(2:L/2+1); % FFt will yield half number of unique points + +f = Fs/2*linspace(0,1,L/2+1).'; % Nyquist frequency of the signal==Fs/2 +f = f(2:end); % Remove zero Hz component + + +% moving average with equally spaced frequency interval in log-space +plot_length = increment_bin*10; +if mod(plot_length,2) == 0 + plot_length = plot_length +1; +end + +intervall = unique(round(logspace(0,log10(L/2),plot_length)),'stable'); +plot_length = length(intervall); + +% Initializing the arrays/preallocation +spek_smooth = zeros(plot_length-2,1); +x_achse_f_spektrum = zeros(plot_length-2,1); + +% Averaging of spectrum and hence smoothing +for i=2:(plot_length-1) + x_achse_f_spektrum(i-1,1) = mean(f(intervall(i-1):intervall(i+1))); + spek_smooth(i-1,1) = mean(spek(intervall(i-1):intervall(i+1))); +end +% ------------------------Windowing / averaging end ------------------------ + +E_k = ((spek_smooth.*m_data)./(2*pi)); +% 2-pi - k Spektrum; Wavenumbers(1/m) +x_achse_k_spektrum_2pi = (2.*pi.*x_achse_f_spektrum)./m_data; + + + +% Wavenumber Spectrum (m^3/sec^2) +k = (2.*pi.*f(1:end))./m_data; +Ek = ((spek(1:end).*m_data)./(2.*pi)); +low_freq_k = (2*pi*low_freq)/m_data; + + +h(1) = figure; +% Plot of Frequency Vs. Power Spectral Density(m^2/sec) without smoothing +loglog(f,spek) +hold on +% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing +loglog(x_achse_f_spektrum,spek_smooth,'-','LineWidth',2) +xlabel('f / Hz','interpreter','latex'); +ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') +xlabel('$f\ (Hz)$','interpreter','latex'); +ylabel('$E\ (m^2/s)$', 'interpreter','latex') + +% title('energy density spectrum','interpreter','latex') +set(gca,'FontSize',10) +set(gcf, 'Color', 'w') +% xlim([min(x_achse_f_spektrum) max(x_achse_f_spektrum)]*2) +xlim([min(x_achse_f_spektrum) 10^2]) +grid on +axis square +% datacursormode on +fig_setup +legend off +grid off +set(gca,'XTick',[10^-2 10^0 10^2 10^4]); +waitfor(msgbox('Use interactive data cursor to select the range of frequency which will be used to linearly extrapolate the value of ESD at a frequency of 0 Hz (see readme).')); +% tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +% uiwait(gcf); +% delete(tmp_ui); + + + +%% First Method==> Calculating Ef0 with using Robust property +% Calculate the integral length scale (macro scale) Roach Eqn 15 +% In this method we will ask you to choose two values of frequencies in Hz such as +% f_start & f_end ===> [f_start0 +trying = true; +attemptcount = 1; +while trying + try + [I,yy] = ginput(2); + if I(1)>I(2) + I = flip(I); + yy = flip(yy); + end + tmp_ui = uicontrol('Position',[10 10 100 40],'String','Processing','Callback','uiresume(gcbf)'); + + f_start_plot = askInput({sprintf('Lowest frequency of constant range in Hz:')}, {num2str(I(1),'%.8f')}); + f_end_plot = askInput({sprintf('Highest frequency of constant range in Hz:')}, {num2str(I(2),'%.8f')}); + f_start = find(f>f_start_plot, 1,'first'); + f_end = find(f<=f_end_plot, 1,'last'); + + % Ef0 = mean(spek(f_start:f_end)); + % Ef0 = median(spek(f_start:f_end)); + + % IntegralLengthScale_1 = (Ef0*m_data)/(4*uprimesquared); % Integral Scale in meters + + %Second Method==> Calculating Ef0 from fit without using Robust property + [xData, yData] = prepareCurveData( f(f_start:f_end),(spek(f_start:f_end))); + + ft = fittype( 'poly1' ); + opts = fitoptions( 'Method', 'LinearLeastSquares' ); + % opts.Algorithm = 'Levenberg-Marquardt'; + % opts.Display = 'Off'; + opts.Lower = [0 0 ]; + % opts.StartPoint = [0.5 0.1]; + [fitresult, gof] = fit( xData, yData, ft, opts ); + IntegralLengthScale_2 = (fitresult.p2*m_data)/(4*uprimesquared); % Integral Scale in meters + fitresult.p1=0; + plot(f,feval(fitresult,f),'k','LineWidth',2,'LineStyle','-') + vline(f_start_plot,'k') % Construct a verticle line at f_start + vline(f_end_plot,'k') % Construct a verticle line at f_end + legend('raw','averaged','Location','southwest') + + trying = false; + catch + waitfor(msgbox('Please try again: f_start should be smaller than f_end and the decimal separator should be "."(period).')); + if attemptcount>maxnumattempts + waitfor(msgbox('Function failed.', 'Error','error')); + error('Function failed after %d times',maxnumattempts) + end + attemptcount=attemptcount+1; + end +end + + +% %Third Method==> Calculating Ef0 from fit with using Robust property='LAR' specifies the least absolute residual method. +% [xData, yData] = prepareCurveData( f(f_start:f_end),spek(f_start:f_end)); +% ft = fittype( 'a*x*0+b', 'independent', 'x', 'dependent', 'y' ); +% opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); +% opts.Algorithm = 'Levenberg-Marquardt'; +% opts.Display = 'Off'; +% opts.Robust = 'LAR'; +% opts.StartPoint = [0.0 0.01]; +% [fitresult, gof] = fit( xData, yData, ft, opts ); +% IntegralLengthScale_3 = (fitresult.b*m_data)/(4*uprimesquared); +% +% %%Fourth Method==> Calculating Ef0 from fit with using Robust property='Bisquare' specifies the bisquare weights method. +% [xData, yData] = prepareCurveData( f(f_start:f_end),spek(f_start:f_end)); +% ft = fittype( 'a*x*0+b', 'independent', 'x', 'dependent', 'y' ); +% opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); +% opts.Algorithm = 'Levenberg-Marquardt'; +% opts.Display = 'Off'; +% opts.Robust = 'Bisquare'; +% opts.StartPoint = [0.0 0.01]; +% [fitresult, gof] = fit( xData, yData, ft, opts ); +% IntegralLengthScale_4 = (fitresult.b*m_data)/(4*uprimesquared); + + + +%% Dissipation from different methods +trying = true; +attemptcount = 1; +while trying + try + clear r tau step stepp + r = unique(round(logspace(log10((1./Fs).*m_data*10^6),log10(20*IntegralLengthScale_2*10^6),increment_bin))./10^6,'stable'); + + tau(1:length(r)) = nan; + step(1:length(r)) = nan; + + for z=1:length(r) + tau(z) = r(z)/m_data; + step(z) = round(tau(z)*Fs); + end + stepp = unique(step); + stepp = stepp(stepp>0); + + clear r R S_exp_3 S_exp_2 + r(1:length(stepp)) = nan; + R(1:length(stepp)) = nan; + S_exp_3(1:length(stepp))=nan; % Third order structure function + S_exp_2(1:length(stepp))=nan; % Second order structure function + + parfor z=1:length(stepp) + % z/length(stepp) + tau = stepp(z) % In steps, just a number + r(z) = (tau./Fs).*m_data; % in meters + incr = (data(tau+1:L) - data(1:L-tau)).'; % velocity Increment in steps of tau + S_exp_2(z) = mean(incr.^2); % Second order structure function + S_exp_3(z) = mean(incr.^3); % Third order structure function + % Autocorr André + R(1,z) = mean(daten(tau+1:L).*daten(1:L-tau))/uprimesquared; + end + + % HIT = Homogeneous Isotropic Turbulence + eps_2 = (1./(r)).*((S_exp_2./C2).^(3/2)); % Estimation of dissipation from S_exp_2 using HIT + eps_3 = -(5/4).*(S_exp_3./r); % Estimation of dissipation from S_exp_3 using HIT + + I0 = find( eps_2==max(eps_2),1); % Finding the maximum value of dissipation in inertial range + I1 = find(-eps_3==max(-eps_3),1); % Finding the maximum value of dissipation in inertial range + + % dissipation rate m^2.s^-3 from S2 + epsi_S2 = mean(eps_2(1,I0-2:I0+2)); % finding the mean amongst 5 points closest to peak value; + % dissipation rate m^2.s^-3 from S3 + epsi_S3 = mean(-eps_3(1,I1-2:I1+2)); % finding the mean amongst 5 points closest to peak value; + + trying = false; + catch +% waitfor(msgbox(' f_start should be smaller than f_end should be. ')); + increment_bin = askInput({sprintf('Please try again by increasing the number of Bin''s used (must be larger than:):')}, {num2str(increment_bin,'%1.0f')}); + if attemptcount>maxnumattempts + waitfor(msgbox('Function failed.', 'Error','error')); + error('Function failed after %d times',maxnumattempts) + end + attemptcount=attemptcount+1; + end +end + +delete(tmp_ui); + + +% figure +% loglog(r,S_exp_2) + + +%% Integral length scale from Auto-corelation or structure function +%% Autocorr André +low_freq_r = m_data/low_freq; + +% Full integration +int_L_full = trapz(r,R); +% trapz(r,abs(R)) + +% integrate up to the first zero crossing +tmp_zero=(find(R<0,1,'first'))-1; +if isempty(tmp_zero) + int_L_0 = nan; +else + % r(tmp_zero) + int_L_0 = trapz(r(1:tmp_zero),R(1:tmp_zero)); +end + +% integrate up to the first 1/e crossing +tmp_exp=(find(R<1/exp(1),1,'first')); +if isempty(tmp_exp) + int_L_1_exp=nan; + theo_exp_Funktion = nan; +else + int_L_1_exp = trapz(r(1:tmp_exp),R(1:tmp_exp)); + % local minimum + % index1 = find(diff(sign(diff(R))) ~= 0,2,'first')+1; + % r(index1) + % int_L_min=trapz(r(1:index1),abs(R(1:index1))); + + %exp Fit to R; Fitregion r=1/exp(1):2*low_freq_r + tmp_up = (find(r>4*low_freq_r,1,'first')); + tmp_low = (find(R<1/exp(1),1,'first')); + + if tmp_up10*IntegralLengthScale_2))))); % Auto-correlation coefficient Using std from S_exp_2 ==>This is a dimentionless quantity +Ruu = [1,Ruu]; % Auto-correlation is 1 at scale=0 +r_Ruu = [0,r]; % Auto-correlation is 1 at scale=0 +LL = (cumsum(Ruu(1,1:end-1).*diff(r_Ruu)))'; % Cumulative integration of Ruu with respect to r +pks = findpeaks(LL,3); % Finding the peaks in LL +Npks = size(pks,1); + +if Npks == 0 +IntegralLengthScale_5 = trapz(r_Ruu,Ruu); % If no peaks are found then simply take the area under the curve which will be in meters +else +IntegralLengthScale_5 = pks(1); % in meters At this length we should reach an asymptotic value on the plot of r Vs. LL +end + +lambda_S2 = (sqrt(15*kin_vis*uprimesquared./epsi_S2)); % Taylors length scale in meters from epsi_S2 and hence from S_exp_2 +lambda_S3 = (sqrt(15*kin_vis*uprimesquared./epsi_S3)); % Taylors length scale in meters from epsi_S3 and hence from S_exp_3 + + + +%% Integral length scale from auto-corelation function 'xcorr' of MATLAB +% tau = 1/Fs; % time in seconds/Time per sample in secs +% [Ruu_xcorr,tau_xcorr] = xcorr(data - mean(data),size(data,1)/2,'unbiased'); +% Ruu_xcorr = Ruu_xcorr(tau_xcorr>=0); +% tau_xcorr = tau_xcorr(tau_xcorr>=0); +% Ruu_xcorr = Ruu_xcorr./max(Ruu_xcorr); +% dist_xcorr = tau_xcorr.*tau.*m_data; +% Ruu_xcorr = Ruu_xcorr'; +% LL_xcorr = (cumsum(Ruu_xcorr(1,1:end-1).*diff(dist_xcorr(1,1:end)))); +% pks_xcorr = findpeaks(LL_xcorr); +% Npks_xcorr = size(pks_xcorr,1); +% +% if Npks_xcorr == 0 +% IntegralLengthScale_6 = trapz(dist_xcorr,Ruu_xcorr); % If no peaks are found then simply take the area under the curve +% else +% IntegralLengthScale_6 = pks_xcorr(1); % in meters at this length we should reach an asymptotic value on plot of r Vs. LL +% end +% +% figure; +% plot(r,R,'-k','LineWidth',2) +% hold on +% plot(r_Ruu,Ruu,'LineWidth',2) +% plot(dist_xcorr,Ruu_xcorr,'LineWidth',2) +% xlim([0 1500*low_freq_r]) + + +% figure; +% plot(r_Ruu(1:end-1),LL,'LineWidth',2) +% hold on +% plot(dist_xcorr(1:end-1),LL_xcorr,'LineWidth',2) + + + +%% Zero-crossing method: Martin Obligado +delete(tmp_ui); +[int_L_zero_cros,lambda_zero_cros,lambda1_zero_cros,Eps_zero_cros,h]=ZeroCrossings(data,Fs,m_data,kin_vis,low_freq,x_achse_k_spektrum_2pi,E_k,h); + +%% +% int_L_calc = [IntegralLengthScale_2,int_L_full,int_L_0,int_L_1_exp,theo_exp_Funktion,IntegralLengthScale_5,IntegralLengthScale_6,int_L_zero_cros];%% meter +int_L_calc = [IntegralLengthScale_2,int_L_full,int_L_0,int_L_1_exp,theo_exp_Funktion,IntegralLengthScale_5,int_L_zero_cros];%% meter + +% Choose the best estimate of integral and Taylor length scale on which you would like to rely on +h(3) = figure; +plot(int_L_calc,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) +xlabel('method', 'interpreter','latex') +ylabel('L/m', 'interpreter','latex') +ylabel('$L\ (m)$','interpreter','latex'); +axis square +set(gcf, 'Color', 'w') +set(gca, 'FontSize',18) +fig_setup +legend off +set(gca,'XTick',[1 2 3 4 5 6 7 8]); +datacursormode on +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); +int_L = askInput({sprintf('Enter the integral length scale in meter. Median integral length scale in meter:')}, {num2str(nanmedian(int_L_calc),'%.5f')}); + + + + + + +%% Taylor length by different methods +%% using Autocorrelation function +trying = true; +attemptcount = 1; +while trying + try + figure; + plot(r_Ruu,Ruu,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) + ylabel('$R_{\widetilde{u}\widetilde{u}}$', 'interpreter','latex') + xlabel('r/m', 'interpreter','latex') + xlabel('$r\ (m)$','interpreter','latex'); + axis square + set(gcf, 'Color', 'w') + set(gca, 'FontSize',18) + ylim([0.7 1.05]) + xlim([0 r_Ruu(find(Ruu<0.7,1,'first'))]) + datacursormode on + waitfor(msgbox('Use interactive data cursor to select the range of scales which will be used to estimate Taylor lenght scalee (see readme).')); + [I,yy] = ginput(1); + i_tmp = askInput({sprintf(['Fit Region Auto-correlation Coefficient e.g. = ' ,num2str(0.98,'%1.2f')])}, {num2str(yy(1),'%.2f')}); + close + + + [xData, yData] = prepareCurveData( r_Ruu(1:(find(Rmaxnumattempts + waitfor(msgbox('Function failed.', 'Error','error')); + error('Function failed after %d times',maxnumattempts) + end + attemptcount=attemptcount+1; + end +end + +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); + + + + +%% numerical differentiation +%<(du/dx)^2> +du_dx = mean((diff(daten)./(m_data*(1/Fs))).^2); +lambda_direct = sqrt(uprimesquared/du_dx); + +% Aronson and Löfdahl +tmp = sqrt((uprimesquared.*r.^2)./S_exp_2); +h(5) = figure; +plot(r,tmp,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) +hold on +xlabel('r/m', 'interpreter','latex') +xlabel('$r\ (m)$','interpreter','latex'); +ylabel('$\sqrt{\frac{u''^2 r^2}{S^{2}(r)}}/m$', 'interpreter','latex') +ylabel('$\sqrt{\frac{u''^2 r^2}{S^{2}}}\ (m)$', 'interpreter','latex') +axis square +set(gcf, 'Color', 'w') +set(gca, 'FontSize',18) +xlim([0 25*low_freq_r]) +datacursormode on +waitfor(msgbox('Use interactive data cursor to select the range of scales which will be used to estimate Taylor lenght scalee (see readme).')); + +tmp_up = (find(r>4*low_freq_r,1,'first')); +vline(r(tmp_up),'k') + +trying = true; +attemptcount = 1; +while trying + try + [I,yy] = ginput(1); + % i_tmp = str2double(inputdlg({'Fit Region rmin ='})); + % tmp_up = (find(r>i_tmp,1,'first')); + i_tmp = askInput({sprintf(['Fit Region r_max e.g. = ' ,num2str(20*low_freq_r,'%0.2f')])}, {num2str(I(1),'%.2f')}); + tmp_low = (find(rmaxnumattempts + waitfor(msgbox('Function failed.', 'Error','error')); + error('Function failed after %d times',maxnumattempts) + end + attemptcount=attemptcount+1; + end +end + +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); + + +% Dissipationspectrum +k_end = find(k<=low_freq_k, 1,'last'); +lambda_spec_low_freq = sqrt(trapz(k(1:k_end),Ek(1:k_end))/trapz(k(1:k_end),Ek(1:k_end).*k(1:k_end).^2)); +lambda_spec_full = sqrt(uprimesquared/trapz(k,Ek.*k.^2)); +% trapz(k,2.*Ek.*k.^2) anstatt trapz(k,Ek.*k.^2) +% lambda_1=sqrt(uprimesquared/trapz(k,2.*Ek.*k.^2)) +% lambda_2=sqrt(trapz(k,2.*Ek)/trapz(k,2.*Ek.*k.^2)) + +% take everthing of the specturm +% lambda_1=sqrt(uprimesquared/trapz(k,Ek.*k.^2)); +% lambda_1=sqrt(uprimesquared/trapz(x_achse_k_spektrum_2pi(2:end),E_k.*x_achse_k_spektrum_2pi(2:end).^2)) +% lambda_2=sqrt(trapz(k,Ek)/trapz(x_achse_k_spektrum_2pi(2:end),E_k.*x_achse_k_spektrum_2pi(2:end).^2)) + +% find Minimum at high frequencies +% k_start = find(k>0.2*10^4, 1,'first'); +% k_end = find(k<=5*10^4, 1,'last'); +% lambda_1_kurz = sqrt(uprimesquared/trapz(k(1:find(spek==min(spek(k_start:k_end)))),Ek(1:find(spek==min(spek(k_start:k_end)))).*k(1:find(spek==min(spek(k_start:k_end)))).^2)); + +% lambda_4 = sqrt(uprimesquared/du_dx_4); +% lambda_6 = sqrt((10*kin_vis/m_data) * (uprimesquared/(uprimesquared/(m_data*(1/Fs))))); + +% taylor_L_calc = [lambda_autocorr,lambda_direct,A_L_lambda,lambda_spec_low_freq,lambda_spec_full, lambda_S2, lambda_S3,lambda_zero_cros,lambda1_zero_cros];%% meter +taylor_L_calc = [lambda_autocorr,lambda_direct,A_L_lambda,lambda_spec_low_freq,lambda_spec_full,lambda_zero_cros,lambda1_zero_cros];%% meter + + +h(6) = figure; +plot(taylor_L_calc,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) +xlabel('method', 'interpreter','latex') +ylabel('$\lambda/m$', 'interpreter','latex') +ylabel('$\lambda\ (m)$', 'interpreter','latex') +axis square +set(gcf, 'Color', 'w') +set(gca, 'FontSize',18) +fig_setup +legend off +set(gca,'XTick',[1 2 3 4 5 6 7]); +datacursormode on +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); +taylor_L = askInput({sprintf('Enter the Taylor length scale in meter. Median Taylor length scale in meter:')}, {num2str(nanmedian(taylor_L_calc),'%.5f')}); + + + +%% Dissipation from different methods +% epsi_1 = 15*kin_vis*trapz(k(1:k_end),Ek(1:k_end).*k(1:k_end).^2); %% From dissipation Spectrum untill cutoff frequency +% epsi_2 = 15*kin_vis*trapz(k,Ek.*k.^2); %%From entire dissipation Spectrum + +% epsi_2 = trapz(k,2.*kin_vis.*Ek.*k.^2); +% epsi_3 = 15*kin_vis*du_dx_3; +% epsi_4 = 15*kin_vis*du_dx_4; +% epsi_5 = 15*kin_vis*du_dx_5; + +% epsi_5 = (m_data/2) * (mean(diff(daten.^2)/(m_data*(1/Fs)))); +% epsi_6 = (3*m_data/2) * (var(diff(daten)./(m_data*(1/Fs)))); +% epsi_7 = 15*kin_vis*(uprimesquared/lambda_1^2); +% epsi_7a= 30*kin_vis*(uprimesquared/lambda_1^2) %longitudinale microscale +% epsi_7b= 15*kin_vis*(uprimesquared/(lambda_1/sqrt(2))^2) %trasnversale microscale +% epsi_8 = m_data^3/int_L + +% epsi_1/m_data +% var(daten)/(m_data*(1/Fs)) +% std(daten)/(m_data*(1/Fs)) +% epsi_calc = [epsi_1, epsi_2, epsi_3, epsi_5, epsi_S2,epsi_S3]; + + +h(7) = figure; +semilogx(r,eps_2,'LineWidth',2) +hold on +semilogx(r,-eps_3,'LineWidth',2) +xlim([min(r)*0.5 max(r)*2]) +xlabel('r/m', 'interpreter','latex') +xlabel('$r\ (m)$','interpreter','latex'); +ylabel('$\epsilon(r)/\frac{m^2}{s^3}$', 'interpreter','latex') +ylabel('$\epsilon\ (m^2/s^3)$','interpreter','latex'); +set(gca,'FontSize',16) +set(gcf, 'Color', 'w') +fig_setup +axis square +% vline(r(I0),'r') +% vline(r(I1),'k') + +plot(linspace(min(r)*0.5,max(r)*2,1000),eps_2(I0).*ones(1000,1),'k','LineWidth',2) +plot(linspace(min(r)*0.5,max(r)*2,1000),-eps_3(I1).*ones(1000,1),'k','LineWidth',2) +legend('$\frac{1}{r}\left[\frac{S^{2}(r)}{C_{2}}\right]^{3/2}$','$-\frac{5}{4}\left[\frac{S^{3}(r)}{r}\right]$','Location','south') + +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); + +etaflow_S2 = ((kin_vis^3/epsi_S2)^(1/4)); % Kolmogorov length scale in meters from epsi_S2 and hence from S_exp_2 +etaflow_S3 = ((kin_vis^3/epsi_S3)^(1/4)); % Kolmogorov length scale in meters from epsi_S3 and hence from S_exp_3 + + + +%% Spectrum-Fit +epsi_calc = [epsi_S2,epsi_S3,(15*kin_vis*(uprimesquared/taylor_L^2))]; + +h(8) = figure; +loglog(x_achse_k_spektrum_2pi,E_k,'-','LineWidth',2) +hold on +a=find(x_achse_k_spektrum_2pi<=(2*pi*((1/(int_L/m_data))/(2*pi))/m_data), 1,'last'); +b=find(x_achse_k_spektrum_2pi>=(2*pi*((1/(taylor_L/m_data))/(2*pi))/m_data), 1,'first'); + +% b=find(x_achse_k_spektrum_2pi>=(1)/diss_scale, 1,'first'); +% a=1; +% b=length(x_achse_k_spektrum_2pi); +[xData, yData] = prepareCurveData( x_achse_k_spektrum_2pi(a:b), E_k(a:b) ); +% [xData, yData] = prepareCurveData( x_achse_f_spektrum,spek_smooth); +% [xData, yData] = prepareCurveData(k, Ek ); + +opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); +opts.DiffMinChange = 1e-12; +opts.Display = 'Off'; +opts.MaxFunEvals = 1200; +opts.MaxIter = 1200; + +ft = fittype( 'a*b^(2/3)*(x-d)^(-5/3)', 'independent', 'x', 'dependent', 'y' ); +% opts.Lower = [0 median(epsi_calc) -Inf]; +% opts.Upper = [Inf median(epsi_calc) Inf]; +opts.Lower = [0 0 -Inf]; +opts.Upper = [Inf Inf Inf]; +opts.StartPoint = [0.5 nanmedian(epsi_calc) 0]; +try + [fitresult, gof] = fit( xData, yData, ft, opts ); + ft2 = fittype( 'a*b^(2/3)*(x)^(-5/3)', 'independent', 'x', 'dependent', 'y' ); + % opts.Lower = [0 nanmedian(epsi_calc)]; + % opts.Upper = [Inf nanmedian(epsi_calc)]; + opts.Lower = [0 0]; + opts.Upper = [Inf Inf]; + opts.StartPoint = [0.5 nanmedian(epsi_calc)]; + [fitresult2, gof] = fit( xData, yData, ft2, opts ); + plot(x_achse_k_spektrum_2pi, feval(fitresult,x_achse_k_spektrum_2pi),'-','LineWidth',2) + plot(x_achse_k_spektrum_2pi, feval(fitresult2,x_achse_k_spektrum_2pi),'-','LineWidth',2) +catch +end +set(gca,'XScale','log'); +set(gca,'YScale','log'); +xlabel('$k= / \frac{1}{m}$', 'interpreter','latex'); +ylabel('$E(k)$ / $\frac{m^3}{s^2}$', 'interpreter','latex') +xlabel('$k\ (1/m)$','interpreter','latex'); +ylabel('$\frac{E }{2 \pi}\ (m^3/s^2)$', 'interpreter','latex') + +xlim([min(x_achse_k_spektrum_2pi) 2*max(x_achse_k_spektrum_2pi)]) +ylim([min(E_k) 2*max(E_k)]) +axis square +% vline(x_achse_k_spektrum_2pi(a),'k') +% vline(x_achse_k_spektrum_2pi(b),'k') +% vline((1)/diss_scale,'k') +set(gcf, 'Color', 'w') +legend('$\frac{E }{2 \pi}$','$C_k\langle \epsilon \rangle^{2/3}(k-k_0)^{-5/3}$','$C_k\langle \epsilon \rangle^{2/3}k^{-5/3}$','Location','south') +fig_setup +set(gca,'XTick',[10^-2 10^0 10^2 10^4]); +% fitresult; +% fitresult2; +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); + +% figure +% plot( fitresult, xData, yData ); +% hold on +% plot( fitresult2, xData, yData ); +% plot( fitresult, xData, yData ); +% loglog(x_achse_k_spektrum_2pi,E_k) +% set(gca,'XScale','log'); +% set(gca,'YScale','log'); + + +epsi_calc = [epsi_S2,epsi_S3, (15*kin_vis*(uprimesquared/taylor_L^2)), fitresult2.b,fitresult.b, Eps_zero_cros]; + +h(9) = figure; +plot(epsi_calc,'MarkerEdgeColor','k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) +xlabel('method', 'interpreter','latex') +ylabel('$\langle \epsilon \rangle/\frac{m^2}{s^3}$', 'interpreter','latex') +ylabel('$\langle \epsilon \rangle\ (m^2/s^3)$', 'interpreter','latex') +axis square +set(gcf, 'Color', 'w') +set(gca, 'FontSize',18) +fig_setup +legend off +set(gca,'XTick',[1 2 3 4 5 6 7 ]); +datacursormode on +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); +epsi = askInput({sprintf('Enter the energy dissipation rate in $m^2/s^3$. Median energy dissipation rate in $m^2/s^3$:')}, {num2str(nanmedian(epsi_calc),'%.5f')}); + + + + +Re = m_data*int_L/kin_vis; +% Re_lambda = uprime*lambda_1_kurz_low_freq/kin_vis; +Re_lambda = uprime*taylor_L/kin_vis; +% Re_lambda = uprime*lambda_1/kin_vis; + +% Calculate the dissipation length scale (micro scale) Roach Eqn 8 +% Z=((2*pi^2)/(m_data^2*uprimesquared))*trapz((f(2:end).^2),spek(2:L/2+1)); % Use trapezoid rule for integration +% DissipationScale=sqrt(1/Z) + +DissipationScale_1 = ((kin_vis^3)/epsi)^0.25; +% DissipationScale_2 = sqrt(1/(trapz(f,spek.*f.^2)*((2*pi^2)/(m_data^2*uprimesquared)))) +% DissipationScale_3 = int_L/(Re^0.75); + +% kolmogorov_calc = [DissipationScale_1, etaflow_S2,etaflow_S3];%% meter +diss_scale = DissipationScale_1; + +%%Non dimentional dissipation constant +Ce = 15*(int_L/taylor_L)/Re_lambda; +Ce_b = epsi*int_L/uprime^3; + +% Ce = 15*(int_L/lambda_1_kurz_low_freq)/Re_lambda; +% Ce_1 = epsi_1*int_L/uprime^3; +% Ce_2 = epsi_2*int_L/uprime^3; +% Ce_3 = epsi_3*int_L/uprime^3; +% Ce_5 = epsi_5*int_L/uprime^3; + +% Ce_calc =[Ce, Ce_1, Ce_2, Ce_3, Ce_5]; +Ce_calc = [Ce, Ce_b]; +Ce = mean(Ce_calc); + + +%% Plot Spectrum +h(10) = figure; +set(gcf, 'Color', 'w') +yyaxis left +loglog(x_achse_k_spektrum_2pi,E_k,'-','LineWidth',2) +% hold on +% loglog(x_achse_k_spektrum_2pi,(x_achse_k_spektrum_2pi.^(-5/3).*ones(length(E_k)).*10),'-','LineWidth',1,'color','k') +% loglog(x_achse_k_spektrum_2pi,(x_achse_k_spektrum_2pi.^(-2).*ones(length(E_k)).*0.7.*10^2),'-','LineWidth',1,'color','k') +% loglog(x_achse_k_spektrum_2pi,(x_achse_k_spektrum_2pi.^(-3).*ones(length(E_k)).*0.6.*10^5),'-','LineWidth',1,'color','k') +% xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); +xlabel('$k= / \frac{1}{m}$', 'interpreter','latex'); +% ylabel('$E(k)=\frac{E(f) }{2 \pi}$ / $\frac{m^3}{s^2}$', 'interpreter','latex') +ylabel('$E(k)$ / $\frac{m^3}{s^2}$', 'interpreter','latex') +%xlabel('k'); +%ylabel('E(k)') +xlabel('$k\ (1/m)$','interpreter','latex'); +ylabel('$\frac{E }{2 \pi}\ (m^3/s^2)$', 'interpreter','latex') +xlim([min(x_achse_k_spektrum_2pi) 2*max(x_achse_k_spektrum_2pi)]) +% ylim([10^-10 1]) +axis square +hold on +yyaxis right +% loglog(x_achse_k_spektrum_2pi,15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi).^2,'-','LineWidth',2) +loglog(x_achse_k_spektrum_2pi,E_k.*(x_achse_k_spektrum_2pi).^2,'-','LineWidth',2) +ylabel('E(k)$\cdot k^2$ / $\frac{m}{s^2}$', 'interpreter','latex') +ylabel('$\frac{E }{2 \pi} k^2\ (m/s^2)$', 'interpreter','latex') + +set(gca,'YScale','log'); +set(gca,'FontSize',24) +% vline(low_freq_k,'r') +% vline((1/(int_L/m_data))/m_data,'k') +vline((2*pi*((1/(int_L/m_data))/(2*pi))/m_data),'k') +vline((2*pi*((1/(taylor_L/m_data))/(2*pi))/m_data),'k') +vline((2*pi*((1/(diss_scale/m_data))/(2*pi))/m_data),'k') +fig_setup +set(gca,'XTick',[10^-2 10^0 10^2 10^4]); +legend off + + + +h(11) = figure; +set(gcf, 'Color', 'w') +yyaxis left +% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing +loglog(x_achse_f_spektrum,spek_smooth,'-','LineWidth',2) +xlabel('f / Hz','interpreter','latex'); +ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') +xlabel('$f\ (Hz)$','interpreter','latex'); +ylabel('$E\ (m^2/s)$', 'interpreter','latex') +set(gca,'FontSize',10) +set(gcf, 'Color', 'w') +xlim([min(x_achse_f_spektrum) max(x_achse_f_spektrum)]*2) +% xlim([min(x_achse_f_spektrum) 10^2]) +grid on +axis square +datacursormode on +fig_setup +grid off +legend off +set(gca,'XTick',[10^-2 10^0 10^2 10^4]); +vline((1/(int_L/m_data))/(2*pi),'k') +vline((1/(taylor_L/m_data))/(2*pi),'k') +vline((1/(diss_scale/m_data))/(2*pi),'k') + +yyaxis right +% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing +loglog(x_achse_f_spektrum,spek_smooth.*x_achse_f_spektrum.^(5/3),'-','LineWidth',2) +ylabel('$E(f)f^{5/3}$ / $\frac{m^2}{s}$', 'interpreter','latex') +ylabel('$E\ f^{5/3}\ (m^2/s)$', 'interpreter','latex') +xlim([min(x_achse_f_spektrum) max(x_achse_f_spektrum)]*2) +ylim([min(spek_smooth.*x_achse_f_spektrum.^(5/3)) max(spek_smooth.*x_achse_f_spektrum.^(5/3))]*2) + + + + +% k Spektrum; Scales,r (m) +x_achse_spektrum_meter = m_data./(2*pi*x_achse_f_spektrum); +Dr_avg_filter=(spek_smooth.*x_achse_f_spektrum.^2)./m_data; +Dk_avg_filter=15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi).^2; + + + +figure; +set(gcf, 'Color', 'w') +subplot(2,2,1) +loglog(x_achse_f_spektrum,spek_smooth,'-','LineWidth',1)%% Plot of Frequency Vs. Power Spectral Density(m^2/sec) with smoothing & Filtering +xlabel('f / Hz','interpreter','latex'); +ylabel('E(f) / $\frac{m^2}{s}$', 'interpreter','latex') +xlabel('$f\ (Hz)$','interpreter','latex'); +ylabel('$E\ (m^2/s)$', 'interpreter','latex') +xlim([min(x_achse_f_spektrum) 2*max(x_achse_f_spektrum)]) +ylim([min(spek_smooth) max(spek_smooth)]*2) +title('frequency domain','interpreter','latex') +set(gca,'FontSize',12) +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +% plot([10^3 10^3],[10^-6 10^-2],'y = x ','-','LineWidth',1) +% h = vline(10^3,'k','The Answer') +% text(245,spek_smooth(find(x_achse_f_spektrum>245,1,'first')),'\leftarrow sin(\pi) = 0','FontSize',16) +set(gca,'XTick',[10^-2 10^0 10^2 10^4]); +hold on +vline((1/(int_L/m_data))/(2*pi),'k') +vline((1/(taylor_L/m_data))/(2*pi),'k') +vline((1/(diss_scale/m_data))/(2*pi),'k') +txt = {'(a)'}; +a=text(4,0.5,txt); +a.Units='normalized'; + +subplot(2,2,2) +loglog(x_achse_k_spektrum_2pi,E_k,'-','LineWidth',1)%% Plot of Wavenumber(k) Vs. Energy(k)(m^3/sec^2) with smoothing & Filtering +% loglog(x_achse_k_spektrum_2pi,x_achse_k_spektrum_2pi.^(-5/3).*(max(spek_smooth).*200),'--','color','k','LineWidth',2) +xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); +ylabel('$E(k)=\frac{E(f) }{2 \pi}$ / $\frac{m^3}{s^2}$', 'interpreter','latex') +xlabel('$k=\frac{2 \pi f}{}\ (1/m)$','interpreter','latex'); +ylabel('$\frac{E }{2 \pi}\ (m^3/s^2)$', 'interpreter','latex') +xlim([min(x_achse_k_spektrum_2pi) 2*max(x_achse_k_spektrum_2pi)]) +ylim([min(E_k) max(E_k)]*2) +title('wave number domain','interpreter','latex') +set(gca,'FontSize',12) +set(gca,'XTick',[10^-2 10^0 10^2 10^4]); +hold on +vline((2*pi*((1/(int_L/m_data))/(2*pi))/m_data),'k') +vline((2*pi*((1/(taylor_L/m_data))/(2*pi))/m_data),'k') +vline((2*pi*((1/(diss_scale/m_data))/(2*pi))/m_data),'k') +txt = {'(b)'}; +b=text(4,0.5,txt); +b.Units='normalized'; + +subplot4=subplot(2,2,3); +loglog(x_achse_spektrum_meter,Dr_avg_filter,'-','LineWidth',1)%% Plot of Scales,r(m) Vs. Energy(r)(m/sec^2) with smoothing & Filtering +xlabel('$r=\frac{}{2 \pi f} / m$', 'interpreter','latex'); +ylabel('$E(r)=\frac{E(f) f^2}{}$ / $\frac{m}{s^2}$', 'interpreter','latex') +xlabel('$r=\frac{}{2 \pi f}\ (m)$','interpreter','latex'); +ylabel('$\frac{E\ f^2}{}\ (m/s^2)$', 'interpreter','latex') +set(subplot4, 'Xdir', 'reverse') +xlim([0.5* min(x_achse_spektrum_meter) max(x_achse_spektrum_meter)]) +ylim([min((spek_smooth.*x_achse_f_spektrum.^2)./m_data) max((spek_smooth.*x_achse_f_spektrum.^2)./m_data)]*2) +set(gca,'FontSize',12) +set(gca,'XTick',[10^-2 10^0 10^2 10^4]); +title('dissipation spectrum','interpreter','latex') +vline(int_L,'k') +vline(taylor_L,'k') +vline(diss_scale,'k') +txt = {'(c)'}; +c=text(4,0.5,txt); +c.Units='normalized'; + + + +% Dissipation Spectrum +% kin_vis = 15.328737178409*10^-6; +subplot(2,2,4) +loglog(x_achse_k_spektrum_2pi,Dk_avg_filter,'-','LineWidth',1)%% Plot of Wavenumber(k) Vs. Dissipation(k)(m/sec^2) with smoothing & Filtering +xlabel('$k=\frac{2 \pi f}{} / m^{-1}$', 'interpreter','latex'); +ylabel('E(k)$\cdot k^2$ / $\frac{m}{s^2}$', 'interpreter','latex') +xlabel('$k=\frac{2 \pi f}{}\ (1/m)$','interpreter','latex'); +ylabel('$\frac{E }{2 \pi}\ k^2 \ (m/s^2)$', 'interpreter','latex') +xlim([min(x_achse_k_spektrum_2pi) 2*max(x_achse_k_spektrum_2pi)]) +ylim([min(15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi).^2) max(15.*kin_vis.*E_k.*(x_achse_k_spektrum_2pi).^2)]*2) +title('dissipation spectrum','interpreter','latex') +set(gca,'FontSize',12) +set(gca,'XTick',[10^-2 10^0 10^2 10^4]); +datacursormode on +hold on +vline((2*pi*((1/(int_L/m_data))/(2*pi))/m_data),'k') +vline((2*pi*((1/(taylor_L/m_data))/(2*pi))/m_data),'k') +vline((2*pi*((1/(diss_scale/m_data))/(2*pi))/m_data),'k') +txt = {'(d)'}; +d=text(4,0.5,txt); +d.Units='normalized'; + +% font=22; +% a.FontSize = font; +% b.FontSize = font; +% c.FontSize = font; +% d.FontSize = font; + +pos_txt=[-0.25 0.9]; +a.Position=pos_txt; +b.Position=pos_txt; +c.Position=pos_txt; +d.Position=pos_txt; + + + + + + + + +if ischar(save_path) + savefig(h,fullfile(save_path,append(save_name,'_','length_scales.fig')),'compact') + for a = 1:length(h) + exportgraphics(h(a),fullfile(save_path,append(save_name,'_',sprintf('length_scales_%d.png', a)))) + end +end +close all end \ No newline at end of file diff --git a/Functions_v5-MATLAB/main.m b/Functions_v5-MATLAB/main.m index a16a60d..aebb737 100644 --- a/Functions_v5-MATLAB/main.m +++ b/Functions_v5-MATLAB/main.m @@ -15,6 +15,9 @@ pre_analysis = askYesno('Would you like to load a pre-analysis?', 'No'); +% answer = 'PART I: Standard turbulence analysis'; +% pre_analysis = 0; + switch answer case 'PART I: Standard turbulence analysis' [data,ikx,bar,tmp_bar,save_path,save_name,Fs,m_data,kin_vis,increment_bin,f, E_f_no_filter, f_avg_no_filter, E_avg_no_filter, P_avg_no_filter,filter,... diff --git a/Functions_v5-MATLAB/plot_conditional_moment.m b/Functions_v5-MATLAB/plot_conditional_moment.m index a0c0d65..1a270bf 100644 --- a/Functions_v5-MATLAB/plot_conditional_moment.m +++ b/Functions_v5-MATLAB/plot_conditional_moment.m @@ -1,134 +1,134 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% This function plots the first and second conditional moments as a function of the scale -% separation. For this purpose, a scale and the number of a bin (value of the increment) condition -% must be specified. In addition, a linear extrapolation in $\Delta r$ (solid black line) of the -% first and second order conditional moments is plotted (see Chapter: Estimation of Kramers-Moyal -% coefficients). -% -% Arguments IN -% scal = Plot conditional moment number of Scale -% bin_num = Number of a bin (value of the velocity increment u_r) -% evaluated = struct array containing all the information about conditional moments for each scale and for each bin -% step_con_moment = the steps at which the value of conditional moments are calculated -% markov = markov length in number of samples -% multi_point = Multipoint condition 1=YES or 2=NO -% increment_bin = number of bins -% condition = This input is for multipoint statistics -% tol = This input is for multipoint statistics -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function plot_conditional_moment(scal,bin_num,evaluated,step_con_moment,markov,multi_point,increment_bin,condition,tol,data,save_path,save_name) -set(groot, 'defaultAxesTickLabelInterpreter','latex'); -set(groot, 'defaulttextinterpreter','latex'); -set(groot, 'defaultLegendInterpreter','latex'); -set(groot, 'defaultAxesTitle','latex'); - -if multi_point==1 - k=askInput({sprintf('Plot: Multi-point number of point condition:')}, {num2str(ceil(length(condition)/2))}); - my_field = sprintf('point_eval_%d', k); - evaluated=evaluated.(my_field); -end - -if (evaluated(scal).r_samp-1)<3*markov - step_con_moment_tmp = unique(round(logspace(0,log10(evaluated(scal).r_samp-1),12)),'stable'); -else - step_con_moment_tmp = unique(round(logspace(0,log10(3*markov),12)),'stable'); -% step_con_moment_tmp = round(linspace(0,2*markov,5)); -% step_con_moment_tmp = round(linspace(markov,2*markov,5)); -end - -tau2 = evaluated(scal).r_samp; -bin_events = NaN(increment_bin,length(step_con_moment_tmp)); -M11 = nan; -M21 = nan; -M31 = nan; -M41 = nan; -eM1 = nan; -eM2 = nan; - -for jj=length(step_con_moment_tmp):-1:1 - if multi_point==1 - [incr1,incr2] = Increment_point((tau2 - step_con_moment_tmp(jj)),tau2,data,condition(k),tol); - elseif multi_point==0 - [incr1,incr2] = Increment((tau2 - step_con_moment_tmp(jj)),tau2,data); - end - - [dx,dy,x,y,dA] = limit(incr1,incr2,increment_bin); - if length(x)==increment_bin & length(y)==increment_bin - % [M11_direct(:,jj),M21_direct(:,jj),M41_direct(:,jj),x_mean_bin_direct,y_mean_bin_direct,events] = conditional_moments_direct(tau1,tau2,incr1,incr2,aufl,min_events); - % bin_events_direct(:,jj)=events.'; - [P_AIB,P_BIA,P_AnB,P_A,P_B,binP_AIB,evaluated(scal).x_mean_bin,evaluated(scal).y_mean_bin,events,counter_A,counter_B] = distribution((tau2 - step_con_moment_tmp(jj)),tau2,incr1,incr2,increment_bin,dx,dy,x,y,dA); - bin_events(:,jj)=events.'; - %----------------------------- conditional moments -------------------------------- - for i=1:increment_bin - if (tau2 - step_con_moment_tmp(jj))>tau2 - M11(i,jj) = nansum(binP_AIB(:,i).^1.*P_AIB(:,i).*dy); - M21(i,jj) = nansum(binP_AIB(:,i).^2.*P_AIB(:,i).*dy); - M31(i,jj) = nansum(binP_AIB(:,i).^3.*P_AIB(:,i).*dy); - M41(i,jj) = nansum(binP_AIB(:,i).^4.*P_AIB(:,i).*dy); - else - M11(i,jj) = nansum(binP_AIB(:,i).^1.*P_AIB(:,i).*dx); - M21(i,jj) = nansum(binP_AIB(:,i).^2.*P_AIB(:,i).*dx); - M31(i,jj) = nansum(binP_AIB(:,i).^3.*P_AIB(:,i).*dx); - M41(i,jj) = nansum(binP_AIB(:,i).^4.*P_AIB(:,i).*dx); - end - end - %Fehler von den Momenten - eM1= real(sqrt(abs((M21 - (M11.^2))./bin_events))); - eM2= real(sqrt(abs((M41 - (M21.^2))./bin_events))); - end -end - -h(1) = figure; -plot(step_con_moment,evaluated(scal).M11(bin_num,:),'Color',[0.00,0.45,0.74],'MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) -hold -plot(step_con_moment,evaluated(scal).M21(bin_num,:),'Color',[0.85,0.33,0.10],'MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) - -plot(step_con_moment_tmp,M11(bin_num,:),'k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) -plot(step_con_moment_tmp,M21(bin_num,:),'k','MarkerSize',6,'Marker','o', 'LineStyle','none','LineWidth',1.5) - -xlabel('$\Delta r/sample$','Interpreter','latex') -% ylabel('Conditional Moment') -set(gca,'FontSize',18) -set(gcf, 'Color', 'w') -axis square -fig_setup -xlim([min(step_con_moment_tmp)-2 max(step_con_moment_tmp)+2]) -ylim([min([M11(bin_num,:) M21(bin_num,:)]) max([M11(bin_num,:) M21(bin_num,:)])]) - - -[xData, yData] = prepareCurveData( step_con_moment,evaluated(scal).M11(bin_num,:)); -ft = fittype( 'poly1' ); -opts = fitoptions( 'Method', 'LinearLeastSquares' ); -[fitresult, gof] = fit( xData, yData, ft, opts ); -plot(linspace(0,2*max(step_con_moment_tmp),100),feval(fitresult,linspace(0,2*max(step_con_moment_tmp),100)),'k','LineWidth',2,'LineStyle','-') - -[xData, yData] = prepareCurveData( step_con_moment,evaluated(scal).M21(bin_num,:)); -ft = fittype( 'poly1' ); -opts = fitoptions( 'Method', 'LinearLeastSquares' ); -[fitresult, gof] = fit( xData, yData, ft, opts ); -plot(linspace(0,2*max(step_con_moment_tmp),100),feval(fitresult,linspace(0,2*max(step_con_moment_tmp),100)),'k','LineWidth',2,'LineStyle','-') - -vline(min(step_con_moment),'k') -vline(max(step_con_moment),'k') - -plot(step_con_moment,evaluated(scal).M11(bin_num,:),'Color',[0.00,0.45,0.74],'MarkerSize',10,'Marker','o', 'LineStyle','none','LineWidth',1.5) -plot(step_con_moment,evaluated(scal).M21(bin_num,:),'Color',[0.85,0.33,0.10],'MarkerSize',10,'Marker','o', 'LineStyle','none','LineWidth',1.5) - -legend('$M^{(1)}\left(u_r,r\right)$ ','$M^{(2)}\left(u_r,r\right)$ ','Location','northwest') - -if ischar(save_path) - savefig(h,fullfile(save_path,append(save_name,'_','con_moment.fig')),'compact') - for a = 1:length(h) - exportgraphics(h(a),fullfile(save_path,append(save_name,'_',sprintf('con_moment_%d.png', a)))) - end -end - -set(gca,'xScale','lin') -set(gca,'yScale','lin') -tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); -uiwait(gcf); -delete(tmp_ui); -close +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% This function plots the first and second conditional moments as a function of the scale +% separation. For this purpose, a scale and the number of a bin (value of the increment) condition +% must be specified. In addition, a linear extrapolation in $\Delta r$ (solid black line) of the +% first and second order conditional moments is plotted (see Chapter: Estimation of Kramers-Moyal +% coefficients). +% +% Arguments IN +% scal = Plot conditional moment number of Scale +% bin_num = Number of a bin (value of the velocity increment u_r) +% evaluated = struct array containing all the information about conditional moments for each scale and for each bin +% step_con_moment = the steps at which the value of conditional moments are calculated +% markov = markov length in number of samples +% multi_point = Multipoint condition 1=YES or 2=NO +% increment_bin = number of bins +% condition = This input is for multipoint statistics +% tol = This input is for multipoint statistics +% data_filter = filtered data +% save_path = path for saving figures and files +% save_name = name for saving files +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function plot_conditional_moment(scal,bin_num,evaluated,step_con_moment,markov,multi_point,increment_bin,condition,tol,data,save_path,save_name) +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +set(groot, 'defaulttextinterpreter','latex'); +set(groot, 'defaultLegendInterpreter','latex'); +set(groot, 'defaultAxesTitle','latex'); + +if multi_point==1 + k=askInput({sprintf('Plot: Multi-point number of point condition:')}, {num2str(ceil(length(condition)/2))}); + my_field = sprintf('point_eval_%d', k); + evaluated=evaluated.(my_field); +end + +if (evaluated(scal).r_samp-1)<3*markov + step_con_moment_tmp = unique(round(logspace(0,log10(evaluated(scal).r_samp-1),12)),'stable'); +else + step_con_moment_tmp = unique(round(logspace(0,log10(3*markov),12)),'stable'); +% step_con_moment_tmp = round(linspace(0,2*markov,5)); +% step_con_moment_tmp = round(linspace(markov,2*markov,5)); +end + +tau2 = evaluated(scal).r_samp; +bin_events = NaN(increment_bin,length(step_con_moment_tmp)); +M11 = nan; +M21 = nan; +M31 = nan; +M41 = nan; +eM1 = nan; +eM2 = nan; + +for jj=length(step_con_moment_tmp):-1:1 + if multi_point==1 + [incr1,incr2] = Increment_point((tau2 - step_con_moment_tmp(jj)),tau2,data,condition(k),tol); + elseif multi_point==0 + [incr1,incr2] = Increment((tau2 - step_con_moment_tmp(jj)),tau2,data); + end + + [dx,dy,x,y,dA] = limit(incr1,incr2,increment_bin); + if length(x)==increment_bin & length(y)==increment_bin + % [M11_direct(:,jj),M21_direct(:,jj),M41_direct(:,jj),x_mean_bin_direct,y_mean_bin_direct,events] = conditional_moments_direct(tau1,tau2,incr1,incr2,aufl,min_events); + % bin_events_direct(:,jj)=events.'; + [P_AIB,P_BIA,P_AnB,P_A,P_B,binP_AIB,evaluated(scal).x_mean_bin,evaluated(scal).y_mean_bin,events,counter_A,counter_B] = distribution((tau2 - step_con_moment_tmp(jj)),tau2,incr1,incr2,increment_bin,dx,dy,x,y,dA); + bin_events(:,jj)=events.'; + %----------------------------- conditional moments -------------------------------- + for i=1:increment_bin + if (tau2 - step_con_moment_tmp(jj))>tau2 + M11(i,jj) = nansum(binP_AIB(:,i).^1.*P_AIB(:,i).*dy); + M21(i,jj) = nansum(binP_AIB(:,i).^2.*P_AIB(:,i).*dy); + M31(i,jj) = nansum(binP_AIB(:,i).^3.*P_AIB(:,i).*dy); + M41(i,jj) = nansum(binP_AIB(:,i).^4.*P_AIB(:,i).*dy); + else + M11(i,jj) = nansum(binP_AIB(:,i).^1.*P_AIB(:,i).*dx); + M21(i,jj) = nansum(binP_AIB(:,i).^2.*P_AIB(:,i).*dx); + M31(i,jj) = nansum(binP_AIB(:,i).^3.*P_AIB(:,i).*dx); + M41(i,jj) = nansum(binP_AIB(:,i).^4.*P_AIB(:,i).*dx); + end + end + %Fehler von den Momenten + eM1= real(sqrt(abs((M21 - (M11.^2))./bin_events))); + eM2= real(sqrt(abs((M41 - (M21.^2))./bin_events))); + end +end + +h(1) = figure; +plot(step_con_moment,evaluated(scal).M11(bin_num,:),'Color',[0.00,0.45,0.74],'MarkerSize',8,'Marker','o', 'LineStyle','none','LineWidth',2) +hold +plot(step_con_moment,evaluated(scal).M21(bin_num,:),'Color',[0.85,0.33,0.10],'MarkerSize',8,'Marker','+', 'LineStyle','none','LineWidth',2) + +plot(step_con_moment_tmp,M11(bin_num,:),'k','MarkerSize',8,'Marker','o', 'LineStyle','none','LineWidth',1.5) +plot(step_con_moment_tmp,M21(bin_num,:),'k','MarkerSize',8,'Marker','+', 'LineStyle','none','LineWidth',1.5) + +xlabel('$\Delta r/sample$','Interpreter','latex') +% ylabel('Conditional Moment') +set(gca,'FontSize',18) +set(gcf, 'Color', 'w') +axis square +fig_setup +xlim([min(step_con_moment_tmp)-2 max(step_con_moment_tmp)+2]) +ylim([min([M11(bin_num,:) M21(bin_num,:)]) max([M11(bin_num,:) M21(bin_num,:)])]) + + +[xData, yData] = prepareCurveData( step_con_moment,evaluated(scal).M11(bin_num,:)); +ft = fittype( 'poly1' ); +opts = fitoptions( 'Method', 'LinearLeastSquares' ); +[fitresult, gof] = fit( xData, yData, ft, opts ); +plot(linspace(0,2*max(step_con_moment_tmp),100),feval(fitresult,linspace(0,2*max(step_con_moment_tmp),100)),'k','LineWidth',1.5,'LineStyle','-') + +[xData, yData] = prepareCurveData( step_con_moment,evaluated(scal).M21(bin_num,:)); +ft = fittype( 'poly1' ); +opts = fitoptions( 'Method', 'LinearLeastSquares' ); +[fitresult, gof] = fit( xData, yData, ft, opts ); +plot(linspace(0,2*max(step_con_moment_tmp),100),feval(fitresult,linspace(0,2*max(step_con_moment_tmp),100)),'k','LineWidth',1.5,'LineStyle','-') + +vline(min(step_con_moment),'k') +vline(max(step_con_moment),'k') + +legend('$M^{(1)}\left(u_r,r\right)$ ','$M^{(2)}\left(u_r,r\right)$ ','Location','northwest') + +if ischar(save_path) + savefig(h,fullfile(save_path,append(save_name,'_','con_moment.fig')),'compact') + for a = 1:length(h) + exportgraphics(h(a),fullfile(save_path,append(save_name,'_',sprintf('con_moment_%d.png', a)))) + end +end + +set(gca,'xScale','lin') +set(gca,'yScale','lin') +tmp_ui=uicontrol('Position',[10 10 100 40],'String','Continue','Callback','uiresume(gcbf)'); +uiwait(gcf); +delete(tmp_ui); +close end \ No newline at end of file diff --git a/Functions_v5-MATLAB/plot_entropy.m b/Functions_v5-MATLAB/plot_entropy.m index 80a1558..3275850 100644 --- a/Functions_v5-MATLAB/plot_entropy.m +++ b/Functions_v5-MATLAB/plot_entropy.m @@ -12,6 +12,9 @@ % Sm = Entropy of the medium % Ds = Entropy of the system or the Shanon entropy % DS = Total entropy production=Sm+Ds +% increment_bin = number of bins +% save_path = path for saving figures and files +% save_name = name for saving files %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function plot_entropy(Sm,Ds,DS,increment_bin,save_path,save_name) diff --git a/Functions_v5-MATLAB/plot_increment_pdf.m b/Functions_v5-MATLAB/plot_increment_pdf.m index e43be28..8345244 100644 --- a/Functions_v5-MATLAB/plot_increment_pdf.m +++ b/Functions_v5-MATLAB/plot_increment_pdf.m @@ -2,7 +2,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This function plots the probability density function (PDF) of the velocity increments % at the scale $r=L$, $r=\lambda$ and $r=\eta$. The colored dashed line correspond to Castaing fits -% (form factor $\lambda^2$ \cite{Castaing_1990}) and grey dashed line to Gaussian fits. +% (form factor $\Lambda_r$ \cite{Castaing_1990}) and grey dashed line to Gaussian fits. % % Arguments IN % data = 1D array of data to which you would like to apply the low pass filter @@ -122,7 +122,7 @@ function plot_increment_pdf(data,nbins,save_path,save_name,int_L,taylor_L,m_data norm1 = pdf(fitdist(incr3,'Normal'),uL); plot(uL,norm1,'LineWidth',2,'LineStyle','--','Color',[0.501960813999176 0.501960813999176 0.501960813999176]) legend({'$u_L$','$u_\lambda$','$u_\eta$'},'Interpreter','latex','Location','northeast','FontSize',18) - legend('$u_L$','$u_\lambda$','$u_\eta$',['Cast. $\lambda^2=$',num2str(Lam_sq_L,'%1.2f')],['Cast. $\lambda^2=$',num2str(Lam_sq_l,'%1.2f')],['Cast. $\lambda^2=$',num2str(Lam_sq_e,'%1.2f')],'Gaussian fit','FontSize',18); + legend('$u_L$','$u_\lambda$','$u_\eta$',['Cast. $\Lambda_r=$',num2str(Lam_sq_L,'%1.2f')],['Cast. $\Lambda_r=$',num2str(Lam_sq_l,'%1.2f')],['Cast. $\Lambda_r=$',num2str(Lam_sq_e,'%1.2f')],'Gaussian fit','FontSize',18); ylim([0.000001*max(puL) 2*max(pue)]) title(['$S(u_L)$ = ',num2str(skewness(incr1),'%1.2f'), ';',... ' $S(u_\lambda)$ = ',num2str(skewness(incr2),'%1.2f'), ';',... @@ -172,8 +172,8 @@ function plot_increment_pdf(data,nbins,save_path,save_name,int_L,taylor_L,m_data norm1 = pdf(fitdist(incr2,'Normal'),uL); plot(uL,norm1,'LineWidth',2,'LineStyle','--','Color',[0.501960813999176 0.501960813999176 0.501960813999176]) % legend({'$u_L$','$u_\lambda$'},'Interpreter','latex','Location','northeast','FontSize',18) - legend('$u_L$','$u_\lambda$',['Cast. $\lambda^2=$',num2str(Lam_sq_L,'%1.2f')],['Cast. $\lambda^2=$',num2str(Lam_sq_l,'%1.2f')]); - + legend('$u_L$','$u_\lambda$',['Cast. $\Lambda_r=$',num2str(Lam_sq_L,'%1.2f')],['Cast. $\Lambda_r=$',num2str(Lam_sq_l,'%1.2f')]); + title(['$S(u_L)$ = ',num2str(skewness(incr1),'%1.2f'), ';',... ' $S(u_\lambda)$ = ',num2str(skewness(incr2),'%1.2f'), ';',... ],'interpreter','latex') diff --git a/Functions_v5-MATLAB/plot_pointwise_KM.m b/Functions_v5-MATLAB/plot_pointwise_KM.m index ca5e3bd..71c4895 100644 --- a/Functions_v5-MATLAB/plot_pointwise_KM.m +++ b/Functions_v5-MATLAB/plot_pointwise_KM.m @@ -6,6 +6,12 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function plot_pointwise_KM(y,x,y_mean_bin,x_mean_bin,x_bin_not_nan,x0,x1,P_B,P_AnB,P_AIB,counter_A,counter_B,min_events,eD1,eD2,markov,fval_start,fval,tau1,tau2,m_data,Fs,taylor_L,tol,dy,increment_bin,ub,lb,norm_ur,norm_r,save_path,save_name) +set(groot, 'defaultAxesTickLabelInterpreter','latex'); +set(groot, 'defaulttextinterpreter','latex'); +set(groot, 'defaultLegendInterpreter','latex'); +set(groot, 'defaultAxesTitle','latex'); + + y_input = y_mean_bin(counter_B>=min_events); x_input = x_mean_bin(counter_A>=min_events); @@ -351,7 +357,7 @@ function plot_pointwise_KM(y,x,y_mean_bin,x_mean_bin,x_bin_not_nan,x0,x1,P_B,P_A ylabel(['$u_{r''=' num2str(tau1/markov,'%1.1f') '\Delta_{EM}}$'], 'interpreter','latex') end fig_setup -title(['$\xi$=' num2str(fval_start,2) '; ' '$\xi_{opti}$=' num2str(fval,2)]) +title(['$\xi_{stp}$=' num2str(fval_start,2) '; ' '$\xi_{stp,opti}$=' num2str(fval,2)]) xPos = 0.0; yPos = 0.0; plot([xPos xPos], get(gca,'ylim'),'LineWidth',2,'LineStyle','--','Color','k'); % Adapts to y limits of current axes @@ -388,7 +394,7 @@ function plot_pointwise_KM(y,x,y_mean_bin,x_mean_bin,x_bin_not_nan,x0,x1,P_B,P_A % axis([-5 5 -5 5]) axis square set(gcf, 'Color', 'w') -title(['$\xi$=' num2str(fval_start,2) '; ' '$\xi_{opti}$=' num2str(fval,2)]) +title(['$\xi_{stp}$=' num2str(fval_start,2) '; ' '$\xi_{stp,opti}$=' num2str(fval,2)]) xPos = 0.0; yPos = 0.0; %vertical cut @@ -436,7 +442,7 @@ function plot_pointwise_KM(y,x,y_mean_bin,x_mean_bin,x_bin_not_nan,x0,x1,P_B,P_A set(gcf, 'Color', 'w') % legend('experiment','optimized','Location','NorthWest') legend('$p_{exp}$','$p_{stp,opti}$','Location','NorthWest','Position',[0.281785714285714 0.657642855417161 0.165338666098458 0.113571428117298]) -title(['$\xi$=' num2str(fval_start,2) '; ' '$\xi_{opti}$=' num2str(fval,2)]) +title(['$\xi_{stp}$=' num2str(fval_start,2) '; ' '$\xi_{stp,opti}$=' num2str(fval,2)]) % title(['directly=' num2str(fval_start,2) '; ' 'optimized=' num2str(fval,2)]) grid off % xlabel(['$u_{r_2=' num2str(tau2/markov,'%1.1f') '\Delta_{EM}}/ \sigma_\infty$'], 'interpreter','latex') diff --git a/Functions_v5-MATLAB/spectrum.m b/Functions_v5-MATLAB/spectrum.m index 1e4b598..1a54934 100644 --- a/Functions_v5-MATLAB/spectrum.m +++ b/Functions_v5-MATLAB/spectrum.m @@ -7,6 +7,8 @@ % % Arguments IN % data = 1D array for which you would like to plot power spectram density(PSD) +% Fs= Sampling frequency in Hz +% increment_bin = The number of bins in which you would like to divide your data % % Arguments OUT % f = Frequency without smoothing