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

📄 data_loader2.m

📁 我认为很不错的语音处理的matlab源代码
💻 M
📖 第 1 页 / 共 4 页
字号:
function [SP, vibs, Fs_SP, Fs_vibs, default_wav_settings_out, default_mat_config_out]=data_loader2(filename, default_wav_settings_in, default_mat_config_in)
% % data_loader2:  Loads data specified as sound or vibrations and further specified as data, time increment or sampling rate  
% % 
% % Syntax;
% % 
% % [SP, vibs, Fs_SP, Fs_vibs, default_wav_settings_out, default_mat_config_out]=data_loader2(filename, default_wav_settings_in, default_mat_config_in)
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% % Description
% % 
% % data_loader2.m loads data stored in a matlab file or a wave file
% %
% % If the file is a wave file it is loaded 
% % Then the user is prompted to specify which tracks are sound and
% % which are vibrations.  
% % 
% % Then the user is prompted for the calibration sensitivies for each
% % channel listed by accelerometer channels and microphone channels. 
% %  
% %
% % This program finds the numeric variables stored in the 
% % specified data file then prompts the user to select the data variables 
% % 
% % Then the user is prompted to specify whether each variable is by
% % typing a single letter for each variable in the dialog box input
% % 
% % s for sound 
% % v for vibrations
% % b for both 
% % n for neither
% % 
% % In the case of both sound and vibrations the user is prompted to
% % specify which channels are sound and which channels are vibrations 
% % 
% % Then the program prompts the user to select the time or sampling rate
% % variables.  These variables are used to specify the sampling rate for
% % each data variable.
% % 
% % The user is prompted to relate each data variable to the corresponding
% % time or sampling rate variable.  
% % 
% % If there are no time or sampling rate variables then the program 
% % prompts the user to enter the sampling rates for each data variable.  
% %
% % 
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% % Input Variables
% % 
% % 
% % filename='test.mat';        % Character Array, (String) including the 
% %                             % extension.  The program will terminate 
% %                             % if the extension is needed and missing.
% % 
% % default_wav_settings_in 
% %                             % used to automatically select sensor types
% %                             % and specify the calibration sensitivities
% %                             % default is to set the values to
% %                             % the user entered data from the dialog
% %                             % boxes then use the code
% %                             % see the example for more details
% % 
% % default_mat_config_in
% %                             % used to automatically match the data variables
% %                             % with the sensor types 
% %                             % specify the time or sampling rate
% %                             % variables
% %                             % match the data variables with the 
% %                             % time or sampling rate
% %                             % The best way to set the valeus is to 
% %                             % run the file through the program then  
% %                             % run the code
% %                             % see the example for more details
% %  
% %  
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Output Variables
% %
% % SP={};        % Pa Sound pressure
% % vibs={};      % m/s^2 acceleration
% % Fs_SP={};     % Hz smpling rate of sound pressure
% % Fs_vibs={};   % Hz smpling rate of acceleration
% %
% % 
% % default_wav_settings_out={};
% %
% %                             % used to automatically select sensor types
% %                             % and specify the calibration sensitivities
% %                             % default is to set the values to
% %                             % the user entered data from the dialog
% %                             % boxes then use the code
% % 
% % default_wav_settings_in=default_wav_settings_out;
% %
% % default_mat_config_out=cell(4, 5);
% % 
% %                             % used to automatically match the data variables
% %                             % with the sensor types 
% %                             % specify the time or sampling rate
% %                             % variables
% %                             % match the data variables with the 
% %                             % time or sampling rate
% %                             % The best way to set the valeus is to 
% %                             % run the file through the program then  
% %                             % run the code
% %
% % default_mat_config_in=default_mat_config_out;
% %
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% 
% Example=''; % for matlab data
% filename='data.mat';       % filename of the matlab file to open
% default_wav_settings_in={[1 0 ], [40.1], [10.1]};
%
%                               % used to automatically select sensor types
%                               % and specify the calibration sensitivities
%                               % default is empty cell array.
%                               % default is to prompt the user with
%                               % dialog boxes.
%                               %
% default_mat_config_in={{'SP'}, {'Fs_SP'}; {'vibs'}, {'Fs_vibs'}; {}, {}; {1}, {};};
%                               %
%                               % used to automatically select sensor types
%                               % and specify the calibration sensitivities
%                               % default is empty cell array.
%                               % default is to prompt the user with
%                               % dialog boxes.
% 
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % List of Sub Programs
% % 
% % file_extension
% % convert_double
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% % Program Written by Edward L. Zechmann
% %
% %     Date 18 December    2007
% % 
% % modified 21 December    2007    updated comments
% %                                 added use default settings
% %                                 for reading wave files
% %
% % modified  2 January     2008    added option to select the data 
% %                                 variable and time or frequency variable
% % 
% % modified  4 January     2008    added more code to find and select 
% %                                 the data variables and time or sampling
% %                                 variables.
% % 
% % modified  6 January     2008    finished the variable selection code
% %                                 and updated comments
% % 
% % modified  7 January     2008    fixed variaous bugs when configuring
% %                                 data for both sound and vibrations 
% %                                 fixed bugs for specifying sampling rates
% % 
% % modified 13 January     2008   
% % 
% % modified 13 January     2008    added the uigetfile program to take 
% %                                 care of the problem of a lack of files 
% %                                 to open.
% %                                 
% % modified  3 September   2008    Updated Comments
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Please Feel Free to Modify This Program
% % 
% % See Also: Load, Save, uigetfile
% % 

if logical(nargin < 1) || logical(length(filename ) < 1)
    [filename, pathname] = uigetfile( {  '*.mat','*.wav'},  'Select the files To Process', 'MultiSelect', 'on');
    cd(pathname);
end

% Make sure that the configuration variables exist for the wav file
if nargin < 2 || isempty(default_wav_settings_in)
    default_wav_settings_in=cell(4,1);
end

default_wav_settings_out=default_wav_settings_in;

% configuring the matlab variables is quite invovled and requires
% checking initializiing the configuration variables

% Make sure that the configuration variables exist
if nargin < 3 || isempty(default_mat_config_in)
    default_mat_config_in=cell(4,5);
end

[cfm1 cfn1]=size(default_mat_config_in);

% Make sure input automated configuration meets the minimum size
% requirements
for e1=1:4;
    for e2=1:5;
        if logical(e1 > cfm1) || logical(e2 > cfn1)
            default_mat_config_in{e1, e2}={};
        end
    end
end

default_mat_config_out=default_mat_config_in;



% Make sure that the output variables exist
SP=[];
vibs=[];
Fs_SP=[];
Fs_vibs=[];

[filename_base, ext]=file_extension(filename);

fexist=exist(filename);

if isequal(fexist, 2) && ~isempty(ext)

    switch ext

        case 'mat'

            keep_config=2;

            if ~isequal(default_mat_config_in{4,1}, 1)

                while keep_config == 2

                    % listing of some variables in the matlab file
                    SP=[];
                    vibs=[];
                    Fs_SP=[];
                    Fs_vibs=[];
                    t_SP=[];
                    t_vibs=[];
                    F_SP=[];
                    F_vibs=[];

                    % determine the variable names in the data file
                    % The case of a data structure has not been programmed
                    % yet
                    bb=whos( '-file', filename);

                    cl_n={'single', 'double', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64'};
                    
                    % make a list of the data variable names which are
                    % structures
                    %
                    % struct_vars=[];
                    % for e1=1:length(bb);
                    %     data_class=bb(e1).class;                 
                    %     bb4=strmatch(data_class, 'istruct', 'exact');
                    %     struct_vars=[struct_vars e1];
                    % end                                      
                    % 
                    % Generalizing the program for structures was abandoned
                    % becasue there are many possible configurations when

⌨️ 快捷键说明

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