📄 calc_diff_metrics.m
字号:
function [s]=calc_diff_metrics(s, diff_chan, ratio_metrics, round_kind, round_digits)
% % calc_diff_metrics: Calculates the differences in metrics between pairs of channels: Impulsive Noise Meter
% %
% % Syntax:
% %
% % [s]=calc_diff_metrics(s, diff_chan);
% %
% % *****************************************************************
% %
% % Description:
% %
% % This program takes the output from the Impulsive_Noise_Meter and
% % calculates the differences in metrics between pairs of channels:
% % Impulsive Noise Meter.
% %
% % This program is specifically for analyzing hearing protection for
% % impulsive noise.
% %
% % *****************************************************************
% %
% % Input Variables
% %
% % s is the data structure created using the Impulsive_Noise_Meter.
% %
% % diff_chan=[1,2]; % A paired column vector of channel numbers.
% % %
% % % The odd and even elements of the vector are
% % % paired for calculating differences
% % % in metrics across channels.
% % %
% % % default is diff_chan=(1:2)';
% %
% % ratio_metrics=[3, 4, 5, 20]; % is an array of indices of metrics for
% % % the diff_chans array that are
% % % calculated as ratios instead of
% % % differences
% %
% % round_kind=1; % Array of values one element for the rta array
% % % and one element for each varargin array
% % % (see example)
% % % 1 round to specified number of significant
% % % digits
% % %
% % % 0 round to specified digits place
% % %
% % % default is round_kind=1;
% %
% % round_digits=3; % Array of values one element for the rta array
% % % and one element for each varargin array
% % % (see example)% Type of rounding depends on round_kind
% % %
% % % if round_kind==1 number of significant digits
% % % if round_kind==0 specified digits place
% % %
% % % default is round_digits=3;
% %
% % *****************************************************************
% %
% % Output Variables
% %
% % s is the data structure created using the Impulsive_Noise_Meter.
% %
% % *****************************************************************
%
% Example='s';
%
% % This is an example using shock tube data! The data compares two
% % data acquisition rates.
%
% % An example which outputs the mean of the metrics.
%
% load shock_tube;
% stat_to_get=1;
% fileout
% [bb_table, bb2]=make_table_compare_systems(s, stat_to_get, fileout);
%
%
% % An example which outputs all of the metrics.
%
% load shock_tube;
% stat_to_get=[1:7];
% fileout
% [bb_table, bb2]=make_table_compare_systems(s, stat_to_get, fileout);
%
%
%
% % *****************************************************************
% %
% % Subprograms
% %
% %
% %
% % List of Dependent Subprograms for
% % calc_diff_metrics
% %
% %
% % Program Name Author FEX ID#
% % 1) genHyper Ben Barrowes 6218
% % 2) LMSloc Alexandros Leontitsis 801
% % 3) m_round
% % 4) pow10_round
% % 5) sd_round
% % 6) t_alpha
% % 7) t_confidence_interval
% % 8) t_icpbf
% %
% %
% % *****************************************************************
% %
% % Written by Edward L. Zechmann
% %
% % date 29 August 2008
% %
% % modified 30 August 2008 Updated comments.
% %
% % modified 17 September 2008 Updated comments.
% %
% % modified 7 January 2009 Updated comments.
% %
% % modified 18 January 2009 Updated to include rounding.
% %
% %
% % *****************************************************************
% %
% % Please feel free to modify this code.
% %
% % See Also: make_summary_impls_stats_table, Impulsive_Noise_Meter, Continuous_Sound_and_Vibrations_Analysis
% %
if nargin < 1 || isempty(s) || ~iscell(s)
load('shock_tube');
warning('Loading and analyzing the default shock tube data.');
end
if nargin < 2 || isempty(diff_chan) || ~isnumeric(diff_chan)
diff_chan=(1:2)';
end
if nargin < 3 || isempty(ratio_metrics) || ~isnumeric(ratio_metrics)
ratio_metrics=[3, 4, 5, 20];
end
if nargin < 5 || isempty(round_kind) || ~isnumeric(round_kind)
round_kind=1;
end
if nargin < 5 || isempty(round_digits) || ~isnumeric(round_digits)
round_digits=3;
end
[num_files, num_vars]=size(s);
num_channels_array=zeros(num_files,1);
% Determine the size of the concatenated metrics table
for e1=1:num_files; % Data files
num_channels=[];
for e3=1:num_vars; % Number of Variables (Number of Data Acquisition Systems)
if ~isempty(s{e1,e3})
[num_metrics, num_channels, num_stats2]=size(s{e1,e3}.stats_of_metrics);
if num_channels >= 1
num_channels_array(e1)=max([num_channels, num_channels_array(e1)]);
end
end
end
end
num_diff_chan=floor(length(diff_chan)/2);
% Determine the length of the one-dimensional rounding arrays.
num_kinds=length(round_kind);
num_digits=length(round_digits);
% Fill in the concatenated metrics table
% Add row headings and column headings
for e1=1:num_files; % Data files
for e3=1:num_vars; % Number of Variables (Number of Data Acquisition Systems)
if ~isempty(s{e1,e3})
[num_metrics, num_channels, num_stats2]=size(s{e1,e3}.stats_of_metrics);
if num_channels >= 1
s{e1,e3}.diff_chan=diff_chan;
% calculate the differences, then the statistics then
% save them to the structure s.
for e2=1:num_diff_chan; % Channels
for e4=1:num_metrics; % Data Metrics
buf1=s{e1,e3}.metrics{diff_chan(2*e2-1), 1}(:, e4);
buf2=s{e1,e3}.metrics{diff_chan(2*e2), 1}(:, e4);
[m1_buf1, n1_buf1]=size(buf1);
[m1_buf2, n1_buf2]=size(buf2);
m1_buf3=min([m1_buf1 m1_buf2]);
n1_buf3=min([n1_buf1 n1_buf2]);
if num_kinds >= (e4)
rk=round_kind(e4);
else
rk=1;
end
if num_digits >= e4
rd=round_digits(e4);
else
rd=3;
end
% Determine whether to compute a difference or
% ratio. Calculate a ratio for metrics that
% are a member of ratio_metrics.
if ismember(e4, ratio_metrics)
rk=1;
rd=3;
buf3=abs(buf1(1:m1_buf3,1:n1_buf3))./abs(buf2(1:m1_buf3,1:n1_buf3));
else
buf3=abs(buf1(1:m1_buf3,1:n1_buf3))-abs(buf2(1:m1_buf3,1:n1_buf3));
end
s{e1,e3}.diff_metrics{e2,1}(:,e4)=m_round(buf3, rk, rd);
% Calculate the Arithmetic Mean
amean_avg=mean(buf3);
% Calculate the Robust Mean
bmean_avg=LMSloc(buf3);
% Calculate Standard Deviation
stdrt=std(buf3);
% Calculate the 95% Confidence Interval of
% the standard error of the
% t-distribution with a two-sided test.
[ci_int]=t_confidence_interval(buf3, 0.95);
% Calculate the Median
medianrt=median(buf3);
% Calculate the Median Index
[mbuf ix]=min(abs(buf3-medianrt));
% Calculate the Minimum
minrt=min(buf3);
% Calculate the Maximum
maxrt=max(buf3);
% Set the metric values to the cell array
s{e1,e3}.diff_stats_of_metrics(e4, e2, 1)=m_round(amean_avg, rk, rd);
s{e1,e3}.diff_stats_of_metrics(e4, e2, 2)=m_round(bmean_avg, rk, rd);
s{e1,e3}.diff_stats_of_metrics(e4, e2, 3)=m_round(stdrt, 1, 3);
s{e1,e3}.diff_stats_of_metrics(e4, e2, 4)=m_round(ci_int, rk, rd);
s{e1,e3}.diff_stats_of_metrics(e4, e2, 5)=ix;
s{e1,e3}.diff_stats_of_metrics(e4, e2, 6)=m_round(medianrt, rk, rd);
s{e1,e3}.diff_stats_of_metrics(e4, e2, 7)=m_round(minrt, rk, rd);
s{e1,e3}.diff_stats_of_metrics(e4, e2, 8)=m_round(maxrt, rk, rd);
end
end
end
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -