% Demonstration script for iPeak function. This is a demo script for % ipeak that demonstrates the operation and the typical measurement % errors of ipeak. It generates a test signal consisting of several % Gaussian peaks, adds random noise, runs ipeak, then calculates the % errors between the actual and the measured peak positions, heights, % and widths. Each time you run it you get a different set of peaks. % increment=5; x=[1:increment:4000]; % For each simulated peak, enter the amplitude, position, and width below amp=randn(1,39); % Amplitudes of the peaks (Change if desired) pos=[200:100:4000]; % Positions of the peaks (Change if desired) wid=60.*ones(size(pos)); % Widths of the peaks (Change if desired) Noise=.02; % Amount of random noise added to the signal. (Change if desired) % A = matrix containing one of the unit-amplidude peak in each of its rows A = zeros(length(pos),length(x)); ActualPeaks=[0 0 0 0]; p=1; for k=1:length(pos) if amp(k)>.2, % Keep only those peaks above a certain amplitude % Create a series of Gaussian peaks A(k,:)=exp(-((x-pos(k))./(0.6006.*wid(k))).^2); % Assembles actual parameters into ActualPeaks matrix ActualPeaks(p,:) = [p pos(k) amp(k) wid(k)]; p=p+1; end; end z=amp*A; % Multiplies each row by the corresponding amplitude and adds them up y=z+Noise.*randn(size(z)); % Optionally adds random noise % y=y+gaussian(x,0,4000); % Optionally adds a broad background signal demodata=[x' y']; % Assembles x and y vectors into data matrix % Now call iPeak, with specified values of AmpT, SlopeT, SmoothW, and FitW. % (You can change theses values if desired). MeasuredlPeaks=ipeak(demodata,0,0.1,0.003,5,13); if length(ActualPeaks)==length(MeasuredlPeaks), disp(' Peak # Position Height Width') diff=MeasuredlPeaks-ActualPeaks; PercentErrors=100.*diff./ActualPeaks; PercentErrors(:,1)=MeasuredlPeaks(:,1); PercentErrors=PercentErrors AveragePercentError=mean(abs(PercentErrors)) else disp('Not all peaks in the signal were detected') end