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

📄 data_loader2.m

📁 我认为很不错的语音处理的matlab源代码
💻 M
📖 第 1 页 / 共 4 页
字号:
                        end
                        
                        % Enter the sampling rates for the both sound and vibrations variables
                        if num_both_vars > 0
                            prompt=cell(num_both_vars,1);
                            defAns=cell(num_both_vars,1);
                            both_tosr_bool=cell(num_both_vars,1);
                            for e1=1:num_both_vars;
                                both_tosr_bool{e1}=0;
                                prompt{e1, 1}=['Enter the Sampling Rate (Hz) for the Variable Named "', default_mat_config_out{3,1}{e1,1}, '"'];
                                defAns{e1, 1}='50000';
                            end
                            dlg_title='Enter Sampling Rates (Hz) for the Variables with Both Sound and Vibrations';
                            num_lines=1;

                            Fs_both_var=inputdlg(prompt,dlg_title,num_lines,defAns);
                            num_Fs_both=length(Fs_both_var);
                            Fs_both=cell(num_Fs_both, 1);
                            for e1=1:num_Fs_both;
                                Fs_both{e1}=str2double(Fs_both_var{e1});
                            end
                            
                        end
                        
                        % Store sampling rate arrays to the
                        % configuration cell array
                        default_mat_config_out{1,2}=Fs_SP;
                        default_mat_config_out{2,2}=Fs_vibs;
                        default_mat_config_out{3,2}=Fs_both;
                        
                        default_mat_config_out{1,3}=snd_tosr_bool;
                        default_mat_config_out{2,3}=vibs_tosr_bool;
                        default_mat_config_out{3,3}=both_tosr_bool;
                        
                    else

                        num_tosr_var=length(tosr_var);
                        tosr_var_names=cell(num_tosr_var, 1);

                        for e1=1:num_tosr_var;
                            tosr_var_names{e1}=var_names2{tosr_var(e1)};
                        end

                        % determine if the variables are time or sampling rate variables.
                        % tosr_bool1: 1 is time increment otherwise is sampling rate
                        % default is time increment
                        tosr_bool1=ones(num_tosr_var, 1);
                        for e1=1:num_tosr_var;
                            tosr_bool1(e1) = menu(['Is the variable Named "', tosr_var_names{e1} ,'" a Time Increment or Sampling Rate?'], 'Time Increment', 'Sampling Rate');
                        end

                        % determine the correspondence between data variables and
                        % Time or Sampling Rate variables
                        snd_tosr_var=cell(num_snd_vars, 1);
                        snd_tosr_bool=cell(num_snd_vars, 1);
                        for e1=1:num_snd_vars;
                            prompt_string3={['For the Sound Variable Named "', default_mat_config_out{1,1}{e1,1}, '"'] , 'Choose the corresponding Time increment or Sampling Rate Variable', 'Time Increment is the delta t (s), can be constant or vector', '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'};
                            [buf,ok] = listdlg('Name', 'Choose the corresponding Time Increment or Sampling Rate Variable', 'PromptString', prompt_string3, 'SelectionMode', 'single', 'ListSize', [500, 500], 'ListString',  tosr_var_names);
                            if ok
                                snd_tosr_var{e1}=tosr_var_names{buf};
                                snd_tosr_bool{e1}=tosr_bool1(buf);
                            else
                                snd_tosr_var{e1}={};
                                snd_tosr_bool{e1}=[];
                            end
                        end

                        vibs_tosr_var=cell(num_vibs_vars, 1);
                        vibs_tosr_bool=cell(num_vibs_vars, 1);
                        for e1=1:num_vibs_vars;
                            prompt_string3={['For the Vibrations Variable Named "', default_mat_config_out{2,1}{e1,1}, '"'] , 'Choose the Corresponding Time Increment or Sampling Rate Variable', 'Time Increment is the delta t (s), can be constant or vector', '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'};
                            [buf,ok] = listdlg('Name', 'Choose the Corresponding Time Increment or Sampling Rate Variable', 'PromptString', prompt_string3, 'SelectionMode', 'single', 'ListSize', [500, 500], 'ListString',  tosr_var_names);
                            if ok
                                vibs_tosr_var{e1}=tosr_var_names{buf};
                                vibs_tosr_bool{e1}=tosr_bool1(buf);
                            else
                                vibs_tosr_var{e1}={};
                                vibs_tosr_bool{e1}=[];
                            end
                        end

                        both_tosr_var=cell(num_both_vars, 1);
                        both_tosr_bool=cell(num_both_vars, 1);
                        for e1=1:num_both_vars;
                            prompt_string3={['For the Variable for both Sound and Vibrations Named "', default_mat_config_out{3,1}{e1,1}, '"'] , 'Choose the Corresponding Time Increment or Sampling Rate Variable', 'Time Increment is the delta t (s), can be constant or vector', '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'};
                            [buf,ok] = listdlg('Name', 'Choose the Corresponsing Time Increment or Sampling Rate Variable', 'PromptString', prompt_string3, 'SelectionMode','single', 'ListSize', [500, 500],'ListString',  tosr_var_names);
                            if ok
                                both_tosr_var{e1}=tosr_var_names{buf};
                                both_tosr_bool{e1}=tosr_bool1(buf);
                            else
                                both_tosr_var{e1}={};
                                both_tosr_bool{e1}=[];
                            end
                        end

                        default_mat_config_out{1,2}=snd_tosr_var;
                        default_mat_config_out{2,2}=vibs_tosr_var;
                        default_mat_config_out{3,2}=both_tosr_var;

                        default_mat_config_out{1,3}=snd_tosr_bool;
                        default_mat_config_out{2,3}=vibs_tosr_bool;
                        default_mat_config_out{3,3}=both_tosr_bool;
                    end


                    % Print the variable configuration Here
                    [out]=print_data_loader_configuration_table(default_mat_config_out);
                    
                    
                    keep_config=menu('Was the Variable Configuration Entered Correctly?', 'Keep Configuration', 'Redo Variable Configuration' );
                    close (out);
                    
                end

                automatic_cal=menu('Use Variable Name Configuration into Sound and Vibration data, Time Increment and Sampling Rate Variables for all files?', 'Yes', 'No');

                default_mat_config_out{4,1}=automatic_cal;
            end

            % load matlab file
            load(filename);

            % check the configuration of the data
            bool_config=ones(3,2);
            bool_config2=ones(3, 1);
            for e1=1:3;
                for e2=1:3;
                    if iscell(default_mat_config_out{e1,e2})
                        if  length(default_mat_config_out{e1,e2}) < 1
                            bool_config(e1, e2)=0;
                        else
                            if iscell(default_mat_config_out{e1,e2}{1,1})
                                if  length(default_mat_config_out{e1,e2}{1,1}{1,1}) < 1
                                    bool_config(e1, e2)=0;
                                else
                                    if iscell(default_mat_config_out{e1,e2}{1,1}{1,1})
                                        bool_config(e1, e2)=0;
                                    else
                                        if ~isempty(default_mat_config_out{e1,e2}{1,1}{1,1})
                                            bool_config(e1, e2)=1;
                                        else
                                            bool_config(e1, e2)=0;
                                        end
                                    end
                                end
                            else
                                if ~isempty(default_mat_config_out{e1,e2}{1,1})
                                    bool_config(e1, e2)=1;
                                else
                                    bool_config(e1, e2)=0;
                                end
                            end
                        end
                    else
                        if ~isempty(default_mat_config_out{e1,e2})
                            bool_config(e1, e2)=1;
                        else
                            bool_config(e1, e2)=0;
                        end
                    end
                end
                bool_config2(e1, 1)=prod(bool_config(e1, :));
            end


            % Transfer the data from the variables with the original names 
            % to cell array with a preprogrammed name.  

            % Determine the number of sound variables that can be loaded
            % correctly

            % Append the sound data to a cell array
            % Append the sound sampling rates to a cell array
            SP_var={};
            Fs_SP_var={};

            if isequal(bool_config2(1,1), 1)

                num_snd_vars=length(default_mat_config_out{1,1});
                num_snd_tosr_vars=length(default_mat_config_out{1,2});
                num_snd_tosr_bools=length(default_mat_config_out{1,3});
                num_snd_vars=min([num_snd_vars, num_snd_tosr_vars, num_snd_tosr_bools]);

                SP_var=cell(num_snd_vars, 1);
                Fs_SP_var=cell(num_snd_vars, 1);

                for e1=1:num_snd_vars;

                    SP_var_buf=eval(default_mat_config_out{1,1}{e1,1});

                    [svb_m1, svbn1]=size(SP_var_buf);
                    if svb_m1> svbn1
                        SP_var_buf=SP_var_buf';
                        [svb_m1, svbn1]=size(SP_var_buf);
                    end
                    SP_var{e1}=SP_var_buf;

                    if ischar(default_mat_config_out{1,2}{e1,1})
                        Fs_buf=eval(default_mat_config_out{1,2}{e1,1});
                    else
                        Fs_buf=default_mat_config_out{1,2}{e1,1};
                    end

                    if max(size(Fs_buf)) > 1
                        Fs_buf=Fs_buf(2)-Fs_buf(1);
                    else
                        Fs_buf=Fs_buf(1);
                    end

                    if isequal(default_mat_config_out{1,3}{e1, 1}, 1)
                        Fs_SP_var{e1}=1./Fs_buf;
                    else
                        Fs_SP_var{e1}=Fs_buf;
                    end

                end

            end

            % Append the vibrations data to a cell array
            % Append the vibrations sampling rates to a cell array
            vibs_var={};
            Fs_vibs_var={};

            if isequal(bool_config2(2,1), 1)

                num_vibs_vars=length(default_mat_config_out{2,1});
                num_vibs_tosr_vars=length(default_mat_config_out{2,2});
                num_vibs_tosr_bools=length(default_mat_config_out{2,3});
                num_vibs_vars=min([num_vibs_vars, num_vibs_tosr_vars, num_vibs_tosr_bools]);


                vibs_var=cell(num_vibs_vars, 1);
                Fs_vibs_var=cell(num_vibs_vars, 1);

                for e1=1:num_vibs_vars;

                    vibs_var_buf=eval(default_mat_config_out{2,1}{e1,1});

                    [vvb_m1, vvbn1]=size(vibs_var_buf);
                    if vvb_m1> vvbn1
                        vibs_var_buf=vibs_var_buf';
                        [vvb_m1, vvbn1]=size(vibs_var_buf);
                    end
                    vibs_var{e1}=vibs_var_buf;

                    if ischar(default_mat_config_out{2,2}{e1,1})
                        Fs_buf=eval(default_mat_config_out{2,2}{e1,1});
                    else
                        Fs_buf=default_mat_config_out{2,2}{e1,1};
                    end

                    if max(size(Fs_buf)) > 1
                        Fs_buf=Fs_buf(2)-Fs_buf(1);
                    else
                        Fs_buf=Fs_buf(1);
                    end

                    if isequal(default_mat_config_out{2,3}{e1, 1}, 1)
                        Fs_vibs_var{e1}=1./Fs_buf;
                    else
                        Fs_vibs_var{e1}=Fs_buf;
                    end

                end

            end

⌨️ 快捷键说明

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