⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snd_peak_metrics.m

📁 我认为很不错的语音处理的matlab源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
% % 28) threshold_bin_peaks		
% % 29) wsmooth		Damien Garcia		NA			
% % 
% % 
% % 
% % ********************************************************************
% %
% %
% % Program was written by Edward L. Zechmann
% %
% %     date 16 October    2007
% %
% % modified 13 January    2008     Updated comments
% %                                 changed from filter.m to filtfilt.m
% %                                 Added impulsive noise method
% %
% % modified 14 January    2008     Reduced number of points allowed for
% %                                 the robust line fit
% %                                 Removed the time truncation
% %                                 updated comments
% %
% % modified 13 August     2008     Added third octave peak levels
% %                                 Added third octave time average levels
% %                                 Updated comments 
% %
% % modified 18 August     2008     Added Ahaah model developed by US Army
% %                                 Updated comments 
% %         
% % modified 10 September  2008     Updated comments
% %   
% % modified 10 December   2008     Upgraded the Nth octave band
% %                                 filtering programs and the A and C-
% %                                 weighting filter programs to include
% %                                 filter settling and resampling.
% %                                 Previously only suppoerted 
% %                                 3rd octave band filters.  
% %   
% % 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 11 January     2009    Added rounding.
% %   
% %   
% % ********************************************************************
% %
% % 
% % Please feel free to modify this code.
% % 
% % See Also: Impulsive_Noise_Meter, plot_peaks, local_peaks, octave, oct3dsgn
% % 


% Check for erroneous input and use reasonable values
if (nargin < 1 || isempty(SP)) || ~isnumeric(SP)
    SP=randn(1, 50000);
end

[SP]=convert_double(SP);

[m1, n1]=size(SP);

if m1 > n1
    SP=SP';
    [m1 n1]=size(SP);
end


if (nargin < 2 || isempty(Fs)) || ~isnumeric(Fs)
    Fs=100000;
end

[Fs]=convert_double(Fs);

if (nargin < 3 || isempty(indices2)) 
    indices2=cell(m1, 1);
    for e1=1:m1;
        indices2{e1, 1}=1;
    end
end

if (nargin < 4 || isempty(num_pts_per_pk_intrl)) || ~isnumeric(num_pts_per_pk_intrl)
    num_pts_per_pk_intrl=n1;
end

% Program Now Supports Nth Octave Band Filtering
if (nargin < 5 || isempty(N)) || ~isnumeric(N)
    N=3;
end

if (nargin < 6 || isempty(min_f)) || ~isnumeric(min_f)
    min_f=200;
end

if (nargin < 7 || isempty(max_f)) || ~isnumeric(max_f)
    max_f=20000;
end

if (nargin < 8 || isempty(max_f)) || ~isnumeric(max_f)
    ear_model=ones(m1, 1);
end

low_bin=floor(0.25*num_pts_per_pk_intrl);
high_bin=num_pts_per_pk_intrl-low_bin;

metrics=cell(m1, 1);


[fc, fc_l, fc_u, fc_str] = nth_freq_band(N, min_f, max_f);
num_snd_simple_metrics=20;
num_metrics=num_snd_simple_metrics+2*length(fc);
metric_str=cell(num_metrics, 1);
metric_units=cell(num_metrics, 1);

array_names={'Peak Index',  'Peak Time',    'Peak Pres. Linear',    'Peak Pres. A-Weight', 'Peak Pres. C-Weight',   'Peak Level Linear ',   'Peak Level A-Weight ', 'Peak Level C-Weight ', 'LeqA', 'LeqA8', 'LeqC', 'LeqC8', 'Leq', 'Leq8', 'Time Span', 'A-Duration', 'B-Duration', 'C-Duration', 'D-Duration', 'Kurtosis'};
array_units={'(Indices)',    '(s)',          '(Pa)',                 '(Pa)',                 '(Pa)',                 '(dB)',                '(dBA)',                 '(dBC)',                '(dBA)','(dBA)', '(dBC)','(dBC)', '(dB)','(dB)', '(s)',      '(s)',         '(s)',        '(s)',        '(s)',        '(No units)'};

% append the strings for the simple sound metrics 
for e1=1:num_snd_simple_metrics;
    metric_str{e1}=array_names{e1};
    metric_units{e1}=array_units{e1};
end

% append the strings for the third octave band sound metrics 
for e1=1:length(fc);
    
    metric_str{num_snd_simple_metrics+e1}=['Peak ', fc_str{e1}, ' Hz'];
    metric_str{num_snd_simple_metrics+length(fc)+e1}=['Level ', fc_str{e1}, ' Hz'];
    
    metric_units{num_snd_simple_metrics+e1}='(dB)';
    metric_units{num_snd_simple_metrics+length(fc)+e1}='(dB)';
    
end

% append the strings for the third octave band sound metrics 
% metric_str{num_snd_simple_metrics+2*length(fc)+1}='AHAAH Warned';
% metric_str{num_snd_simple_metrics+2*length(fc)+2}='AHAAH UnWarned';

% metric_units{num_snd_simple_metrics+2*length(fc)+1}='(AHU)';
% metric_units{num_snd_simple_metrics+2*length(fc)+2}='(AHU)';
ahaah_strs={'Outer Ear', 'Middle Ear', 'Inner Ear'};
AHAAH_str=cell(m1, 1);

for e2=1:m1; % number of microphone channels
    
    max_size=length(indices2{e2}); % number of impulsive peaks found
    buffer4=zeros(max_size, num_metrics);
    
    for e1=1:max_size;
        
        index1=indices2{e2}(e1)-low_bin;

        if index1 < 0
            index1=1;
        end
        
        index2=index1+num_pts_per_pk_intrl;
                
        if  (index2 > n1)
            index2 = n1;    
        end
        
        if index2 <= n1 

            p=SP(e2, index1:index2);
            
            % Calculate the A-weighted, C-weighted, and Linear-Weighted
            % sound pressure levels (dB) and peak amplitudes (Pa)
            
            % Set the settling time to 0.1 seconds which is a typical
            % value.  
            settling_time=0.1;
            % Set the calibration factor to 1.
            cf=1;
            [LeqA, LeqA8, LeqC, LeqC8, Leq, Leq8, spl_peak, spl_peakA, spl_peakC, peak, peakA, peakC]=Leq_all_calc(p, Fs, cf, settling_time);
            
            % Calculate the durations for each peak
            [a, b, c, d]=abcd_durations(p, Fs, 0);

            
            kurt1=kurtosis2(p, 2);

            if isempty(kurt1)
                kurt1=-1;
            end
            
            
            % Calculate the one-third octave linear time average levels and peak levels.  
            % Run the third octave band fitler twice.
            num_x_filter=1;
            sensor=1;
            settling_time=0.1;
            filter_program=2;
            [fc_out, SP_levels, SP_peak_levels]=Nth_oct_time_filter2(p, Fs, num_x_filter, N, fc, sensor, settling_time, filter_program);            
            num_fc=length(fc_out);
            % AHAAH model metrics are not currently available.  
            %[err, WAHU, UwAHU] = ahaah(p, int32(fs), int32(ear_model(e2)));
            AHAAH_str{e2}=ahaah_strs(ear_model(e2));
            
            
            % Specify the kind of rounding.
            round_kind=  [0 1 1 1 1 0 0 0  0  0  0  0  0  0 1 1 1 1 1 1 zeros(1, num_fc) zeros(1, num_fc)];
            
            % Specify the number of significant digits or the digits place.
            round_digits=[0 3 3 3 3 0 0 0 -1 -1 -1 -1 -1 -1 4 3 3 3 3 3 zeros(1, num_fc) -ones(1, num_fc)];
            
            % Concatenate all the metrics into one variable.
            all_metrics=[indices2{e2}(e1), 1/Fs*indices2{e2}(e1), peak, peakA, peakC, spl_peak, spl_peakA, spl_peakC, LeqA, LeqA8, LeqC, LeqC8, Leq, Leq8, num_pts_per_pk_intrl/Fs, [a, b, c, d], kurt1, SP_peak_levels, SP_levels];
            
            % Apply teh specified rounding to the metrics.
            buffer4(e1, :)=m_round(all_metrics, round_kind, round_digits);
            
            
        end
        
    end
    
    metrics{e2, 1}=buffer4;
    
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -