% -*- octave -*- % (C) COPYRIGHT 2023 THUNDER BEAST ARMS CORP ALL RIGHTS RESERVED function [pass] = process_string_flat(Num_Shots,fn, mic_name, mfgr_name, can_name, run_name, cal_name, cart_name) % You will need the following packages installed to run this: octave octave-signal % e.g. apt-get install octave octave-signal % % PARAMETERS: % Num_Shots number of shots in this string % fn input filename for this run, e.g. "Shot 1/Time Group_Expanded Time(Mil Left) - Input.dat' % mic_name microphone name, e.g. SE, ML, 225 % mfgr_name manufacturer name for reporting % can_name suppressor name for reporting % run_name "run name" or "series name", e.g. Day3 % cal_name caliber of suppressor % cart_name cartridge name (or cartridge+gun identifier) % % run from base directory that contains the "Shot [0-9]" directories % for example, % octave -p "/path/to/dot-m-files" --no-gui -H --eval "process_string(5, \"Time Group_Expanded Time(225 Deg ASA) - Input.dat\", \"225\", \"Aero Precision\", \"Lahar-30K\", \"Day3\", \".30\", \"5.56\")" % % where /path/to/dot-n-files is where you put this file, adsgn.m, and Leq_fast.m % % Before you run this, you will need to take all the "Time Group_Expanded Time*.txt" files and trim all the text out of the % header and footer, just leaving the raw numerical data. E.g. remove everything up to but not including % 1 0.0000000000e+00 5.59023e-03 % and everthing after the last numerical line (typically something like "131072 4.9999618981e-01 8.42261e-01") % starting with TagsBegin: to the end of the file. % For each corresponding .txt file, create a .dat file that is truncated as described above. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Edit these only Time_Start=.001; % Short=0; cart_name; if (strncmp(".22", cart_name,3)==1) Short=1; % .22LR needs a different interval to prevent trigger problems endif ArrayLimit=75000; Time_Stop=.125; if (Short==1) Time_Stop=0.100; ArrayLimit=26000; endif Time_Stop; Leq_Width=.025;%How long after shot starts to measure Peak_STOP=.075;%end of peak window, time after shot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %End edit area %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 26000 P_0=20*10^-6; %Absolute Pressure in Pa FS=262144; %Sample rate Tau=.010; %Leq time step Leq_Width=Leq_Width*1000; %Get rid of ms [B, A]=adsgn(FS); %Get filter parameters ofb=sprintf("Results_%s.txt", mic_name); file_id=fopen(ofb,'w'); Peak_Sum=0; Imp_Sum=0; A_Peak_Sum=0; A_Leq_Peak_Sum=0; Shot=1; fprintf(file_id, "SERIES: %s\n", run_name); fprintf(file_id, "CAN: %s %s (%s on %s)\n", mfgr_name, can_name, cal_name, cart_name); fprintf(file_id, "MIC: %s\n", mic_name); fprintf(file_id, "NUMBER OF SHOTS: %d\n", Num_Shots); fprintf(file_id, 'Sample rate 262144 Hz \n'); fprintf(file_id, 'Start Time %.3f s, End Time %.3f s \n', Time_Start, Time_Stop); fprintf(file_id, 'Peak Leq(10ms) window width of %.1f ms \n\n', Leq_Width); while Shot<(Num_Shots+1) %Read in data filename = sprintf('%s%i.dat', fn, Shot); filename_leq = sprintf('%s%i.dat.leq', fn, Shot); filename_imp = sprintf('%s%i.dat.imp', fn, Shot); M=load("-ascii",filename); X1=M(1:ArrayLimit,2:2); T_Start=round(Time_Start/X1(2)); T_Stop=round(Time_Stop/X1(2)); %Parse down the string to analysis window X=M(T_Start:T_Stop,2:2); Y=M(T_Start:T_Stop,3:3); X=X*1000; %convert times to msec X_50=round(.05*FS); DT=X(2)-X(1); %Find time step Q=cumtrapz(X,Y); %Integrate pressure curve Peak_Stop_ROW=round(Peak_STOP*FS);%Initial window convert from sec to row number [Min_Q, Imp_Stop_ROW2]=min(Q(1:Peak_Stop_ROW)); %Find min impulse and set impulse window [Max_Q, X_of_Max_Q]=max(Q(1:Imp_Stop_ROW2)); %Find max impulse using the dynamic window T_Max_Q=X(X_of_Max_Q); %Find time of max impulse dB_Max_Q=20*log10(Max_Q/P_0); %Convert max impulse from Pa-msec to dB-msec Y_A = filter(B,A,Y); %Apply A weight filter to raw data [Max_Y_A, X_of_Y_A_Max]=max(Y_A(1:Peak_Stop_ROW)); %Find peak A-weighted within window Y_A_dB_Max=20*log10(Max_Y_A/P_0); %Convert Peak A-weighted from Pa to dB T_Y_A_Max=X(X_of_Y_A_Max); %Find time of peak A-weighted Leq_Start_ROW=find(Y>1.);%finds everytime relative Pressure is positive Leq_Start1_ROW=Leq_Start_ROW(1); %Finds the first time relative Pressure is positive Leq_Stop_ROW=Leq_Start1_ROW+(round(Leq_Width*FS/1000)); %Set LEQ analysis window Leq_Start_T=X(Leq_Start1_ROW); %Converts from Row to time Leq_Stop_T=Leq_Start_T+Leq_Width; %Defines the end of the window in time Leq_A_Y=Leq_fast(Y_A,FS,Tau,'rectangular'); %Calculates LEQ Leq_AdB_Y = 20*log10(abs(Leq_A_Y)/P_0); %Converts LEQ to dB LEQOUT = [ X(Leq_Start1_ROW:end)/1000 Leq_AdB_Y(Leq_Start1_ROW:end) ]; % converts back to seconds for consistency save("-ascii", filename_leq, "LEQOUT" ); IMPOUT = [ X(1:end)/1000 Q(1:end) ]; % converts back to seconds for consistency save("-ascii", filename_imp, "IMPOUT" ); Leq_Max_Pa=max(Leq_A_Y(Leq_Start1_ROW:Leq_Stop_ROW)); %Finds max LEQ [Leq_MaxdB, Leq_Max_ROW]=max(Leq_AdB_Y(Leq_Start1_ROW:Leq_Stop_ROW)); %Finds the Row position of max LEQ Leq_Max_ROW=Leq_Max_ROW+Leq_Start1_ROW; Leq_Max_T=X(Leq_Max_ROW); %Converts position of max LEQ to time [Max_Y, Y_Max_ROW]=max(Y(1:Peak_Stop_ROW)); %Finds peak pressure dB_Max_Y=20*log10(Max_Y/P_0); %Converts peak to dB Y_Max_T=X(Y_Max_ROW); %Finds time of peak dB fprintf(file_id, "Shot %d\n", Shot); fprintf(file_id, 'Peak of gas flow at %.2f Pa (%.2f dB) at t=%.2f ms \n', Max_Y, dB_Max_Y, Y_Max_T); fprintf(file_id, 'Peak impulse of %.2f Pa*ms (%.2f dB*ms) at t=%.2f ms \n', Max_Q, dB_Max_Q, T_Max_Q); fprintf(file_id, 'Peak A-Weighted dB of %.2f dB at t=%.2f ms\n',Y_A_dB_Max, T_Y_A_Max); fprintf(file_id, 'Peak A-Weighted Leq of %.2f dB at t=%.2f ms\n', Leq_MaxdB, Leq_Max_T); fprintf(file_id, 'Leq window of %.2f ms to %.2f ms\n', Leq_Start_T, Leq_Stop_T); fprintf(file_id, "\n\n"); Peak_Sum=Peak_Sum+Max_Y; Imp_Sum=Imp_Sum+Max_Q; A_Peak_Sum=A_Peak_Sum+Max_Y_A; A_Leq_Peak_Sum=A_Leq_Peak_Sum+Leq_Max_Pa; Shot=Shot+1; end %Calculates and outputs averages Peak_Avg=Peak_Sum/Num_Shots; Peak_Avg_dB=20*log10(Peak_Avg/P_0); Imp_Avg=Imp_Sum/Num_Shots; Imp_Avg_dB=20*log10(Imp_Avg/P_0); A_Peak_Avg_dB=20*log10((A_Peak_Sum/Num_Shots)/P_0); A_Leq_Peak_Avg_dB=20*log10((A_Leq_Peak_Sum/Num_Shots)/P_0); fprintf(file_id, "\n"); fprintf(file_id, "SUMMARY---\n"); fprintf(file_id, 'Peak of gas flow at %.2f Pa (%.2f dB) \n', Peak_Avg, Peak_Avg_dB); fprintf(file_id, 'Peak impulse of %.2f Pa*ms (%.2f dB*ms) \n', Imp_Avg, Imp_Avg_dB); fprintf(file_id, 'Peak A Weighted Average of %.2f dB \n', A_Peak_Avg_dB); fprintf(file_id, 'Peak A Weighted Leq Average of %.2f dB \n', A_Leq_Peak_Avg_dB); fprintf(file_id, "\n\n\n"); fprintf(file_id, "PEAK_UNWEIGHTED_PA: %.2f Pa\n",Peak_Avg); fprintf(file_id, "PEAK_UNWEIGHTED_DB: %.2f dB\n",Peak_Avg_dB); fprintf(file_id, "PEAK_A_WEIGHTED_DB: %.2f dB(A)\n",A_Peak_Avg_dB); fprintf(file_id, "PEAK_IMPULSE_UNWEIGHTED_PAMS: %.2f Pa*ms\n",Imp_Avg); fprintf(file_id, "PEAK_IMPULSE_UNWEIGHTED_DB: %.2f dB*ms\n",Imp_Avg_dB); fprintf(file_id, "PEAK_LEQ_10MS_A_WEIGHTED_DB: %.2f dB\n",A_Leq_Peak_Avg_dB); fclose('all'); endfunction % end