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

📄 demofindpeakg.m

📁 A fast customizable function for locating and measuring the peaks in noisy time-series signals.
💻 M
字号:
% Graphical demo of findpeaks function, showing fit of each peak.
% Generates a synthetic set of data containing 25 narrow peaks of random
% amplitude.
format compact
figure(1);clf
clear
global amp
global pos
global wid
increment=0.1;
x=[1:increment:400];
% For each simulated peak, enter the amplitude, position, and width below
amp=0.1+rand(1,25);  % Amplitudes of the peaks
pos=[20:15:390];   % Positions of the peaks
pos=pos+2.*randn(size(pos));  % Shift the peaks about randomly so that some of the overlap a bit 
wid=2.*ones(size(pos));   % Widths of the peaks
Noise=.01;
% Construct matrix A containing one of the unit-amplidude peak in each of its srow
A = zeros(length(pos),length(x));
for k=1:length(pos)
  A(k,:)=gaussian(x,pos(k),wid(k)); % Or you can use lorentzian function
end
z=amp*A;  % Multiplies each row by the corresponding amplitude and adds them up
y=z+Noise.*randn(size(z)); % Add random noise
figure(1);plot(x,y,'r')  % Graph the signal in red
title('Press any key to move to next peak')
hold on
SlopeThreshold=0.00000001;
AmpThreshold=.03;
SmoothWidth=mean(wid)./increment;  % SmoothWidth should be roughly equal to the peak widths (in points)
PeakWidth=mean(wid)./increment; % PeakWidth should be roughly equal to the peak widths  (in points)
start=cputime;
P=findpeaksG(x,y,SlopeThreshold,AmpThreshold,SmoothWidth,PeakWidth);
PeaksPerSecond=length(P)/(cputime-start)
'    Peak #   Position    Height    Width'
P  % Display table of peaks
% (Optional) Display table of peak measurement errors
%'    Peak #    SNR      X Error%  Y Error%  WidthError%'
%[P(:,1) amp'./Noise 100.*(P(:,2)-pos')./pos' 100.*(P(:,3)-amp')./amp' 100.*(P(:,4)-wid')./wid']
hold off

⌨️ 快捷键说明

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