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

📄 data_loader2.m

📁 我认为很不错的语音处理的matlab源代码
💻 M
📖 第 1 页 / 共 4 页
字号:
                    % using data structures.
                    %
                    % It is better for the Matlab user to write their own
                    % data loader program if they are using structures.
                    
                    data_vars=[];
                    % make a list of the data variable names containing
                    % numeric data
                    for e1=1:length(bb);
                        data_class=bb(e1).class;

                        % make sure the data variables are numeric
                        bb3=strmatch(data_class, cl_n, 'exact');

                        % make sure the data variables are not empty
                        data_not_empty=(max(bb(e1).size) > 0);

                        if ~isempty(bb3) && data_not_empty
                            data_vars=[data_vars e1];
                        end
                        
                    end

                    % get the data variable names
                    if ~isempty(data_vars)
                        num_data_vars=length(data_vars);
                        var_names=cell(num_data_vars, 1);

                        % var_names is a cell array of the data variable
                        % names.
                        for e1=1:num_data_vars;
                            var_names{e1}=bb(data_vars(e1)).name;
                        end
                        prompt_string1={'Select (highlight) all of the Data Variables', 'Only Select Variables containing Sound and Vibrations', 'Do not choose the Time Increment or Sampling Rate variables'};
                        [data_var_ix,ok] = listdlg('Name', 'Select the Data Variables', 'PromptString', prompt_string1, 'SelectionMode', 'multiple', 'ListSize', [500, 500],'ListString', var_names);

                        if isequal(ok, 1)

                            select_data_var=data_vars(data_var_ix);

                            % update the data_vars2 array
                            ix_set=setdiff(1:num_data_vars, data_var_ix);
                            data_vars2=data_vars(ix_set);

                            num_data_vars2=length(data_vars2);
                            var_names2=cell(num_data_vars2, 1);

                            % update the var_names2
                            for e1=1:num_data_vars2;
                                var_names2{e1}=bb(data_vars2(e1)).name;
                            end

                        else
                            select_data_var=[];
                            var_names2=var_names;
                            data_vars2=data_vars;
                        end

                        num_select_data_var=length(select_data_var);

                        prompt=cell(num_select_data_var,1);
                        defAns=cell(num_select_data_var,1);

                        % determine if each data variable contains
                        % sound data
                        % vibrations data
                        % both sound and vibrations
                        % neither
                        %
                        for e1=1:num_select_data_var;
                            prompt{e1, 1}=['Variable Name "', bb(select_data_var(e1)).name, '". Enter s for sound, v for vibrations, b for both, n for none'];
                            switch e1
                                case 1
                                    defAns{e1, 1}='s';
                                case 2
                                    defAns{e1, 1}='v';
                                otherwise
                                    defAns{e1, 1}='n';
                            end
                        end

                        dlg_title='Data Variable Type, s, v, n';
                        num_lines=1;

                        % The inputdlg prompts the user to specify the sensors for each
                        % channel
                        datatype_str=inputdlg(prompt,dlg_title,num_lines,defAns);

                        % convert the data_type string into integers
                        data_type=zeros(num_select_data_var, 1);
                        for e1=1:num_select_data_var;
                            switch datatype_str{e1}
                                case 's'
                                    data_type(e1)=1;
                                case 'v'
                                    data_type(e1)=2;
                                case 'b'
                                    data_type(e1)=3;
                                otherwise
                                    data_type(e1)=4;
                            end
                        end

                        snd_var=select_data_var(find(data_type == 1));
                        vibs_var=select_data_var(find(data_type == 2));
                        both_var=select_data_var(find(data_type == 3));

                        num_snd_vars=length(snd_var);
                        num_vibs_vars=length(vibs_var);
                        num_both_vars=length(both_var);

                        % store the sound variables in the configuration
                        % cell array
                        snd_var_name=cell(num_snd_vars, 1);
                        for e1=1:num_snd_vars;
                            snd_var_name{e1, 1}=bb(snd_var(e1)).name;
                        end

                        % cell array of sound variable names
                        default_mat_config_out{1,1}=snd_var_name;

                        vibs_var_name=cell(num_vibs_vars, 1);
                        for e1=1:num_vibs_vars;
                            vibs_var_name{e1, 1}=bb(vibs_var(e1)).name;
                        end

                        % cell array of vibs variable names
                        default_mat_config_out{2,1}=vibs_var_name;

                        both_var_name=cell(num_both_vars, 1);
                        for e1=1:num_both_vars;
                            both_var_name{e1, 1}=bb(both_var(e1)).name;
                        end

                        % cell array of both variable names
                        default_mat_config_out{3,1}=both_var_name;

                    end


                    % For the data variables that have both microphone and
                    % accelerometer data.  Each channel can only be a 
                    % microphone or an accelerometer.  Teh user will input 
                    % whether a channel is a microphone or an 
                    % accelerometer.  The channels which are microphones 
                    % will be grouped together.  The channels which are 
                    % accelerometers will be grouped together.  
                    % 
                    both_snd_ch=cell(num_both_vars, 1);
                    both_vibs_ch=cell(num_both_vars, 1);


                    if num_both_vars > 0
                        for e1=1:num_both_vars;
                            buf=bb(both_var(e1)).size;
                            bvm1=buf(1);
                            bvn1=buf(2);
                            num_channels=min(bvm1, bvn1);

                            % The variable contains both sound and
                            % vibrations data; however, the sensor is
                            % either a microphone or an accelerometer.
                            % 
                            % prompt the user for which channels are microphones and
                            % accelerometers
                            prompt=cell(num_channels,1);
                            defAns=cell(num_channels,1);

                            for e2=1:num_channels;
                                prompt{e2, 1}=['For Channel ', num2str(e2), ' :  Enter s for sound or v for vibrations'];
                                defAns{e2, 1}='s';
                            end
                            dlg_title=['For Variable Named "', both_var_name{e1, 1}, '": Enter the Input Sensor Type, s or v'];
                            num_lines=1;

                            % The inputdlg prompts the user to specify the sensors for each
                            % channel
                            datatype_str=inputdlg(prompt,dlg_title,num_lines,defAns);
                            data_type=ones(num_channels, 1);

                            for e2=1:num_channels;
                                k = strfind(datatype_str{e2}, 's');
                                if ~isempty(k)
                                    data_type(e2)=1;
                                else
                                    data_type(e2)=0;
                                end
                            end

                            % Calculate the number of microphones and accelerometers
                            both_snd_ch{e1, 1}=find(data_type == 1);
                            both_vibs_ch{e1, 1}=find(data_type == 0);

                        end
                    end

                    default_mat_config_out{3,4}=both_snd_ch;
                    default_mat_config_out{3,5}=both_vibs_ch;

                    % Get the Time Increment or Sampling Rate variable 
                    % names.
                    % 
                    % tosr is an acronym for Time increment Or Sampling
                    % Rate
                    
                    num_data_vars2=length(data_vars2);
                    var_names2=cell(num_data_vars2, 1);

                    for e1=1:num_data_vars2;
                        var_names2{e1}=bb(data_vars2(e1)).name;
                    end
                    
                    prompt_string2={'Select the Time Increment and Sampling Rate Variables:', 'Time Increment is the delta t (s)', 'Time Increment can be constant delta t or a vector of constant delta t', 'Sampling rate is a constant 1/delta t (Hz)', 'If Sampling rate is a vector, then the difference in the first two elements is used'};
                    % tosr acronym for (time or sampling rate)
                    [tosr_var, ok] = listdlg('Name', 'Choose the Time Increment or Rate Variables.', 'PromptString', prompt_string2, 'SelectionMode', 'multiple', 'ListSize', [500, 500], 'ListString', var_names2);

                    % If there are not any time or frequency variables prompt user
                    % to input the sampling rate for each data variable.  
                    if isempty(tosr_var) || isequal(ok, 0)
                        
                        snd_tosr_bool={};
                        Fs_SP={};
                        vibs_tosr_bool={};
                        Fs_vibs={};
                        both_tosr_bool={};
                        Fs_both={};
                            
                        % Enter the sampling rates for the sound variables
                        if num_snd_vars > 0
                            prompt=cell(num_snd_vars,1);
                            defAns=cell(num_snd_vars,1);
                            snd_tosr_bool=cell(num_snd_vars,1);
                            for e1=1:num_snd_vars;
                                snd_tosr_bool{e1}=0;
                                prompt{e1, 1}=['Enter the Sampling Rate (Hz) for the Sound Variable Named "', default_mat_config_out{1,1}{e1,1}, '"'];
                                defAns{e1, 1}='50000';
                            end
                            dlg_title='Enter the Sampling Rate (Hz) for each Sound Variable.';
                            num_lines=1;

                            Fs_SP_var=inputdlg(prompt,dlg_title,num_lines,defAns);
                            num_Fs_SP=length(Fs_SP_var);
                            Fs_SP=cell(num_Fs_SP, 1);
                            for e1=1:num_Fs_SP;
                                Fs_SP{e1}=str2double(Fs_SP_var{e1});
                            end
                        end
                        
                        % Enter the sampling rates for the vibrations variables
                        if num_vibs_vars > 0
                            prompt=cell(num_vibs_vars,1);
                            defAns=cell(num_vibs_vars,1);
                            vibs_tosr_bool=cell(num_vibs_vars,1);
                            for e1=1:num_vibs_vars;
                                vibs_tosr_bool{e1}=0;
                                prompt{e1, 1}=['Enter Sampling Rate (Hz) for the Vibrations Variable Named "', default_mat_config_out{2,1}{e1,1}, '"'];
                                defAns{e1, 1}='5000';
                            end
                            dlg_title='Enter the Sampling Rate (Hz) for each Vibrations Variable';
                            num_lines=1;

                            Fs_vibs_var=inputdlg(prompt,dlg_title,num_lines,defAns);
                            num_Fs_vibs=length(Fs_vibs_var);
                            Fs_vibs=cell(num_Fs_vibs, 1);
                            for e1=1:num_Fs_vibs;
                                Fs_vibs{e1}=str2double(Fs_vibs_var{e1});
                            end

⌨️ 快捷键说明

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