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

📄 localpeaks.m

📁 我认为很不错的语音处理的matlab源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
function [SP_local_max2, indices2, SP_peaka, index_peaka, t_SP, gp, threshold_a ]=localpeaks(SP, Fs, num_pts_per_pk_intrl, min_peak, sar, Align_peaks, make_plot, peak_alignment_tol, percent1, exhaust_cycle)      
% % localpeaks: Finds impulsive peaks adn returns the amplitudes and indices 
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% % Syntax:
% % 
% % [SP_local_max2 indices2, SP_peaka, index_peaka]=localpeaks(SP, Fs,...
% % num_pts_per_pk_intrl, min_peak, sar, Align_peaks, make_plot, ...
% % peak_alignment_tol, percent1);
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% % Description
% % 
% % This progam finds the impulsive peaks and determines whether the
% % impulsive peak criteria are satisfied.
% % 
% % The program can handle large data arrays with multiple channels.
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% % Input Variables
% % 
% % SP=randn(4, 100000);  % (Pa) is the Sound pressure data in Pa.  
% %                       % default value is randn(4, 100000).
% % 
% % Fs=100000;      % (Hz) is the sampling rate.  
% %                 % default value is 100000 Hz.  
% % 
% % num_pts_per_pk_intrl=100000;
% %                 % is the number of data points used to characterize
% %                 % each impulsive peak  Usually 1 second to 1/2 a
% %                 % second of data points works well. 
% %                 % 
% %                 % default value is 1 second of data points or the 
% %                 % length of the SP whichever is shorter.  
% % 
% % min_peak=30;    % (Pa) is the lowest ampitude for a peak to be considered
% %                 % impulsive. 
% %                 % The default value is 30.
% % 
% % sar=1;          % is an acronym which stands for 
% %                 % "surpress all requirements"
% %                 % sar=1; allows all detected impulses to be analyzed.
% %                 % othwerwise only the impulses with a peak pressure 
% %                 % above the min_peak will be analyzed.  
% %                 % 
% %                 % The default value is 0.
% % 
% % Align_peaks=1;  % is the channel number for the impulsive peaks to be
% %                 % aligned to.  default value is [];
% %                 % Align_peaks=1;  peaks are aligned to channel 1.  
% %                 % Align_peaks=[]; peaks are not aligned.  
% %                 % 
% %                 % If Align_peaks > num_channels then 
% %                 % Align_peaks is set to [];
% %                 % 
% %                 % If Align_peaks < num_channels then 
% %                 % Align_peaks is set to [];
% %                 % The default value is [];
% % 
% % make_plot=1;    % 1 Plots the processing data of the peaks.  
% %                 % Otherwise no plots are made. 
% %                 % 
% %                 % default is make_plot=0;  
% % 
% % peak_alignment_tol=0.25; 
% %                 % This input sets the fraction of the datapoints 
% %                 % of num_pts_per_pk_intrl that a peak can be offset. 
% %                 % When aligning peaks, the channels are 
% %                 % synchronized, but temorally the peaks may be  
% %                 % misaligned by a few milliseconds.  The 
% %                 % alignment tolerance allows the program to find 
% %                 % the maximum peak within the alignment 
% %                 % tolerance. 
% %                 % 
% %                 % default is peak_alignment_tol=0.25; 
% %
% %
% %                 % Further explanation of peak_alignment_tol
% %
% %                 % One-half of the datapoints of num_pts_per_pk_intrl are 
% %                 % used for finding the index of the maximum sound 
% %                 % pressure amplitude.    
% %             
% %                 % The impulsive peak is found by selecting the highest 
% %                 % sound pressure amplitude starting at the center of 
% %                 % the bin and working toward the maximum radius which 
% %                 % is one-half of teh data points for the impulse.  
% % 
% % 
% % percent1=[];        % Is the percentage of the peak levels of the  
% %                     % time record after signal processing to remove
% %                     % continuous noise and sharpen the peak levels.
% %                     % The default is percent1=[];    
% %                     % 
% %                     % If percent1 is empty, < 0, or > 100 then 
% %                     % it is set to [] and not considered during
% %                     % processing;   
% %                     % 
% %                     % percent1=75; is a typical value
% % 
% % exhaust_cycle=0;    % 1 use the threshold method approppriate for 
% %                     % finding exhaust noise type impulses.   
% %                     % 
% %                     % Otherwise the method for impact type impulsive
% %                     % noises is used.
% %                     % 
% %                     % The default value is exhaust_cycle=0;
% % 
% %                     
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% % Output Variables
% %
% % SP_local_max2 is a cell array of peak pressures in Pa for each
% % impulsive peak and for each channel
% %
% % indices2 is the cell arrray of indices for each impulsive peak and for
% % each channel
% % 
% % SP_peaka is the cell array of the peak amplitudes that are greater 
% %     than the threshold and before implementing the min_peak and other 
% %     selection criterion.
% % 
% % index_peaka is the cell array of the indices corresponding to 
% %      SP_peaka. 
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
%
% Example
%
% Fs=100000; fc=1000; td=1; tau=0.01; delay=0.1; A1=5; A2=20;
% [SP, t]=analytic_impulse(Fs, fc, td, tau, delay, A1, A2);
%                   % Pa sound pressure time record
%                   
% Fs=100000;        % Hz sampling rate
% 
% num_pts_per_pk_intrl=50000;    % number of data points used to characterize
%                           % the impulsive peak usually 1 second to 1/2 a
%                           % second of data points works well
% 
% min_peak=30;              % is the peak value in Pa that is the minimum
%                           % for being considered an impulsive noise.
% 
% sar=1;                    % will suspend the requiremnts for being a peak
%                           % and force the program to find at least one
%                           % peak.  The program can crash if it does
%                           % not find a peak.  This has rarely been a
%                           % problem.
%                           
% Align_peaks=1;            % Specify the channel number to align peaks to
%                           % For the subordinate channels, the highest 
%                           % peak within a radius of 0.25*num_pts_per_pk_intrl
%                           % data points of the impulsive peak of the 
%                           % align_peaks channel is selected. 
%
% make_plot=1;              % 1 for make the plot
%                           % 0 for no plot
%                           % Default is to not make any plots.
%  
% [SP_local_max2 indices2]=localpeaks(SP, Fs, num_pts_per_pk_intrl, min_peak, sar, Align_peaks, make_plot);
% 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% % 
% % List of Dependent Subprograms for 
% % localpeaks
% % 
% % FEX ID# is the File ID on the Matlab Central File Exchange
% % 
% % Program Name   Author   FEX ID#
% %  1) allstats		Duane Hanselman		NA	
% %  2) calc_impuls_threshold_and_index		
% %  3) convert_double		
% %  4) fix_YTick		
% %  5) func_threshold		Jing Tian		10462	
% %  6) hilbert2		
% %  7) kurtosis2		
% %  8) parseArgs		Malcolm Wood		10670	
% %  9) peak_index		
% % 10) peak_threshhold_function		
% % 11) percentiles		
% % 12) psuedo_box		
% % 13) resample_plot		
% % 14) sub_mean		
% % 15) subaxis		Aslak Grinsted		3696	
% % 16) wsmooth		Damien Garcia	
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % localpeaks is written by Edward L. Zechmann
% % 
% %      date 10 August     2007
% % 
% %  modified 18 December   2007   Improved signal processing methods
% %                                Improved the empty array handling
% %                                Added align peaks
% %                                Added analytic_impulse example
% % 
% %  modified 21 December   2007   Improved plotting the peak threshold 
% %                                function
% %                                Improved the zero crossing and slope 
% %                                calculation for removing peaks at teh end
% %                                of the file
% %                                Added more comments
% % 
% %  modified 27 December   2007   Changed the process of grouping peaks 
% %                                from marchinig in time to selecting the 
% %                                highest peak to the lowest peak
% %                                Fixed pts_per_bin to number of points   
% %                                in 0.01 seconds
% %                     
% %  modified 20 February   2008   Updated comments
% %                              
% % 
% %  modified 26 February   2008   Changed the peak_index for the align 
% %                                peaks to use a radius of 
% %                                0.25*num_pts_per_pk_intrl data points.  
% %                                Now the peak circles of the protected 
% %                                signals are located at the peaks.    
% % 
% %  modified 27 February   2008   Made the threshold limit for finding
% %                                a peak vary with time.  
% %  
% %  modified 11 March      2008   The process of selecting detecting 
% %                                impulsive peaks was greatly improved.  
% % 
% %  modified 12 March      2008    Updated Comments
% %                     
% %  modified 21 March      2008    Updated Comments
% %                     
% %  modified 24 March      2008    Added radius option for
% %                                 selecting the size of the range
% %                                 of data points to find the peak 
% %                                 sound pressure amplitude.  
% % 
% %  modified 22 July       2008    Modified Method of finding
% %                                 peaks now uses percentiles.
% %  
% %  modified 19 August     2008    Added input variable percent1 
% %                                 to specify threshold for 
% %                                 identifying peaks
% %  
% %  modified 10 September  2008    Added optional method for finding 
% %                                 impulsive Exhaust Noise 
% %  
% %  modified 11 November   2008    Fixed a bug with the exhaust noise
% %                                 feature and with bin size.  
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Please feel free to modify this code.
% % 
% % See Also: Impulsive_Noise_Meter, snd_peak_metrics, plot_peaks
% % 
 

