📄 threshold_bin_peaks.m
字号:
function [maix, epts]=threshold_bin_peaks(y3, threshold, bin_size, max_bins, make_plot)
% % Syntax;
% %
% % [maix, epts]=threshold_bin_peaks(y3, maxy2_thresh, rptb, max_bins, make_plot);
% %
% % Description:
% %
% % This program selects the highest peaks from the given data set y3.
% %
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Input Parameters
% %
% % threshold is the threshold that the peaks must be greater than to
% % qualify to be a peak.
% %
% % bin_size is the number of datapoints to put into each bin.
% % The data array is broken up into bins and the maximum value of each
% % bin is selected as a local bin peak.
% %
% % max_bins is the maximum number of bins.
% %
% % make_plot % 0 for no plot
% % % 1 for make the plot
% % % Default is to not make any plots.
% %
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Output Parameters
% %
% % maix is the indices of the intersection of the peaks local peaks and
% % local bin peaks.
% %
% % epts is the indices of the local bin peaks
% %
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Example='';
% y3=randn(10000,1);
% threshold=2;
% bin_size=10;
% max_bins=1000;
% make_plot=1;
%
% [maix, epts]=threshold_bin_peaks(y3, threshold, bin_size, max_bins,...
% make_plot);
% %
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% % Program was written by Edward L. Zechmann
% %
% % date 19 February 2008
% %
% % modified 20 February 2008 Updated comments
% % added the make plot option
% %
% %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Please feel free to modify code.
% %
if nargin < 1
y3=randn(10000,1);
end
if nargin < 2
threshold=2;
end
if nargin < 3
bin_size=10;
end
if nargin < 4
max_bins=1000;
end
if nargin < 5
make_plot=0;
end
[maix, miix]=findextrema(y3);
rmaix=round(maix);
% maix is the interpolated indices of the local maxima
% miix is the interpolated indices of the local minima
% make sure the local maxima are above the threshold
% make sure the local maxima are unique
maix=unique(rmaix(y3(rmaix) >= threshold));
% Break up the signal into bins
% Select a local maxima from each bin
num_pts=length(y3);
num_bins=min([num_pts/bin_size, max_bins]);
bin_size=floor(num_pts/num_bins);
bins=(1:bin_size:num_pts);
epts=zeros((length(bins)-1), 1);
for e3=1:(length(bins)-1);
[buf, eptsix]=max(y3(bins(e3):bins(e3+1)));
epts(e3)=bins(e3)-1+eptsix;
end
% Select the intersection of all the local maxima
% and the local maxima form each bin
maix=intersect(maix, epts);
if isequal(make_plot, 1)
figure(1);
delete(1);
figure(1);
plot(y3);
hold on;
plot(maix, y3(maix), 'linestyle', 'none', 'Marker', 'o', 'MarkerEdgeColor', 'k');
title('Plot of the Peaks', 'Fontsize', 18);
xlabel('Indices of the Data Points', 'Fontsize', 16);
ylabel('Values of the Data Points', 'Fontsize', 16);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -