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

📄 impulsive_noise_meter.m

📁 我认为很不错的语音处理的matlab源代码
💻 M
📖 第 1 页 / 共 4 页
字号:
    default_mat_config_in=default_mat_config_out;
    
    if iscell(SP_var)
        num_vars=length(SP_var);
    else
        num_vars=1;
    end
    
    for e7=1:num_vars;
        
        if iscell(SP_var)
            if length(SP_var) >= e7
                SP=SP_var{e7};
            end

            if length(Fs_SP_var) >= e7
                Fs_SP=Fs_SP_var{e7};
            end

            % currently there is not any code for impulsive vibrations
            % analysis
            %if length(vibs_var) >= e7
            %    vibs=vibs_var{e7};
            %end
            %
            %if length(Fs_vibs_var) >= e7
            %    Fs_vibs=Fs_vibs_var{e7};
            %end
        else
            SP=SP_var;
            Fs_SP=Fs_SP_var;
            %vibs=vibs_var;
            %Fs_vibs=Fs_vibs_var;
        end

        % make sure that input data is double precision.
        [SP]=convert_double(SP);
        [Fs_SP]=convert_double(Fs_SP);
        
        
        [m1 n1]=size(SP);

        if m1 > n1
            SP=SP';
            [m1 n1]=size(SP);
        end
        
        % reinitialize the durations cell array
        metrics={};

        % increment the counter which counts all of the variables which
        % have been processed
        e1=e1+1;

        % sub_mean2 program interpolates to create a running average
        % pressure then subtracts the running average pressure
        if max(size(SP)) > 0
            [SP]=sub_mean2(SP, Fs_SP, 25);
        end

        % Currently this program does not contian any programs 
        % specifically for impulsive vibrations.
        % 
        %if max(size(vibs)) > 0
        %    [vibs]=vibs-mean(vibs, 2)*ones(1, size(vibs, 2));
        %end

        metrics={};

        if exist('SP','var') == 1 && length(SP) > 1
            
            filename1=filenamesin{e6};
            
            fprintf(1, '%s\r', ['Processing file ', num2str(e6), '   ', filename1, ' Variable ', num2str(e7) ]);
            % minimum peak preessure to be an impulsive noise

            num_pts_per_pk_intrl=floor(peak_interval*Fs_SP);

            if num_pts_per_pk_intrl < 1
                num_pts_per_pk_intrl=1;
            end

            if num_pts_per_pk_intrl > max(size(SP))
                num_pts_per_pk_intrl=max(size(SP));
            end
            
            
            % plot the peak values and calculate the impulsive metrics
            [h, h2, indices2]=plotpeaks(SP, Fs_SP, num_pts_per_pk_intrl, make_plot, Tool_Name, [filename1 ' var ', num2str(e7)], same_ylim, min_peak, sar, plot_str, Align_peaks, peak_alignment_tol, percent1, exhaust_cycle );
            
            % This program calculates all of the impulsive noise metrics
            N=3;
            min_f=20;
            max_f=20000;
            ear_model=ones(m1, 1);
            [metrics, metric_str, metric_units, AHAAH_str, round_kind, round_digits]=snd_peak_metrics(SP, Fs_SP, indices2, num_pts_per_pk_intrl, N, min_f, max_f, ear_model);
            
            round_kind2=[1 round_kind];
            round_digits2=[3 round_digits];
            
            % Get the number of metrics
            num_metrics=size(metrics{1, 1}, 2);
            
            % Get the number of channels
            % metrics is a cell array of size [num_channels, 1]
            % each cell within metrics contains a 2d array of metrics
            % of size {num_impulses, num_metrics}
            msd=size(metrics, 1); 

            figure(1);
            for e2=1:length(h2);
                axes(h2(e2));
            end

            % Save the plot of the time rcords identifying the impulsive peaks
            % change the filename for each file and variable.  
            if save_plot == 1
                for e2=1:length(fig_format);
                    save_a_plot2_audiological(fig_format(e2), [filename1(1:(length(filename1)-4)), '_peaks_var_', num2str(e7) ], portrait_landscape);
                end
            end
            
            fprintf(fid, 'filename\t%s\r\n', filename1, ' Variable ', num2str(e7) );

            abs_metrics=[3 4 5];

            num_peaks=length(metrics{1}(:, 1));
            ba2=cell(msd, num_metrics);
            
            for e4=1:num_metrics;
                for e2=1:msd;
                    num_peaks=length(metrics{e2}(:, 1));
                    buf=ones(num_peaks, 1);
                    for e3=1:num_peaks;
                        buf(e3, 1)=metrics{e2,1}(e3, e4);
                    end
                    
                    ba2{e2, e4}=buf;
                    
                end
            end
            
            % use the data outliers program to statistically evaluate the data
            % Call data_outliers using the cell array format which allows
            % for a different number of peaks for each channel
            % print data to a file using the fid
            
            abs_rta=1;
            abs_other=[ 0 0 1 1 1 zeros(1, num_metrics-5)];

            metric_str2=cell(1, num_metrics+1);
            metric_units2=cell(1, num_metrics+1);
            
            metric_str2{1}=metric_str{6};
            metric_units2{1}=metric_units{6};
            
            for e4=1:num_metrics;
                metric_str2{e4+1}=metric_str{e4};
                metric_units2{e4+1}=metric_units{e4};
            end
            
            
            % Outliers are identified for all
            % metric arrays independently.
            dep_var=0;
            
            function_str='data_outliers3(ba2(1:msd,6), dep_var, round_kind2, round_digits2, abs_rta, abs_other, sod, 2, fid, 1, row_names, row_unit, col_name, metric_str2, metric_units2';
            
            for e4=1:num_metrics;
                function_str=[function_str, ', ba2(1:msd, ', num2str(e4), ')'];
            end
            
            function_str=[function_str,' )'];
                
            [ptsa, nptsa, rt_stats, other_stats, rt_outlier_stats, other_outlier_stats]=eval(function_str);
            
            fprintf(fid, '\r\n');
            
            
            % These four lines of voided code are present to identify
            % data_outliers as a dependent function.
            void_call=0;
            if void_call
                data_outliers3(0);
            end
            
            
            % Print the same information from the data_outliers program,
            % but print the data horizontally.
            for e2=1:msd;
                sizedur=size(metrics{e2});
                fprintf(fid, ['Microphone Channel ' num2str(e2), ' \r\n']);
                fprintf(fid, '\tPeak Number\t');

                % Print the names of the metrics
                for e3=1:length(metric_str);
                    fprintf(fid, '%s\t', metric_str{e3});
                end
                
                fprintf(fid,'\r\n\t\t');
                
                % Print the units of the metrics
                for e3=1:length(metric_str);
                    fprintf(fid, '%s\t', metric_units{e3});
                end
                
                fprintf(fid,'\r\n');
                
                format_str='\t%i\t%i\t%f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%f\t%f\t%f\t%f\t%f\t%3.2f';
                
                for e3=1:(num_metrics-20);
                    format_str=[format_str, '\t%f'];
                end
                
                format_str=[format_str, '\t\r\n'];
                fprintf(fid,'Data');
                fprintf(fid, format_str, [(1:sizedur(1))' metrics{e2}]');
                [m1, n11]=size(metrics{e2});
                fprintf(fid,'Descriptive Statistics');
                
                for e5=1:num_stats;
                    
                    buf2=zeros(1, n11);
                    for e4=1:n11;
                        buf2(1, e4)=other_stats(e4, e2, e5);
                    end
                    fprintf(fid, '\t%s', stat_str{e5});
                    fprintf(fid, format_str(5:end), buf2');
                    
                end
                fprintf(fid, '\r\n');
                
                % List the indices of the data outlier
                if ~isequal(sod, 1) && logical(numel(other_outlier_stats) >= max([n11*num_stats*msd, 1])) 
                    fprintf(fid, '%s\t%s\t', 'Data Outliers', 'Microphone Indices');

                    [fid]=print_outliers_indices(nptsa(e2, 2:end), fid);

                    fprintf(fid, '\r\n');
                    fprintf(fid, '\r\n');

                    for e5=1:num_stats;

                        buf2=zeros(1, n11);
                        for e4=1:n11;
                            buf2(1, e4)=other_outlier_stats(e4, e2, e5);
                        end
                        fprintf(fid, '\t%s', stat_str{e5});
                        fprintf(fid, format_str(5:end), buf2');

                    end
                    fprintf(fid, '\r\n');

                end
                
                
            end

            fprintf(fid, '\r\n');
            fprintf(fid, '\r\n');
        end
        
        % md stands for "metrics description"
        md=cell(2, length(metric_str));
        
        for e2=1:length(metric_str);
            md{1, e2}=metric_str{e2};
            md{2, e2}=metric_units{e2};
        end
        
        % A cell array of data structures is formed to collect the data for each 
        % file and each variable for each peak.  
        s{e6, e7}.filename=filenamesin{e6};
        s{e6, e7}.variable=e7;
        s{e6, e7}.metrics=metrics;
        s{e6, e7}.stats_of_metrics=other_stats;
        s{e6, e7}.stats_of_outliers_metrics=other_outlier_stats;
        s{e6, e7}.metrics_description=md;
        s{e6, e7}.stats_description=stat_str;
        
        
    end
    
end

if save_struct == 1
    save(fileout_struct, 's');
end

fclose(fid);
fclose('all');


⌨️ 快捷键说明

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