if nargin < 1 || isempty(SP) || ~isnumeric(SP)
    SP=randn(4, 100000);
end

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

% Make sure the data has the channels and data array in the
% correct order, transpose if necessary.
[m1 n1]=size(SP);

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

if nargin < 2 || isempty(Fs) || ~isnumeric(Fs)
    Fs=100000;
end

[Fs]=convert_double(Fs);

% number of points in each peak interval
if nargin < 3 || isempty(num_pts_per_pk_intrl) || ~isnumeric(num_pts_per_pk_intrl)
    n1=length(SP);
    if Fs < n1
        num_pts_per_pk_intrl=Fs;
    else
        num_pts_per_pk_intrl=n1;
    end
end

% minimum peak preessure to be an impulsive noise
if nargin < 4 || isempty(min_peak) || ~isnumeric(min_peak)
    min_peak=30;
end

% sar is suspend absolute peak requirement
% a value of zero will not supress any requirements
if nargin < 5 || isempty(sar) || ~isnumeric(sar)
    sar=0;
end

% minimum peak preessure to be an impulsive noise
if nargin < 6 || isempty(Align_peaks) || ~isnumeric(Align_peaks)
    Align_peaks=[];
end

if ~isempty(Align_peaks)
    Align_peaks=round(Align_peaks);

    if Align_peaks < 1
        Align_peaks=[];
    end

    if Align_peaks > m1
        Align_peaks=[];
    end
end

% make a plot of the bin selection criterion
if nargin < 7 || isempty(make_plot) || ~isnumeric(make_plot)
    make_plot=0;
end
    
% set the peak alignment tolerance
if nargin < 8 || isempty(peak_alignment_tol) || ~isnumeric(peak_alignment_tol)
    peak_alignment_tol=0.25;
end

% set the percentile for finding impulsive peaks
if (nargin < 9 || isempty(percent1)) || ((~isnumeric(percent1) || logical(percent1 > 100)) || logical(percent1 <= 0))
    percent1=[];
end

if nargin < 10 || isempty(exhaust_cycle) || ~isnumeric(exhaust_cycle)
    exhaust_cycle=0;
end

sh=0.0;
sv=0.0;
ml=0.14;
mr=0.1;
mt=0.08;
mb=0.12;


% pts_per_bin is the number of points in the sub bins for speedings up 
% the process of analyzing the data array.  
% The pts_per_bin is the number of pts in 0.01 seconds  
pts_per_bin=floor(Fs/100);

⌨️ 快捷键说明

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