Code covered by the BSD License  

Highlights from
Impulsive Noise Meter

image thumbnail
from Impulsive Noise Meter by Edward Zechmann
Calculates Impulsive noise metrics for hazardous acoustic noise assessent

[a, b_mil, c, d, ee]=abcd_durations(p, Fs, make_plot, flag)
function [a, b_mil, c, d, ee]=abcd_durations(p, Fs, make_plot, flag)
% % abcd_durations: Calculates the A, B, C, and D durations for impulsive noise
% % 
% % Syntax:   [a, b_mil, c, d, ee]=abcd_durations(p, Fs, make_plot);
% %  
% % *********************************************************************
% % 
% % Description 
% % 
% % This program calculates the A, B, C, D, and E-durations for impulsive 
% % noise analysis.
% % 
% % The A-dureation is indicative of the frequency content of the impulse. 
% % 
% % *********************************************************************
% % 
% % Input variables
% % 
% % p is the sound pressure in Pa for a single channel data array
% %                 the default value is randn(1, 50000);
% %
% % Fs sampling rate in Hz.  default value is 100000 Hz.  
% % 
% % make_plot=1;    plots the time records and places a circle at each 
% %                 chosen peak. Otherwise no plots are made. 
% %                 default value is 0.
% % 
% % flag=1;     % 1 Multiplies the time record p by -1 to correct for the 
% %             % voltage inversion of polarized microhpones.  
% %             % 0 does not alter the time record, p. 
% %             % default value is flag=0;
% % 
% % *********************************************************************
% % 
% % Output variables
% % 
% % a is the A-duration in seconds
% % 
% % b_mil is the B-duration in seconds according to MIL-STD-1474D 
% %      Requirement 4.
% % 
% % c is the C-duration in seconds.
% % 
% % d is the D-duration in seconds.
% % 
% % ee is the E-duration in seconds using a non-standard hilbert transform.
% %      approach.  the E-duration may be similar to the B-duration.   
% % 
% % *********************************************************************
% 
% Example='';
% p=rand(10000, 1); % Pa sound pressure, single channel data array
% Fs=50000;         % Hz sample rate frequency
% make_plot=0;      % 0 do not make_plots default is to not make plots
%                   % 1 make plots 
%  
% [a, b_mil, c, d, ee]=abcd_durations(p, Fs, make_plot);
% 
% 
%  
% % *********************************************************************
% %
% %
% % References: 
% %            
% %            
% % 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
% % 
% % 
% % *********************************************************************
% % 
% % 
% % 
% % List of Dependent Subprograms for 
% % abcd_durations
% % 
% % FEX ID# is the File ID on the Matlab Central File Exchange
% % 
% % 
% % Program Name   Author   FEX ID#
% %  1) A_duration		Edward L. Zechmann			
% %  2) analytic_impulse		Edward L. Zechmann			
% %  3) B_Duration_second_flucts		Edward L. Zechmann			
% %  4) B_mil_1474D_duration		Edward L. Zechmann			
% %  5) C_duration		Edward L. Zechmann			
% %  6) convert_double		Edward L. Zechmann			
% %  7) D_duration		Edward L. Zechmann			
% %  8) E_duration		Edward L. Zechmann			
% %  9) findextrema		Schuberth Schuberth		3586	
% % 10) geomean2		Edward L. Zechmann			
% % 11) geospace		Edward L. Zechmann			
% % 12) LMS_trim		Edward L. Zechmann			
% % 13) LMTSregor		Edward L. Zechmann			
% % 14) moving		Aslak Grinsted		8251	
% % 15) rand_int		Edward L. Zechmann			
% % 16) sd_round		Edward L. Zechmann			
% % 17) sub_mean		Edward L. Zechmann			
% % 18) sub_mean2		Edward L. Zechmann			
% % 19) threshold_bin_peaks		Edward L. Zechmann			
% % 
% % 
% % *********************************************************************
% %
% % This program was originally developed by Chucri Kardous.  
% %
% % This program was written by Edward L. Zechmann  
% % 
% %      date 11 December   2007
% % 
% %  modified 17 December   2007    Added comments
% % 
% %  modified 13 August     2008    Updated comments
% % 
% %  modified 21 September  2008    Check output for being empty
% %                                 Updated Comments
% %  
% % modified 21 March       2009    Updated comments
% % 
% % modified  6 October     2009    Updated comments
% % 
% % modified  6 October     2009    Updated comments
% % 
% % modified 19 January     2010    Changed name to E-Duration 
% %                                 from B-Duration.  Updated Comments
% % 
% % modified 11 February    2011    Fixed bug in outputting the E-Duration 
% %                                 Updated Comments
% % 
% % 
% % *********************************************************************
% % 
% % Please feel free to modify this code.
% % 
% % See also: A_Duration, B_Duration, C_Duration, D_Duration
% % 

if (nargin < 1 || isempty(p)) || ~isnumeric(p)
    p=randn(1, 50000);
end

% If sampling rate is not specified, then 
% assume a data acquisition rate of 50 KHz;
if (nargin < 2 || isempty(Fs)) || ~isnumeric(Fs)
    Fs=100000; 
end

if (nargin < 3 || isempty(make_plot)) || ~isnumeric(make_plot)
    make_plot=0; 
end

if (nargin < 4 || isempty(flag)) || ~isnumeric(flag)
    flag=0;
end

if ~isequal(flag, 0)
    flag=1;
end


% A-duration in seconds
% % a is the A-duration
% % at2 is the prepeak crossing
% % at1 is the post peak crossing
[a, at2, at1]=A_duration(p, Fs, flag);

% check  the data array for a zero crossing after max peak
% if the signal isn't close to a zero crossing stop
% the program and return -1
if (at2 > length(p))
    a=-1;
    b=-1;
    c=-1;
    d=-1;
    
else
    
    % B-duration usign a non-standard conceptual Hilbert transform approach
    % (assuming only one impulse)
    % B-duration in seconds
    [ee]=E_duration(p, Fs);
    
    % B-duration according to MIL-STD-1474D Requirement 4.
    [b_mil]=B_mil_1474D_duration(p, Fs, flag, make_plot);
    
    % C-duration in seconds
    [c, c2, error_cond]=C_duration(p, Fs, make_plot);
    
    % D-duration in seconds 
    % (assuming only one impulse) 
    [d]=D_duration(p, Fs, make_plot);
end


% make sure the durations are not empty
if isempty(a)
    a=-1;
end

if isempty(b_mil)
    b_mil=-1;
end

if isempty(c)
    c=-1;
end

if isempty(d)
    d=-1;
end

if isempty(ee)
    ee=-1;
end

% If the durations are not positive,
% then set them to -1.
a(a<0)=-1;
ee(ee<0)=-1;
b_mil(b_mil<0)=-1;
c(c<0)=-1;
d(d<0)=-1;
            
    


Contact us at files@mathworks.com