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

📄 data_loader2.m

📁 我认为很不错的语音处理的matlab源代码
💻 M
📖 第 1 页 / 共 4 页
字号:


            % Append the both data to a cell array
            % Append the both sampling rates to a cell array
            if isequal(bool_config2(3,1), 1)

                num_both_vars=length(default_mat_config_out{3,1});
                num_both_tosr_vars=length(default_mat_config_out{3,2});
                num_both_tosr_bools=length(default_mat_config_out{3,3});
                num_both_vars=min([num_both_vars, num_both_tosr_vars, num_both_tosr_bools]);

                for e1=1:num_both_vars;

                    both_var=eval(default_mat_config_out{3,1}{e1,1});

                    [bv_m1, bvn1]=size(both_var);
                    if bv_m1 > bvn1
                        both_var=both_var';
                        [bv_m1, bvn1]=size(both_var);
                    end

                    if ischar(default_mat_config_out{3,2}{e1,1})
                        Fs_buf=eval(default_mat_config_out{3,2}{e1,1});
                    else
                        Fs_buf=default_mat_config_out{3,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{3,3}{e1, 1}, 1)
                        Fs_both_var=1./Fs_buf;
                    else
                        Fs_both_var=Fs_buf;
                    end

                    both_snd_ch=default_mat_config_out{3,4}{e1,1};

                    if length(both_snd_ch) > 1

                        buf=(both_snd_ch > 0);

                        if isequal(all(buf), 1)
                            SP_m1=length(SP_var);
                            SP_var{SP_m1+1}=both_var(both_snd_ch, :);
                            Fs_SP_var{SP_m1+1}=Fs_both_var;
                        end
                    end

                    both_vibs_ch=default_mat_config_out{3,5}{e1,1};

                    if length(both_vibs_ch) > 1

                        buf=(both_vibs_ch > 0);

                        if isequal(all(buf), 1)
                            vibs_m1=length(vibs_var);
                            vibs_var{vibs_m1+1}=both_var(both_vibs_ch, :);
                            Fs_vibs_var{vibs_m1+1}=Fs_both_var;
                        end
                    end

                end

            end
            
            % Data may be stored in single precision or other formats
            % and must be changed to double precision to be processed 
            % by Matlab. 
            
            SP=cell(length(SP_var), 1);
            for e1=1:length(SP_var);
                [buf]=convert_double(SP_var{e1});
                SP_var{e1}=[];
                SP{e1}=buf;
            end

            vibs=cell(length(vibs_var), 1);
            for e1=1:length(vibs_var);
                [buf]=convert_double(vibs_var{e1});
                vibs_var{e1}=[];
                vibs{e1}=buf;
            end

            Fs_SP=cell(length(Fs_SP_var), 1);
            for e1=1:length(Fs_SP_var);
                [buf]=convert_double(Fs_SP_var{e1});
                Fs_SP_var{e1}=[];
                Fs_SP{e1}=buf;
            end

            Fs_vibs=cell(length(Fs_vibs_var), 1);
            for e1=1:length(Fs_vibs_var);
                [buf]=convert_double(Fs_vibs_var{e1});
                Fs_vibs_var{e1}=[];
                Fs_vibs{e1}=buf;
            end
            

        case 'wav'
            % Read the wave file
            % y is the data
            % fs is the sampling rate
            [y, fs, nbits, opts] = wavread(filename);

            [num_data, num_channels]=size(y);

            cal_snd=[];
            cal_vibs=[];
            Fs_SP=fs;
            Fs_vibs=fs;
            keep_config=2;

            % Determine whether to use the automated configuration
            if ~isequal(default_wav_settings_in{4,1}, 1)

                while keep_config == 2

                    % prompt the user for which channels are microphones and
                    % accelerometers
                    prompt=cell(num_channels,1);
                    defAns=cell(num_channels,1);

                    for e1=1:num_channels;
                        prompt{e1, 1}=['For Channel ', num2str(e1), ', Enter: s for sound, v for vibrations'];
                        defAns{e1, 1}='s';
                    end
                    dlg_title='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 e1=1:num_channels;
                        k = strfind(datatype_str{e1}, 's');
                        if ~isempty(k)
                            data_type(e1)=1;
                        else
                            data_type(e1)=0;
                        end
                    end

                    % Calculate the number of microphones and accelerometers
                    num_snd=length(data_type(data_type==1));
                    num_vibs=length(data_type(data_type==0));

                    if num_snd+num_vibs < num_channels
                        data_type=ones(num_channels, 1);
                        num_vibs=0;
                        num_snd=num_channels;
                    end

                    % get the calibration sensitivities for each sound channel
                    if num_snd > 0
                        prompt=cell(num_snd, 1);
                        defAns=cell(num_snd, 1);

                        for e1=1:num_snd;
                            prompt{e1, 1}=['Mic ', num2str(e1), ', Scale factor from Wave File to Pa, (WaveScale/Pa)'];
                            defAns{e1, 1}=num2str(40.00, 1);
                        end

                        dlg_title='For the Sound Sensor, Enter the scale factor to convert from wave file scale to Pa.';
                        num_lines=1;

                        cal_snd_str=inputdlg(prompt,dlg_title,num_lines,defAns);
                        cal_snd=ones(num_snd, 1);

                        for e1=1:num_snd;
                            cal_snd(e1)=str2double(cal_snd_str{e1});
                        end
                    end

                    % get the calibration sensitivities for each accelerometer
                    % channel

                    if num_vibs > 0
                        prompt=cell(num_vibs, 1);
                        defAns=cell(num_vibs, 1);

                        for e1=1:num_vibs;
                            prompt{e1, 1}=['Accel ', num2str(e1), ', Scale factor from Wave File to g''s, (WaveScale/g)'];
                            defAns{e1, 1}=num2str(10.00, 1);
                        end

                        dlg_title='For the Accelerometer Enter the Scale factor to convert from the Wave file scale to g''s, (WaveScale/g).  The program converts from g''s to to m/s^2 ';
                        num_lines=1;

                        % The inputdlg prompts the user to specify the calibration
                        % sensitivities
                        cal_vibs_str=inputdlg(prompt,dlg_title,num_lines,defAns);
                        cal_vibs=ones(num_vibs, 1);

                        for e1=1:num_vibs;
                            cal_vibs(e1)=str2double(cal_vibs_str{e1});
                        end
                    end

                    keep_config=menu('Keep Sensor Scale Factors Configuration for each variable', 'Yes', 'No');
                end

                automatic_cal=menu('Use Variable Configuration for each of the data files', 'Yes', 'No');

            else

                % Apply the input settings
                data_type=default_wav_settings_in{1, 1};
                cal_snd=default_wav_settings_in{2, 1};
                cal_vibs=default_wav_settings_in{3, 1};
                automatic_cal=default_wav_settings_in{4, 1};

                % Calculate the number of microphones and accelerometers
                num_snd=length(data_type(data_type==1));
                num_vibs=length(data_type(data_type==0));

            end

            % Set the output settings
            default_wav_settings_out{1,1}=data_type;
            default_wav_settings_out{2,1}=cal_snd;
            default_wav_settings_out{3,1}=cal_vibs;
            default_wav_settings_out{4,1}=automatic_cal;

            [cal_snd_a]=meshgrid(cal_snd, 1:num_data );
            [cal_vibs_a]=meshgrid(cal_vibs, 1:num_data );

            % Calibrate the wave files and convert to engineering units
            if num_snd > 0
                SP=1./cal_snd_a.*y(:, data_type==1);            % Pa
            else
                SP=[];                                          % Pa
            end

            if num_vibs > 0
                vibs=9.806./cal_vibs_a.*y(:, data_type==0);     % m/s^2
            else
                vibs=[];                                         % m/s^2
            end

        otherwise

    end

end

[m1 n1]=size(SP);

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

[m1 n1]=size(vibs);

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

⌨️ 快捷键说明

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