function Main_Sound
% % Main_Sound: Main Program for the Impulsive Noise Meter and outputs a table of impulsive noise metrics
% %
% % Syntax:
% %
% % Main_Sound;
% %
% % ********************************************************************
% %
% % Description
% %
% % Main_Sound calculates metrics for impulsive noise.
% % Sound metrics include: peaks, Leq, LeqA, LeqC, kurtosis,
% % third octave band peaks and levels, and more.
% %
% % Main_Sound prompts the user for all of the inputs to the
% % Impulsive_Noise_Meter.m program and to the make_table_compare_systems.m
% %
% % Main_Sound has no Input or Output Variables.
% %
% % The user selects either matlab or wav files to analyze for sound.
% % There are a series of prompts for output filenames,
% % formating of output images of the figures, and the Name of the device
% % under test (Tool Name).
% %
% % The metrics calculated in this program are for time records of 1 second
% % or longer. Time records shorter than 1 second may not have accurate
% % results.
% %
% % The program is limited in its memory and capacity to process long
% % time records and calculate the metrics. In general, the program can
% % process files with a few million data points without crashing.
% %
% %
% % ********************************************************************
%
% Example='1';
%
% % One Example is shown for sound data.
% % The example illustrates the definitions of the time
% % increment variables which the user is prompted to select.
%
%
% % Step 1) Create a data file;
%
% % Set the sampling rate variables for sound and vibrations
% Fs_SP=50000;
%
% % Set the time increment variables for the sound data
% % t_SP, dt_SP are time increment variables for sound
%
% dt_SP=1/Fs_SP;
% t_SP=0:(1/Fs_SP):20;
%
% % SP is the sound pressure data
% % (3 channels for 20 seconds at 50 KHz sampling rate)
% SP=randn(3, length(t_SP));
%
% save('Example_data_file.mat', 'SP', 'Fs_SP','t_SP', 'dt_SP');
%
% % Step 2) Run the program;
%
% Main_Sound;
%
%
%
%
% Example='1';
%
% clear all;
% Fs_SP=50000; fc=1000; td=1; tau=0.01; delay=0.1; A1=8; A2=21;
% [SP1, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=1000; td=1; tau=0.1; delay=0.1; A1=2; A2=22;
% [SP2, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=1000; td=2; tau=0.4; delay=0.1; A1=2; A2=17;
% [SP3, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=2000; td=1; tau=0.1; delay=0.1; A1=8; A2=15;
% [SP4, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% SP=[[0.9*SP4 SP1 0.3*SP3 SP2 0.5*SP4 0.2*SP1 SP3 5*SP2];...
% [SP1 0.7*SP4 10*SP2 SP3 0.4*SP2 0.5*SP3 SP1 1*SP4];...
% [SP3 0.2*SP1 0.5*SP4 2*SP2 0.4*SP2 0.7*SP3 0.3*SP1 10*SP4];...
% [SP1 0.7*SP2 0.3*SP3 SP4 0.4*SP1 10*SP2 SP3 1*SP4]];
% [SP]=sub_mean2(SP, Fs_SP, 25);
% save('default_data_file.mat', 'SP', 'Fs_SP');
%
%
% Fs_SP=50000; fc=100; td=1; tau=0.1; delay=0.2; A1=4; A2=12;
% [SP1, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=500; td=1; tau=0.2; delay=0.15; A1=3; A2=12;
% [SP2, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=2500; td=2; tau=0.2; delay=0.05; A1=6; A2=9;
% [SP3, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=2000; td=1; tau=0.01; delay=0.12; A1=5; A2=11;
% [SP4, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% SP=[[0.9*SP4 SP1 0.3*SP3 SP2 0.5*SP4 0.2*SP1 SP3 5*SP2];...
% [SP1 0.7*SP4 10*SP2 SP3 0.4*SP2 0.5*SP3 SP1 1*SP4];...
% [SP3 0.2*SP1 0.5*SP4 2*SP2 0.4*SP2 0.7*SP3 0.3*SP1 10*SP4];...
% [SP1 0.7*SP2 0.3*SP3 SP4 0.4*SP1 10*SP2 SP3 1*SP4]];
% [SP]=sub_mean2(SP, Fs_SP, 25);
% save('default_data_file2.mat', 'SP', 'Fs_SP');
%
%
% Fs_SP=50000; fc=2000; td=1; tau=0.15; delay=0.2; A1=3; A2=135;
% [SP1, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=5000; td=1; tau=0.2; delay=0.15; A1=3; A2=12;
% [SP2, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=4000; td=2; tau=0.1; delay=0.05; A1=2; A2=34;
% [SP3, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=600; td=1; tau=0.01; delay=0.12; A1=5; A2=141;
% [SP4, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% SP=[[0.9*SP4 SP1 0.3*SP3 SP2 0.5*SP4 0.2*SP1 SP3 5*SP2];...
% [SP1 0.7*SP4 10*SP2 SP3 0.4*SP2 0.5*SP3 SP1 1*SP4];...
% [SP3 0.2*SP1 0.5*SP4 2*SP2 0.4*SP2 0.7*SP3 0.3*SP1 10*SP4];...
% [SP1 0.7*SP2 0.3*SP3 SP4 0.4*SP1 10*SP2 SP3 1*SP4]];
% [SP]=sub_mean2(SP, Fs_SP, 25);
% save('default_data_file3.mat', 'SP', 'Fs_SP');
%
%
% Fs_SP=50000; fc=3000; td=1; tau=0.23; delay=0.2; A1=33; A2=167;
% [SP1, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=2000; td=1; tau=0.23; delay=0.15; A1=34; A2=122;
% [SP2, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=400; td=2; tau=0.15; delay=0.05; A1=12; A2=134;
% [SP3, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% Fs_SP=50000; fc=1000; td=1; tau=0.13; delay=0.12; A1=52; A2=121;
% [SP4, t]=analytic_impulse(Fs_SP, fc, td, tau, delay, A1, A2);
% SP=[[0.9*SP4 SP1 0.3*SP3 SP2 0.5*SP4 0.2*SP1 SP3 5*SP2];...
% [SP1 0.7*SP4 10*SP2 SP3 0.4*SP2 0.5*SP3 SP1 1*SP4];...
% [SP3 0.2*SP1 0.5*SP4 2*SP2 0.4*SP2 0.7*SP3 0.3*SP1 10*SP4];...
% [SP1 0.7*SP2 0.3*SP3 SP4 0.4*SP1 10*SP2 SP3 1*SP4]];
% [SP]=sub_mean2(SP, Fs_SP, 25);
% save('default_data_file4.mat', 'SP', 'Fs_SP');
%
% Main_Sound;
%
%
%
%
% % ********************************************************************
% %
% % References:
% %
% %
% % ANSI S1.4-1983 American National Standard
% % Specificaitons for Sound Level Meters
% %
% % ANSI S1.6-1984 Preferred Frequencies, Frequency Levels, and Band
% % Numbers for Acoustical Measurements
% %
% % ANSI S1.43-1997 American National Standard
% % Specificaitons for Integrating-Averaging Sound Level
% % Meters
% %
% % ANSI S1.11-1986 American National Standard
% % Specification for Octave-band and Fractional-Octave-
% % band Analog and Digital Filters
% %
% % ANSI S3.44-1986 American National Standard
% % Determination of Occupational Noise Exposure and
% % Estimation of Noise Induced Hearing Impairment
% %
% %
% % Mil Standard 1474D, DEPARTMENT OF DEFENSE
% % DESIGN CRITERIA STANDARDm, NOISE LIMITS, 12 February 1997
% % www.silencertests.com/docs/mil-std-1474d.pdf
% %
% % Guido F. Smoorenburg, "Damage Risk Criteria for Impulsive
% % Noise," New Perspectives on Noise Induced Hearing Loss,
% % Raven Press, New York, pages(471-490) 1982
% %
% % ********************************************************************
% %
% %
% % Subprograms
% %
% % This program requires the Matlab Signal Processing Toolbox
% % This program contains code based on oct3dsgn by Christophe Couvreur 69
% %
% %
% %
% % List of Dependent Subprograms for
% % Main_Sound
% %
% % FEX ID# is the File ID on the Matlab Central File Exchange
% %
% %
% % Program Name Author FEX ID#
% % 1) A_duration Edward L. Zechmann
% % 2) abcd_durations Edward L. Zechmann
% % 3) ACdsgn Edward L. Zechmann
% % 4) ACweight_time_filter Edward L. Zechmann
% % 5) analytic_impulse Edward L. Zechmann
% % 6) B_Duration_second_flucts Edward L. Zechmann
% % 7) B_mil_1474D_duration Edward L. Zechmann
% % 8) bessel_antialias Edward L. Zechmann
% % 9) bessel_digital Edward L. Zechmann
% % 10) bessel_down_sample Edward L. Zechmann
% % 11) C_duration Edward L. Zechmann
% % 12) calc_diff_metrics Edward L. Zechmann
% % 13) choosebox Peter Wasmeier 4141
% % 14) convert_double Edward L. Zechmann
% % 15) D_duration Edward L. Zechmann
% % 16) data_loader2 Edward L. Zechmann
% % 17) data_outliers3 Edward L. Zechmann
% % 18) dB_to_Pa Edward L. Zechmann
% % 19) E_duration
% % 20) estimatenoise John D'Errico 16683
% % 21) file_extension Edward L. Zechmann
% % 22) filter_settling_data3 Edward L. Zechmann
% % 23) find_nums Edward L. Zechmann
% % 24) find_previous_crossing Edward L. Zechmann
% % 25) findextrema Schuberth Schuberth 3586
% % 26) findjobj Yair M. Altman 14317
% % 27) fix_YTick Edward L. Zechmann
% % 28) func_threshold Jing Tian 10462
% % 29) genHyper Ben Barrowes 6218
% % 30) geomean2 Edward L. Zechmann
% % 31) geospace Edward L. Zechmann
% % 32) get_p_q2 Edward L. Zechmann
% % 33) Impulsive_Noise_Meter Edward L. Zechmann
% % 34) kurtosis2 William Murphy
% % 35) Leq_all_calc Edward L. Zechmann
% % 36) LMS_trim Edward L. Zechmann
% % 37) LMSloc Alexandros Leontitsis 801
% % 38) LMTSregor Edward L. Zechmann
% % 39) localpeaks Edward L. Zechmann
% % 40) m_round Edward L. Zechmann
% % 41) make_summary_impls_stats_table Edward L. Zechmann
% % 42) match_height_and_slopes2 Edward L. Zechmann
% % 43) maximize Oliver Woodford 25471
% % 44) moving Aslak Grinsted 8251
% % 45) nth_freq_band Edward L. Zechmann
% % 46) Nth_oct_time_filter2 Edward L. Zechmann
% % 47) Nth_octdsgn Edward L. Zechmann
% % 48) num_impulsive_samples Edward L. Zechmann
% % 49) Pa_to_dB Edward L. Zechmann
% % 50) parseArgs Malcolm Wood 10670
% % 51) peak_index Edward L. Zechmann
% % 52) peak_ix Edward L. Zechmann
% % 53) peak_threshhold_function2 Edward L. Zechmann
% % 54) peakfinder Nate Yoder 25500
% % 55) plot_snd_vibs Edward L. Zechmann
% % 56) plotpeaks Edward L. Zechmann
% % 57) pow10_round Edward L. Zechmann
% % 58) print_channel_stats Edward L. Zechmann
% % 59) print_data_loader_configuration_table Edward L. Zechmann
% % 60) print_outliers_indices Edward L. Zechmann
% % 61) print_overall_stats Edward L. Zechmann
% % 62) psuedo_box Edward L. Zechmann
% % 63) rand_int Edward L. Zechmann
% % 64) remove_filter_settling_data Edward L. Zechmann
% % 65) resample_interp3 Edward L. Zechmann
% % 66) resample_plot Edward L. Zechmann
% % 67) rise_time Edward L. Zechmann
% % 68) rms_val Edward L. Zechmann
% % 69) save_a_plot2_audiological Edward L. Zechmann
% % 70) sd_round Edward L. Zechmann
% % 71) snd_peak_metrics Edward L. Zechmann
% % 72) splat_cell Edward L. Zechmann
% % 73) sub_mean Edward L. Zechmann
% % 74) sub_mean2 Edward L. Zechmann
% % 75) subaxis Aslak Grinsted 3696
% % 76) t_alpha Edward L. Zechmann
% % 77) t_confidence_interval Edward L. Zechmann
% % 78) t_icpbf Edward L. Zechmann
% % 79) tableGUI Joaquim Luis 10045
% % 80) threshold_bin_peaks Edward L. Zechmann
% % 81) wsmooth Damien Garcia NA
% %
% %
% %
% % ********************************************************************
% %
% % Program Written by Edward L. Zechmann
% %
% % date 16 September 2008
% %
% % modified 17 September 2008 Updated Comments
% % Added the option to print a summary
% % statistics table
% %
% % modified 19 September 2008 Updated Comments
% %
% % modified 11 November 2008 Fixed a bug in the selection of
% % channels for calculating differences in
% % metrics between two channels.
% %
% % modified 10 December 2008 Upgraded the third octave band
% % filtering programs and the A and C-
% % weighting filter programs to include
% % filter settling and resampling.
% %
% % modified 11 December 2008 Upgraded the A and C-
% % weighting filter programs,
% % to include iterative filtering.
% % The filters are now very stable.
% %
% % Removed filter coefficients from input
% % and output;
% % Peaks pressures and Levels are output.
% %
% % modified 16 December 2008 Use convolution to make filter
% % coefficients (b and a) into
% % arrays from cell arrays.
% %
% % modified 5 January 2009 Added sub_mean to the Nth octave
% % band filters and A and C weighting
% % filters.
% %
% % modified 19 January 2009 Updated summary table to include
% % rounding.
% %
% % modified 21 March 2009 Added the B-Mil-Std-1474-D-Duration
% % Added the peak analysis time for
% % calculating metrics.
% % Added a flag to data_outliers3 to
% % convert dB data to Pa before
% % calculating mean and median values.
% % Updated comments
% %
% % modified 25 September 2009 Added a no selection button to the
% % 200 Volt mic selection box.
% %
% % modified 6 October 2009 Updated comments
% %
% % modified 5 August 2010 Added resampling using Bessel
% % antialiasing filter
% % Updated Comments
% %
% % modified 10 August 2010 Added rise time
% % Updated Comments
% %
% % modified 11 October 2010 Changed peak finder to peak_ix
% % Updated comments.
% %
% % modified 11 February 2011 Updated to new method of finding peaks.
% % Updated Comments.
% %
% %
% %
% %
% % ********************************************************************
% %
% % Please feel free to modify this code.
% %
% % See Also: Impulsive_Noise_Meter, Continuous_Sound_and_Vibrations_Analysis
% %
% % ********************************************************************
%
% Get input parameters using various input boxes, menus, listboxes, etc...
%
% % ********************************************************************
%
% Get the filenames to process
%
% Set the default values for unspecified input variables
[filenamesin, pathname, filterindex] = uigetfile( { '*.mat'; '*.wav'}, 'Select the files To Process', 'MultiSelect', 'on');
if isempty(filenamesin) || ischar(filenamesin) || (~iscell(filenamesin) && numel(filenamesin) > 1)
% expecting a cell array of strings
% if only one file is selected then it will be a character array or a
% single string
% convert into a cell array if necessary
if ~isempty(filenamesin) && ischar(filenamesin) && isequal(exist(filenamesin, 'file'), 2)
filenamesin={filenamesin};
else
if isempty(filenamesin)
[filenamesin, pathname] = uigetfile( { '*.mat';'*.wav'}, 'Select the files To Process', 'MultiSelect', 'on');
end
if ischar(filenamesin) && isequal(exist(filenamesin, 'file'), 2)
filenamesin={filenamesin};
end
end
pathname=cd;
cd(pathname);
else
cd( pathname);
end
if ~iscell(filenamesin) || isempty(filenamesin) || length(filenamesin) < 1
error('Must select at least 1 file to analyze');
end
if ~iscell(filenamesin) || isempty(filenamesin) || length(filenamesin) < 1
error('Must select at least 1 file to analyze');
end
filenamesin=sort(filenamesin);
% % ********************************************************************
%
% Get the filenames to save the text file and the matlab structures.
%
prompt= {['Enter the File Name for the Output Text file .'], ['Enter the File Name for the Output Matlab Structure Data file. .']};
defAns={'Impulse_snd', 'Impulse_snd'};
dlg_title='Enter File Names for Saving the Program Metrics and Descriptive Statistics';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
file_name_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(file_name_cell)
fileout_txt='Impulse_text';
fileout_struct='Impulse_snd';
else
fileout_txt=file_name_cell{1};
fileout_struct=file_name_cell{2};
end
% % ********************************************************************
%
% Determine whether to save the Matlab structure or not
%
save_struct=menu('Save the Matlab Output Data Structure?', 'Yes', 'No', 'Default');
if isequal(save_struct, 2)
save_struct=0;
else
save_struct=1;
end
% % ********************************************************************
%
% Get the Peak Time Window
%
prompt= {'Enter Peak Window time (seconds) for Identifying a Peak', 'Enter time width for Processing time (seconds) for Calculating Metrics'};
defAns={'1.0', '1.0'};
dlg_title='Enter the time window length for identifying and analyzing a single peak. Default is 1.0 seconds';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
peak_window_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(peak_window_cell)
peak_identification_time=1;
peak_metric_time=1;
else
peak_identification_time=str2double(peak_window_cell{1});
peak_metric_time=str2double(peak_window_cell{2});
end
% % ********************************************************************
%
% Determine whether to make a plot of impulsive noise time records
% including all identified impulsive peaks.
%
make_plot=menu('Make a plot of the impulsive noise time records?', 'Yes', 'No', 'Default');
if isequal(make_plot, 2)
make_plot=0;
else
make_plot=1;
end
if isequal(make_plot, 1)
% % ********************************************************************
%
% Get whether the figures should be saved in portrait or landscape
%
dB_scale = menu('Choose Y-Scaling of the Sound Time Record.', 'Linear', 'dB_Scale', 'Default');
if isequal(dB_scale, 2)
dB_scale=1;
else
dB_scale=0;
end
else
dB_scale=0;
end
% % ********************************************************************
%
% Determine whether to make a plot of impulsive noise time records
% including all identified impulsive peaks.
%
if isequal(make_plot, 1)
save_plot=menu('Save a plot of the impulsive noise time records?', 'Yes', 'No', 'Default');
if isequal(save_plot, 2)
save_plot=0;
else
save_plot=1;
end
else
save_plot=0;
end
% % ********************************************************************
%
% Get the Tool Name
%
prompt= {['Enter the Tool Name or Description']};
defAns={'Circular Saw 6000'};
dlg_title='Device Under Test Name, Tool Name, or Description';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
Tool_Name_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(Tool_Name_cell)
Tool_Name='';
else
Tool_Name=Tool_Name_cell{1};
end
if isequal(make_plot, 1)
% % ********************************************************************
%
% Prompt the user to declare which File Formats to save the Figures as
% Images
%
str{1}='1 .pdf Portable Document Format Default';
str{2}='2 .fig Matlab Figure Format';
str{3}='3 .jpg (200 dpi resolution)';
str{4}='4 .eps Encapsulated Post Script';
str{5}='5 .tiff Tagged Image File Format (200 dpi resolution)';
str{6}='6 .tiff (no compression) suggested for publications)';
prompt={'Which formats should the Files be saved in?', 'Select Desired Formats',' For Saving Figure Images'};
[fig_format,ok] = listdlg('Name', 'figure Formats', 'PromptString', prompt,'SelectionMode','multiple','ListString',str, 'InitialValue', [1], 'ListSize', [500, 500]);
if (isempty(fig_format) || any(logical(fig_format < 1))) || (any(logical(fig_format > 6)) || any(~isequal(ok, 1)))
fig_format=1;
end
else
fig_format=1;
end
if isequal(make_plot, 1)
% % ********************************************************************
%
% Get whether the y-axes should have the same limits
%
same_ylim = menu('Should the y-axes have the same limits For each channel?', 'Yes', 'No', 'Default');
if isequal(same_ylim, 2)
same_ylim=0;
else
same_ylim=1;
end
else
same_ylim=1;
end
% % ********************************************************************
%
% Get whether to ignore the threshold requirement
%
ignore_threshold = menu('Ignore the threshhhold requirement?', 'Yes', 'No', 'Default');
if isequal(ignore_threshold, 2)
ignore_threshold=0;
else
ignore_threshold=1;
end
% % ********************************************************************
%
% Get the required minimum peak amplitude (Pa) converted from (dB)
%
if isequal(ignore_threshold, 0)
prompt= {'Enter the Minimum Peak Level (dB)'};
defAns={'100'};
dlg_title='Each peak must be greater than the minimum peak level.';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
min_peak_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(min_peak_cell)
min_peak=100;
else
nums=find_nums(min_peak_cell{1}, 2);
min_peak=nums(1);
end
else
ignore_threshold=1;
min_peak=100;
end
% % ********************************************************************
%
% Enter the maximum number of channels to be analyzed in a single file
%
prompt= {'Enter the Maximum number of channels of sound data to be analyzed in a single file and variable.'};
defAns={'2'};
dlg_title='Enter the maximum number of channels of sound data to analyze.';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
num_chan_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(num_chan_cell)
num_chan=2;
else
num_chan=str2double(num_chan_cell{1});
end
num_chan=round(num_chan);
if num_chan < 1
num_chan=1;
end
% % ********************************************************************
%
% Select the polarized 200 Volt Microphones
%
Polarized_or_ICP=zeros(num_chan, 1);
prompt=cell(num_chan, 1);
for e1=1:num_chan;
prompt{e1,1}=['Channel ', num2str(e1)];
end
dlg_title='Select all of the 200 Volt Polarized Microphones.';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
[Selection, ok]=listdlg('ListString', prompt, 'SelectionMode', 'multiple', 'ListSize', [500 500], 'InitialValue', (1:num_chan), 'Name', dlg_title,'CancelString', 'Select None' );
if ok == 1
for e1=1:length(Selection);
Polarized_or_ICP(Selection(e1))=1;
end
end
% % ********************************************************************
%
% Enter the names of the channels such as {'Unprotected', 'Protected'}
%
% These labels will appear on the time record plots in the bottom right
% corner for each channel
%
switch num_chan
case 1
plot_str={'Channel 1'};
case 2
plot_str={'Unprotected', 'Protected'};
otherwise
plot_str={'Unprotected', 'Protected'};
for e1=1:(num_chan-2);
plot_str{e1+2}=num2str(e1+2);
end
end
% initialize the default answers for the channel labels (plot_str)
prompt=cell(num_chan,1);
defAns=cell(num_chan,1);
for e1=1:num_chan;
prompt{e1}= ['Enter label for Channel ', num2str(e1), '.'];
if isempty(plot_str{e1})
defAns{e1}=['Channel ', num2str(e1)];
else
defAns{e1}=plot_str{e1};
end
end
dlg_title='Enter the maximum number of channels of sound data to analyze.';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
plot_str_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(plot_str_cell)
plot_str=defAns;
else
plot_str=plot_str_cell;
end
% % ********************************************************************
%
% Get the channel number to align the impulsive peaks
%
Align_peaks = menu('Align peaks to the peaks of a channel?', 'Yes', 'No', 'Default');
if isequal(Align_peaks, 2)
Align_peaks=0;
else
Align_peaks=1;
end
if isequal(Align_peaks, 0)
Align_peaks=[];
else
prompt= {'Enter the channel number to align all of the impulsive peaks to.'};
defAns={'1'};
dlg_title='Enter the number of the channel to align the peaks.';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
Align_peaks_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(Align_peaks_cell)
Align_peaks=1;
else
Align_peaks=ceil(str2double(Align_peaks_cell{1}));
if Align_peaks > num_chan
Align_peaks=num_chan;
end
if Align_peaks < 1
Align_peaks=1;
end
end
end
if isequal(make_plot, 1)
% % ********************************************************************
%
% Get whether the figures should be saved in portrait or landscape
%
portrait_landscape = menu('Choose Orientation of the Figures? Portrait is better for more than 4 channels of data.', 'Portrait', 'Landscape', 'Default');
if isequal(portrait_landscape, 2)
portrait_landscape=2;
else
portrait_landscape=1;
end
else
portrait_landscape=1;
end
% % ********************************************************************
%
% Get the peak alignment tolerance fraction
%
if ~isempty(Align_peaks)
prompt= {'Enter the peak alignment tolerance fraction.'};
defAns={'0.25'};
dlg_title='Enter the fraction of the impulsive peak interval for aligning the impulses.';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
peak_alignment_tol_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(peak_alignment_tol_cell)
peak_alignment_tol=0.25;
else
peak_alignment_tol=str2double(peak_alignment_tol_cell{1});
if peak_alignment_tol > 1
peak_alignment_tol=0.9;
end
if peak_alignment_tol < 0
peak_alignment_tol=0.01;
end
end
else
peak_alignment_tol=0.25;
end
% % ********************************************************************
%
% Determine whether to Surpress Outlier Detection
%
sod=menu({'Identify Outliers and Remove them from Calculations of the Mean, STD, etc.', 'Allow Automated Detection and Removal of Anomalous Data.'}, 'Yes', 'No', 'Default');
if isequal(sod, 2)
sod=1;
else
sod=0;
end
% % ********************************************************************
%
% Determine whether to print a summary table of the statistics
%
flag2=menu('Print a summary table of statistics to a text file?', 'Yes', 'No', 'Default');
if isequal(flag2, 2)
flag2=0;
else
flag2=1;
end
% % ********************************************************************
%
% Determine whether to print the Metrics for each channel, Difference of Values, or both
%
if isequal(flag2, 1)
% % *******************************************************************
%
% Determine whether to print the Values, Difference of values, or both
%
flag=menu('Select whether to Write to text file the Metrics, Difference of Metrics, or both?', 'Metrics for each channel', 'Difference in Metrics for each pair of Channels', 'Both Metrics and Differences in Metric', 'Default (Both)');
if flag >= 3
flag=3;
end
% % *******************************************************************
%
% Get the filenames to save the text file and the matlab structures.
%
prompt= {'Enter the File Name for the Output Text file'};
defAns={'metrics_stats',};
dlg_title='Enter File Name for the Summary Descriptive Statistics';
num_lines=1;
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
file_name_cell = inputdlg(prompt,dlg_title,num_lines,defAns,options);
if isempty(file_name_cell)
fileout='metrics_stats';
else
fileout=file_name_cell{1};
end
% % *******************************************************************
%
% Determine which channels to output the difference of the metrics.
%
% diff chan is initially a row vector must be a column vector
accept_config=2;
diff_chan=[];
%
count=0;
prompt={'Select pairs of Channels', ' to Calculate a Difference',' in Metrics between the two channels'};
[buf, str]=pow10_round((1:num_chan), 0);
ColNames={'Channel Pair Number', 'Primary Channel', 'Minus Channel'};
out=[];
if isequal(flag, 2) || isequal(flag, 3)
while isequal(accept_config, 2) && logical(count < 3+(floor(num_chan/2))^2)
% Provide help for selecting the channels to calculate a difference
% in the metrics.
h3=helpdlg({'To add a pair of Channels to Calculate Differences in Metrics.', ...
'Add the Primary Channel then the Minus Channel.', '', ...
'The channels are paired together', 'Alternating Primary then Minus', ...
'The pairing of Channels is displayed in a Editable Table.'},'Channel Selection Help');
count=count+1;
[diff_chan_update, ok] = choosebox('Name', 'Channel Selection to Calculate a Difference', 'PromptString', prompt, ...
'SelectString','Ordered Pairs of Channels to Calculate Differences in Metrics:', ...
'SelectionMode', 'multiple', 'ChooseMode', 'copy', ...
'ListString', str, 'OKString', 'Finish and Update', 'ListSize', [300, 300]);
if ishandle(h3)
close(h3);
end
if length(diff_chan_update) >= 2
% The number of pairs must be even
num_new_pairs=floor(length(diff_chan_update)/2);
diff_chan=[diff_chan' diff_chan_update(1:(2*num_new_pairs))' ]';
end
if length(diff_chan) >= 2
[A2, A_str]=pow10_round(diff_chan', 0);
num_pairs=floor(length(A_str)/2);
t_cell=zeros(num_pairs, 3);
for e1=1:(num_pairs);
t_cell(e1,1)=e1;
t_cell(e1,2)=diff_chan(2*e1-1, 1);
t_cell(e1,3)=diff_chan(2*e1, 1);
end
if ishandle(out)
close(out);
end
out = tableGUI('FigName', 'Difference Channel Selection Table', ...
'array', t_cell, 'ColNames', ColNames, 'ColWidth', 180, ...
'RowHeight', 30, 'HorAlin', 'center', 'modal', '', 'position', 'center');
% Select to Accept or Modify Configuration
accept_config=menu('In the Table, are all of the pairings for channels present and correct?', 'Accept Configuration', 'Modify, Add, or Delete channels to Configuration' );
% Retrieve the channel difference configuration table.
hand=get(out, 'UserData');
data_new=zeros(num_pairs, 3);
row_list=[];
for e1=1:num_pairs;
for e2=1:3;
buf1=round(str2double(get(hand.hEdits(e1, e2), 'string')));
if (~isempty(buf1) && logical(buf1 >= 1)) && logical(buf1 <= num_chan)
data_new(e1, e2)=buf1;
else
row_list=[row_list e1];
end
end
end
buf2=setdiff(1:num_pairs, row_list);
diff_chan=zeros(2*length(buf2), 1);
for e1=1:length(buf2);
for e2=1:3;
buf1=round(str2double(get(hand.hEdits(buf2(e1), e2), 'string')));
if isequal(e2,2)
diff_chan(2*e1-1, 1)=buf1;
elseif isequal(e2,3)
diff_chan(2*e1, 1)=buf1;
end
end
end
if ishandle(out) && isequal(accept_config, 1)
close(out);
end
end
end
% Print the Configuration Table for the Last Time
[A2, A_str]=pow10_round(diff_chan', 0);
num_pairs=floor(length(A_str)/2);
t_cell=zeros(num_pairs, 3);
for e1=1:(num_pairs);
t_cell(e1,1)=e1;
t_cell(e1,2)=diff_chan(2*e1-1, 1);
t_cell(e1,3)=diff_chan(2*e1, 1);
end
h3=helpdlg({'Last Chance to Make sure the Channel Configuration is Correct', '', ...
'To add a pair of Channels to Calculate Differences in Metrics.', ...
'Add the Primary Channel then the Minus Channel.', '', ...
'The channels are paired together', 'Alternating Primary then Minus', ...
'The pairing of Channels is displayed in a Editable Table.'},...
'Channel Selection Help');
out = tableGUI('FigName', 'Difference Channel Selection Table', ...
'array', t_cell, 'ColNames', ColNames, 'ColWidth', 180, ...
'RowHeight', 30, 'HorAlin', 'center', 'modal', '', 'position', 'center');
% Retrieve the channel difference configuration table.
hand=get(out, 'UserData');
data_new=zeros(num_pairs, 3);
row_list=[];
for e1=1:num_pairs;
for e2=1:3;
buf1=round(str2double(get(hand.hEdits(e1, e2), 'string')));
if (~isempty(buf1) && logical(buf1 >= 1)) && logical(buf1 <= num_chan)
data_new(e1, e2)=buf1;
else
row_list=[row_list e1];
end
end
end
buf2=setdiff(1:num_pairs, row_list);
data_new=zeros(length(buf2), 3);
for e1=1:length(buf2);
for e2=1:3
buf1=round(str2double(get(hand.hEdits(e1, e2), 'string')));
if isequal(e2,2)
diff_chan(2*e1-1, 1)=buf1;
elseif isequal(e2,3)
diff_chan(2*e1, 1)=buf1;
end
end
end
if ishandle(out) && isequal(accept_config, 1)
close(out);
end
if ishandle(h3)
close(h3);
end
end
% % ********************************************************************
%
% Determine which descriptive statistics to print to a text file.
%
str{1}='1 Artihmetic Mean';
str{2}='2 Robust Mean';
str{3}='3 Standard Deviation';
str{4}='4 95% Confidence Interval';
str{5}='5 Median';
str{6}='6 Median Index';
str{7}='7 Minimum';
str{8}='8 Maximum';
prompt={'Which descriptive statistics of the metrics across impulses for each channel should be output to the file?', 'Select Desired descriptive statistics',' for printing to a text file.'};
[stat_to_get,ok] = listdlg('Name', 'Descriptive Statistics ', 'PromptString', prompt,'SelectionMode','multiple','ListString',str, 'InitialValue', [1,2,3,7,8], 'ListSize', [500, 500]);
if (isempty(stat_to_get) || any(logical(stat_to_get < 1))) || (any(logical(stat_to_get > 8)) || any(~isequal(ok, 1)))
stat_to_get=1;
end
prompt={'Which descriptive statistics of the metrics across files for each channel should be output to the file?', 'Select Desired descriptive statistics',' for printing to a text file.'};
[stat_to_get2,ok] = listdlg('Name', 'Descriptive Statistics ', 'PromptString', prompt,'SelectionMode','multiple','ListString',str, 'InitialValue', [1,2,3,7,8], 'ListSize', [500, 500]);
if (isempty(stat_to_get2) || any(logical(stat_to_get2 < 1))) || (any(logical(stat_to_get2 > 8)) || any(~isequal(ok, 1)))
stat_to_get2=1;
end
end
% ********************************************************************
%
% Run the Impulsive_Noise_Meter
%
[s, round_kind, round_digits]=Impulsive_Noise_Meter(filenamesin, fileout_txt, fileout_struct, save_struct, peak_identification_time, peak_metric_time, make_plot, save_plot, dB_scale, fig_format, Tool_Name, same_ylim, min_peak, ignore_threshold, plot_str, Align_peaks, portrait_landscape, peak_alignment_tol, sod, Polarized_or_ICP );
% % ********************************************************************
% %
% % The output matlab data structures, snd and vibs were saved to
% % file names of the format
% %
% % For Sound Data fileout_txt '_snd.mat'
% %
% %
if isequal(flag2, 1)
% % ********************************************************************
%
% Calculate the difference or ratio between channels selected for
% difference calculations.
%
ratio_metrics=[3, 4, 5, 21];
if ~isempty(diff_chan)
[s]=calc_diff_metrics(s, diff_chan, ratio_metrics, round_kind, round_digits);
end
if save_struct == 1
save(fileout_struct, 's');
end
% ********************************************************************
%
% Run the make_table_compare_systems
%
make_summary_impls_stats_table(s, stat_to_get, stat_to_get2, fileout, flag, ratio_metrics, round_kind, round_digits);
end
fclose('all');